| 
            Last change
 on this file since 1399 was             754, checked in by ansari, 26 years ago           | 
        
        
          
            
Restruction de Sophya en modules plus petit (TArray , SkyMap, HiStats, ...) 
 
Reza 2/3/2000 
 
 
 
           | 
        
        
          | 
            File size:
            1.5 KB
           | 
        
      
      
| Line |   | 
|---|
| 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 |   virtual   void        SetDataObj(AnyDataObj & o) 
 | 
|---|
| 29 |           {  T * po = dynamic_cast< T * >(& o); if (po == NULL) return;
 | 
|---|
| 30 |           if (ownobj && dobj) delete dobj;  dobj = po; ownobj = false; }    
 | 
|---|
| 31 | 
 | 
|---|
| 32 |   inline operator T() { return(*dobj); }
 | 
|---|
| 33 | 
 | 
|---|
| 34 | protected :
 | 
|---|
| 35 |   virtual void       ReadSelf(PInPersist&);           
 | 
|---|
| 36 |   virtual void       WriteSelf(POutPersist&) const;  
 | 
|---|
| 37 | 
 | 
|---|
| 38 |   T * dobj;
 | 
|---|
| 39 |   bool ownobj;       // True si dobj obtenu par new
 | 
|---|
| 40 | };
 | 
|---|
| 41 | 
 | 
|---|
| 42 | /*
 | 
|---|
| 43 | template <class T>
 | 
|---|
| 44 | inline POutPersist& operator << (POutPersist& os, T const & obj)
 | 
|---|
| 45 | { ObjFileIO<T> fio((const_cast)&obj);  fio.Write(os);  return(os); } 
 | 
|---|
| 46 | 
 | 
|---|
| 47 | template <class T>
 | 
|---|
| 48 | inline PInPersist& operator >> (PInPersist& is, T & obj)
 | 
|---|
| 49 | { ObjFileIO<T> fio(&obj);  fio.Read(is);  return(is); }  
 | 
|---|
| 50 | */
 | 
|---|
| 51 | 
 | 
|---|
| 52 | 
 | 
|---|
| 53 | } // Fin namespace
 | 
|---|
| 54 | 
 | 
|---|
| 55 | #endif
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.