00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __SARRAY_H__
00020 #define __SARRAY_H__
00021
00026 #define CS_DECLARE_STATIC_ARRAY(Name,Type) \
00027 CS_PRIVATE_DECLARE_STATIC_ARRAY (Name, Type)
00028
00029
00030
00031
00032
00033 class csStaticArray
00034 {
00035 protected:
00036 void *Map;
00037 int Size;
00038
00039
00040
00041
00042
00043 void Copy (const csStaticArray *other, bool DeleteOld = true);
00044
00045
00046
00047
00048 void Copy (void *NewData, int NewSize, bool DeleteOld = true);
00049
00050
00051
00052
00053
00054 inline void TakeOver (csStaticArray *other, bool DeleteOld = true);
00055
00056
00057
00058
00059 inline void TakeOver (void *NewData, int NewSize, bool DeleteOld = true);
00060
00061
00062 virtual void *AllocateArray (int Size) const = 0;
00063
00064 virtual void DeleteArray (void *Array) const = 0;
00065
00066 virtual void CopyArray (void *Dest, void *src, int Count) const = 0;
00067
00068 public:
00069
00070 csStaticArray (int Size = 0);
00071
00072 virtual ~csStaticArray ();
00073
00074
00075 inline int GetSize () const;
00076
00077
00078
00079
00080 void Clear (bool DeleteOld = true);
00081
00082
00083
00084
00085 void Alloc (int s, bool DeleteOld = true);
00086
00087
00088
00089 void ReAlloc (int s);
00090 };
00091
00092 #define CS_PRIVATE_DECLARE_STATIC_ARRAY(Name,Type) \
00093 class Name : public csStaticArray \
00094 { \
00095 typedef Type cont_type; \
00096 private: \
00097 void *AllocateArray (int n) const {return new cont_type[n];} \
00098 void DeleteArray (void *a) const {delete[] ((cont_type*)a);} \
00099 void CopyArray (void *Dest, void *Src, int n) const \
00100 {memcpy (Dest, Src, n*sizeof (cont_type)); } \
00101 public: \
00102 inline Name (int Size = 0) : \
00103 csStaticArray (Size) {} \
00104 virtual ~Name () \
00105 { Clear (); } \
00106 inline cont_type *GetArray () \
00107 { return (cont_type*)Map; } \
00108 inline const cont_type *GetArray () const \
00109 { return (cont_type*)Map; } \
00110 inline void Copy (cont_type *NewData, int NewSize, bool DeleteOld = true) \
00111 { csStaticArray::Copy (NewData, NewSize, DeleteOld); } \
00112 inline void Copy (const Name *other, bool DeleteOld = true) \
00113 { csStaticArray::Copy (other, DeleteOld); } \
00114 inline void TakeOver (cont_type *NewData, int NewSize, bool DeleteOld = true) \
00115 { csStaticArray::TakeOver (NewData, NewSize, DeleteOld); } \
00116 inline void TakeOver (Name *other, bool DeleteOld = true) \
00117 { csStaticArray::TakeOver (other, DeleteOld); } \
00118 inline cont_type &operator[] (int n) \
00119 { return GetArray () [n]; } \
00120 inline const cont_type &operator[] (int n) const \
00121 { return GetArray () [n]; } \
00122 }
00123
00124 inline int csStaticArray::GetSize () const
00125 {
00126 return Size;
00127 }
00128 inline void csStaticArray::TakeOver (csStaticArray *other, bool DeleteOld)
00129 {
00130 TakeOver (other->Map, other->Size, DeleteOld);
00131 other->Map = NULL;
00132 other->Size = 0;
00133 }
00134 inline void csStaticArray::TakeOver (void *NewData, int NewSize, bool DeleteOld)
00135 {
00136 if (DeleteOld) Clear ();
00137 Map = NewData;
00138 Size = NewSize;
00139 }
00140
00141 #endif // __SARRAY_H__