aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/MyBuffer.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Common/MyBuffer.h49
1 files changed, 29 insertions, 20 deletions
diff --git a/CPP/Common/MyBuffer.h b/CPP/Common/MyBuffer.h
index 18ab6fa..bc829f4 100644
--- a/CPP/Common/MyBuffer.h
+++ b/CPP/Common/MyBuffer.h
@@ -1,13 +1,15 @@
1// Common/MyBuffer.h 1// Common/MyBuffer.h
2 2
3#ifndef __COMMON_MY_BUFFER_H 3#ifndef ZIP7_INC_COMMON_MY_BUFFER_H
4#define __COMMON_MY_BUFFER_H 4#define ZIP7_INC_COMMON_MY_BUFFER_H
5
6#include <string.h>
5 7
6#include "Defs.h" 8#include "Defs.h"
7#include "MyTypes.h" 9#include "MyTypes.h"
8 10
9/* 7-Zip now uses CBuffer only as CByteBuffer. 11/* 7-Zip now uses CBuffer only as CByteBuffer.
10 So there is no need to use MY_ARRAY_NEW macro in CBuffer code. */ 12 So there is no need to use Z7_ARRAY_NEW macro in CBuffer code. */
11 13
12template <class T> class CBuffer 14template <class T> class CBuffer
13{ 15{
@@ -20,16 +22,23 @@ public:
20 if (_items) 22 if (_items)
21 { 23 {
22 delete []_items; 24 delete []_items;
23 _items = 0; 25 _items = NULL;
24 } 26 }
25 _size = 0; 27 _size = 0;
26 } 28 }
27 29
28 CBuffer(): _items(0), _size(0) {}; 30 CBuffer(): _items(NULL), _size(0) {}
29 CBuffer(size_t size): _items(0), _size(0) { _items = new T[size]; _size = size; } 31 CBuffer(size_t size): _items(NULL), _size(0)
30 CBuffer(const CBuffer &buffer): _items(0), _size(0) 32 {
33 if (size != 0)
34 {
35 _items = new T[size];
36 _size = size;
37 }
38 }
39 CBuffer(const CBuffer &buffer): _items(NULL), _size(0)
31 { 40 {
32 size_t size = buffer._size; 41 const size_t size = buffer._size;
33 if (size != 0) 42 if (size != 0)
34 { 43 {
35 _items = new T[size]; 44 _items = new T[size];
@@ -136,7 +145,7 @@ typedef CBuffer<unsigned char> CByteBuffer;
136 145
137class CByteBuffer_Wipe: public CByteBuffer 146class CByteBuffer_Wipe: public CByteBuffer
138{ 147{
139 CLASS_NO_COPY(CByteBuffer_Wipe) 148 Z7_CLASS_NO_COPY(CByteBuffer_Wipe)
140public: 149public:
141 // CByteBuffer_Wipe(): CBuffer<unsigned char>() {} 150 // CByteBuffer_Wipe(): CBuffer<unsigned char>() {}
142 CByteBuffer_Wipe(size_t size): CBuffer<unsigned char>(size) {} 151 CByteBuffer_Wipe(size_t size): CBuffer<unsigned char>(size) {}
@@ -157,17 +166,17 @@ public:
157 void Free() 166 void Free()
158 { 167 {
159 delete []_items; 168 delete []_items;
160 _items = 0; 169 _items = NULL;
161 } 170 }
162 CObjArray(size_t size): _items(0) 171 CObjArray(size_t size): _items(NULL)
163 { 172 {
164 if (size != 0) 173 if (size != 0)
165 { 174 {
166 MY_ARRAY_NEW(_items, T, size) 175 Z7_ARRAY_NEW(_items, T, size)
167 // _items = new T[size]; 176 // _items = new T[size];
168 } 177 }
169 } 178 }
170 CObjArray(): _items(0) {}; 179 CObjArray(): _items(NULL) {}
171 ~CObjArray() { delete []_items; } 180 ~CObjArray() { delete []_items; }
172 181
173 operator T *() { return _items; } 182 operator T *() { return _items; }
@@ -176,8 +185,8 @@ public:
176 void Alloc(size_t newSize) 185 void Alloc(size_t newSize)
177 { 186 {
178 delete []_items; 187 delete []_items;
179 _items = 0; 188 _items = NULL;
180 MY_ARRAY_NEW(_items, T, newSize) 189 Z7_ARRAY_NEW(_items, T, newSize)
181 // _items = new T[newSize]; 190 // _items = new T[newSize];
182 } 191 }
183}; 192};
@@ -201,12 +210,12 @@ public:
201 void Free() 210 void Free()
202 { 211 {
203 delete []_items; 212 delete []_items;
204 _items = 0; 213 _items = NULL;
205 _size = 0; 214 _size = 0;
206 } 215 }
207 CObjArray2(): _items(0), _size(0) {}; 216 CObjArray2(): _items(NULL), _size(0) {}
208 /* 217 /*
209 CObjArray2(const CObjArray2 &buffer): _items(0), _size(0) 218 CObjArray2(const CObjArray2 &buffer): _items(NULL), _size(0)
210 { 219 {
211 size_t newSize = buffer._size; 220 size_t newSize = buffer._size;
212 if (newSize != 0) 221 if (newSize != 0)
@@ -221,7 +230,7 @@ public:
221 } 230 }
222 */ 231 */
223 /* 232 /*
224 CObjArray2(size_t size): _items(0), _size(0) 233 CObjArray2(size_t size): _items(NULL), _size(0)
225 { 234 {
226 if (size != 0) 235 if (size != 0)
227 { 236 {
@@ -247,7 +256,7 @@ public:
247 T *newBuffer = NULL; 256 T *newBuffer = NULL;
248 if (size != 0) 257 if (size != 0)
249 { 258 {
250 MY_ARRAY_NEW(newBuffer, T, size) 259 Z7_ARRAY_NEW(newBuffer, T, size)
251 // newBuffer = new T[size]; 260 // newBuffer = new T[size];
252 } 261 }
253 delete []_items; 262 delete []_items;