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/info.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   ISOStreamWrapper isosw(out);
00089 
00090   // cast the Streamable as a ISSerializableWrapper
00091   const ISSerializableWrapper<T>& wrapper = 
00092     dynamic_cast <const ISSerializableWrapper<T>&> ( ob );
00093 
00094   // use the inner class to make the publishGuts method public:
00095   InnerClass inner( const_cast<T&> ( *wrapper.getWrappedObject()) );
00096 
00097   // use the publishGuts method to stream.
00098   inner.publishGuts(isosw);
00099 }
00100 
00101 template<class T> 
00102  inline void ISStreamerWrapper<T>::read(IStream& in, Sct::Streamable& ob, const IOManager& manager) const{
00103     // cast the Streamable as a ISSerializableWrapper
00104   const ISSerializableWrapper<T>& wrapper = 
00105     dynamic_cast <const ISSerializableWrapper<T>&> ( ob );
00106 
00107    // make an InnerClass to make the refreshGuts public:
00108   InnerClass inner( const_cast<T&> (*wrapper.getWrappedObject()) );
00109 
00110    // convert the stream
00111   ISIStreamWrapper isisw(in);
00112   
00113    // use the refreshGuts to update.
00114   inner.refreshGuts(isisw);
00115   wrapper.constructUniqueID();
00116  }
00117 
00118 template<class T>
00119 inline shared_ptr<Streamable> ISStreamerWrapper<T>::read(IStream& in, const IOManager& manager) const {
00120   // wrap it as a serializable
00121   shared_ptr<ISSerializableWrapper<T> > ob = shared_ptr<ISSerializableWrapper<T> >( new ISSerializableWrapper<T>() ) ;
00122   read(in, *ob, manager);
00123   return ob;
00124 }
00125 
00126 }
00127 
00128 #endif //SCT_ISSTREAMERWRAPPER_H

Generated on Mon Feb 6 14:01:22 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6