The Gaudi Framework  v33r0 (d5ea422b)
IInspector.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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
constexpr auto size(const T &, Args &&...) noexcept
StatusCode inspectByValue(const T &obj, const O *pOwner, const std::string &comment)
Inspect single item by its value (const)
Definition: IInspector.h:95
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
virtual void release()
Definition: IInspector.h:40
virtual void construct(void *b) const
Definition: IInspector.h:61
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
constexpr double second
STL class.
_V(const T &v)
Definition: IInspector.h:59
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
Inspector base class.
Definition: IInspector.h:25
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
virtual long size() const
Definition: IInspector.h:60
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:23
const std::type_info & second
Definition: IInspector.h:49
const void * ptr() const
Definition: IInspector.h:42
string s
Definition: gaudirun.py:328
#define GAUDI_API
Definition: Kernel.h:81
Tag(long f, const std::type_info &s)
Definition: IInspector.h:50