CMS 3D CMS Logo

SerializeBase.h

Go to the documentation of this file.
00001 // Author : Samvel Khalatian (samvel at fnal dot gov)
00002 // Created: 07/25/07
00003 // License: GPL
00004 
00005 #ifndef SERIALIZE_BASE
00006 #define SERIALIZE_BASE
00007 
00008 #include <iosfwd>
00009 #include <istream>
00010 
00011 #include <boost/archive/archive_exception.hpp>
00012 
00013 class FlagTxt;
00014 
00015 // --[ BASE ARCHIVE MANAGER ]--------------------------------------------------
00016 
00022 class SerializeBase {
00023   public:
00024     SerializeBase();
00025     virtual ~SerializeBase();
00026 
00040     bool write( std::ostream &roOut, const FlagTxt &roFLAGTXT) const;
00041 
00064     template<class T> T *read( std::istream &roIn);
00065 
00073     inline FlagTxt *getFlag() { return poFlagTxt_; }
00074 
00075   private:
00084     virtual void writeFlag( std::ostream &roOut, 
00085                             const FlagTxt &roFLAGTXT) const = 0;
00086 
00098     virtual void readFlag ( FlagTxt *poFlagTxt, std::istream &roIn) = 0;
00099 
00100     FlagTxt *poFlagTxt_;
00101 };
00102 
00103 template<class T> T *SerializeBase::read( std::istream &roIn) {
00104   if( poFlagTxt_) {
00105     delete poFlagTxt_;
00106     poFlagTxt_ = 0;
00107   }
00108 
00109   // [Note: Object will be deleted by SerializeTxt (!)]
00110   T *poT = new T();
00111 
00112   // Check if this is actually child class of FlagTxt
00113   if( FlagTxt *poFlagTxt = dynamic_cast<FlagTxt *>( poT)) {
00114 
00115     // Attempt to read flag from tree
00116     try {
00117       readFlag( poFlagTxt, roIn);
00118 
00119       poFlagTxt_ = poFlagTxt;
00120     } catch( ...) { 
00121       // Failed: maybe stream contains other flag saved - not T?
00122       delete poT;
00123       poT = 0;
00124     }
00125   } else {
00126     // Not a child
00127     delete poT;
00128     poT = 0;
00129   }
00130 
00131   return poT;
00132 }
00133 
00134 #endif // SERIALIZE_BASE

Generated on Tue Jun 9 17:25:52 2009 for CMSSW by  doxygen 1.5.4