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


Ignore:
Timestamp:
Dec 4, 2003, 5:43:27 PM (22 years ago)
Author:
ansari
Message:

Separation ppersist.h .cc en deux : ajout de ppfbinstream.h .cc - Reza 4 Dec 2003

File:
1 edited

Legend:

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

    r2459 r2475  
    99// R. Ansari      LAL IN2P3/CNRS  03/2000
    1010
     11// -------------------- Historique -----------------------
     12//  Separe en deux (CVS version 1.19 - ppersist.h) 
     13//  Classes PPFBinaryIn/OutputStream ds ppfbinstream.h
     14// -------------------------------------------------------
     15
    1116
    1217#include "machdefs.h"
    1318#include "pexceptions.h"
    1419#include "gnumd5.h"
    15 #include "rawstream.h"
    16 
    17 
    18 #include <time.h>
    19 
    20 #include <complex>
     20#include "ppfbinstream.h"
     21
    2122#include <string>
    2223#include <map>
     
    6768
    6869
    69 //! Ancestor for PInPersist and POutPersist PPF streams.
     70//! Ancestor for PInPersist and POutPersist object serialisation streams.
    7071// Handles (statically) the registration of classes.
    7172
    7273  class PIOPersist {
    7374  public:
    74     enum                         {PPS_NATIVE = -1, PPS_LITTLE_ENDIAN = 0, PPS_BIG_ENDIAN = 1};
    7575    typedef PPersist*            (*ClassCreatorFunc)();
    7676 
     
    9292    static void Initialize();   // Pour initialiser classList
    9393
    94     int    Version() {return version;}  // PIn/OutPersist version number
    95     string FileName() { return filename; }   // Retourne le nom de fichier
    9694
    9795  private:
     
    103101    static map<string, uint_8> * dobjclassNameList;  // PPersist classId = f(DataObjClassName)
    104102
    105   protected:
    106 
    107     enum {PPS_NULL = 0,             // this is a null object
    108           PPS_STRING = 1,           // string, length (4b) + data
    109           PPS_OBJECT = 2,           // classId, data...
    110           PPS_REFERENCE = 3,        // objectId
    111           PPS_NAMETAG_TABLE = 4,    // Name tag table (Written at the end of file/stream)
    112           PPS_EOF = 5,              // Just before tag infomation, offset to PPS_TAG
    113           PPS_ENDOBJECT = 6,        // marks the end of a given object information
    114           PPS_NAMETAG_MARK = 7,     // To have a name tag, position marker in a file
    115           PPS_POSTAG_MARK = 8,      // Position tag mark + 8 bytes (=stream position)
    116           PPS_POSTAG_TABLE = 9,     // Position tag table + 8 bytes (=stream position)
    117           PPS_SIMPLE = 16,          // 16 + number of bytes, up to 8 bytes
    118           PPS_SIMPLE_ARRAY4 = 32,   // 32 + number of bytes, up to 8 bytes, then 4 bytes of length
    119           PPS_SIMPLE_ARRAY8 = 48    // 48 + number of bytes, up to 8 bytes, then 8 bytes of length
    120     };
    121   // The following values are used with PPS_SIMPLE and PPS_SIMPLE_ARRAY (Using OR)
    122    enum  {PPS_DATATYPE_CHAR = 0,        // 0  : DataType=character
    123           PPS_DATATYPE_FLOAT = 64,      // 64 : DataType=float
    124           PPS_DATATYPE_COMPLEX = 65,    // 65 : DataType=complex
    125           PPS_DATATYPE_INTEGER = 128,   // 128 :DataType=integer
    126           PPS_DATATYPE_UNSIGNED = 192   // 192 :DataType=Unsigned integer
    127    };
    128 
    129     map<string, int_8> tags;
    130     string filename;
    131     int version;     // PPersist(In/Out) version
    132103  };
    133104
     
    136107
    137108//! Input stream for PPersit objects.
    138   class PInPersist : public PIOPersist {
     109  class PInPersist : public PPFBinaryInputStream, public PIOPersist {
    139110  public:
    140111    PInPersist(string const& flnm, bool scan=true);
    141     ~PInPersist();
    142 
    143     // Gestion des tags
    144     bool   GotoPositionTag(int_8 pos);
    145     bool   GotoNameTag(string const& name);
    146     int    NbNameTags();
    147     bool   GotoNameTagNum(int itag);  // 0..NbTags-1
    148     string GetTagName(int itag);  // 0..NbTags-1
    149     string GetTagClassName(int itag);  // 0..NbTags-1
    150     vector<string> const &  GetNameTags(); 
    151 
    152     // Saut jusqu'au prochain objet
    153     bool   SkipToNextObject();
    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 
     112    virtual ~PInPersist();
     113
     114    // A faire - Reza Dec 2003
     115    string     GetTagClassName(int itag);
    218116    //   Object Reading
    219117    PPersist*  ReadObject();
     
    222120    PPersist*  GetPPObject(AnyDataObj * po=NULL);
    223121
    224     time_t CreationDate() { return creationdate; }
    225     string CreationDateStr();
    226 
    227     void   AnalyseTags(int lev=0);   // List (all or some) tags ...
    228 
    229122    //  Reza 03/2000
    230123    //  Methodes qui pourraient etre protected, mais doivent etre utilisables par PPersist
     
    234127
    235128  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     RawInOutStream* s;
    250 
    251     bool bigEndian;
    252 
    253     time_t creationdate;
    254129
    255130    // already read objects
    256131    typedef map<uint_8, PPersist * > ObjList;
    257132    ObjList objList;
    258     // Si on a fait une lecture non sequentielle  -> seqread = false
    259     bool seqread;
    260133    friend class PPersist;
    261134  };
    262135
    263136//! Output stream for PPersit objects.
    264   class POutPersist : public PIOPersist {
     137  class POutPersist : public PPFBinaryOutputStream, public PIOPersist {
    265138  public:
    266139    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&);
     140    virtual ~POutPersist();
     141
     142    //    void   Put(PPersist const* x) {PutPPObject(x);}
    335143
    336144    // Objet Write - Ecriture des objets
     
    342150
    343151  protected:
    344     RawInOutStream* 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);
    355152    bool     serializeNullAndRepeat(PPersist const* x);
    356153    uint_8   findObjectId(PPersist const* x, int_8 & pos);
     
    444241#define DObjRegister(ppclassName, className) PIOPersist::RegisterDataObjClass(PIOPersist::Hash(#ppclassName), typeid(className).name());
    445242
    446 } // namespace
     243} // namespace SOPHYA
     244
     245// La classe PPFNameTag facilite la manipulation des Nametag ds les fichiers
     246// PPersist - definie ds ppfnametag.h
     247#include "ppfnametag.h"
     248
    447249
    448250#endif
Note: See TracChangeset for help on using the changeset viewer.