1 /* 2 * Copyright 2013, Gerasim Troeglazov, 3dEyes@gmail.com. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #ifndef PSD_DATA_ARRAY_H 8 #define PSD_DATA_ARRAY_H 9 10 #include <stdlib.h> 11 #include <stdio.h> 12 #include <string.h> 13 14 #include <String.h> 15 #include <DataIO.h> 16 #include <File.h> 17 #include <ByteOrder.h> 18 19 #define DATAARRAY_BLOCK_SIZE 1024 20 21 class BDataArray { 22 public: 23 BDataArray(int32 blockSize = DATAARRAY_BLOCK_SIZE); 24 ~BDataArray(); 25 26 BDataArray& Append(int8 val); 27 BDataArray& Append(uint8 val); 28 BDataArray& Append(int16 val); 29 BDataArray& Append(uint16 val); 30 BDataArray& Append(int32 val); 31 BDataArray& Append(uint32 val); 32 BDataArray& Append(int64 val); 33 BDataArray& Append(uint64 val); 34 BDataArray& Append(const char *str); 35 BDataArray& Append(BString& str); 36 BDataArray& Append(BDataArray& str); 37 BDataArray& Append(uint8 *ptr, int32 len); 38 39 BDataArray& Repeat(uint8 byte, int32 count); 40 41 BDataArray& operator<<(int8); 42 BDataArray& operator<<(uint8); 43 BDataArray& operator<<(int16); 44 BDataArray& operator<<(uint16); 45 BDataArray& operator<<(int32); 46 BDataArray& operator<<(uint32); 47 BDataArray& operator<<(int64); 48 BDataArray& operator<<(uint64); 49 BDataArray& operator<<(const char*); 50 BDataArray& operator<<(BDataArray&); 51 52 uint8 *Buffer(void); 53 int32 Length(void); 54 55 ssize_t WriteToStream(BPositionIO *stream); 56 57 private: 58 inline status_t _ReallocArrayFor(int32 size); 59 60 uint8 *fData; 61 int32 fDataSize; 62 int32 fAllocatedDataSize; 63 int32 fBlockSize; 64 }; 65 66 67 #endif /* PSD_DATA_ARRAY_H */ 68