Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

ISStreamerWrapper.h

00001 #ifndef SCT_ISSTREAMERWRAPPER_H
00002 #define SCT_ISSTREAMERWRAPPER_H
00003 #include "Streamer.h"
00004 #include "LogicErrors.h"
00005 #include "IoExceptions.h"
00006 #include "ISOStreamWrapper.h"
00007 #include "ISIStreamWrapper.h"
00008 #include "ISSerializableWrapper.h"
00009 #include "is/isinfo.h"
00010 
00011 namespace Sct{
00012 class OStream;
00013 class IStream;
00014 class Streamable;
00015 class IOManager;
00032 template<class T>
00033 class ISStreamerWrapper : public virtual Streamer {
00034  public:
00038   virtual void write(OStream& out, const Streamable& ob, const IOManager& manager) const;
00039 
00043   virtual shared_ptr<Streamable> read(IStream& in, const IOManager& manager) const;
00044 
00048   virtual void read(IStream& in, Streamable& ob, const IOManager& manager) const;
00049 
00053   ISStreamerWrapper() {; }
00054 
00057   virtual unsigned getVersion() const throw();
00058  protected:
00063   class InnerClass : public ISInfo {
00064   public:
00066     InnerClass(ISInfo& ob) : m_ob(ob) {}
00068     virtual void publishGuts( ISostream & out ) {m_ob.publishGuts(out);}
00070     virtual void refreshGuts( ISistream & in ) {m_ob.refreshGuts(in);}
00071   private:
00072     InnerClass();
00073     ISInfo& m_ob;
00074   };
00075 };
00076 
00078 
00079 template<class T>
00080 inline unsigned ISStreamerWrapper<T>::getVersion() const throw() {
00081   T t;
00082   return t.version;
00083 }
00084 
00085 template<class T>
00086 inline void ISStreamerWrapper<T>::write(OStream& out, const Streamable& ob, const IOManager& manager) const {
00087   // wrap the stream
00088   //#warning probable slow memory leak forced by using Sct/isstream_bugfix.h
00089   ISOStreamWrapper isosw(out);
00090 
00091   // cast the Streamable as a ISSerializableWrapper
00092   const ISSerializableWrapper<T>& wrapper = 
00093     dynamic_cast <const ISSerializableWrapper<T>&> ( ob );
00094 
00095   // use the inner class to make the publishGuts method public:
00096   InnerClass inner( const_cast<T&> ( *wrapper.getWrappedObject()) );
00097 
00098   // use the publishGuts method to stream.
00099   inner.publishGuts(isosw);
00100 }
00101 
00102 template<class T> 
00103  inline void ISStreamerWrapper<T>::read(IStream& in, Sct::Streamable& ob, const IOManager& manager) const{
00104     // cast the Streamable as a ISSerializableWrapper
00105   const ISSerializableWrapper<T>& wrapper = 
00106     dynamic_cast <const ISSerializableWrapper<T>&> ( ob );
00107 
00108    // make an InnerClass to make the refreshGuts public:
00109   InnerClass inner( const_cast<T&> (*wrapper.getWrappedObject()) );
00110 
00111   //#warning forced slow memory leak below. The ISIStreamWrapper destructor has problems because we have kludged the ISistream in file isstream_bugfix.h
00112    // convert the stream
00113   ISIStreamWrapper isisw(in);
00114   
00115    // use the refreshGuts to update.
00116   inner.refreshGuts(isisw);
00117   wrapper.constructUniqueID();
00118  }
00119 
00120 template<class T>
00121 inline shared_ptr<Streamable> ISStreamerWrapper<T>::read(IStream& in, const IOManager& manager) const {
00122   // wrap it as a serializable
00123   shared_ptr<ISSerializableWrapper<T> > ob = shared_ptr<ISSerializableWrapper<T> >( new ISSerializableWrapper<T>() ) ;
00124   read(in, *ob, manager);
00125   return ob;
00126 }
00127 
00128 }
00129 
00130 #endif //SCT_ISSTREAMERWRAPPER_H

Generated on Thu Jul 15 09:50:47 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5