[241] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 |
|
---|
[219] | 3 | #ifndef PPERSIST_H_SEEN
|
---|
| 4 | #define PPERSIST_H_SEEN
|
---|
| 5 |
|
---|
[241] | 6 | // Flat file persistance, similar to Java serialization
|
---|
| 7 | //
|
---|
| 8 | // E. Aubourg CEA DAPNIA/SPP 1999
|
---|
[802] | 9 | // R. Ansari LAL IN2P3/CNRS 03/2000
|
---|
[219] | 10 |
|
---|
| 11 |
|
---|
[241] | 12 | #include "machdefs.h"
|
---|
| 13 | #include "pexceptions.h"
|
---|
[742] | 14 | #include "gnumd5.h"
|
---|
[241] | 15 |
|
---|
[742] | 16 |
|
---|
[480] | 17 | #include <time.h>
|
---|
| 18 |
|
---|
[2441] | 19 | #include <complex>
|
---|
[219] | 20 | #include <string>
|
---|
| 21 | #include <map>
|
---|
[241] | 22 | #include <vector>
|
---|
| 23 | #include <typeinfo>
|
---|
[219] | 24 |
|
---|
| 25 |
|
---|
[269] | 26 | // Classe de base pour les objets qui peuvent devenir PPersist
|
---|
| 27 |
|
---|
[552] | 28 | namespace SOPHYA {
|
---|
[241] | 29 |
|
---|
[269] | 30 | class AnyDataObj;
|
---|
| 31 |
|
---|
[241] | 32 | class PIOPersist;
|
---|
| 33 | class PInPersist;
|
---|
| 34 | class POutPersist;
|
---|
| 35 | class PPersist;
|
---|
[219] | 36 |
|
---|
[895] | 37 | //! Persistent (delegate or mixin) base class
|
---|
[241] | 38 | class PPersist {
|
---|
| 39 | public:
|
---|
| 40 | virtual ~PPersist() {}
|
---|
[252] | 41 | // J'ajoute cette fonction pour assurer la compatibilite
|
---|
| 42 | // avec l'ancien PPersist d'Eros (Reza 23/04/99)
|
---|
| 43 | virtual int_4 ClassId() const { return(0); }
|
---|
[219] | 44 |
|
---|
[241] | 45 | void Write(string const& fn) const;
|
---|
| 46 | void Read(string const& fn);
|
---|
[219] | 47 |
|
---|
[241] | 48 | virtual void Write(POutPersist&) const;
|
---|
| 49 | void Read(PInPersist& s); // Reads the type tag and the object
|
---|
| 50 | void Write(POutPersist&, string const& tag) const;
|
---|
| 51 | void ReadAtTag(PInPersist& s, string const& tag);
|
---|
[269] | 52 |
|
---|
[754] | 53 | virtual AnyDataObj* DataObj()=0; // Retourne l'objet reel
|
---|
[802] | 54 | virtual void SetDataObj(AnyDataObj &)=0;
|
---|
[754] | 55 |
|
---|
[802] | 56 | virtual uint_8 getMemOId() const ; // Renvoie l'identificateur de l'objet - par defaut=0
|
---|
| 57 | // Ces deux methodes doivent etre redefinies si getMemOId() renvoie non nul (>0)
|
---|
| 58 | virtual void ShareDataReference(PPersist &);
|
---|
| 59 | virtual PPersist* CloneSharedReference();
|
---|
| 60 | // doit etre surcharge pour renvoyer un mem-oid correct
|
---|
[241] | 61 | protected:
|
---|
| 62 | virtual void ReadSelf(PInPersist&)=0;
|
---|
[802] | 63 | virtual void WriteSelf(POutPersist&) const=0;
|
---|
[219] | 64 |
|
---|
[241] | 65 | friend class PInPersist;
|
---|
| 66 | friend class POutPersist;
|
---|
[219] | 67 | };
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
[895] | 71 | //! Ancestor for PInPersist and POutPersist PPF streams.
|
---|
| 72 | // Handles (statically) the registration of classes.
|
---|
[219] | 73 |
|
---|
[241] | 74 | class PIOPersist {
|
---|
| 75 | public:
|
---|
| 76 | enum {PPS_NATIVE = -1, PPS_LITTLE_ENDIAN = 0, PPS_BIG_ENDIAN = 1};
|
---|
| 77 | typedef PPersist* (*ClassCreatorFunc)();
|
---|
| 78 |
|
---|
[802] | 79 | static void RegisterPPHandlerClass(uint_8 classId, string ppclass_name, ClassCreatorFunc f);
|
---|
| 80 | static void RegisterDataObjClass(uint_8 classId, string class_name);
|
---|
| 81 |
|
---|
[241] | 82 | static ClassCreatorFunc FindCreatorFunc(uint_8 classId);
|
---|
[802] | 83 |
|
---|
| 84 | static string getPPClassName(uint_8 classId);
|
---|
| 85 | static uint_8 getPPClassId(string const & typ_name);
|
---|
| 86 | static uint_8 getPPClassId(PPersist const & ppo);
|
---|
| 87 | static string getDataObjClassName(uint_8 classId);
|
---|
| 88 | static uint_8 getDataObjClassId(string const & typ_name);
|
---|
| 89 | static uint_8 getDataObjClassId(AnyDataObj const & o);
|
---|
| 90 |
|
---|
[1202] | 91 | static uint_8 Hash(string const& typname);
|
---|
[742] | 92 | static MD5_CONTEXT ctx;
|
---|
[241] | 93 |
|
---|
[269] | 94 | static void Initialize(); // Pour initialiser classList
|
---|
[802] | 95 |
|
---|
[2441] | 96 | int Version() {return version;} // PIn/OutPersist version number
|
---|
[802] | 97 | string FileName() { return filename; } // Retourne le nom de fichier
|
---|
| 98 |
|
---|
[241] | 99 | private:
|
---|
[219] | 100 |
|
---|
[241] | 101 | typedef map<uint_8, ClassCreatorFunc, less<uint_8> > ClassList;
|
---|
[269] | 102 | // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99
|
---|
[802] | 103 | static ClassList * ppclassList; // PPersist class list
|
---|
| 104 | static map<string, uint_8> * ppclassNameList; // PPersist classId = f(PPersistClassName)
|
---|
| 105 | static map<string, uint_8> * dobjclassNameList; // PPersist classId = f(DataObjClassName)
|
---|
[219] | 106 |
|
---|
[241] | 107 | protected:
|
---|
[588] | 108 |
|
---|
[241] | 109 | enum {PPS_NULL = 0, // this is a null object
|
---|
[821] | 110 | PPS_STRING = 1, // string, length (4b) + data
|
---|
[241] | 111 | PPS_OBJECT = 2, // classId, data...
|
---|
| 112 | PPS_REFERENCE = 3, // objectId
|
---|
[2441] | 113 | PPS_NAMETAG_TABLE = 4, // Name tag table (Written at the end of file/stream)
|
---|
[241] | 114 | PPS_EOF = 5, // Just before tag infomation, offset to PPS_TAG
|
---|
[802] | 115 | PPS_ENDOBJECT = 6, // marks the end of a given object information
|
---|
[2441] | 116 | PPS_NAMETAG_MARK = 7, // To have a name tag, position marker in a file
|
---|
| 117 | PPS_POSTAG_MARK = 8, // Position tag mark + 8 bytes (=stream position)
|
---|
| 118 | PPS_POSTAG_TABLE = 40, // Position tag table + 8 bytes (=stream position)
|
---|
[241] | 119 | PPS_SIMPLE = 16, // 16 + number of bytes, up to 8 bytes
|
---|
[802] | 120 | PPS_SIMPLE_ARRAY4 = 32, // 32 + number of bytes, up to 8 bytes, then 4 bytes of length
|
---|
| 121 | PPS_SIMPLE_ARRAY8 = 48 // 48 + number of bytes, up to 8 bytes, then 8 bytes of length
|
---|
| 122 | };
|
---|
[821] | 123 | // The following values are used with PPS_SIMPLE and PPS_SIMPLE_ARRAY (Using OR)
|
---|
[802] | 124 | enum {PPS_DATATYPE_CHAR = 0, // 0 : DataType=character
|
---|
| 125 | PPS_DATATYPE_FLOAT = 64, // 64 : DataType=float
|
---|
[2441] | 126 | PPS_DATATYPE_COMPLEX = 65, // 65 : DataType=complex
|
---|
[802] | 127 | PPS_DATATYPE_INTEGER = 128, // 128 :DataType=integer
|
---|
| 128 | PPS_DATATYPE_UNSIGNED = 192 // 192 :DataType=Unsigned integer
|
---|
[241] | 129 | };
|
---|
[219] | 130 |
|
---|
[241] | 131 | map<string, int_8> tags;
|
---|
[802] | 132 | string filename;
|
---|
[2441] | 133 | int version; // PPersist(In/Out) version
|
---|
[241] | 134 | };
|
---|
[219] | 135 |
|
---|
| 136 |
|
---|
[2441] | 137 | // TBD : use hash tables instead of maps. Check hashtbl status in STL.
|
---|
[219] | 138 |
|
---|
[895] | 139 | //! Input stream for PPersit objects.
|
---|
[241] | 140 | class PInPersist : public PIOPersist {
|
---|
| 141 | public:
|
---|
| 142 | PInPersist(string const& flnm, bool scan=true);
|
---|
| 143 | ~PInPersist();
|
---|
[219] | 144 |
|
---|
[2441] | 145 | // Gestion des tags
|
---|
| 146 | bool GotoPositionTag(int_8 pos);
|
---|
| 147 | bool GotoNameTag(string const& name);
|
---|
| 148 | inline bool GotoTag(string const& name) { return GotoNameTag(name); }
|
---|
[256] | 149 | int NbTags();
|
---|
| 150 | bool GotoTagNum(int itag); // 0..NbTags-1
|
---|
[582] | 151 | string GetTagName(int itag); // 0..NbTags-1
|
---|
[802] | 152 | string GetTagClassName(int itag); // 0..NbTags-1
|
---|
[582] | 153 | vector<string> const & GetTagNames();
|
---|
[219] | 154 |
|
---|
[2441] | 155 | // Lecture donnees de base et tableaux de donnees de base
|
---|
| 156 | // Basic data type (and corresponding arrays) reading
|
---|
[241] | 157 | void GetByte (char& c);
|
---|
| 158 | void GetBytes(void* ptr, size_t bytes);
|
---|
| 159 | void GetR4 (r_4&);
|
---|
| 160 | void GetR4s (r_4*, size_t);
|
---|
| 161 | void GetR8 (r_8&);
|
---|
| 162 | void GetR8s (r_8*, size_t);
|
---|
[2441] | 163 | void GetI1 (int_1&);
|
---|
| 164 | void GetI1s (int_1*, size_t);
|
---|
| 165 | void GetU1 (uint_1&);
|
---|
| 166 | void GetU1s (uint_1*, size_t);
|
---|
[241] | 167 | void GetI2 (int_2&);
|
---|
| 168 | void GetI2s (int_2*, size_t);
|
---|
| 169 | void GetU2 (uint_2&);
|
---|
| 170 | void GetU2s (uint_2*, size_t);
|
---|
| 171 | void GetI4 (int_4&);
|
---|
| 172 | void GetI4s (int_4*, size_t);
|
---|
| 173 | void GetU4 (uint_4&);
|
---|
| 174 | void GetU4s (uint_4*, size_t);
|
---|
| 175 | void GetI8 (int_8&);
|
---|
| 176 | void GetI8s (int_8*, size_t);
|
---|
| 177 | void GetU8 (uint_8&);
|
---|
| 178 | void GetU8s (uint_8*, size_t);
|
---|
| 179 | void GetLine (char* ptr, size_t len);
|
---|
| 180 | void GetStr (string&);
|
---|
[2441] | 181 | void GetZ4 (complex<r_4> &);
|
---|
| 182 | void GetZ4s (complex<r_4> *, size_t);
|
---|
| 183 | void GetZ8 (complex<r_8> &);
|
---|
| 184 | void GetZ8s (complex<r_8> *, size_t);
|
---|
[219] | 185 |
|
---|
[2441] | 186 | inline void Get(char& c) {GetByte(c);}
|
---|
| 187 | inline void Get(r_4& x) {GetR4(x);}
|
---|
| 188 | inline void Get(r_8& x) {GetR8(x);}
|
---|
| 189 | inline void Get(uint_1& x) {GetU1(x);}
|
---|
| 190 | inline void Get(int_1& x) {GetI1(x);}
|
---|
| 191 | inline void Get(uint_2& x) {GetU2(x);}
|
---|
| 192 | inline void Get(int_2& x) {GetI2(x);}
|
---|
| 193 | inline void Get(uint_4& x) {GetU4(x);}
|
---|
| 194 | inline void Get(int_4& x) {GetI4(x);}
|
---|
| 195 | inline void Get(uint_8& x) {GetU8(x);}
|
---|
| 196 | inline void Get(int_8& x) {GetI8(x);}
|
---|
| 197 | inline void Get(complex<r_4> & x) {GetZ4(x);}
|
---|
| 198 | inline void Get(complex<r_8> & x) {GetZ8(x);}
|
---|
| 199 |
|
---|
| 200 | inline void Get(r_4* x, size_t n) {GetR4s(x,n);}
|
---|
| 201 | inline void Get(r_8* x, size_t n) {GetR8s(x,n);}
|
---|
| 202 | inline void Get(uint_1* x, size_t n) {GetU1s(x,n);}
|
---|
| 203 | inline void Get(int_1* x, size_t n) {GetI1s(x,n);}
|
---|
| 204 | inline void Get(uint_2* x, size_t n) {GetU2s(x,n);}
|
---|
| 205 | inline void Get(int_2* x, size_t n) {GetI2s(x,n);}
|
---|
| 206 | inline void Get(uint_4* x, size_t n) {GetU4s(x,n);}
|
---|
| 207 | inline void Get(int_4* x, size_t n) {GetI4s(x,n);}
|
---|
| 208 | inline void Get(uint_8* x, size_t n) {GetU8s(x,n);}
|
---|
| 209 | inline void Get(int_8* x, size_t n) {GetI8s(x,n);}
|
---|
| 210 | inline void Get(string& x) {GetStr(x);}
|
---|
| 211 | inline void Get(complex<r_4> * x, size_t n) { GetZ4s(x, n); }
|
---|
| 212 | inline void Get(complex<r_8> * x, size_t n) { GetZ8s(x, n); }
|
---|
| 213 |
|
---|
| 214 | // Reading a list (table) of position tags
|
---|
| 215 | void GetPosTagTable(int_8*, size_t);
|
---|
| 216 | void GetPosTagTable(vector<int_8>&);
|
---|
| 217 |
|
---|
[802] | 218 | // Object Reading
|
---|
[241] | 219 | PPersist* ReadObject();
|
---|
[802] | 220 | void GetObject(AnyDataObj & o);
|
---|
| 221 | void GetObject(AnyDataObj & o, string tagname);
|
---|
| 222 | PPersist* GetPPObject(AnyDataObj * po=NULL);
|
---|
[219] | 223 |
|
---|
[241] | 224 | time_t CreationDate() { return creationdate; }
|
---|
[802] | 225 | string CreationDateStr();
|
---|
[219] | 226 |
|
---|
[802] | 227 | void AnalyseTags(int lev=0); // List (all or some) tags ...
|
---|
| 228 |
|
---|
| 229 | // Reza 03/2000
|
---|
| 230 | // Methodes qui pourraient etre protected, mais doivent etre utilisables par PPersist
|
---|
| 231 | void ReadReference(PPersist & ppo); // Fill the ppo object from the reference tag
|
---|
| 232 | PPersist * ReadReference(); // Creates object from the reference tag
|
---|
| 233 | void KeepOId(uint_8 oid, PPersist & ppo); // Keeps the ppo in the objList
|
---|
| 234 |
|
---|
[241] | 235 | protected:
|
---|
[802] | 236 | void CheckTag (short datasz, short datatype);
|
---|
| 237 | void CheckArrayTag(short datasz, size_t sz, short datatype);
|
---|
| 238 | void GetTypeTag (unsigned char& c);
|
---|
[241] | 239 | void GetRawByte (char& c);
|
---|
[802] | 240 | void GetRawUByte (unsigned char& c);
|
---|
[241] | 241 | void GetRawBytes(void* ptr, size_t bytes);
|
---|
| 242 | void GetRawI2 (int_2&);
|
---|
| 243 | void GetRawI4 (int_4&);
|
---|
| 244 | void GetRawI8 (int_8&);
|
---|
| 245 | void GetRawU8 (uint_8&);
|
---|
[802] | 246 |
|
---|
[241] | 247 | void Scan();
|
---|
[219] | 248 |
|
---|
[241] | 249 | istream* s;
|
---|
[219] | 250 |
|
---|
[241] | 251 | bool bigEndian;
|
---|
[219] | 252 |
|
---|
[241] | 253 | time_t creationdate;
|
---|
[219] | 254 |
|
---|
[802] | 255 | // already read objects
|
---|
| 256 | typedef map<uint_8, PPersist * > ObjList;
|
---|
[241] | 257 | ObjList objList;
|
---|
[802] | 258 | // Si on a fait une lecture non sequentielle -> seqread = false
|
---|
| 259 | bool seqread;
|
---|
[241] | 260 | friend class PPersist;
|
---|
| 261 | };
|
---|
[219] | 262 |
|
---|
[895] | 263 | //! Output stream for PPersit objects.
|
---|
[241] | 264 | class POutPersist : public PIOPersist {
|
---|
| 265 | public:
|
---|
| 266 | POutPersist(string const& flnm, int endianness = PPS_NATIVE);
|
---|
| 267 | ~POutPersist();
|
---|
[219] | 268 |
|
---|
[2441] | 269 | // Ecriture de tags
|
---|
| 270 | int_8 WritePositionTag();
|
---|
| 271 | void WriteNameTag(string const& name);
|
---|
| 272 | inline void WriteTag(string const& name) { WriteNameTag(name); }
|
---|
[241] | 273 |
|
---|
| 274 | void PutByte (char c);
|
---|
| 275 | void PutBytes(void const* ptr, size_t bytes);
|
---|
| 276 | void PutR4 (r_4);
|
---|
| 277 | void PutR4s (r_4 const*, size_t);
|
---|
| 278 | void PutR8 (r_8);
|
---|
| 279 | void PutR8s (r_8 const*, size_t);
|
---|
[2441] | 280 | void PutI1 (int_1);
|
---|
| 281 | void PutI1s (int_1 const*, size_t);
|
---|
| 282 | void PutU1 (uint_1);
|
---|
| 283 | void PutU1s (uint_1 const*, size_t);
|
---|
[241] | 284 | void PutI2 (int_2);
|
---|
| 285 | void PutI2s (int_2 const*, size_t);
|
---|
| 286 | void PutU2 (uint_2);
|
---|
| 287 | void PutU2s (uint_2 const*, size_t);
|
---|
| 288 | void PutI4 (int_4);
|
---|
| 289 | void PutI4s (int_4 const*, size_t);
|
---|
| 290 | void PutU4 (uint_4);
|
---|
| 291 | void PutU4s (uint_4 const*, size_t);
|
---|
| 292 | void PutI8 (int_8);
|
---|
| 293 | void PutI8s (int_8 const*, size_t);
|
---|
| 294 | void PutU8 (uint_8);
|
---|
| 295 | void PutU8s (uint_8 const*, size_t);
|
---|
| 296 | void PutLine (char const* ptr, size_t len=0); // deprecated ?
|
---|
| 297 | void PutStr (string const&);
|
---|
[2441] | 298 | void PutZ4 (complex<r_4>);
|
---|
| 299 | void PutZ4s (complex<r_4> const*, size_t);
|
---|
| 300 | void PutZ8 (complex<r_8>);
|
---|
| 301 | void PutZ8s (complex<r_8> const*, size_t);
|
---|
[219] | 302 |
|
---|
[802] | 303 |
|
---|
[241] | 304 | void Put(char c) {PutByte(c);}
|
---|
| 305 | void Put(r_4 x) {PutR4(x);}
|
---|
| 306 | void Put(r_8 x) {PutR8(x);}
|
---|
[2441] | 307 | void Put(complex<r_4> x) {PutZ4(x);}
|
---|
| 308 | void Put(complex<r_8> x) {PutZ8(x);}
|
---|
| 309 | void Put(uint_1 x) {PutU1(x);}
|
---|
| 310 | void Put(int_1 x) {PutI1(x);}
|
---|
[241] | 311 | void Put(uint_2 x) {PutU2(x);}
|
---|
| 312 | void Put(int_2 x) {PutI2(x);}
|
---|
| 313 | void Put(uint_4 x) {PutU4(x);}
|
---|
| 314 | void Put(int_4 x) {PutI4(x);}
|
---|
| 315 | void Put(uint_8 x) {PutU8(x);}
|
---|
| 316 | void Put(int_8 x) {PutI8(x);}
|
---|
| 317 | void Put(r_4 const* x, size_t n) {PutR4s(x,n);}
|
---|
| 318 | void Put(r_8 const* x, size_t n) {PutR8s(x,n);}
|
---|
[2441] | 319 | void Put(complex<r_4> const* x, size_t n) {PutZ4s(x,n);}
|
---|
| 320 | void Put(complex<r_8> const* x, size_t n) {PutZ8s(x,n);}
|
---|
| 321 | void Put(uint_1 const* x, size_t n) {PutU1s(x,n);}
|
---|
| 322 | void Put(int_1 const* x, size_t n) {PutI1s(x,n);}
|
---|
[241] | 323 | void Put(uint_2 const* x, size_t n) {PutU2s(x,n);}
|
---|
| 324 | void Put(int_2 const* x, size_t n) {PutI2s(x,n);}
|
---|
| 325 | void Put(uint_4 const* x, size_t n) {PutU4s(x,n);}
|
---|
| 326 | void Put(int_4 const* x, size_t n) {PutI4s(x,n);}
|
---|
| 327 | void Put(uint_8 const* x, size_t n) {PutU8s(x,n);}
|
---|
| 328 | void Put(int_8 const* x, size_t n) {PutI8s(x,n);}
|
---|
| 329 | void Put(string const& s) {PutStr(s);}
|
---|
[802] | 330 | void Put(PPersist const* x) {PutPPObject(x);}
|
---|
[219] | 331 |
|
---|
[2441] | 332 | // Writing a list of position tag table
|
---|
| 333 | void PutPosTagTable(int_8 const *, size_t);
|
---|
| 334 | void PutPosTagTable(vector<int_8> const&);
|
---|
[219] | 335 |
|
---|
[2441] | 336 | // Objet Write - Ecriture des objets
|
---|
| 337 | void PutPPObject (PPersist const*); // Like doing Write(stream) on PPersist object
|
---|
| 338 |
|
---|
| 339 | void PutObject(AnyDataObj & o); // Creates the corresponding PPersist Object and call Write()
|
---|
| 340 | void PutObject(AnyDataObj & o, string tagname);
|
---|
| 341 |
|
---|
| 342 |
|
---|
[241] | 343 | protected:
|
---|
| 344 | ostream* s;
|
---|
| 345 | bool bigEndian;
|
---|
[219] | 346 |
|
---|
[802] | 347 | void PutArrayTag(short datasz, size_t sz, short datatype);
|
---|
[241] | 348 | void PutRawByte (char);
|
---|
[802] | 349 | void PutRawUByte (unsigned char);
|
---|
[241] | 350 | void PutRawI2 (int_2);
|
---|
| 351 | void PutRawI4 (int_4);
|
---|
| 352 | void PutRawI8 (int_8);
|
---|
| 353 | void PutRawU8 (uint_8);
|
---|
| 354 | void PutRawBytes(void const* ptr, size_t bytes);
|
---|
| 355 | bool serializeNullAndRepeat(PPersist const* x);
|
---|
[802] | 356 | uint_8 findObjectId(PPersist const* x, int_8 & pos);
|
---|
| 357 | uint_8 assignObjectId(PPersist const* x);
|
---|
[219] | 358 |
|
---|
[802] | 359 | // objreftag contains the assigned POutStream Object Id and the stream position
|
---|
| 360 | // of the original written object
|
---|
| 361 | typedef struct { uint_8 ppsoid; int_8 ppspos; } objreftag;
|
---|
| 362 | // already serialized objects are kept in a map as a function of the Objects memory Id
|
---|
| 363 | typedef map<uint_8, objreftag, less<uint_8> > ObjList;
|
---|
[241] | 364 | ObjList objList;
|
---|
[802] | 365 | uint_8 pps_OId; // PPS Object Id
|
---|
[241] | 366 | };
|
---|
| 367 |
|
---|
[2441] | 368 |
|
---|
| 369 | // Le macro suivant permettent de simplifier la declaration
|
---|
| 370 | // des operateurs >> << sur les POutPersist et PInPersist
|
---|
[219] | 371 | #define RAWPERSISTIO(_Type_,_xtyp_) \
|
---|
[241] | 372 | inline POutPersist& operator << (POutPersist& c, _Type_ const& data) \
|
---|
| 373 | { \
|
---|
| 374 | c.Put##_xtyp_(data); \
|
---|
| 375 | return c; \
|
---|
| 376 | } \
|
---|
[219] | 377 | \
|
---|
[241] | 378 | inline PInPersist& operator >> (PInPersist& c, _Type_& data) \
|
---|
| 379 | { \
|
---|
| 380 | c.Get##_xtyp_(data); \
|
---|
| 381 | return c; \
|
---|
| 382 | }
|
---|
[219] | 383 |
|
---|
[2441] | 384 | // On utilise le macro RAWPERSISTIO pour declarer POutPersist << et PInPersist >>
|
---|
| 385 | // pour les types de base r_4 r_8 int_4 int_8 ...
|
---|
[241] | 386 | RAWPERSISTIO(int_4,I4);
|
---|
| 387 | RAWPERSISTIO(uint_4,U4);
|
---|
| 388 | RAWPERSISTIO(int_2,I2);
|
---|
| 389 | RAWPERSISTIO(uint_2,U2);
|
---|
| 390 | RAWPERSISTIO(char,Byte);
|
---|
| 391 | RAWPERSISTIO(r_4,R4);
|
---|
| 392 | RAWPERSISTIO(r_8,R8);
|
---|
[2441] | 393 | RAWPERSISTIO(complex<r_4>,Z4);
|
---|
| 394 | RAWPERSISTIO(complex<r_8>,Z8);
|
---|
| 395 | RAWPERSISTIO(string,Str);
|
---|
[241] | 396 |
|
---|
[219] | 397 | #if 0
|
---|
| 398 | #define STRUCTPERSISTIO(_Type_, _field_, _size_) \
|
---|
[241] | 399 | inline POutPersist& operator << (POutPersist& c, _Type_ const& data) \
|
---|
| 400 | { \
|
---|
| 401 | c.PutBytes(&data._field_, _size_); \
|
---|
| 402 | return c; \
|
---|
| 403 | } \
|
---|
[219] | 404 | \
|
---|
[241] | 405 | inline PInPersist& operator >> (PInPersist& c, _Type_& data) \
|
---|
| 406 | { \
|
---|
| 407 | c.GetBytes(&data._field_, _size_); \
|
---|
| 408 | return c; \
|
---|
| 409 | }
|
---|
[219] | 410 |
|
---|
| 411 | #endif
|
---|
[241] | 412 |
|
---|
[802] | 413 |
|
---|
| 414 | // --- Cela risque d'etre dangereux --- On le laisse au niveau des DataObj
|
---|
| 415 | // Reza 24/3/2000
|
---|
| 416 | // inline POutPersist& operator << (POutPersist& c, PPersist const& obj)
|
---|
| 417 | // {
|
---|
| 418 | // obj.Write(c);
|
---|
| 419 | // return c;
|
---|
| 420 | // }
|
---|
[241] | 421 |
|
---|
[802] | 422 | // inline PInPersist& operator >> (PInPersist& c, PPersist& obj)
|
---|
| 423 | // {
|
---|
| 424 | // obj.Read(c);
|
---|
| 425 | // return c;
|
---|
| 426 | // }
|
---|
| 427 |
|
---|
[241] | 428 | // Utility class to
|
---|
| 429 | // - compute the class ID from a MD5 hash of the class name
|
---|
| 430 | // - register classes with PIOPersist, through PPRegister macro
|
---|
[895] | 431 |
|
---|
| 432 | //! template class for handling the PPersist registration mechanism.
|
---|
[241] | 433 | template <class T>
|
---|
| 434 | class PPersistRegistrar {
|
---|
| 435 | public:
|
---|
| 436 | static PPersist* Create() {return new T();}
|
---|
[802] | 437 | static void Register(string id) { PIOPersist::RegisterPPHandlerClass(Hash(id), typeid(T).name(), Create); }
|
---|
[576] | 438 | static uint_8 Hash(string id) {
|
---|
| 439 | return PIOPersist::Hash(id);
|
---|
[241] | 440 | }
|
---|
| 441 | };
|
---|
| 442 |
|
---|
[576] | 443 | #define PPRegister(className) PPersistRegistrar<className>::Register(#className);
|
---|
[802] | 444 | #define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name());
|
---|
[754] | 445 |
|
---|
[241] | 446 | } // namespace
|
---|
[219] | 447 |
|
---|
| 448 | #endif
|
---|