CMS 3D CMS Logo

SerializeXML.h

Go to the documentation of this file.
00001 // Flag Store Manager (store in external file/stream). Serialize in XML 
00002 // format.
00003 // 
00004 // Author : Samvel Khalatian (samvel at fnal dot gov)
00005 // Created: 06/01/07
00006 // License: GPL
00007 
00008 #ifndef SERIALIZE_XML
00009 #define SERIALIZE_XML
00010 
00011 #include <iosfwd>
00012 
00013 class FlagXML;
00014 
00015 // --[ XML ARCHIVE MANAGER ]---------------------------------------------------
00016 
00022 class SerializeXML {
00023   public:
00024     SerializeXML();
00025     ~SerializeXML();
00026 
00040     bool write( std::ostream &roOut, const FlagXML &roFLAGXML) const;
00041 
00064     template<class T> T *read( std::istream &roIn);
00065 
00073     inline FlagXML *getFlag() { return poFlagXML_; }
00074 
00075   private:
00086     void readFlag( FlagXML *poFlagXML, std::istream &roIn);
00087 
00088     FlagXML *poFlagXML_;
00089 };
00090 
00091 template<class T> T *SerializeXML::read( std::istream &roIn) {
00092   if( poFlagXML_) {
00093     delete poFlagXML_;
00094     poFlagXML_ = 0;
00095   }
00096 
00097   // [Note: Object will be deleted by SerializeXML (!)]
00098   T *poT = new T();
00099 
00100   // Check if this is actually child class of FlagXML
00101   if( FlagXML *poFlagXML = dynamic_cast<FlagXML *>( poT)) {
00102 
00103     // Attempt to read flag from tree
00104     try {
00105       readFlag( poFlagXML, roIn);
00106 
00107       poFlagXML_ = poFlagXML;
00108     } catch( ...) { 
00109       // Failed: maybe stream contains other flag saved - not T?
00110       delete poT;
00111       poT = 0;
00112     }
00113   } else {
00114     // Not a child
00115     delete poT;
00116     poT = 0;
00117   }
00118 
00119   return poT;
00120 }
00121 
00122 #endif // SERIALIZE_XML

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