aboutsummaryrefslogtreecommitdiff
path: root/CPP/Common/MyVector.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/Common/MyVector.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/CPP/Common/MyVector.h b/CPP/Common/MyVector.h
index 3417a17..9ee7105 100644
--- a/CPP/Common/MyVector.h
+++ b/CPP/Common/MyVector.h
@@ -1,10 +1,12 @@
1// Common/MyVector.h 1// Common/MyVector.h
2 2
3#ifndef __COMMON_MY_VECTOR_H 3#ifndef ZIP7_INC_COMMON_MY_VECTOR_H
4#define __COMMON_MY_VECTOR_H 4#define ZIP7_INC_COMMON_MY_VECTOR_H
5 5
6#include <string.h> 6#include <string.h>
7 7
8#include "Common.h"
9
8const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1; 10const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1;
9 11
10template <class T> 12template <class T>
@@ -22,7 +24,7 @@ class CRecordVector
22 void ReAllocForNewCapacity(const unsigned newCapacity) 24 void ReAllocForNewCapacity(const unsigned newCapacity)
23 { 25 {
24 T *p; 26 T *p;
25 MY_ARRAY_NEW(p, T, newCapacity); 27 Z7_ARRAY_NEW(p, T, newCapacity)
26 // p = new T[newCapacity]; 28 // p = new T[newCapacity];
27 if (_size != 0) 29 if (_size != 0)
28 memcpy(p, _items, (size_t)_size * sizeof(T)); 30 memcpy(p, _items, (size_t)_size * sizeof(T));
@@ -53,7 +55,7 @@ public:
53 const unsigned size = v.Size(); 55 const unsigned size = v.Size();
54 if (size != 0) 56 if (size != 0)
55 { 57 {
56 // MY_ARRAY_NEW(_items, T, size) 58 // Z7_ARRAY_NEW(_items, T, size)
57 _items = new T[size]; 59 _items = new T[size];
58 _size = size; 60 _size = size;
59 _capacity = size; 61 _capacity = size;
@@ -68,7 +70,7 @@ public:
68 { 70 {
69 if (size != 0) 71 if (size != 0)
70 { 72 {
71 MY_ARRAY_NEW(_items, T, size) 73 Z7_ARRAY_NEW(_items, T, size)
72 // _items = new T[size]; 74 // _items = new T[size];
73 _capacity = size; 75 _capacity = size;
74 } 76 }
@@ -100,7 +102,7 @@ public:
100 delete []_items; 102 delete []_items;
101 _items = NULL; 103 _items = NULL;
102 _capacity = 0; 104 _capacity = 0;
103 MY_ARRAY_NEW(_items, T, newCapacity) 105 Z7_ARRAY_NEW(_items, T, newCapacity)
104 // _items = new T[newCapacity]; 106 // _items = new T[newCapacity];
105 _capacity = newCapacity; 107 _capacity = newCapacity;
106 } 108 }
@@ -119,7 +121,7 @@ public:
119 T *p = NULL; 121 T *p = NULL;
120 if (_size != 0) 122 if (_size != 0)
121 { 123 {
122 // MY_ARRAY_NEW(p, T, _size) 124 // Z7_ARRAY_NEW(p, T, _size)
123 p = new T[_size]; 125 p = new T[_size];
124 memcpy(p, _items, (size_t)_size * sizeof(T)); 126 memcpy(p, _items, (size_t)_size * sizeof(T));
125 } 127 }
@@ -264,6 +266,8 @@ public:
264 266
265 const T& operator[](unsigned index) const { return _items[index]; } 267 const T& operator[](unsigned index) const { return _items[index]; }
266 T& operator[](unsigned index) { return _items[index]; } 268 T& operator[](unsigned index) { return _items[index]; }
269 const T& operator[](int index) const { return _items[(unsigned)index]; }
270 T& operator[](int index) { return _items[(unsigned)index]; }
267 const T& Front() const { return _items[0]; } 271 const T& Front() const { return _items[0]; }
268 T& Front() { return _items[0]; } 272 T& Front() { return _items[0]; }
269 const T& Back() const { return _items[(size_t)_size - 1]; } 273 const T& Back() const { return _items[(size_t)_size - 1]; }
@@ -497,6 +501,8 @@ public:
497 501
498 const T& operator[](unsigned index) const { return *((T *)_v[index]); } 502 const T& operator[](unsigned index) const { return *((T *)_v[index]); }
499 T& operator[](unsigned index) { return *((T *)_v[index]); } 503 T& operator[](unsigned index) { return *((T *)_v[index]); }
504 const T& operator[](int index) const { return *((T *)_v[(unsigned)index]); }
505 T& operator[](int index) { return *((T *)_v[(unsigned)index]); }
500 const T& Front() const { return operator[](0); } 506 const T& Front() const { return operator[](0); }
501 T& Front() { return operator[](0); } 507 T& Front() { return operator[](0); }
502 const T& Back() const { return *(T *)_v.Back(); } 508 const T& Back() const { return *(T *)_v.Back(); }
@@ -604,6 +610,7 @@ public:
604 delete (T *)_v[index]; 610 delete (T *)_v[index];
605 _v.Delete(index); 611 _v.Delete(index);
606 } 612 }
613 // void Delete(int index) { Delete((unsigned)index); }
607 614
608 /* 615 /*
609 void Delete(unsigned index, unsigned num) 616 void Delete(unsigned index, unsigned num)