Changeset 802 in Sophya for trunk/SophyaLib/BaseTools/ppersist.h
- Timestamp:
- Apr 3, 2000, 7:32:27 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/ppersist.h
r754 r802 7 7 // 8 8 // E. Aubourg CEA DAPNIA/SPP 1999 9 // R. Ansari LAL IN2P3/CNRS 03/2000 9 10 10 11 … … 51 52 52 53 virtual AnyDataObj* DataObj()=0; // Retourne l'objet reel 53 virtual void SetDataObj(AnyDataObj &)=0; 54 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 55 61 protected: 56 62 virtual void ReadSelf(PInPersist&)=0; 57 virtual void WriteSelf(POutPersist&) const=0; 63 virtual void WriteSelf(POutPersist&) const=0; 58 64 59 65 friend class PInPersist; … … 71 77 typedef PPersist* (*ClassCreatorFunc)(); 72 78 73 static void RegisterClass(uint_8 classId, string typname, ClassCreatorFunc f); 79 static void RegisterPPHandlerClass(uint_8 classId, string ppclass_name, ClassCreatorFunc f); 80 static void RegisterDataObjClass(uint_8 classId, string class_name); 81 74 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 75 91 static uint_8 Hash(string const& typname) { 76 92 md5_init(&ctx); … … 82 98 83 99 static void Initialize(); // Pour initialiser classList 84 static uint_8 getTypeId(string s) {return (*typeids)[s];} 100 101 string FileName() { return filename; } // Retourne le nom de fichier 102 85 103 private: 86 104 87 105 typedef map<uint_8, ClassCreatorFunc, less<uint_8> > ClassList; 88 106 // Pas de createur appele pour objets statiques sur Linux - $CHECK$ Reza 26/04/99 89 static ClassList * classList; 90 static map<string, uint_8> * typeids; 107 static ClassList * ppclassList; // PPersist class list 108 static map<string, uint_8> * ppclassNameList; // PPersist classId = f(PPersistClassName) 109 static map<string, uint_8> * dobjclassNameList; // PPersist classId = f(DataObjClassName) 91 110 92 111 protected: … … 98 117 PPS_TAG = 4, // tag entries 99 118 PPS_EOF = 5, // Just before tag infomation, offset to PPS_TAG 100 PPS_ LINE = 6, // '\n'-terminated, deprecated ?101 PPS_TAG_MARK = 7, // to reset object count when skipped119 PPS_ENDOBJECT = 6, // marks the end of a given object information 120 PPS_TAG_MARK = 7, // To have a name tag, position marker in a file 102 121 PPS_SIMPLE = 16, // 16 + number of bytes, up to 8 bytes 103 PPS_SIMPLE_ARRAY = 32, // 32 + number of bytes, up to 8 bytes, then 2 bytes of length 104 PPS_SIMPLE_ARRAY4 = 64, // 64 + number of bytes, up to 8 bytes, then 4 bytes of length 105 PPS_SIMPLE_ARRAY8 = 128 // 64 + number of bytes, up to 8 bytes, then 8 bytes of length 122 PPS_SIMPLE_ARRAY4 = 32, // 32 + number of bytes, up to 8 bytes, then 4 bytes of length 123 PPS_SIMPLE_ARRAY8 = 48 // 48 + number of bytes, up to 8 bytes, then 8 bytes of length 124 }; 125 // The following values are used PPS_SIMPLE and PPS_SIMPLE_ARRAY (Using OR) 126 enum {PPS_DATATYPE_CHAR = 0, // 0 : DataType=character 127 PPS_DATATYPE_FLOAT = 64, // 64 : DataType=float 128 PPS_DATATYPE_INTEGER = 128, // 128 :DataType=integer 129 PPS_DATATYPE_UNSIGNED = 192 // 192 :DataType=Unsigned integer 106 130 }; 107 131 108 132 map<string, int_8> tags; 133 string filename; 109 134 }; 110 135 … … 121 146 bool GotoTagNum(int itag); // 0..NbTags-1 122 147 string GetTagName(int itag); // 0..NbTags-1 148 string GetTagClassName(int itag); // 0..NbTags-1 123 149 vector<string> const & GetTagNames(); 124 150 … … 163 189 void Get(string& x) {GetStr(x);} 164 190 191 // Object Reading 165 192 PPersist* ReadObject(); 166 193 void GetObject(AnyDataObj & o); 194 void GetObject(AnyDataObj & o, string tagname); 195 PPersist* GetPPObject(AnyDataObj * po=NULL); 167 196 168 197 int Version() {return version;} 169 198 time_t CreationDate() { return creationdate; } 199 string CreationDateStr(); 200 201 void AnalyseTags(int lev=0); // List (all or some) tags ... 202 203 // Reza 03/2000 204 // Methodes qui pourraient etre protected, mais doivent etre utilisables par PPersist 205 void ReadReference(PPersist & ppo); // Fill the ppo object from the reference tag 206 PPersist * ReadReference(); // Creates object from the reference tag 207 void KeepOId(uint_8 oid, PPersist & ppo); // Keeps the ppo in the objList 170 208 171 209 protected: 172 void CheckTag (short datasz );173 void CheckArrayTag(short datasz, size_t sz );174 void GetTypeTag ( char& c);210 void CheckTag (short datasz, short datatype); 211 void CheckArrayTag(short datasz, size_t sz, short datatype); 212 void GetTypeTag (unsigned char& c); 175 213 void GetRawByte (char& c); 214 void GetRawUByte (unsigned char& c); 176 215 void GetRawBytes(void* ptr, size_t bytes); 177 216 void GetRawI2 (int_2&); … … 179 218 void GetRawI8 (int_8&); 180 219 void GetRawU8 (uint_8&); 181 void GetObject(PPersist*); // Object has been allocated with correct type 182 int_4 assignObjectId(PPersist* x); 220 183 221 void Scan(); 184 char* GetCStr(uint_2 l);185 222 186 223 istream* s; … … 191 228 time_t creationdate; 192 229 193 // already read objects , id = order in array194 typedef vector<PPersist*> ObjList;230 // already read objects 231 typedef map<uint_8, PPersist * > ObjList; 195 232 ObjList objList; 196 233 // Si on a fait une lecture non sequentielle -> seqread = false 234 bool seqread; 197 235 friend class PPersist; 198 236 }; … … 225 263 void PutLine (char const* ptr, size_t len=0); // deprecated ? 226 264 void PutStr (string const&); 227 void PutObject (PPersist const*); // Like doing Write(stream) on object 265 void PutPPObject (PPersist const*); // Like doing Write(stream) on PPersist object 266 267 void PutObject(AnyDataObj & o); // Creates the corresponding PPersist Object and call Write() 268 void PutObject(AnyDataObj & o, string tagname); 228 269 229 270 void Put(char c) {PutByte(c);} … … 245 286 void Put(int_8 const* x, size_t n) {PutI8s(x,n);} 246 287 void Put(string const& s) {PutStr(s);} 247 void Put(PPersist const* x) {Put Object(x);}288 void Put(PPersist const* x) {PutPPObject(x);} 248 289 249 290 … … 252 293 bool bigEndian; 253 294 254 void PutArrayTag(short datasz, size_t sz );295 void PutArrayTag(short datasz, size_t sz, short datatype); 255 296 void PutRawByte (char); 297 void PutRawUByte (unsigned char); 256 298 void PutRawI2 (int_2); 257 299 void PutRawI4 (int_4); … … 260 302 void PutRawBytes(void const* ptr, size_t bytes); 261 303 bool serializeNullAndRepeat(PPersist const* x); 262 int_4 findObjectId(PPersist const* x); 263 int_4 assignObjectId(PPersist const* x); 264 265 // already serialized objects 266 typedef map<PPersist const*, int_4, less<PPersist const*> > ObjList; 304 uint_8 findObjectId(PPersist const* x, int_8 & pos); 305 uint_8 assignObjectId(PPersist const* x); 306 307 // objreftag contains the assigned POutStream Object Id and the stream position 308 // of the original written object 309 typedef struct { uint_8 ppsoid; int_8 ppspos; } objreftag; 310 // already serialized objects are kept in a map as a function of the Objects memory Id 311 typedef map<uint_8, objreftag, less<uint_8> > ObjList; 267 312 ObjList objList; 313 uint_8 pps_OId; // PPS Object Id 268 314 }; 269 315 … … 306 352 #endif 307 353 308 inline POutPersist& operator << (POutPersist& c, PPersist const& obj) 309 { 310 obj.Write(c); 311 return c; 312 } 313 314 inline PInPersist& operator >> (PInPersist& c, PPersist& obj) 315 { 316 obj.Read(c); 317 return c; 318 } 319 354 355 // --- Cela risque d'etre dangereux --- On le laisse au niveau des DataObj 356 // Reza 24/3/2000 357 // inline POutPersist& operator << (POutPersist& c, PPersist const& obj) 358 // { 359 // obj.Write(c); 360 // return c; 361 // } 362 363 // inline PInPersist& operator >> (PInPersist& c, PPersist& obj) 364 // { 365 // obj.Read(c); 366 // return c; 367 // } 368 320 369 // Utility class to 321 370 // - compute the class ID from a MD5 hash of the class name … … 326 375 public: 327 376 static PPersist* Create() {return new T();} 328 static void Register(string id) { PIOPersist::RegisterClass(Hash(id),typeid(T).name(),Create);}377 static void Register(string id) { PIOPersist::RegisterPPHandlerClass(Hash(id), typeid(T).name(), Create); } 329 378 static uint_8 Hash(string id) { 330 379 return PIOPersist::Hash(id); … … 333 382 334 383 #define PPRegister(className) PPersistRegistrar<className>::Register(#className); 384 #define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name()); 335 385 336 386 } // namespace
Note:
See TracChangeset
for help on using the changeset viewer.