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

ISSerializableWrapper.h

00001 #ifndef SCT_ISSERIALIZABLEWRAPPER_H
00002 #define SCT_ISSERIALIZABLEWRAPPER_H
00003 #include "Serializable.h"
00004 #include "SctNames.h"
00005 #include "is/isinfo.h"
00006 #include <boost/shared_ptr.hpp>
00007 
00008 using boost::shared_ptr;
00009 
00010 namespace Sct{
00012   class ISSerializableWrapperI : public virtual Serializable {
00013   public:
00015     virtual void publishWrappedObjectToServer(const string& isServerName)const =0;
00016   };
00017   
00027   template<class T> class ISSerializableWrapper : public ISSerializableWrapperI {
00028   public:
00030     ISSerializableWrapper() : ob(new T), m_uniqueID("unknown") {
00031 //      std::cout << "SerWrap Default constructor " << std::endl;
00032     }
00038     ISSerializableWrapper(shared_ptr<T> ob) : ob(ob) {
00039 //        std::cout << "SerWrap Non Default Contstructor" << std::endl;
00040             constructUniqueID(); 
00041     }
00043     virtual ~ISSerializableWrapper() { /*std::cout << "~SerWrap" << std::endl;*/}
00045     virtual string getClassName() const;
00047     virtual string getUniqueID() const; 
00049     shared_ptr<T> getWrappedObject() {return ob;}
00051     shared_ptr<const T> getWrappedObject() const {return ob;}
00056     virtual void publishWrappedObjectToServer(const string& isServerName) const;
00058     void constructUniqueID() const;
00059   private:
00060     shared_ptr<T> ob; 
00061     mutable string m_uniqueID; 
00062   };
00064   template<class T>
00065   inline string ISSerializableWrapper<T>::getClassName() const {
00066     return ob->type().name();
00067   }
00068   
00069   template<class T>
00070   inline string ISSerializableWrapper<T>::getUniqueID() const {
00071     return m_uniqueID;
00072   }
00073 
00074   template<class T>
00075     inline void ISSerializableWrapper<T>::publishWrappedObjectToServer(const string& serverName) const {
00076 //    std::cout << "publish wrapped" << std::endl;
00077     constructUniqueID();
00078     ISInfoDictionary& is = SctNames::getISDictionary();
00079     string name=serverName;
00080     name+=".";
00081     name+=getClassName();
00082     name+=".";
00083     name+=getUniqueID();
00084 //    std::cout << getUniqueID() << ", " << getClassName() << std::endl;
00085     ISInfo::Status s = is.insert(name.c_str(), const_cast<T&>(*getWrappedObject()) );
00086     if (s != ISInfo::Success) throw IsException(s, name + " publish failed", __FILE__, __LINE__);
00087   }
00088 
00089 }
00090 
00091 #endif //SCT_ISSERIALIZABLEWRAPPER_H

Generated on Thu Jul 8 11:41:11 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5