00001
00002
00003
00004 #ifndef DYNARR_HPP
00005 #define DYNARR_HPP
00006
00007
00008
00009 #include "pi/int64.h"
00010
00011 template<class T>
00012 class DynArrI;
00013
00014 typedef DynArrI<char> DynArrChar;
00015 typedef DynArrI<wchar_t> DynArrWCharT;
00016 typedef DynArrI<short> DynArrShort;
00017 typedef DynArrI<int> DynArrInt;
00018 typedef DynArrI<int64> DynArrInt64;
00019 typedef DynArrI<void*> DynArrPtr;
00020 typedef DynArrI<VObj*> DynArrPtrVObj;
00021 typedef DynArrI<DynI*> DynArrPtrDynI;
00022
00023 template<>
00024 class doTypeInfo<DynArrI<wchar_t> >{
00025 public:
00026 static int Id( ){ return DYNARRWCHART_TYPE_ID; }
00027 static const char* Name( ){ return "DynArrWCharT"; }
00028 };
00029
00030
00031
00032
00033 template<class T>
00034 class doTypeInfo<DynArrI<T*> >{
00035 public:
00036 static int Id( ){ return DYNARRPTR_TYPE_ID; }
00037 static const char* Name( ){ return "DynArrPtr"; }
00038 };
00039
00040
00041 template<>
00042 class doTypeInfo<DynArrI<VObj*> >{
00043 public:
00044 static int Id( ){ return DYNARRPTRVOBJ_TYPE_ID; }
00045 static const char* Name( ){ return "DynArrPtrVObj"; }
00046 };
00047
00048
00049 template<>
00050 class doTypeInfo<DynArrI<DynI*> >{
00051 public:
00052 static int Id( ){ return DYNARRPTRDYNI_TYPE_ID; }
00053 static const char* Name( ){ return "DynArrPtrDynI"; }
00054 };
00055
00056
00057 template<class T>
00058 class doTypeInfo<DynArrI<T> >{
00059 public:
00060 static int Id( ){
00061 switch(sizeof(T)){
00062 case 1: return DYNARRCHAR_TYPE_ID;
00063 case 2: return DYNARRSHORT_TYPE_ID;
00064 case 4: return DYNARRINT_TYPE_ID;
00065 case 8: return DYNARRINT64_TYPE_ID;
00066 default: return INVALID_TYPE_ID;
00067 }
00068 }
00069 static const char* Name( ){
00070 switch(sizeof(T)){
00071 case 1: return "DynArrChar";
00072 case 2: return "DynArrShort";
00073 case 4: return "DynArrInt";
00074 case 8: return "DynArrInt64";
00075 default: return NULL;
00076 }
00077 }
00078 };
00079
00080
00081 #include "utils/ArrBase.hpp"
00082
00083 #define DA_AT_END ((int)0x80000000)
00084
00085
00086
00087 template<class T>
00088 class DynArrI : public DynObj {
00089 public:
00090 virtual DynObjType* docall doGetType( const DynI **pself ) const;
00091
00092
00093 virtual const ArrBase<T,int>& docall GetArrBase( ) const = 0;
00094 virtual T& docall ElemRef( int ix ) = 0;
00095
00096 virtual DynArrI& docall Push( T t ) = 0;
00097 virtual T docall Pop( ) = 0;
00098 virtual T& docall Top( ) = 0;
00099
00100 virtual DynArrI& docall Empty( ) = 0;
00101 virtual bool docall MakeSpaceAt( int at_ix, int n_space=1 ) = 0;
00102 virtual DynArrI& docall OverWrite( const T* pt, int cnt, int at_ix ) = 0;
00103
00104 virtual T& docall GetNullElem() const {
00105 static T t;
00106 return t;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 T* Base( ) const { return GetArrBase().Base(); }
00117 int Size( ) const { return GetArrBase().Size(); }
00118 T& operator [] (int ix){ return ElemRef(ix); }
00119 T ElemSafe( int ix ) const {
00120 ArrBase<T,int> &ab = GetArrBase();
00121 if( ix<0 || ix>=ab.Size() ) return GetNullElem();
00122 return ab.Base()[ix];
00123 }
00124
00125
00126 DynArrI& InsertOrdered( const T& elem, int ix ){
00127 MakeSpaceAt( ix,1 );
00128 GetArrBase().Base()[ix] = elem;
00129 return *this;
00130 }
00131
00132
00133 DynArrI& Insert( const T* pt, int cnt, int at_ix=DA_AT_END ){
00134 if( at_ix==DA_AT_END ) at_ix=this->Size();
00135 if( !MakeSpaceAt(at_ix,cnt) ) return *this;
00136 return OverWrite( pt, cnt, at_ix );
00137 }
00138 };
00139
00140 typedef DynArrI<char> DynArrChar;
00141 typedef DynArrI<wchar_t> DynArrWCharT;
00142 typedef DynArrI<short> DynArrShort;
00143 typedef DynArrI<int> DynArrInt;
00144 typedef DynArrI<int64> DynArrInt64;
00145 typedef DynArrI<void*> DynArrPtr;
00146 typedef DynArrI<VObj*> DynArrPtrVObj;
00147 typedef DynArrI<DynI*> DynArrPtrDynI;
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 #ifdef DO_IMPLEMENT_DYNARR
00163
00164
00165 DynObjType g_do_vtype_DynArrChar("DynArrChar","DynObj",DYNARRCHAR_TYPE_ID,0,sizeof(DynArrChar),NULL,NULL,__FILE__);
00166 template<>
00167 DynObjType* DynArrChar::doGetType( const DynI **pself ) const {
00168 if(pself) *pself=(const DynI*)(const void*)this;
00169 return &g_do_vtype_DynArrChar;
00170 }
00171 DynObjType g_do_vtype_DynArrWCharT("DynArrWCharT","DynObj",DYNARRWCHART_TYPE_ID,0,sizeof(DynArrWCharT),NULL,NULL,__FILE__);
00172 template<>
00173 DynObjType* DynArrWCharT::doGetType( const DynI **pself ) const {
00174 if(pself) *pself=(const DynI*)(const void*)this;
00175 return &g_do_vtype_DynArrWCharT;
00176 }
00177 DynObjType g_do_vtype_DynArrShort("DynArrShort","DynObj",DYNARRSHORT_TYPE_ID,0,sizeof(DynArrShort),NULL,NULL,__FILE__);
00178 template<>
00179 DynObjType* DynArrShort::doGetType( const DynI **pself ) const {
00180 if(pself) *pself=(const DynI*)(const void*)this;
00181 return &g_do_vtype_DynArrShort;
00182 }
00183 DynObjType g_do_vtype_DynArrInt("DynArrInt","DynObj",DYNARRINT_TYPE_ID,0,sizeof(DynArrInt),NULL,NULL,__FILE__);
00184 template<>
00185 DynObjType* DynArrInt::doGetType( const DynI **pself ) const {
00186 if(pself) *pself=(const DynI*)(const void*)this;
00187 return &g_do_vtype_DynArrInt;
00188 }
00189 DynObjType g_do_vtype_DynArrInt64("DynArrInt64","DynObj",DYNARRINT64_TYPE_ID,0,sizeof(DynArrInt64),NULL,NULL,__FILE__);
00190 template<>
00191 DynObjType* DynArrInt64::doGetType( const DynI **pself ) const {
00192 if(pself) *pself=(const DynI*)(const void*)this;
00193 return &g_do_vtype_DynArrInt64;
00194 }
00195 DynObjType g_do_vtype_DynArrPtr("DynArrPtr","DynObj",DYNARRPTR_TYPE_ID,0,sizeof(DynArrPtr),NULL,NULL,__FILE__);
00196 template<>
00197 DynObjType* DynArrPtr::doGetType( const DynI **pself ) const {
00198 if(pself) *pself=(const DynI*)(const void*)this;
00199 return &g_do_vtype_DynArrPtr;
00200 }
00201 DynObjType g_do_vtype_DynArrPtrVObj("DynArrPtrVObj","DynObj",DYNARRPTRVOBJ_TYPE_ID,0,sizeof(DynArrPtrVObj),NULL,NULL,__FILE__);
00202 template<>
00203 DynObjType* DynArrPtrVObj::doGetType( const DynI **pself ) const {
00204 if(pself) *pself=(const DynI*)(const void*)this;
00205 return &g_do_vtype_DynArrPtrVObj;
00206 }
00207 DynObjType g_do_vtype_DynArrPtrDynI("DynArrPtrDynI","DynObj",DYNARRPTRDYNI_TYPE_ID,0,sizeof(DynArrPtrDynI),NULL,NULL,__FILE__);
00208 template<>
00209 DynObjType* DynArrPtrDynI::doGetType( const DynI **pself ) const {
00210 if(pself) *pself=(const DynI*)(const void*)this;
00211 return &g_do_vtype_DynArrPtrDynI;
00212 }
00213 #endif //DO_IMPLEMENT_...
00214
00215
00216 #endif // DYNLIST_H
00217
00218