Last change
on this file since 1779 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
|
Rev | Line | |
---|
[269] | 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 |
|
---|
[552] | 13 | namespace SOPHYA {
|
---|
[269] | 14 |
|
---|
| 15 |
|
---|
| 16 | template <class T>
|
---|
| 17 | class ObjFileIO : public PPersist {
|
---|
| 18 |
|
---|
| 19 | public :
|
---|
[277] | 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; }
|
---|
[269] | 26 |
|
---|
| 27 | virtual AnyDataObj* DataObj() { return(dobj); }
|
---|
[754] | 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 |
|
---|
[269] | 32 | inline operator T() { return(*dobj); }
|
---|
| 33 |
|
---|
| 34 | protected :
|
---|
| 35 | virtual void ReadSelf(PInPersist&);
|
---|
| 36 | virtual void WriteSelf(POutPersist&) const;
|
---|
| 37 |
|
---|
| 38 | T * dobj;
|
---|
[277] | 39 | bool ownobj; // True si dobj obtenu par new
|
---|
[269] | 40 | };
|
---|
| 41 |
|
---|
[277] | 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); }
|
---|
[269] | 46 |
|
---|
[277] | 47 | template <class T>
|
---|
| 48 | inline PInPersist& operator >> (PInPersist& is, T & obj)
|
---|
| 49 | { ObjFileIO<T> fio(&obj); fio.Read(is); return(is); }
|
---|
| 50 | */
|
---|
[269] | 51 |
|
---|
| 52 |
|
---|
| 53 | } // Fin namespace
|
---|
| 54 |
|
---|
| 55 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.