00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_SARRAY_H__
00020 #define __CS_SARRAY_H__
00021
00022 #ifndef COMP_VC
00023 # warning csStaticArray is DEPRECATED. Use csGrowingArray instead
00024 #endif
00025
00034 #define CS_DECLARE_STATIC_ARRAY(Name,Type) \
00035 CS_PRIVATE_DECLARE_STATIC_ARRAY (Name, Type)
00036
00037
00038
00039
00040
00042 class csStaticArray
00043 {
00044 protected:
00045 void *Map;
00046 int Size;
00047
00052 void Copy (const csStaticArray *other, bool DeleteOld = true);
00057 void Copy (void *NewData, int NewSize, bool DeleteOld = true);
00063 inline void TakeOver (csStaticArray *other, bool DeleteOld = true);
00068 inline void TakeOver (void *NewData, int NewSize, bool DeleteOld = true);
00069
00071 virtual void *AllocateArray (int Size) const = 0;
00073 virtual void DeleteArray (void *Array) const = 0;
00075 virtual void CopyArray (void *Dest, void *src, int Count) const = 0;
00076
00077 public:
00079 csStaticArray (int Size = 0);
00081 virtual ~csStaticArray ();
00082
00084 inline int GetSize () const;
00089 void Clear (bool DeleteOld = true);
00094 void Alloc (int s, bool DeleteOld = true);
00098 void ReAlloc (int s);
00099 };
00100
00101 #define CS_PRIVATE_DECLARE_STATIC_ARRAY(Name,Type) \
00102 class Name : public csStaticArray \
00103 { \
00104 typedef Type cont_type; \
00105 private: \
00106 void *AllocateArray (int n) const {return new cont_type[n];} \
00107 void DeleteArray (void *a) const {delete[] ((cont_type*)a);} \
00108 void CopyArray (void *Dest, void *Src, int n) const \
00109 {memcpy (Dest, Src, n*sizeof (cont_type)); } \
00110 public: \
00111 inline Name (int Size = 0) : \
00112 csStaticArray (Size) {} \
00113 virtual ~Name () \
00114 { Clear (); } \
00115 inline cont_type *GetArray () \
00116 { return (cont_type*)Map; } \
00117 inline const cont_type *GetArray () const \
00118 { return (cont_type*)Map; } \
00119 inline void Copy (cont_type *NewData, int NewSize, bool DeleteOld = true) \
00120 { csStaticArray::Copy (NewData, NewSize, DeleteOld); } \
00121 inline void Copy (const Name *other, bool DeleteOld = true) \
00122 { csStaticArray::Copy (other, DeleteOld); } \
00123 inline void TakeOver (cont_type *NewData, int NewSize, bool DeleteOld = true) \
00124 { csStaticArray::TakeOver (NewData, NewSize, DeleteOld); } \
00125 inline void TakeOver (Name *other, bool DeleteOld = true) \
00126 { csStaticArray::TakeOver (other, DeleteOld); } \
00127 inline cont_type &operator[] (int n) \
00128 { return GetArray () [n]; } \
00129 inline const cont_type &operator[] (int n) const \
00130 { return GetArray () [n]; } \
00131 }
00132
00133 inline int csStaticArray::GetSize () const
00134 {
00135 return Size;
00136 }
00137 inline void csStaticArray::TakeOver (csStaticArray *other, bool DeleteOld)
00138 {
00139 TakeOver (other->Map, other->Size, DeleteOld);
00140 other->Map = NULL;
00141 other->Size = 0;
00142 }
00143 inline void csStaticArray::TakeOver (void *NewData, int NewSize, bool DeleteOld)
00144 {
00145 if (DeleteOld) Clear ();
00146 Map = NewData;
00147 Size = NewSize;
00148 }
00149
00150 #endif // __CS_SARRAY_H__