The Gaudi Framework  master (37c0b60a)
IInspector.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_IINSPECTOR_H
12 #define GAUDIKERNEL_IINSPECTOR_H
13 
14 // STL Include files
15 #include <string>
16 #include <typeinfo>
17 
18 // Framework Include files
19 #include <GaudiKernel/IInterface.h>
20 
25 class GAUDI_API IInspector : virtual public IInterface {
26 public:
29 
30  enum { Mutable = 1 << 1, Const = 1 << 2 };
31 
32 protected:
33  class IValue {
34  protected:
35  void* m_P{};
36  IValue() = default;
37 
38  public:
39  virtual ~IValue() = default;
40  virtual void release() { delete this; }
41  void* ptr() { return m_P; }
42  const void* ptr() const { return m_P; }
43  virtual long size() const = 0;
44  virtual void construct( void* buffer ) const = 0;
45  };
46 
47  struct Tag {
48  long first;
50  Tag( long f, const std::type_info& s ) : first( f ), second( s ) {}
51  };
52 
53 private:
54  template <class T>
55  class _V : public IValue {
56  T m_O;
57 
58  public:
59  _V( const T& v ) : m_O( v ) { m_P = &m_O; }
60  virtual long size() const { return sizeof( T ); }
61  virtual void construct( void* b ) const { ::new ( b ) T(); }
62  };
63 
64  template <class T>
65  class _TT : public Tag {
66  public:
67  _TT() : Tag( sizeof( T ), typeid( T ) ) {}
68  };
69 
70 protected:
71  // Referenced implementation of the IInspector interface:
73  virtual StatusCode inspectByRef( const void* pObj, const Tag& typ, void* pOwner, const Tag& otag,
74  const std::string& comment, long flag ) = 0;
76  virtual StatusCode inspectByValue( IValue* pObj, const Tag& typ, void* pOwner, const Tag& oTag,
77  const std::string& comment ) = 0;
79  virtual StatusCode inspectContByRef( const void* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
80  const void* pOwner, const Tag& otag, const std::string& comment,
81  long flags ) = 0;
83  virtual StatusCode inspectContByValue( IValue* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
84  const void* pOwner, const Tag& otag, const std::string& comment ) = 0;
85 
86 public:
87  // User interface of the IInspector interface
89  template <class T, class O>
90  StatusCode inspectByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
91  return inspectByRef( pObj, _TT<T>(), (void*)pOwner, _TT<O>(), comment, flag );
92  }
94  template <class T, class O>
95  StatusCode inspectByValue( const T& obj, const O* pOwner, const std::string& comment ) {
96  return inspectByValue( new _V<T>( obj ), _TT<T>(), (void*)pOwner, _TT<O>(), comment );
97  }
99  template <class T, class O>
100  StatusCode inspectContByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
101  typedef typename T::value_type _VVV;
102  typedef typename T::value_type _TTT;
103  // Unfortunately this is not implemented on G++:
104  // typedef typename T::allocator_type::value_type _TTT;
105  return inspectContByRef( (void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag );
106  }
108  template <class T, class O>
109  StatusCode inspectContByValue( const T& obj, const O* pOwner, const std::string& comment ) {
110  typedef typename T::value_type _VVV;
111  typedef typename T::value_type _TTT;
112  // Unfortunately this is not implemented on G++:
113  // typedef typename T::allocator_type::value_type _TTT;
114  return inspectContByValue( new _V<T>( obj ), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment );
115  }
116 };
117 #endif // GAUDIKERNEL_IINSPECTOR_H
IInspector::IValue::release
virtual void release()
Definition: IInspector.h:40
std::string
STL class.
IInspector::IValue::ptr
void * ptr()
Definition: IInspector.h:41
IInspector::_V::size
virtual long size() const
Definition: IInspector.h:60
IInspector::IValue::~IValue
virtual ~IValue()=default
gaudirun.s
string s
Definition: gaudirun.py:346
std::type_info
IInspector::IValue::size
virtual long size() const =0
IInspector::inspectByValue
virtual StatusCode inspectByValue(IValue *pObj, const Tag &typ, void *pOwner, const Tag &oTag, const std::string &comment)=0
Inspect object by Value.
IInspector::DeclareInterfaceID
DeclareInterfaceID(IInspector, 1, 0)
InterfaceID.
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:139
IInspector::inspectContByValue
StatusCode inspectContByValue(const T &obj, const O *pOwner, const std::string &comment)
Inspect container of object items by its value (const)
Definition: IInspector.h:109
IInspector::Tag::first
long first
Definition: IInspector.h:48
IInspector::inspectByRef
virtual StatusCode inspectByRef(const void *pObj, const Tag &typ, void *pOwner, const Tag &otag, const std::string &comment, long flag)=0
Inspect object by Reference.
StatusCode
Definition: StatusCode.h:65
IInterface.h
IInspector
Definition: IInspector.h:25
IInspector::_V::m_O
T m_O
Definition: IInspector.h:56
IInspector::IValue::IValue
IValue()=default
IInspector::Tag
Definition: IInspector.h:47
IInspector::_V::construct
virtual void construct(void *b) const
Definition: IInspector.h:61
IInspector::_V::_V
_V(const T &v)
Definition: IInspector.h:59
IInspector::_TT::_TT
_TT()
Definition: IInspector.h:67
IInspector::_TT
Definition: IInspector.h:65
IInspector::_V
Definition: IInspector.h:55
IInspector::inspectContByValue
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
Inspect container of objects by value.
IInspector::IValue
Definition: IInspector.h:33
IInterface
Definition: IInterface.h:239
Properties.v
v
Definition: Properties.py:122
IInspector::inspectContByRef
StatusCode inspectContByRef(const T *pObj, const O *pOwner, const std::string &comment, long flag=Mutable)
Inspect container of object items by its reference (mutable and const)
Definition: IInspector.h:100
IInspector::inspectByRef
StatusCode inspectByRef(const T *pObj, const O *pOwner, const std::string &comment, long flag=Mutable)
Inspect single item by its reference (mutable and const)
Definition: IInspector.h:90
IInspector::Tag::Tag
Tag(long f, const std::type_info &s)
Definition: IInspector.h:50
IInspector::Tag::second
const std::type_info & second
Definition: IInspector.h:49
IInspector::IValue::ptr
const void * ptr() const
Definition: IInspector.h:42
IInspector::IValue::construct
virtual void construct(void *buffer) const =0
IInspector::inspectByValue
StatusCode inspectByValue(const T &obj, const O *pOwner, const std::string &comment)
Inspect single item by its value (const)
Definition: IInspector.h:95
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
IInspector::inspectContByRef
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
Inspect container of objects by reference.