Last change
on this file since 2739 was 2698, checked in by ansari, 20 years ago |
1/ Simplification de la classe gestionnairee PPersist ObjFile<T> (objfio.h)
2/ Ajout DECL_TEMP_SPEC ds ppftpointerio.h
3/ Nom specifique pour methode SegDBInterface::GetSegment() const devenu
SegDBInterface::GetCstSegment() const pour eviter l'appel a la methode non const
et adapatation classes derivees (segdatablock.h et swsegdb.h)
4/ Ajout SkipToNextObjet() ds PInPersist::ReadObject() (ppersist.cc) et protection contre pointeur NULL -> new DVList pour la lecture PPersist de DVList
Reza - 27 Avril 2005
|
File size:
1.6 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"
|
---|
[1981] | 10 | #include <stdio.h>
|
---|
[269] | 11 | #include "anydataobj.h"
|
---|
| 12 | #include "ppersist.h"
|
---|
| 13 |
|
---|
[552] | 14 | namespace SOPHYA {
|
---|
[269] | 15 |
|
---|
| 16 |
|
---|
| 17 | template <class T>
|
---|
| 18 | class ObjFileIO : public PPersist {
|
---|
| 19 |
|
---|
| 20 | public :
|
---|
[2698] | 21 | ObjFileIO() { dobj=NULL; ownobj=true; }
|
---|
[277] | 22 | ObjFileIO(T * obj) { dobj = obj; ownobj=false; }
|
---|
| 23 | virtual ~ObjFileIO() { if (ownobj && dobj) delete dobj; }
|
---|
[269] | 24 |
|
---|
| 25 | virtual AnyDataObj* DataObj() { return(dobj); }
|
---|
[754] | 26 | virtual void SetDataObj(AnyDataObj & o)
|
---|
[1967] | 27 | {
|
---|
| 28 | T * po = dynamic_cast< T * >(& o);
|
---|
| 29 | if (po == NULL) {
|
---|
| 30 | char buff[160];
|
---|
| 31 | sprintf(buff,"ObjFileIO<T>::SetDataObj(%s) - Object type error ! ",
|
---|
| 32 | typeid(o).name());
|
---|
| 33 | throw TypeMismatchExc(PExcLongMessage(buff));
|
---|
| 34 | }
|
---|
| 35 | if (ownobj && dobj) delete dobj; dobj = po; ownobj = false;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[2698] | 38 | inline operator T&() { return(*dobj); }
|
---|
[269] | 39 |
|
---|
| 40 | protected :
|
---|
| 41 | virtual void ReadSelf(PInPersist&);
|
---|
| 42 | virtual void WriteSelf(POutPersist&) const;
|
---|
| 43 |
|
---|
| 44 | T * dobj;
|
---|
[277] | 45 | bool ownobj; // True si dobj obtenu par new
|
---|
[269] | 46 | };
|
---|
| 47 |
|
---|
[277] | 48 | /*
|
---|
| 49 | template <class T>
|
---|
| 50 | inline POutPersist& operator << (POutPersist& os, T const & obj)
|
---|
| 51 | { ObjFileIO<T> fio((const_cast)&obj); fio.Write(os); return(os); }
|
---|
[269] | 52 |
|
---|
[277] | 53 | template <class T>
|
---|
| 54 | inline PInPersist& operator >> (PInPersist& is, T & obj)
|
---|
[2477] | 55 | { ObjFileIO<T> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
[277] | 56 | */
|
---|
[269] | 57 |
|
---|
| 58 |
|
---|
| 59 | } // Fin namespace
|
---|
| 60 |
|
---|
| 61 | #endif
|
---|
Note:
See
TracBrowser
for help on using the repository browser.