00001 #ifndef gSTORAGE_X_H
00002 #define gSTORAGE_X_H
00003
00004 #include <stdio.h>
00005 #include "gmain.h"
00006
00007 #define nil 0
00008 #define MAX_INTSTGKIND 1000
00009 #ifdef DEBUG
00010 #define GENUCHAR_USU_BUFSIZE 20 // for debug, only (a small buffer)
00011 #else
00012 #define GENUCHAR_USU_BUFSIZE 4096 // UCharBuffer...
00013 #endif //DEBUG
00014
00015 #ifndef LOG_NONE
00016 #define LOG_NONE -1
00017 #endif
00018 #ifndef LOG_ERROR
00019 #define LOG_ERROR 0
00020 #endif
00021 #ifndef LOG_WARNING
00022 #define LOG_WARNING 1
00023 #endif
00024 #ifndef LOG_NOTICE
00025 #define LOG_NOTICE 2
00026 #endif
00027 #ifndef LOG_INFO
00028 #define LOG_INFO 3
00029 #endif
00030 #ifndef LOG_LOGMAX
00031 #define LOG_LOGMAX (LOG_INFO+1)
00032 #endif
00033 #ifndef LOG_NOCLASS
00034 #define LOG_NOCLASS 99
00035 #endif
00036
00037 struct sStorageDesc {
00038 char* descStr;
00039 short refKind;
00040 };
00041
00042 class gTop {
00043 public:
00044 virtual ~gTop () ;
00045
00046
00047 t_uint16 stgKind;
00048 static short nObjHistogram[MAX_INTSTGKIND];
00049
00050 int GetNumObjects () {
00051 return nObjs;
00052 }
00053
00054 protected:
00055 gTop (t_uint16 intStgKind) ;
00056
00057 private:
00058 static int nObjs;
00059 };
00060
00061 class gUCharBuffer {
00062 public:
00063 gUCharBuffer (t_uint16 bufSize=0) ;
00064 ~gUCharBuffer () ;
00065
00066
00067 t_uint16 size;
00068 t_uchar* uBuf;
00069
00070
00071 char* Str () {
00072 return (char*)uBuf;
00073 }
00074
00075
00076 void Copy (t_uchar* s) ;
00077 void Copy (char* s) ;
00078 void Clear () ;
00079
00080 private:
00081 void thisAllocate (t_uint16 bufSize) ;
00082 void thisCopy (t_uchar* s, t_uint16 len) ;
00083
00084
00085 gUCharBuffer (gUCharBuffer& ) ;
00086 gUCharBuffer& operator= (gUCharBuffer& ) ;
00087 };
00088
00089 class gStorage : public gTop {
00090 public:
00091
00092 enum eStorage {
00093 e_NoStorage,
00094 e_ResvdStore = 1,
00095 e_UChar = 2,
00096 e_SChar = 3,
00097 e_UInt = 4,
00098 e_SInt = 5,
00099 e_ULongInt = 6,
00100 e_SLongInt = 7,
00101 e_ResvdStore8 = 8,
00102 e_ResvdStore9 = 9,
00103 e_Real = 10,
00104 e_List = 11,
00105 e_ResvdStore12= 12,
00106 e_ResvdStore13= 13,
00107 e_ResvdStore14= 14,
00108 e_ResvdStore15= 15,
00109 e_ResvdStore16= 16,
00110 e_ResvdStore17= 17,
00111 e_ResvdStore18= 18,
00112 e_ResvdStore19= 19,
00113 e_String = 20,
00114 e_StrUnicode = 21,
00115 e_ResvdStore22= 22,
00116 e_ResvdStore23= 23,
00117 e_ResvdStore24= 24,
00118 e_ResvdStore25= 25,
00119 e_ResvdStore26= 26,
00120 e_ResvdStore27= 27,
00121 e_ResvdStore28= 28,
00122 e_ResvdStore29= 29,
00123 e_ResvdStore30= 30,
00124 e_StoreExtend = 31,
00125 e_Control,
00126 e_UnusedStore
00127 };
00128 enum eStoreMethod {
00129 e_StgNoStore = 0,
00130 e_StgGlobalString = 1,
00131 e_StgGlobalFlat = 2,
00132 e_StgString = 3,
00133 e_StgFlat = 4,
00134 e_StgDefault = 64
00135 };
00136
00137 virtual ~gStorage () ;
00138
00139
00140 static const sStorageDesc storeKindDesc[];
00141
00142
00143 virtual bool IsOk () {
00144 return true;
00145 }
00146 eStorage Kind () {
00147 return kind;
00148 }
00149 virtual eStoreMethod GetStoreMethod () {
00150 return storeMethod;
00151 }
00152 virtual char* StorageName () ;
00153
00154 virtual bool IsString () {
00155 return MinimumStorageSize()==-1;
00156 }
00157
00158 virtual char* Str () ;
00159
00160 virtual int MinimumStorageSize () {
00161 return 1;
00162 }
00163 virtual int MaximumStorageSize () {
00164 #ifdef gUINT_IS_32bit
00165 return 10;
00166 #else
00167 return 5;
00168 #endif
00169 }
00170
00171
00172 virtual void Reset () {
00173 SetError( 0 );
00174 }
00175 virtual int SetError (int opError) ;
00176 virtual void SetStoreMethod (eStoreMethod aMethod) ;
00177
00178
00179 virtual gStorage* NewObject () = 0;
00180
00181
00182 virtual t_uchar* ToString (t_uchar* uBuf) = 0;
00183 virtual bool EndGuts () ;
00184 virtual bool SaveGuts (FILE* f) = 0;
00185 virtual bool RestoreGuts (FILE* f) = 0;
00186
00187
00188 virtual void Show (bool doShowAll=true) ;
00189
00190 protected:
00191 gStorage (eStorage aKind,
00192 eStoreMethod aMethod=e_StgDefault) ;
00193
00194 eStorage kind;
00195 eStoreMethod storeMethod;
00196 static gUCharBuffer oneCharBuf;
00197
00198 bool thisSetStoreMethod (eStoreMethod aMethod,
00199 eStoreMethod& resMethod) ;
00200
00201 bool CanSave (FILE* f) ;
00202 bool CanRestore (FILE* f) ;
00203
00204 private:
00205 static eStoreMethod globalStoreMethod;
00206
00207
00208 gStorage (gStorage& ) ;
00209 gStorage& operator= (gStorage& ) ;
00210 };
00211
00212 struct sServiceNode {
00213 sServiceNode ()
00214 : used( -1 ),
00215 index( 0 ),
00216 handle( -1 ),
00217 pStorage( nil ) {
00218 Delete();
00219 }
00220 ~sServiceNode () ;
00221
00222
00223 short used;
00224 short index;
00225 int handle;
00226 char shortName[60];
00227 gStorage* pStorage;
00228
00229
00230 void Copy (sServiceNode& copy) ;
00231 void Delete () ;
00232
00233
00234 sServiceNode (sServiceNode& ) ;
00235 sServiceNode& operator= (sServiceNode& ) ;
00236 };
00237
00238 struct sServiceArray {
00239 sServiceArray (unsigned max) ;
00240 ~sServiceArray () ;
00241
00242 unsigned n, maxN;
00243 sServiceNode* pNodes;
00244
00245
00246 void Allocate (unsigned nAlloc) ;
00247 void Release () ;
00248 bool Add (sServiceNode& aNode) ;
00249 bool Delete (gStorage* pStorage) ;
00250 unsigned FindFreeNode () ;
00251
00252
00253 sServiceArray (sServiceArray& ) ;
00254 sServiceArray& operator= (sServiceArray& ) ;
00255 };
00256
00257 struct sServiceRegister {
00258 sServiceRegister (unsigned aMediumNodes=5)
00259 : nMediumNodes( aMediumNodes ),
00260 data( nil ) {
00261 descriptor.descStr = nil;
00262 descriptor.refKind = 0;
00263 }
00264 ~sServiceRegister () ;
00265
00266
00267 sStorageDesc descriptor;
00268 unsigned nMediumNodes;
00269 sServiceArray* data;
00270
00271
00272 bool HasNodes () {
00273 return data!=nil;
00274 }
00275 unsigned NumberOfNodes () {
00276 return nMediumNodes;
00277 }
00278 int AllocateNodes () ;
00279 void ReleaseDescriptor () ;
00280 void ReleaseData () ;
00281
00282
00283 sServiceRegister (sServiceRegister& ) ;
00284 sServiceRegister& operator= (sServiceRegister& ) ;
00285 };
00286
00287 class gUChar : public gStorage {
00288 public:
00289 gUChar (t_uchar v='\0')
00290 : gStorage( e_UChar ),
00291 c( v ) {
00292 }
00293 virtual ~gUChar () {
00294 }
00295
00296
00297 virtual t_uchar GetUChar () {
00298 return c;
00299 }
00300
00301 virtual int MaximumStorageSize () {
00302 return 1;
00303 }
00304
00305
00306 virtual void Reset () ;
00307 virtual bool SetUChar (t_uchar v) {
00308 c = v;
00309 return true;
00310 }
00311
00312 virtual gStorage* NewObject () ;
00313
00314
00315 virtual t_uchar* ToString (t_uchar* uBuf) ;
00316 virtual bool SaveGuts (FILE* f) ;
00317 virtual bool RestoreGuts (FILE* f) ;
00318
00319 protected:
00320 t_uchar c;
00321
00322 private:
00323
00324 gUChar (gUChar& ) ;
00325 gUChar& operator= (gUChar& ) ;
00326 };
00327
00328 class gSwitch : public gUChar {
00329 public:
00330 gSwitch (bool isOn=false)
00331 : gUChar( isOn ? 'T' : '\0' ) {
00332 }
00333 virtual ~gSwitch () {
00334 }
00335
00336 virtual bool IsOn () {
00337 return c!=0;
00338 }
00339 virtual bool SetOn (bool isOn) {
00340 return (c = isOn ? 'T' : '\0')!=0;
00341 }
00342
00343 private:
00344
00345 gSwitch (gSwitch& ) ;
00346 gSwitch& operator= (gSwitch& ) ;
00347 };
00348
00349 class gInt : public gStorage {
00350 public:
00351 gInt (int v=0)
00352 : gStorage( e_SInt ),
00353 c( v ) {
00354 }
00355 virtual ~gInt () {
00356 }
00357
00358
00359 virtual int GetInt () {
00360 return c;
00361 }
00362
00363 int GetMinInt () {
00364 #ifdef gUINT_IS_32bit
00365 return (int)MIN_DLINT32;
00366 #else
00367 return -32768;
00368 #endif
00369 }
00370
00371 int GetMaxInt () {
00372 #ifdef gUINT_IS_32bit
00373 return (int)MAX_DLINT32;
00374 #else
00375 return MAX_INT16_I;
00376 #endif
00377 }
00378
00379
00380 virtual void Reset () ;
00381 virtual bool SetInt (int v) {
00382 c = v;
00383 return true;
00384 }
00385
00386 virtual int Incr (int v=1) {
00387 c += v;
00388 return c;
00389 }
00390
00391 virtual gStorage* NewObject () ;
00392
00393
00394 virtual t_uchar* ToString (t_uchar* uBuf) ;
00395 virtual bool SaveGuts (FILE* f) ;
00396 virtual bool RestoreGuts (FILE* f) ;
00397
00398
00399 virtual void Show (bool doShowAll=true) ;
00400
00401 protected:
00402 int c;
00403
00404 private:
00405
00406 gInt (gInt& ) ;
00407 gInt& operator= (gInt& ) ;
00408 };
00409
00410 class gUInt : public gStorage {
00411 public:
00412 gUInt (unsigned v=0)
00413 : gStorage( e_UInt ),
00414 c( v ) {
00415 }
00416 virtual ~gUInt () {
00417 }
00418
00419
00420 virtual unsigned GetUInt () {
00421 return c;
00422 }
00423
00424 int GetMaxUInt () {
00425 #ifdef gUINT_IS_32bit
00426 return (int)MAX_DUINT32;
00427 #else
00428 return MAX_UINT16_U;
00429 #endif
00430 }
00431
00432
00433 virtual void Reset () ;
00434 virtual bool SetUInt (unsigned v) {
00435 c = v;
00436 return true;
00437 }
00438
00439 virtual gStorage* NewObject () ;
00440
00441
00442 virtual t_uchar* ToString (t_uchar* uBuf) ;
00443 virtual bool SaveGuts (FILE* f) ;
00444 virtual bool RestoreGuts (FILE* f) ;
00445
00446
00447 virtual void Show (bool doShowAll=true) ;
00448
00449 protected:
00450 unsigned c;
00451
00452 private:
00453
00454 gUInt (gUInt& ) ;
00455 gUInt& operator= (gUInt& ) ;
00456 };
00457
00458 class gReal : public gStorage {
00459 public:
00460 gReal (float v)
00461 : gStorage( e_Real ),
00462 c( (double)v ) {
00463 }
00464 gReal (unsigned v=0)
00465 : gStorage( e_Real ),
00466 c( (double)v ) {
00467 }
00468 virtual ~gReal () {
00469 }
00470
00471
00472 virtual int GetInt () {
00473 return (int)c;
00474 }
00475
00476 virtual int MaximumStorageSize () {
00477 return oneCharBuf.size;
00478 }
00479
00480
00481 virtual void Reset () ;
00482 virtual bool SetInt (int v) {
00483 c = (double)v;
00484 return true;
00485 }
00486
00487 virtual gStorage* NewObject () ;
00488
00489
00490 virtual t_uchar* ToString (t_uchar* uBuf) ;
00491 virtual bool SaveGuts (FILE* f) ;
00492 virtual bool RestoreGuts (FILE* f) ;
00493
00494
00495 virtual void Show (bool doShowAll=true) ;
00496
00497 protected:
00498 double c;
00499
00500 private:
00501
00502 gReal (gReal& ) ;
00503 gReal& operator= (gReal& ) ;
00504 };
00505
00506 #endif //gSTORAGE_X_H
00507