Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

jAPIcollectors.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 
00003 #ifndef jAPIcollectorsH
00004 #define jAPIcollectorsH
00005 //---------------------------------------------------------------------------
00006 
00007 #include <map.h>
00008 #include "jAPItexts.h"
00009 #include "jAPImemory.h"
00010 
00011 /*
00012 * jAPICollectors
00013 * (part of the C++ Builder jAPI)
00014 * Author : Jean-Etienne GOUBARD
00015 * Description :
00016 *       contains objects that act like hashtable, value are stored and are indexed by their ID 
00017 */
00018 
00019 class jBitmap;
00020 
00021 // Virtual class for all these objects
00022 class jMap
00023 {
00024         public:
00025 
00026         bool __fastcall load(AnsiString _location);
00027         bool __fastcall save(AnsiString _location);        
00028         virtual bool __fastcall load(FILE * _fichier)=0;
00029         virtual bool __fastcall save(FILE * _fichier)=0;
00030         virtual bool __fastcall load(TStream * _str)=0;        
00031         virtual bool __fastcall save(TStream * _str)=0;
00032 
00033         virtual bool __fastcall clear()=0;
00034         virtual int __fastcall  count()=0;
00035 };
00036 
00037 // An Hashtable of integers
00038 class IntMap : public jMap
00039 {
00040         protected:
00041         map<AnsiString, int, less<AnsiString> >       m_data;
00042 
00043         public:
00044         IntMap();
00045         ~IntMap();
00046 
00047         bool __fastcall load(FILE * _fichier);
00048         bool __fastcall save(FILE * _fichier);
00049         bool __fastcall load(TStream * _str);
00050         bool __fastcall save(TStream * _str);
00051 
00052         bool __fastcall clear();
00053         int  __fastcall count();
00054         bool __fastcall add(AnsiString _key, int _value);
00055         bool __fastcall remove(int _pos);
00056         bool __fastcall remove(AnsiString _key);
00057 
00058         int __fastcall at(int _pos);
00059         int __fastcall getValue(int _pos);
00060         AnsiString __fastcall getKey(int _pos);
00061         int __fastcall maxKey(); 
00062 
00063         int __fastcall at(AnsiString _key);
00064 };
00065 
00066 // An Hashtable of Strings
00067 class StringMap : public jMap
00068 {
00069         protected:
00070         map<AnsiString, AnsiString, less<AnsiString> >       m_strings;
00071 
00072         public:
00073         StringMap();
00074         ~StringMap();
00075 
00076         bool __fastcall load(FILE * _fichier);
00077         bool __fastcall save(FILE * _fichier);
00078         bool __fastcall load(TStream * _str);
00079         bool __fastcall save(TStream * _str);        
00080 
00081         bool __fastcall clear();
00082         int  __fastcall count();
00083         bool __fastcall add(AnsiString _key, AnsiString _value);
00084         bool __fastcall modify(AnsiString _key, AnsiString _value);        
00085         bool __fastcall remove(unsigned int _pos);
00086         bool __fastcall remove(AnsiString _key);
00087 
00088         AnsiString __fastcall at(int _pos);
00089         AnsiString __fastcall getValue(int _pos);
00090         AnsiString __fastcall getKey(int _pos); 
00091 
00092         AnsiString __fastcall at(AnsiString _key);
00093 };
00094 
00095 // An Reversed Hashtable of Strings, wich acts like an bijective association
00096 class StringAssociationMap : public StringMap
00097 {
00098         map<AnsiString, AnsiString, less<AnsiString> >       m_reverseStrings;
00099 
00100         public:
00101         StringAssociationMap();
00102         ~StringAssociationMap();
00103 
00104         bool __fastcall clear();
00105         int  __fastcall count();
00106 
00107         bool __fastcall load(FILE * _fichier);
00108         bool __fastcall save(FILE * _fichier);        
00109         bool __fastcall load(TStream * _str);
00110         bool __fastcall save(TStream * _str);
00111 
00112         bool __fastcall add(AnsiString _key, AnsiString _value);
00113 
00114         bool __fastcall remove(unsigned int _pos);        
00115         bool __fastcall removeFromKey(AnsiString _key);
00116         bool __fastcall removeFromValue(AnsiString _key);        
00117 
00118         AnsiString __fastcall getValueFromKey(AnsiString _key);
00119         AnsiString __fastcall getKeyFromValue(AnsiString _value);
00120 };
00121 
00122 // A HashTable of anything
00123 class VoidMap : public jMap
00124 {
00125         map<AnsiString, void *, less<AnsiString> >       m_data;
00126 
00127         public:
00128 
00129         VoidMap();
00130         ~VoidMap();
00131 
00132         bool __fastcall clear();
00133         int  __fastcall count();
00134 
00135         bool __fastcall load(FILE * _fichier);
00136         bool __fastcall save(FILE * _fichier);        
00137         bool __fastcall load(TStream * _str);
00138         bool __fastcall save(TStream * _str);
00139         
00140         bool __fastcall modify(AnsiString _key, void * _value);
00141 
00142         bool __fastcall add(AnsiString _key, void * _value);
00143         bool __fastcall remove(unsigned int _pos);
00144         bool __fastcall remove(AnsiString _key);
00145 
00146         void * __fastcall atPos(int _pos);
00147         void * __fastcall getValue(int _pos);
00148         AnsiString __fastcall getKey(int _pos); 
00149 
00150         void * __fastcall at(AnsiString _key);
00151 };
00152 
00153 // A HashTable of jBitmap, that physically caries the image
00154 class BitmapMap : public jMap
00155 {
00156         map<AnsiString, jBitmap *, less<AnsiString> >       m_bitmaps;
00157 
00158         public:
00159 
00160         BitmapMap();
00161         ~BitmapMap();
00162 
00163         bool __fastcall load(FILE * _fichier);
00164         bool __fastcall save(FILE * _fichier);
00165         bool __fastcall clear();
00166         int  __fastcall count();
00167         bool __fastcall add(AnsiString _key, jBitmap * _value);
00168 
00169         jBitmap * __fastcall at(int _pos);
00170         jBitmap * __fastcall at(AnsiString _key);
00171 };
00172 
00173 class BitmapVector : public jMap
00174 {
00175         vector<jBitmap *>       m_bitmaps;
00176 
00177         public:
00178         BitmapVector();
00179         ~BitmapVector();
00180 
00181         bool __fastcall load(FILE * _fichier);
00182         bool __fastcall save(FILE * _fichier);
00183         bool __fastcall load(TStream * _str);
00184         bool __fastcall save(TStream * _str);
00185                         
00186         bool __fastcall clear();
00187         int  __fastcall count();
00188         bool __fastcall add(jBitmap * _value);
00189 
00190         bool __fastcall remove(unsigned int _pos);
00191         jBitmap * __fastcall at(unsigned int _pos);
00192 };
00193 
00194 class FileDBMap : public StringAssociationMap
00195 {
00196         AnsiString m_location;
00197         AnsiString m_indexName;
00198 
00199         bool __fastcall save();
00200         bool __fastcall load();
00201         bool __fastcall load(TStream * _str) { return false; }
00202         bool __fastcall save(TStream * _str) { return false; }
00203 
00204         bool __fastcall setLocation(AnsiString _location);
00205         bool __fastcall setIndex(AnsiString _indexName);
00206 
00207         public:
00208         
00209         static FileDBMap * __fastcall getInstance(AnsiString _location, AnsiString _indexName);
00210 
00211         bool __fastcall connect(AnsiString _location, AnsiString _indexName);
00212 
00213         bool __fastcall clear();
00214 
00215         AnsiString __fastcall add(AnsiString _key, TMemoryStream * _stream);
00216         bool __fastcall removeFromKey(AnsiString _key);
00217         bool __fastcall removeFromRef(AnsiString _ref);
00218         bool __fastcall getFromKey(AnsiString _key, TMemoryStream * _stream);
00219         bool __fastcall getFromRef(AnsiString _ref, TMemoryStream * _stream);
00220         bool __fastcall synchronize();
00221 };
00222 
00223 class DBMap
00224 {
00225         private:
00226         int m_indexRef;
00227 
00228 
00229         protected:
00230         HANDLE mutexHandle;
00231 
00232         int             start;          // real start of the stream
00233         int             idxStart;       // position where to find the Index reference
00234         int             dbStart;        // start of the avaibable storage space (header excluded)
00235         IntMap          index;
00236         AnsiString      m_header;
00237         jMemoryManager  m_mgr;
00238         TStream *       m_stream;
00239 
00240         bool __fastcall loadIndex();
00241         bool __fastcall saveIndex();
00242         bool __fastcall checkHeader();
00243         bool __fastcall writeHeader();
00244 
00245         public:
00246 
00247         DBMap()   { m_header = "J_DBMAP"; m_stream = NULL; start = 0; SECURITY_ATTRIBUTES l_attributes; mutexHandle = CreateMutex(&l_attributes, true, "orders_mutex"); }
00248         ~DBMap()  { disconnect(); }
00249         static DBMap * __fastcall getInstance(AnsiString _location);
00250 
00251         bool __fastcall connect(AnsiString _location);
00252         bool __fastcall connect(TStream * _stream, bool _create = false);
00253         bool __fastcall disconnect();
00254 
00255         bool __fastcall clear();
00256         int  __fastcall count() { return index.count(); }
00257         int  __fastcall maxRef();
00258 
00259         int  __fastcall add(TStream * _stream);
00260         bool __fastcall remove(int _ref);
00261         int  __fastcall removeAtPos(int _pos);        
00262         bool __fastcall replace(int _ref, TStream * _stream);
00263         int  __fastcall atPos(int _pos, TStream * _stream);
00264         bool __fastcall at(int _key, TStream * _stream);
00265         bool __fastcall atPtr(int _key, TStream ** _stream, int & _size);
00266         int  __fastcall getKey(int _pos)  { return index.getKey(_pos).ToIntDef(-1); }
00267 
00268         bool __fastcall getIndex(TStrings * _sl);
00269 
00270         void    __fastcall lock();
00271         void    __fastcall unlock();        
00272 
00273         bool __fastcall debug(TStrings * _sl, TCanvas * _cv = NULL, TRect rect = TRect(0, 0, 0, 0));
00274 };
00275 
00276 class DBMapDataBundle : public DBMap
00277 {
00278         public:
00279         int     __fastcall add(const jMEMdataBundle & _dataBundle);
00280         bool    __fastcall at(int _ref, jMEMdataBundle & _order);
00281         int     __fastcall atPos(int _pos, jMEMdataBundle & _order);
00282         bool    __fastcall replace(int _ref, jMEMdataBundle & _order);
00283 };
00284 
00285 class IndexedDBMap
00286 {
00287         StringAssociationMap ids;
00288         DBMap                dbmap;
00289         AnsiString           m_header;
00290         TStream *            m_stream;
00291         int                  start;          // real start of the stream        
00292         int                  dbStart;        // start of the avaibable storage space (header excluded)
00293         int                  idsStart;       // position where to find the Ids reference
00294 
00295 
00296         bool __fastcall loadIds();
00297         bool __fastcall saveIds();
00298 
00299         bool __fastcall checkHeader();
00300         bool __fastcall writeHeader();        
00301 
00302         public:
00303 
00304         IndexedDBMap()   { m_header = "J_INDEXED_DBMAP"; m_stream = NULL; start = 0; }        
00305         bool __fastcall connect(AnsiString _location);
00306         bool __fastcall connect(TStream * _stream, bool _create = false);
00307         bool __fastcall disconnect();
00308 
00309         int  __fastcall maxRef();
00310         int  __fastcall count() { return dbmap.count(); }        
00311 
00312         bool __fastcall clear();
00313 
00314         int  __fastcall add(AnsiString _id, TStream * _stream);
00315         bool __fastcall remove(AnsiString _id);
00316         bool __fastcall remove(int _ref);
00317 
00318         bool __fastcall replace(AnsiString _id, TStream * _stream, AnsiString _newID = "");
00319         bool __fastcall replace(int _ref, AnsiString _id, TStream * _stream = NULL);
00320         bool __fastcall replace(int _ref, TStream * _stream);        
00321 
00322         int        __fastcall at(AnsiString _id, TStream * _stream = NULL);
00323         AnsiString __fastcall at(int _ref, TStream * _stream = NULL);
00324         AnsiString __fastcall getId(int _ref) { return at(_ref); }
00325 
00326         bool __fastcall getRefsAndIDs(TStrings * _sl);        
00327         bool __fastcall getRefsAndIDs(vector<int> * _refs, TStrings * _sl);
00328         bool __fastcall getRefs(vector<int> * _refs);
00329         bool __fastcall getRefs(TStrings * _sl);
00330         bool __fastcall getIds(TStrings * _sl);        
00331 
00332         bool __fastcall debug(TStrings * _sl, TCanvas * _cv = NULL, TRect rect = TRect(0, 0, 0, 0));
00333 };
00334 
00335 class IndexedDBMapDataBundle : public IndexedDBMap
00336 {
00337         public:
00338         int             __fastcall add(AnsiString _id, const jMEMdataBundle & _dataBundle);
00339         int             __fastcall set(AnsiString _id, const jMEMdataBundle & _dataBundle);
00340         AnsiString      __fastcall at(int _ref, jMEMdataBundle & _order);
00341         int             __fastcall at(AnsiString _id, jMEMdataBundle & _order);
00342 
00343         bool            __fastcall replace(int _ref, const jMEMdataBundle & _order);
00344         bool            __fastcall replace(AnsiString _id, const jMEMdataBundle & _stream, AnsiString _newID = "");
00345         bool            __fastcall replace(int _ref, AnsiString _id, const jMEMdataBundle & _stream);
00346 };
00347 
00348 class IndexedDBMapData : public IndexedDBMap
00349 {
00350         public:
00351         int             __fastcall add(AnsiString _id, const jMEMdata & _data);
00352         int             __fastcall set(AnsiString _id, const jMEMdata & _data);
00353         AnsiString      __fastcall at(int _ref, jMEMdata & _order);
00354         int             __fastcall at(AnsiString _id, jMEMdata & _order);
00355 
00356         bool            __fastcall replace(int _ref, const jMEMdata & _order);
00357         bool            __fastcall replace(AnsiString _id, const jMEMdata & _stream, AnsiString _newID = "");
00358         bool            __fastcall replace(int _ref, AnsiString _id, const jMEMdata & _stream);
00359 };
00360 
00361 #endif

Generated on Sat Nov 15 10:52:34 2003 for JAPI by doxygen 1.3.4