Changeset 802 in Sophya for trunk/SophyaLib/BaseTools/ppersist.h


Ignore:
Timestamp:
Apr 3, 2000, 7:32:27 PM (25 years ago)
Author:
ansari
Message:

Mise au point du nouveau schema (Version=2) de PPersist - Mise en place

de tag complet pour toutes les donnees/objets ecrits - Gestion a peu
pres correct des objets references plusieurs fois, ecrit une seule fois.
Mecanisme d'enregistrement pour les DataObject associe et Methodes
(PutObject/GetObjet) facilitant l'ecriture/lecture de DataObject.
Separation du fichier de la classe FIO_NDataBlock<T>.

Reza03/04/2000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/ppersist.h

    r754 r802  
    77//
    88// E. Aubourg     CEA DAPNIA/SPP  1999
     9// R. Ansari      LAL IN2P3/CNRS  03/2000
    910
    1011
     
    5152
    5253    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
    5561  protected: 
    5662    virtual void       ReadSelf(PInPersist&)=0;           
    57     virtual void       WriteSelf(POutPersist&) const=0; 
     63    virtual void       WriteSelf(POutPersist&) const=0;
    5864
    5965    friend class       PInPersist;
     
    7177    typedef PPersist*            (*ClassCreatorFunc)();
    7278 
    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
    7482    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
    7591    static uint_8 Hash(string const& typname) {
    7692        md5_init(&ctx);
     
    8298 
    8399    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
    85103  private:
    86104
    87105    typedef map<uint_8, ClassCreatorFunc, less<uint_8> > ClassList; 
    88106    // 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)
    91110
    92111  protected:
     
    98117          PPS_TAG = 4,              // tag entries
    99118          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 skipped
     119          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
    102121          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
    106130   };
    107131
    108132    map<string, int_8> tags;
     133    string filename;
    109134  };
    110135
     
    121146    bool   GotoTagNum(int itag);  // 0..NbTags-1
    122147    string GetTagName(int itag);  // 0..NbTags-1
     148    string GetTagClassName(int itag);  // 0..NbTags-1
    123149    vector<string> const &  GetTagNames(); 
    124150
     
    163189    void   Get(string& x) {GetStr(x);}
    164190 
     191    //   Object Reading
    165192    PPersist*  ReadObject();
    166 
     193    void       GetObject(AnyDataObj & o);
     194    void       GetObject(AnyDataObj & o, string  tagname);
     195    PPersist*  GetPPObject(AnyDataObj * po=NULL);
    167196
    168197    int    Version() {return version;}
    169198    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
    170208
    171209  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);
    175213    void   GetRawByte (char& c);
     214    void   GetRawUByte (unsigned char& c);
    176215    void   GetRawBytes(void* ptr, size_t bytes);
    177216    void   GetRawI2   (int_2&);
     
    179218    void   GetRawI8   (int_8&);
    180219    void   GetRawU8   (uint_8&);
    181     void   GetObject(PPersist*);               // Object has been allocated with correct type
    182     int_4  assignObjectId(PPersist* x);
     220
    183221    void   Scan();
    184     char*  GetCStr(uint_2 l);
    185222
    186223    istream* s;
     
    191228    time_t creationdate;
    192229
    193     // already read objects, id = order in array
    194     typedef vector<PPersist*> ObjList;
     230    // already read objects
     231    typedef map<uint_8, PPersist * > ObjList;
    195232    ObjList objList;
    196 
     233    // Si on a fait une lecture non sequentielle  -> seqread = false
     234    bool seqread;
    197235    friend class PPersist;
    198236  };
     
    225263    void PutLine (char const* ptr, size_t len=0); // deprecated ?
    226264    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);
    228269
    229270    void   Put(char   c) {PutByte(c);}
     
    245286    void   Put(int_8 const*  x, size_t n) {PutI8s(x,n);}
    246287    void   Put(string const& s) {PutStr(s);}
    247     void   Put(PPersist const* x) {PutObject(x);}
     288    void   Put(PPersist const* x) {PutPPObject(x);}
    248289
    249290
     
    252293    bool bigEndian;
    253294
    254     void     PutArrayTag(short datasz, size_t sz);
     295    void     PutArrayTag(short datasz, size_t sz, short datatype);
    255296    void     PutRawByte (char);
     297    void     PutRawUByte (unsigned char);
    256298    void     PutRawI2   (int_2);
    257299    void     PutRawI4   (int_4);
     
    260302    void     PutRawBytes(void const* ptr, size_t bytes);
    261303    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;
    267312    ObjList objList;
     313    uint_8 pps_OId;    // PPS Object Id
    268314  };
    269315 
     
    306352#endif
    307353 
    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
    320369  // Utility class to
    321370  //   - compute the class ID from a MD5 hash of the class name
     
    326375    public:
    327376      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); }
    329378      static uint_8 Hash(string id) {
    330379        return PIOPersist::Hash(id);
     
    333382 
    334383#define PPRegister(className) PPersistRegistrar<className>::Register(#className);
     384#define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name());
    335385
    336386} // namespace
Note: See TracChangeset for help on using the changeset viewer.