00001
00002 #ifndef GAUDIKERNEL_IINSPECTOR_H
00003 #define GAUDIKERNEL_IINSPECTOR_H
00004
00005
00006 #include <typeinfo>
00007 #include <string>
00008
00009
00010 #include "GaudiKernel/IInterface.h"
00011
00016 class IInspector : virtual public IInterface {
00017 public:
00018 enum { MUTABLE = 1<<1, CONST = 1<<2};
00019
00020 protected:
00021
00024 class IValue {
00025 protected:
00026 void* m_P;
00027 IValue() { }
00028 public:
00029 virtual ~IValue() { }
00030 virtual void release() { delete this; }
00031 void* ptr() { return m_P; }
00032 const void* ptr() const { return m_P; }
00033 virtual long size() const = 0;
00034 virtual void construct(void* buffer) const = 0;
00035 };
00036
00039 class Tag {
00040 public:
00041 long first;
00042 const std::type_info& second;
00043 Tag(long f, const std::type_info& s) : first(f), second(s) { }
00044 Tag(const Tag& t) : first(t.first), second(t.second) { }
00045 };
00046
00047 private:
00050 template <class T> class _V : public IValue {
00051 T m_O;
00052 public:
00053 _V(const T& v) : m_O(v) { m_P = &m_O; }
00054 virtual ~_V() { }
00055 virtual long size() const { return sizeof(T); }
00056 void construct(void* b) const { ::new(b) T(); }
00057 };
00058
00061 template <class T> class _TT : public Tag {
00062 public: _TT() : Tag(sizeof(T), typeid(T)) { }
00063 };
00064
00065 protected:
00066
00068 virtual StatusCode inspectByRef(const void* pObj, const Tag& typ, void* pOwner, const Tag& otag, const std::string& comment, long flag) = 0;
00070 virtual StatusCode inspectByValue(IValue* pObj, const Tag& typ, void* pOwner, const Tag& oTag, const std::string& comment) = 0;
00072 virtual StatusCode inspectContByRef(const void* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag, const void* pOwner, const Tag& otag, const std::string& comment, long flags) = 0;
00074 virtual StatusCode inspectContByValue(IValue* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag, const void* pOwner, const Tag& otag, const std::string& comment) = 0;
00075
00076 public:
00077
00079 template < class T, class O >
00080 StatusCode inspectByRef(const T* pObj, const O* pOwner, const std::string& comment, long flag=MUTABLE) {
00081 return inspectByRef(pObj, _TT<T>(), (void*)pOwner, _TT<O>(), comment, flag);
00082 }
00084 template < class T, class O >
00085 StatusCode inspectByValue(const T& obj, const O* pOwner, const std::string& comment) {
00086 return inspectByValue(new _V<T>(obj), _TT<T>(), (void*)pOwner, _TT<O>(), comment);
00087 }
00089 template < class T, class O >
00090 StatusCode inspectContByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag=MUTABLE) {
00091 typedef typename T::value_type _VVV;
00092 typedef typename T::value_type _TTT;
00093
00094
00095 return inspectContByRef((void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag);
00096 }
00098 template < class T, class O >
00099 StatusCode inspectContByValue( const T& obj, const O* pOwner, const std::string& comment) {
00100 typedef typename T::value_type _VVV;
00101 typedef typename T::value_type _TTT;
00102
00103
00104 return inspectContByValue(new _V<T>(obj), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment);
00105 }
00106 };
00107 #endif // GAUDIKERNEL_IINSPECTOR_H