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

jAPImemory.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 #ifndef jAPImemoryH
00003 #define jAPImemoryH
00004 //---------------------------------------------------------------------------
00005 
00006 #include <math.h>
00007 
00008 #include <NMUDP.hpp>
00009 #include <scktcomp.hpp>
00010 #include <vector.h>
00011 
00012 class VoidMap;
00013 class jSound;
00014 class jBitmap;
00015 
00016 #define TBITMAP Graphics::TBitmap
00017 
00018 bool __fastcall jUDPsend(TNMUDP * udp, AnsiString adr, int prt, void * buffer, unsigned long len, int prt_lcl=0);
00019 bool __fastcall jUDPreceive(TNMUDP * udp, void * buffer, unsigned long len, int prt_lcl=0);
00020 
00021 bool __fastcall jTCPestablish(TClientSocket * cs, AnsiString adr, int prt);
00022 bool __fastcall jTCPsend(TClientSocket * cs, void * buffer, unsigned long len, unsigned long timeout);
00023 bool __fastcall jTCPreceive(TClientSocket * cs, void * buffer, unsigned long len, unsigned long timeout);
00024 
00025 // DEBUG : ne marchent pas encore
00026 AnsiString jHSTlocalName()
00027 {
00028         hostent host;
00029         return host.h_name;
00030 }
00031 
00032 AnsiString jHSTlocalAdress()
00033 {
00034         hostent host;
00035         return host.h_addr_list[0];
00036 }
00037 
00038 /* jMEMdata : a class that can store any type of data
00039 */
00040 class jMEMdata
00041 {
00042         public:
00043         enum Type {TYP_None=0, TYP_AnsiString, TYP_TBitmap, TYP_TStream, TYP_TDateTime, TYP_Int, TYP_Error, TYP_JSound, TYP_JBitmapJpg};
00044 
00045         private:
00046         void * data;
00047         Type type;
00048 
00049         public:
00050         __fastcall jMEMdata();
00051         __fastcall jMEMdata(AnsiString _data);
00052         __fastcall jMEMdata(TBITMAP * _bitmap);
00053         __fastcall jMEMdata(TStream * _stream);
00054         __fastcall jMEMdata(TDateTime _dateTime);
00055         __fastcall jMEMdata(int       _data);
00056         __fastcall jMEMdata(char *    _data);
00057         __fastcall jMEMdata(jSound *  _sound);
00058         __fastcall jMEMdata(jBitmap * _bitmap);
00059         __fastcall jMEMdata(jBitmap * _bitmap, Type _type);
00060 
00061         __fastcall jMEMdata::jMEMdata(const jMEMdata & _data);
00062         __fastcall jMEMdata::jMEMdata(const jMEMdata * _data);
00063         void __fastcall jMEMdata::operator=(const jMEMdata & _data);
00064         void __fastcall jMEMdata::operator=(const jMEMdata * _data);
00065         
00066         __fastcall ~jMEMdata();
00067 
00068         bool __fastcall clear();
00069 
00070         bool __fastcall assign(const jMEMdata & _data);
00071         bool __fastcall assign(const jMEMdata * _data);        
00072 
00073         bool __fastcall set(char *    _data);
00074         bool __fastcall set(jSound *  _sound);
00075         bool __fastcall set(jBitmap *  _bitmap, Type _type);
00076         bool __fastcall set(AnsiString _data);
00077         bool __fastcall set(TBITMAP * _bitmap);
00078         bool __fastcall set(TStream * _stream);
00079         bool __fastcall set(TDateTime _dateTime);
00080         bool __fastcall set(int       _data);
00081         bool __fastcall setError(); 
00082 
00083         bool __fastcall isEmpty();
00084         bool __fastcall isError();                
00085 
00086         bool __fastcall toStream(TStream * _stream);
00087         bool __fastcall fromStream(TStream * _stream);
00088 
00089         AnsiString getAnsiString();
00090         TBITMAP *  getTBitmapPtr();
00091         TStream *  getTStreamPtr();
00092         jSound  *  getJSoundPtr();        
00093         TDateTime  getTDateTime();
00094         int        getInt();
00095 };
00096 
00097 class jMEMdataBundle
00098 {
00099         jMEMdata error;  // to return an error eventually
00100         bool isAnError;
00101 
00102         VoidMap * datas;
00103 
00104         bool __fastcall add(AnsiString _ref, const jMEMdata & _data);
00105         bool __fastcall add(AnsiString _ref, const jMEMdata * _data);
00106 
00107         public:
00108 
00109         __fastcall jMEMdataBundle();
00110         __fastcall jMEMdataBundle(const jMEMdataBundle & _dataBundle);
00111         __fastcall jMEMdataBundle(const jMEMdataBundle * _dataBundle);
00112 
00113         void __fastcall operator=(const jMEMdataBundle & _dataBundle);
00114 
00115         __fastcall ~jMEMdataBundle();
00116 
00117         bool __fastcall clear();
00118         int  __fastcall count();
00119         bool __fastcall assign(const jMEMdataBundle & _databundle);
00120         bool __fastcall assign(const jMEMdataBundle * _databundle);
00121         bool __fastcall remove(AnsiString _ref);
00122         bool __fastcall remove(int _pos);
00123         bool __fastcall set(AnsiString _ref, const jMEMdata & _data);
00124         bool __fastcall set(AnsiString _ref, const jMEMdata * _data);
00125         bool __fastcall setPos(int _pos, const jMEMdata & _data);
00126         bool __fastcall setPos(int _pos, const jMEMdata * _data);
00127         jMEMdata & __fastcall atPos(int _pos);
00128         jMEMdata * __fastcall atPosPtr(int _pos);
00129         jMEMdata & __fastcall at(AnsiString _ref);
00130         jMEMdata * __fastcall atPtr(AnsiString _ref);
00131 
00132         void __fastcall setError();
00133         bool __fastcall isError();
00134 //        bool __fastcall set(AnsiString _ref, AnsiString _value);
00135 
00136         bool __fastcall toStream(TStream * _stream);
00137         bool __fastcall fromStream(TStream * _stream);
00138         bool __fastcall fromTStrings(TStrings * _strings);
00139         AnsiString __fastcall toString();
00140 };
00141 
00142 // charge un fichier dans un flux memoire
00143 bool __fastcall jMEMloadFromFile(AnsiString FileName, TMemoryStream * ms);
00144 bool __fastcall jMEMsaveToFile(AnsiString FileName, TMemoryStream * ms);
00145 
00146 bool __fastcall jMEMcrypt(void * ms, unsigned long len);
00147 bool __fastcall jMEMunCrypt(void * ms, unsigned long len) { return jMEMcrypt(ms, len); }
00148 
00149 bool __fastcall jMEMcrypt(void * ms, unsigned long len, void * key, unsigned long lenKey);
00150 bool __fastcall jMEMunCrypt(void * ms, unsigned long len, void * key, unsigned long lenKey) { return jMEMcrypt(ms, len, key, lenKey); }
00151 
00152 bool __fastcall jMEMcrypt(TMemoryStream * ms, unsigned long len);
00153 bool __fastcall jMEMunCrypt(TMemoryStream * ms, unsigned long len) { return jMEMcrypt(ms, len); }
00154 
00155 bool __fastcall jMEMfill(void * buffer, unsigned long len, AnsiString octets);
00156 
00157 void            __fastcall jMEMcopy(void * dest, void * src, int offset, int nb);
00158 unsigned long   __fastcall jMEMchars2Ulong(unsigned char * data, unsigned long pos, unsigned long len);
00159 AnsiString      __fastcall jMEMdata2str(char * src, unsigned long length);
00160 
00161 bool            __fastcall jMEMwriteInt(int _data, TStream * _stream);
00162 int             __fastcall jMEMreadInt(TStream * _stream);
00163 
00164 unsigned char __fastcall jMEMstring2byte(AnsiString val);
00165 
00166 struct jMemoryEntry
00167 {
00168         int  position;
00169         int  size;
00170         bool taken;
00171 };
00172 
00173 // this class manage a stream with memory managment algorithm
00174 class jMemoryManager
00175 {
00176         TStream * stream;
00177         int             start;
00178         int             idxStart;
00179         int             idxLength;
00180         AnsiString header;
00181 
00182         vector<jMemoryEntry> entries;
00183 
00184         jMemoryEntry * __fastcall getEntry(int _pos);
00185         bool __fastcall  write(int _position, TStream * _stream);
00186         bool __fastcall  read(int _position, int _size, TStream * _stream);        
00187         jMemoryEntry * __fastcall  findFreeEntry(int _size, int & _ref);
00188         bool __fastcall  setEntry(int _size, jMemoryEntry *, int _ref);
00189         bool __fastcall  readIndex();
00190         bool __fastcall  writeIndex();
00191         bool __fastcall  resize();
00192         
00193         bool __fastcall checkHeader();
00194         bool __fastcall writeHeader();
00195 
00196         public:
00197 
00198         jMemoryManager();
00199         jMemoryManager(TStream * _stream);
00200         bool __fastcall setStream(TStream * _stream);
00201         
00202         int  __fastcall size() { if (!stream)   return -1; return stream->Size; }        
00203 
00204         bool __fastcall clear();
00205 
00206         int  __fastcall add(TStream * _stream);
00207         bool __fastcall at(int _pos, TStream * _stream);
00208         bool __fastcall atPtr(int _pos, TStream ** _stream, int & _size);     
00209         bool __fastcall remove(int _pos);
00210 
00211         bool __fastcall display(TStrings * sl);
00212         bool __fastcall display(TCanvas * sl, const TRect & rect);
00213 };
00214 
00215 #endif

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