| Rev | Line |   | 
|---|
| [658] | 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
 | 2 | // Classe de gestion des I/O fichiers des objets 
 | 
|---|
 | 3 | //                          R.Ansari          04/99
 | 
|---|
 | 4 | // LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 | #ifndef OBJFILEIO_H_SEEN
 | 
|---|
 | 7 | #define OBJFILEIO_H_SEEN
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | #include "machdefs.h"
 | 
|---|
 | 10 | #include "anydataobj.h"
 | 
|---|
 | 11 | #include "ppersist.h"
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | namespace SOPHYA {
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | template <class T>
 | 
|---|
 | 17 | class ObjFileIO : public PPersist {
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | public :
 | 
|---|
 | 20 |             ObjFileIO() { dobj=new T; ownobj=true; }
 | 
|---|
 | 21 |             ObjFileIO(string const & filename) 
 | 
|---|
 | 22 |                         { dobj=new T; ownobj=true; Read(filename); }
 | 
|---|
 | 23 |             ObjFileIO(const T & obj) { dobj = new T(obj); ownobj=true; }
 | 
|---|
 | 24 |             ObjFileIO(T * obj) { dobj = obj; ownobj=false; }
 | 
|---|
 | 25 |   virtual   ~ObjFileIO() { if (ownobj && dobj) delete dobj; }
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 |   virtual   AnyDataObj* DataObj() { return(dobj); }
 | 
|---|
 | 28 |   inline operator T() { return(*dobj); }
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | protected :
 | 
|---|
 | 31 |   virtual void       ReadSelf(PInPersist&);           
 | 
|---|
 | 32 |   virtual void       WriteSelf(POutPersist&) const;  
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |   T * dobj;
 | 
|---|
 | 35 |   bool ownobj;       // True si dobj obtenu par new
 | 
|---|
 | 36 | };
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | /*
 | 
|---|
 | 39 | template <class T>
 | 
|---|
 | 40 | inline POutPersist& operator << (POutPersist& os, T const & obj)
 | 
|---|
 | 41 | { ObjFileIO<T> fio((const_cast)&obj);  fio.Write(os);  return(os); } 
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | template <class T>
 | 
|---|
 | 44 | inline PInPersist& operator >> (PInPersist& is, T & obj)
 | 
|---|
 | 45 | { ObjFileIO<T> fio(&obj);  fio.Read(is);  return(is); }  
 | 
|---|
 | 46 | */
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | } // Fin namespace
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | #endif
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.