1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 |
|
---|
3 | #ifndef PPERSIST_H_SEEN
|
---|
4 | #define PPERSIST_H_SEEN
|
---|
5 |
|
---|
6 | // Flat file persistance, similar to Java serialization
|
---|
7 | //
|
---|
8 | // E. Aubourg CEA DAPNIA/SPP 1999
|
---|
9 | // R. Ansari LAL IN2P3/CNRS 03/2000
|
---|
10 |
|
---|
11 |
|
---|
12 | #include "machdefs.h"
|
---|
13 | #include "pexceptions.h"
|
---|
14 | #include "gnumd5.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | #include <time.h>
|
---|
18 |
|
---|
19 | #include <complex>
|
---|
20 | #include <string>
|
---|
21 | #include <map>
|
---|
22 | #include <vector>
|
---|
23 | #include <typeinfo>
|
---|
24 |
|
---|
25 |
|
---|
26 | // Classe de base pour les objets qui peuvent devenir PPersist
|
---|
27 |
|
---|
28 | namespace SOPHYA {
|
---|
29 |
|
---|
30 | class AnyDataObj;
|
---|
31 |
|
---|
32 | class PIOPersist;
|
---|
33 | class PInPersist;
|
---|
34 | class POutPersist;
|
---|
35 | class PPersist;
|
---|
36 |
|
---|
37 | //! Persistent (delegate or mixin) base class
|
---|
38 | class PPersist {
|
---|
39 | public:
|
---|
40 | virtual ~PPersist() {}
|
---|
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); }
|
---|
44 |
|
---|
45 | void Write(string const& fn) const;
|
---|
46 | void Read(string const& fn);
|
---|
47 |
|
---|
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);
|
---|
52 |
|
---|
53 | virtual AnyDataObj* DataObj()=0; // Retourne l'objet reel
|
---|
54 | virtual void SetDataObj(AnyDataObj &)=0;
|
---|
55 |
|
---|
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
|
---|
61 | protected:
|
---|
62 | virtual void ReadSelf(PInPersist&)=0;
|
---|
63 | virtual void WriteSelf(POutPersist&) const=0;
|
---|
64 |
|
---|
65 | friend class PInPersist;
|
---|
66 | friend class POutPersist;
|
---|
67 | };
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | //! Ancestor for PInPersist and POutPersist PPF streams.
|
---|
72 | // Handles (statically) the registration of classes.
|
---|
73 |
|
---|
74 | class PIOPersist {
|
---|
75 | public:
|
---|
76 | enum {PPS_NATIVE = -1, PPS_LITTLE_ENDIAN = 0, PPS_BIG_ENDIAN = 1};
|
---|
77 | typedef PPersist* (*ClassCreatorFunc)();
|
---|
78 |
|
---|
79 | static void RegisterPPHandlerClass(uint_8 classId, string ppclass_name, ClassCreatorFunc f);
|
---|
80 | static void RegisterDataObjClass(uint_8 classId, string class_name);
|
---|
81 |
|
---|
82 | static ClassCreatorFunc FindCreatorFunc(uint_8 classId);
|
---|
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 |
|
---|
91 | static uint_8 Hash(string const& typname);
|
---|
92 | static MD5_CONTEXT ctx;
|
---|
93 |
|
---|
94 | static void Initialize(); // Pour initialiser classList
|
---|
95 |
|
---|
96 | int Version() {return version;} // PIn/OutPersist version number
|
---|
97 | string FileName() { return filename; } // Retourne le nom de fichier
|
---|
98 |
|
---|
99 | private:
|
---|
100 |
|
---|
101 | typedef map<uint_8, ClassCreatorFunc, less<uint_8> > ClassList;
|
---|
102 | // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99
|
---|
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)
|
---|
106 |
|
---|
107 | protected:
|
---|
108 |
|
---|
109 | enum {PPS_NULL = 0, // this is a null object
|
---|
110 | PPS_STRING = 1, // string, length (4b) + data
|
---|
111 | PPS_OBJECT = 2, // classId, data...
|
---|
112 | PPS_REFERENCE = 3, // objectId
|
---|
113 | PPS_NAMETAG_TABLE = 4, // Name tag table (Written at the end of file/stream)
|
---|
114 | PPS_EOF = 5, // Just before tag infomation, offset to PPS_TAG
|
---|
115 | PPS_ENDOBJECT = 6, // marks the end of a given object information
|
---|
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)
|
---|
119 | PPS_SIMPLE = 16, // 16 + number of bytes, up to 8 bytes
|
---|
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 | };
|
---|
123 | // The following values are used with PPS_SIMPLE and PPS_SIMPLE_ARRAY (Using OR)
|
---|
124 | enum {PPS_DATATYPE_CHAR = 0, // 0 : DataType=character
|
---|
125 | PPS_DATATYPE_FLOAT = 64, // 64 : DataType=float
|
---|
126 | PPS_DATATYPE_COMPLEX = 65, // 65 : DataType=complex
|
---|
127 | PPS_DATATYPE_INTEGER = 128, // 128 :DataType=integer
|
---|
128 | PPS_DATATYPE_UNSIGNED = 192 // 192 :DataType=Unsigned integer
|
---|
129 | };
|
---|
130 |
|
---|
131 | map<string, int_8> tags;
|
---|
132 | string filename;
|
---|
133 | int version; // PPersist(In/Out) version
|
---|
134 | };
|
---|
135 |
|
---|
136 |
|
---|
137 | // TBD : use hash tables instead of maps. Check hashtbl status in STL.
|
---|
138 |
|
---|
139 | //! Input stream for PPersit objects.
|
---|
140 | class PInPersist : public PIOPersist {
|
---|
141 | public:
|
---|
142 | PInPersist(string const& flnm, bool scan=true);
|
---|
143 | ~PInPersist();
|
---|
144 |
|
---|
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); }
|
---|
149 | int NbTags();
|
---|
150 | bool GotoTagNum(int itag); // 0..NbTags-1
|
---|
151 | string GetTagName(int itag); // 0..NbTags-1
|
---|
152 | string GetTagClassName(int itag); // 0..NbTags-1
|
---|
153 | vector<string> const & GetTagNames();
|
---|
154 |
|
---|
155 | // Lecture donnees de base et tableaux de donnees de base
|
---|
156 | // Basic data type (and corresponding arrays) reading
|
---|
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);
|
---|
163 | void GetI1 (int_1&);
|
---|
164 | void GetI1s (int_1*, size_t);
|
---|
165 | void GetU1 (uint_1&);
|
---|
166 | void GetU1s (uint_1*, size_t);
|
---|
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&);
|
---|
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);
|
---|
185 |
|
---|
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 |
|
---|
218 | // Object Reading
|
---|
219 | PPersist* ReadObject();
|
---|
220 | void GetObject(AnyDataObj & o);
|
---|
221 | void GetObject(AnyDataObj & o, string tagname);
|
---|
222 | PPersist* GetPPObject(AnyDataObj * po=NULL);
|
---|
223 |
|
---|
224 | time_t CreationDate() { return creationdate; }
|
---|
225 | string CreationDateStr();
|
---|
226 |
|
---|
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 |
|
---|
235 | protected:
|
---|
236 | void CheckTag (short datasz, short datatype);
|
---|
237 | void CheckArrayTag(short datasz, size_t sz, short datatype);
|
---|
238 | void GetTypeTag (unsigned char& c);
|
---|
239 | void GetRawByte (char& c);
|
---|
240 | void GetRawUByte (unsigned char& c);
|
---|
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&);
|
---|
246 |
|
---|
247 | void Scan();
|
---|
248 |
|
---|
249 | istream* s;
|
---|
250 |
|
---|
251 | bool bigEndian;
|
---|
252 |
|
---|
253 | time_t creationdate;
|
---|
254 |
|
---|
255 | // already read objects
|
---|
256 | typedef map<uint_8, PPersist * > ObjList;
|
---|
257 | ObjList objList;
|
---|
258 | // Si on a fait une lecture non sequentielle -> seqread = false
|
---|
259 | bool seqread;
|
---|
260 | friend class PPersist;
|
---|
261 | };
|
---|
262 |
|
---|
263 | //! Output stream for PPersit objects.
|
---|
264 | class POutPersist : public PIOPersist {
|
---|
265 | public:
|
---|
266 | POutPersist(string const& flnm, int endianness = PPS_NATIVE);
|
---|
267 | ~POutPersist();
|
---|
268 |
|
---|
269 | // Ecriture de tags
|
---|
270 | int_8 WritePositionTag();
|
---|
271 | void WriteNameTag(string const& name);
|
---|
272 | inline void WriteTag(string const& name) { WriteNameTag(name); }
|
---|
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);
|
---|
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);
|
---|
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&);
|
---|
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);
|
---|
302 |
|
---|
303 |
|
---|
304 | void Put(char c) {PutByte(c);}
|
---|
305 | void Put(r_4 x) {PutR4(x);}
|
---|
306 | void Put(r_8 x) {PutR8(x);}
|
---|
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);}
|
---|
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);}
|
---|
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);}
|
---|
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);}
|
---|
330 | void Put(PPersist const* x) {PutPPObject(x);}
|
---|
331 |
|
---|
332 | // Writing a list of position tag table
|
---|
333 | void PutPosTagTable(int_8 const *, size_t);
|
---|
334 | void PutPosTagTable(vector<int_8> const&);
|
---|
335 |
|
---|
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 |
|
---|
343 | protected:
|
---|
344 | ostream* s;
|
---|
345 | bool bigEndian;
|
---|
346 |
|
---|
347 | void PutArrayTag(short datasz, size_t sz, short datatype);
|
---|
348 | void PutRawByte (char);
|
---|
349 | void PutRawUByte (unsigned char);
|
---|
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);
|
---|
356 | uint_8 findObjectId(PPersist const* x, int_8 & pos);
|
---|
357 | uint_8 assignObjectId(PPersist const* x);
|
---|
358 |
|
---|
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;
|
---|
364 | ObjList objList;
|
---|
365 | uint_8 pps_OId; // PPS Object Id
|
---|
366 | };
|
---|
367 |
|
---|
368 |
|
---|
369 | // Le macro suivant permettent de simplifier la declaration
|
---|
370 | // des operateurs >> << sur les POutPersist et PInPersist
|
---|
371 | #define RAWPERSISTIO(_Type_,_xtyp_) \
|
---|
372 | inline POutPersist& operator << (POutPersist& c, _Type_ const& data) \
|
---|
373 | { \
|
---|
374 | c.Put##_xtyp_(data); \
|
---|
375 | return c; \
|
---|
376 | } \
|
---|
377 | \
|
---|
378 | inline PInPersist& operator >> (PInPersist& c, _Type_& data) \
|
---|
379 | { \
|
---|
380 | c.Get##_xtyp_(data); \
|
---|
381 | return c; \
|
---|
382 | }
|
---|
383 |
|
---|
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 ...
|
---|
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);
|
---|
393 | RAWPERSISTIO(complex<r_4>,Z4);
|
---|
394 | RAWPERSISTIO(complex<r_8>,Z8);
|
---|
395 | RAWPERSISTIO(string,Str);
|
---|
396 |
|
---|
397 | #if 0
|
---|
398 | #define STRUCTPERSISTIO(_Type_, _field_, _size_) \
|
---|
399 | inline POutPersist& operator << (POutPersist& c, _Type_ const& data) \
|
---|
400 | { \
|
---|
401 | c.PutBytes(&data._field_, _size_); \
|
---|
402 | return c; \
|
---|
403 | } \
|
---|
404 | \
|
---|
405 | inline PInPersist& operator >> (PInPersist& c, _Type_& data) \
|
---|
406 | { \
|
---|
407 | c.GetBytes(&data._field_, _size_); \
|
---|
408 | return c; \
|
---|
409 | }
|
---|
410 |
|
---|
411 | #endif
|
---|
412 |
|
---|
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 | // }
|
---|
421 |
|
---|
422 | // inline PInPersist& operator >> (PInPersist& c, PPersist& obj)
|
---|
423 | // {
|
---|
424 | // obj.Read(c);
|
---|
425 | // return c;
|
---|
426 | // }
|
---|
427 |
|
---|
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
|
---|
431 |
|
---|
432 | //! template class for handling the PPersist registration mechanism.
|
---|
433 | template <class T>
|
---|
434 | class PPersistRegistrar {
|
---|
435 | public:
|
---|
436 | static PPersist* Create() {return new T();}
|
---|
437 | static void Register(string id) { PIOPersist::RegisterPPHandlerClass(Hash(id), typeid(T).name(), Create); }
|
---|
438 | static uint_8 Hash(string id) {
|
---|
439 | return PIOPersist::Hash(id);
|
---|
440 | }
|
---|
441 | };
|
---|
442 |
|
---|
443 | #define PPRegister(className) PPersistRegistrar<className>::Register(#className);
|
---|
444 | #define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name());
|
---|
445 |
|
---|
446 | } // namespace
|
---|
447 |
|
---|
448 | #endif
|
---|