diff options
Diffstat (limited to 'CPP/Common/MyBuffer.h')
| -rw-r--r-- | CPP/Common/MyBuffer.h | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/CPP/Common/MyBuffer.h b/CPP/Common/MyBuffer.h index 80f0205..08c10a3 100644 --- a/CPP/Common/MyBuffer.h +++ b/CPP/Common/MyBuffer.h | |||
| @@ -202,7 +202,53 @@ public: | |||
| 202 | } | 202 | } |
| 203 | }; | 203 | }; |
| 204 | 204 | ||
| 205 | typedef CObjArray<Byte> CByteArr; | 205 | |
| 206 | /* CSmallObjArray can be used for Byte arrays | ||
| 207 | or for arrays whose total size in bytes does not exceed size_t ranges. | ||
| 208 | So there is no need to use Z7_ARRAY_NEW macro in CSmallObjArray code. */ | ||
| 209 | template <class T> class CSmallObjArray | ||
| 210 | { | ||
| 211 | protected: | ||
| 212 | T *_items; | ||
| 213 | private: | ||
| 214 | // we disable copy | ||
| 215 | CSmallObjArray(const CSmallObjArray &buffer); | ||
| 216 | void operator=(const CSmallObjArray &buffer); | ||
| 217 | public: | ||
| 218 | void Free() | ||
| 219 | { | ||
| 220 | delete []_items; | ||
| 221 | _items = NULL; | ||
| 222 | } | ||
| 223 | CSmallObjArray(size_t size): _items(NULL) | ||
| 224 | { | ||
| 225 | if (size != 0) | ||
| 226 | { | ||
| 227 | // Z7_ARRAY_NEW(_items, T, size) | ||
| 228 | _items = new T[size]; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | CSmallObjArray(): _items(NULL) {} | ||
| 232 | ~CSmallObjArray() { delete []_items; } | ||
| 233 | |||
| 234 | operator T *() { return _items; } | ||
| 235 | operator const T *() const { return _items; } | ||
| 236 | const T* ConstData() const { return _items; } | ||
| 237 | T* NonConstData() const { return _items; } | ||
| 238 | T* NonConstData() { return _items; } | ||
| 239 | // const T* Data() const { return _items; } | ||
| 240 | // T* Data() { return _items; } | ||
| 241 | |||
| 242 | void Alloc(size_t newSize) | ||
| 243 | { | ||
| 244 | delete []_items; | ||
| 245 | _items = NULL; | ||
| 246 | // Z7_ARRAY_NEW(_items, T, newSize) | ||
| 247 | _items = new T[newSize]; | ||
| 248 | } | ||
| 249 | }; | ||
| 250 | |||
| 251 | typedef CSmallObjArray<Byte> CByteArr; | ||
| 206 | typedef CObjArray<bool> CBoolArr; | 252 | typedef CObjArray<bool> CBoolArr; |
| 207 | typedef CObjArray<int> CIntArr; | 253 | typedef CObjArray<int> CIntArr; |
| 208 | typedef CObjArray<unsigned> CUIntArr; | 254 | typedef CObjArray<unsigned> CUIntArr; |
