The Gaudi Framework  master (01b473db)
IInspector.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <GaudiKernel/IInterface.h>
14 #include <string>
15 #include <typeinfo>
16 
21 class GAUDI_API IInspector : virtual public IInterface {
22 public:
25 
26  enum { Mutable = 1 << 1, Const = 1 << 2 };
27 
28 protected:
29  class IValue {
30  protected:
31  void* m_P{};
32  IValue() = default;
33 
34  public:
35  virtual ~IValue() = default;
36  virtual void release() { delete this; }
37  void* ptr() { return m_P; }
38  const void* ptr() const { return m_P; }
39  virtual long size() const = 0;
40  virtual void construct( void* buffer ) const = 0;
41  };
42 
43  struct Tag {
44  long first;
45  const std::type_info& second;
46  Tag( long f, const std::type_info& s ) : first( f ), second( s ) {}
47  };
48 
49 private:
50  template <class T>
51  class _V : public IValue {
52  T m_O;
53 
54  public:
55  _V( const T& v ) : m_O( v ) { m_P = &m_O; }
56  virtual long size() const { return sizeof( T ); }
57  virtual void construct( void* b ) const { ::new ( b ) T(); }
58  };
59 
60  template <class T>
61  class _TT : public Tag {
62  public:
63  _TT() : Tag( sizeof( T ), typeid( T ) ) {}
64  };
65 
66 protected:
67  // Referenced implementation of the IInspector interface:
69  virtual StatusCode inspectByRef( const void* pObj, const Tag& typ, void* pOwner, const Tag& otag,
70  const std::string& comment, long flag ) = 0;
72  virtual StatusCode inspectByValue( IValue* pObj, const Tag& typ, void* pOwner, const Tag& oTag,
73  const std::string& comment ) = 0;
75  virtual StatusCode inspectContByRef( const void* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
76  const void* pOwner, const Tag& otag, const std::string& comment,
77  long flags ) = 0;
79  virtual StatusCode inspectContByValue( IValue* pObj, const Tag& tag, const Tag& rtag, const Tag& vtag,
80  const void* pOwner, const Tag& otag, const std::string& comment ) = 0;
81 
82 public:
83  // User interface of the IInspector interface
85  template <class T, class O>
86  StatusCode inspectByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
87  return inspectByRef( pObj, _TT<T>(), (void*)pOwner, _TT<O>(), comment, flag );
88  }
90  template <class T, class O>
91  StatusCode inspectByValue( const T& obj, const O* pOwner, const std::string& comment ) {
92  return inspectByValue( new _V<T>( obj ), _TT<T>(), (void*)pOwner, _TT<O>(), comment );
93  }
95  template <class T, class O>
96  StatusCode inspectContByRef( const T* pObj, const O* pOwner, const std::string& comment, long flag = Mutable ) {
97  typedef typename T::value_type _VVV;
98  typedef typename T::value_type _TTT;
99  // Unfortunately this is not implemented on G++:
100  // typedef typename T::allocator_type::value_type _TTT;
101  return inspectContByRef( (void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag );
102  }
104  template <class T, class O>
105  StatusCode inspectContByValue( const T& obj, const O* pOwner, const std::string& comment ) {
106  typedef typename T::value_type _VVV;
107  typedef typename T::value_type _TTT;
108  // Unfortunately this is not implemented on G++:
109  // typedef typename T::allocator_type::value_type _TTT;
110  return inspectContByValue( new _V<T>( obj ), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment );
111  }
112 };
IInspector::IValue::release
virtual void release()
Definition: IInspector.h:36
IInspector::IValue::ptr
void * ptr()
Definition: IInspector.h:37
IInspector::_V::size
virtual long size() const
Definition: IInspector.h:56
IInspector::IValue::~IValue
virtual ~IValue()=default
gaudirun.s
string s
Definition: gaudirun.py:346
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:138
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:105
IInspector::Tag::first
long first
Definition: IInspector.h:44
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:64
IInterface.h
IInspector
Definition: IInspector.h:21
IInspector::_V::m_O
T m_O
Definition: IInspector.h:52
IInspector::IValue::IValue
IValue()=default
IInspector::Tag
Definition: IInspector.h:43
IInspector::_V::construct
virtual void construct(void *b) const
Definition: IInspector.h:57
IInspector::_V::_V
_V(const T &v)
Definition: IInspector.h:55
IInspector::_TT::_TT
_TT()
Definition: IInspector.h:63
IInspector::_TT
Definition: IInspector.h:61
IInspector::_V
Definition: IInspector.h:51
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:29
IInterface
Definition: IInterface.h:225
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:96
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:86
IInspector::Tag::Tag
Tag(long f, const std::type_info &s)
Definition: IInspector.h:46
IInspector::Tag::second
const std::type_info & second
Definition: IInspector.h:45
IInspector::IValue::ptr
const void * ptr() const
Definition: IInspector.h:38
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:91
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
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.