File indexing completed on 2025-02-22 10:36:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_IINSPECTOR_H
0012 #define GAUDIKERNEL_IINSPECTOR_H
0013
0014
0015 #include <string>
0016 #include <typeinfo>
0017
0018
0019 #include "GaudiKernel/IInterface.h"
0020
0021
0022
0023
0024
0025 class GAUDI_API IInspector : virtual public IInterface {
0026 public:
0027
0028 DeclareInterfaceID( IInspector, 1, 0 );
0029
0030 enum { Mutable = 1 << 1, Const = 1 << 2 };
0031
0032 protected:
0033 class IValue {
0034 protected:
0035 void* m_P;
0036 IValue() = default;
0037
0038 public:
0039 virtual ~IValue() = default;
0040 virtual void release() { delete this; }
0041 void* ptr() { return m_P; }
0042 const void* ptr() const { return m_P; }
0043 virtual long size() const = 0;
0044 virtual void construct( void* buffer ) const = 0;
0045 };
0046
0047 struct Tag {
0048 long first;
0049 const std::type_info& second;
0050 Tag( long f, const std::type_info& s ) : first( f ), second( s ) {}
0051 };
0052
0053 private:
0054 template <class T>
0055 class _V : public IValue {
0056 T m_O;
0057
0058 public:
0059 _V( const T& v ) : m_O( v ) { m_P = &m_O; }
0060 virtual long size() const { return sizeof( T ); }
0061 virtual void construct( void* b ) const { ::new ( b ) T(); }
0062 };
0063
0064 template <class T>
0065 class _TT : public Tag {
0066 public:
0067 _TT() : Tag( sizeof( T ), typeid( T ) ) {}
0068 };
0069
0070 protected:
0071
0072
0073 virtual StatusCode inspectByRef( const void* pObj, const Tag& typ, void* pOwner, const Tag& otag,
0074 const std::string& comment, long flag ) = 0;
0075
0076 virtual StatusCode inspectByValue( IValue* pObj, const Tag& typ, void* pOwner, const Tag& oTag,
0077 const std::string& comment ) = 0;
0078
0079 virtual StatusCode inspectContByRef( const void* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
0080 const void* pOwner, const Tag& otag, const std::string& comment,
0081 long flags ) = 0;
0082
0083 virtual StatusCode inspectContByValue( IValue* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
0084 const void* pOwner, const Tag& otag, const std::string& comment ) = 0;
0085
0086 public:
0087
0088
0089 template <class T, class O>
0090 StatusCode inspectByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
0091 return inspectByRef( pObj, _TT<T>(), (void*)pOwner, _TT<O>(), comment, flag );
0092 }
0093
0094 template <class T, class O>
0095 StatusCode inspectByValue( const T& obj, const O* pOwner, const std::string& comment ) {
0096 return inspectByValue( new _V<T>( obj ), _TT<T>(), (void*)pOwner, _TT<O>(), comment );
0097 }
0098
0099 template <class T, class O>
0100 StatusCode inspectContByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
0101 typedef typename T::value_type _VVV;
0102 typedef typename T::value_type _TTT;
0103
0104
0105 return inspectContByRef( (void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag );
0106 }
0107
0108 template <class T, class O>
0109 StatusCode inspectContByValue( const T& obj, const O* pOwner, const std::string& comment ) {
0110 typedef typename T::value_type _VVV;
0111 typedef typename T::value_type _TTT;
0112
0113
0114 return inspectContByValue( new _V<T>( obj ), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment );
0115 }
0116 };
0117 #endif