| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# IInspector.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/IInspector.h,v 1.4 2006/11/30 15:22:07 dquarrie Exp $
    00002 #ifndef GAUDIKERNEL_IINSPECTOR_H
    00003 #define GAUDIKERNEL_IINSPECTOR_H
    00004
    00005 // STL Include files
    00006 #include <typeinfo>
    00007 #include <string>
    00008
    00009 // Framework Include files
    00010 #include "GaudiKernel/IInterface.h"
    00011
    00016 class GAUDI_API IInspector: virtual public IInterface {
    00017 public:
    00019   DeclareInterfaceID(IInspector,1,0);
    00020
    00021   enum { MUTABLE = 1<<1, CONST = 1<<2};
    00022
    00023 protected:
    00024
    00027   class IValue  {
    00028   protected:
    00029     void* m_P;
    00030     IValue()                      {                            }
    00031   public:
    00032     virtual ~IValue()             { }
    00033     virtual void release()        {      delete this;          }
    00034     void* ptr()                   {      return m_P;           }
    00035     const void* ptr()  const      {      return m_P;           }
    00036     virtual long size()  const = 0;
    00037     virtual void construct(void* buffer) const = 0;
    00038   };
    00039
    00042   class Tag  {
    00043   public:
    00044     long             first;
    00045     const std::type_info& second;
    00046     Tag(long f, const std::type_info& s) : first(f), second(s) {    }
    00047     Tag(const Tag& t) : first(t.first), second(t.second)  {    }
    00048   };
    00049
    00050 private:
    00053   template <class T> class _V : public IValue    {
    00054     T m_O;
    00055   public:
    00056     _V(const T& v) : m_O(v)       {      m_P = &m_O;           }
    00057     virtual ~_V()                 {                            }
    00058     virtual long size()  const    {      return sizeof(T);     }
    00059     void construct(void* b) const {      ::new(b) T();         }
    00060   };
    00061
    00064   template <class T> class _TT : public Tag   {
    00065   public:    _TT() : Tag(sizeof(T), typeid(T))    {         }
    00066   };
    00067
    00068 protected:
    00069   // Referenced implementation of the IInspector interface:
    00071         virtual StatusCode inspectByRef(const void* pObj, const Tag& typ, void* pOwner, const Tag& otag, const std::string& comment, long flag) = 0;
    00073         virtual StatusCode inspectByValue(IValue* pObj,   const Tag& typ, void* pOwner, const Tag& oTag, const std::string& comment) = 0;
    00075         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;
    00077         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;
    00078
    00079 public:
    00080   // User interface of the IInspector interface
    00082         template < class T, class O >
    00083   StatusCode inspectByRef(const T* pObj, const O* pOwner, const std::string& comment, long flag=MUTABLE)        {
    00084                 return inspectByRef(pObj, _TT<T>(), (void*)pOwner, _TT<O>(), comment, flag);
    00085         }
    00087         template < class T, class O >
    00088   StatusCode inspectByValue(const T& obj, const O* pOwner, const std::string& comment) {
    00089                 return inspectByValue(new _V<T>(obj), _TT<T>(), (void*)pOwner, _TT<O>(), comment);
    00090         }
    00092         template < class T, class O >
    00093   StatusCode inspectContByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag=MUTABLE)     {
    00094           typedef typename T::value_type                 _VVV;
    00095           typedef typename T::value_type                 _TTT;
    00096           // Unfortunately this is not implemented on G++:
    00097           // typedef typename T::allocator_type::value_type _TTT;
    00098     return inspectContByRef((void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag);
    00099   }
    00101         template < class T, class O >
    00102   StatusCode inspectContByValue( const T& obj, const O* pOwner, const std::string& comment)       {
    00103           typedef typename T::value_type                 _VVV;
    00104           typedef typename T::value_type                 _TTT;
    00105           // Unfortunately this is not implemented on G++:
    00106           // typedef typename T::allocator_type::value_type _TTT;
    00107     return inspectContByValue(new _V<T>(obj), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment);
    00108   }
    00109 };
    00110 #endif // GAUDIKERNEL_IINSPECTOR_H