// This may look like C code, but it is really -*- C++ -*- // Classe de gestion des I/O fichiers des objets // R.Ansari 04/99 // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA #ifndef OBJFILEIO_H_SEEN #define OBJFILEIO_H_SEEN #include "machdefs.h" #include #include "anydataobj.h" #include "ppersist.h" namespace SOPHYA { template class ObjFileIO : public PPersist { public : ObjFileIO() { dobj=NULL; ownobj=true; } ObjFileIO(T * obj) { dobj = obj; ownobj=false; } virtual ~ObjFileIO() { if (ownobj && dobj) delete dobj; } virtual AnyDataObj* DataObj() { return(dobj); } virtual void SetDataObj(AnyDataObj & o) { T * po = dynamic_cast< T * >(& o); if (po == NULL) { char buff[160]; sprintf(buff,"ObjFileIO::SetDataObj(%s) - Object type error ! ", typeid(o).name()); throw TypeMismatchExc(PExcLongMessage(buff)); } if (ownobj && dobj) delete dobj; dobj = po; ownobj = false; } inline operator T&() { return(*dobj); } protected : virtual void ReadSelf(PInPersist&); virtual void WriteSelf(POutPersist&) const; T * dobj; bool ownobj; // True si dobj obtenu par new }; /* template inline POutPersist& operator << (POutPersist& os, T const & obj) { ObjFileIO fio((const_cast)&obj); fio.Write(os); return(os); } template inline PInPersist& operator >> (PInPersist& is, T & obj) { ObjFileIO fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); } */ } // Fin namespace #endif