garray.h

Go to the documentation of this file.
00001 #ifndef gARRAY_X_H
00002 #define gARRAY_X_H
00003 
00004 #include "gstring.h"
00005 #include "gcontrol.h"
00006 
00007 #define GDEF_DIM 100
00008 
00009 #define GARRAY_LOGF stderr
00010 #define GARRAY_ANY_LOG(level,y) { \
00011         /* fprintf(GARRAY_LOGF,":::%s:%u:%s\n",__FILE__,__LINE__,y); */ ; \
00012         if ( level!=LOG_NONE ) gStorageControl::Self().Log( GARRAY_LOGF, level, "%s:%u:%s\n", __FILE__, __LINE__, y ); \
00013 }
00014 ////////////////////////////////////////////////////////////
00015 class gVector : public gInt {
00016 public:
00017     gVector (unsigned nMax=0) ;
00018     gVector (gVector& copy) ;
00019     virtual ~gVector () ;
00020 
00021     // Public data-members
00022     gString sVector;
00023 
00024     // Get methods
00025     virtual unsigned N () {
00026         return n;
00027     }
00028 
00029     virtual int GetNumInt (unsigned iter) {
00030         return (iter>=1 && iter<=n && IsOk()==true) ? v[ iter ] : -1;
00031     }
00032 
00033     virtual bool IsOk () {
00034         return v!=nil && gInt::IsOk();
00035     }
00036 
00037     virtual char* Str () ;
00038     virtual char* StrFormat (char* fmtOptions, char* fmtString) ;
00039 
00040     // Set methods
00041     virtual void Reset () {
00042         Zero();
00043     }
00044 
00045     virtual void Release () ;
00046 
00047     virtual void Resize (unsigned nMax) ;
00048 
00049     void Zero () {
00050         Set( 0 );
00051     }
00052 
00053     void Set (int iVal) ;
00054 
00055     gVector& Sort (bool isAscending=true) ;
00056 
00057     // All operators
00058     virtual gVector& operator= (gVector& copy) ;
00059     virtual gVector& operator+ (gVector& copy) ;
00060     virtual gVector& operator- (gVector& copy) ;
00061     virtual gVector& operator* (gVector& copy) ;
00062     virtual int& operator[] (unsigned idx) ;
00063     virtual bool operator== (gVector& copy) ;
00064     virtual bool operator!= (gVector& copy) ;
00065 
00066 protected:
00067     unsigned n;
00068     int* v;
00069 };
00070 ////////////////////////////////////////////////////////////
00071 class gArray : public gInt {
00072 public:
00073     gArray (unsigned y=0, unsigned x=0) ;
00074     gArray (gArray& copy) ;
00075     virtual ~gArray () ;
00076 
00077     // Public data-members
00078     static int defaultFmtDigits;
00079     gString sArray;
00080 
00081     // Get methods
00082     virtual unsigned DimY () {
00083         return dimY;
00084     }
00085 
00086     virtual unsigned DimX () {
00087         return dimX;
00088     }
00089 
00090     virtual int GetNumInt (unsigned y, unsigned x) {
00091         return (y>=1 && y<=dimY && IsOk()==true) ? pV[y][x] : -1;
00092     }
00093 
00094     virtual bool IsOk () {
00095         return pV!=nil && gInt::IsOk();
00096     }
00097 
00098     virtual char* Str () ;
00099     virtual char* StrFormat (char* fmtOptions, char* fmtString) ;
00100 
00101     // Set methods
00102     virtual void Reset () {
00103         Zero();
00104     }
00105 
00106     virtual void Release () ;
00107 
00108     virtual void Resize (unsigned newY, unsigned newX) {
00109         thisNewDim( newY, newX );
00110     }
00111 
00112     void Zero () {
00113         Set( 0 );
00114     }
00115 
00116     void Set (int iVal) ;
00117     void Set (gVector& iVector) ;
00118 
00119     virtual void TransposeMe () ;
00120     virtual gArray& Transpose () ;
00121 
00122     virtual gArray& AddRow (gVector& aV) ;
00123     virtual gArray& AddEmptyRow (unsigned iter=1) ;
00124     virtual gArray& AddColumn (gVector& aV) ;
00125     virtual gArray& AddEmptyColumn (unsigned iter=1) ;
00126     gArray& JoinArrayRight (gArray& copy, bool doForceDim=false) ;
00127     gArray& JoinArrayDown (gArray& copy, bool doForceDim=false) ;
00128 
00129     // All operators
00130     virtual gArray& operator= (gArray& copy) ;
00131     virtual gArray& operator+ (gArray& copy) ;
00132     virtual gArray& operator- (gArray& copy) ;
00133     virtual gArray& operator* (gArray& copy) ;
00134     virtual gArray& operator| (gArray& copy) ;
00135     virtual gVector& operator[] (unsigned idx) ;
00136     virtual bool operator== (gArray& copy) ;
00137     virtual bool operator!= (gArray& copy) ;
00138 
00139 protected:
00140     unsigned dimY, dimX;
00141     gVector* pV;
00142 
00143     int thisNewDim (unsigned y, unsigned x) ;
00144     int thisCopyArray (gArray& copy) ;
00145     char* thisFmtOptions (int nrFmtDigits, char fmtChar) ;
00146 };
00147 ////////////////////////////////////////////////////////////
00148 class gArrayCollect {
00149 public:
00150     virtual ~gArrayCollect () ;
00151 
00152     static gArrayCollect& Self () {
00153         return myself;
00154     }
00155 
00156     // Get methods
00157     virtual int NumObjs () {
00158         return lGarbage.N();
00159     }
00160 
00161     virtual gStorage* GetObjectPtr (unsigned idx) {
00162         return lGarbage.GetObjectPtr( idx );
00163     }
00164     virtual gStorage* GetFirstObjectPtr () {
00165         return lGarbage.GetFirstObjectPtr();
00166     }
00167     virtual gStorage* GetLastObjectPtr () {
00168         return lGarbage.GetLastObjectPtr();
00169     }
00170 
00171     // Set methods
00172     int Garbage (gStorage* newA) ;
00173     int ReleaseAll () ;
00174 
00175 protected:
00176     gArrayCollect () ;
00177 
00178     int thisAddIntoList (gStorage* newA, gList& aList) ;
00179 
00180 private:
00181     static short iCtrl;
00182     static gArrayCollect myself;
00183     gList lGarbage;
00184 
00185     // Operators,empty
00186     gArrayCollect (gArrayCollect& ) ; //empty
00187     gArrayCollect& operator= (gArrayCollect& ) ; //empty
00188 };
00189 ////////////////////////////////////////////////////////////
00190 #endif //gARRAY_X_H
00191 

Generated on Sat Aug 18 02:40:50 2007 for xpfweb_v2x lib by  doxygen 1.4.2