The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
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
14#include <string>
15#include <typeinfo>
16
21class GAUDI_API IInspector : virtual public IInterface {
22public:
25
26 enum { Mutable = 1 << 1, Const = 1 << 2 };
27
28protected:
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
49private:
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
66protected:
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
82public:
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 }
89
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 }
94
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 }
103
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};
#define GAUDI_API
Definition Kernel.h:49
virtual long size() const
Definition IInspector.h:56
virtual void construct(void *b) const
Definition IInspector.h:57
_V(const T &v)
Definition IInspector.h:55
virtual ~IValue()=default
virtual void release()
Definition IInspector.h:36
virtual long size() const =0
virtual void construct(void *buffer) const =0
const void * ptr() const
Definition IInspector.h:38
Inspector base class.
Definition IInspector.h:21
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
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.
virtual StatusCode inspectByValue(IValue *pObj, const Tag &typ, void *pOwner, const Tag &oTag, const std::string &comment)=0
Inspect object by Value.
DeclareInterfaceID(IInspector, 1, 0)
InterfaceID.
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.
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
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
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 inspectByValue(const T &obj, const O *pOwner, const std::string &comment)
Inspect single item by its value (const)
Definition IInspector.h:91
Definition of the basic interface.
Definition IInterface.h:225
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const std::type_info & second
Definition IInspector.h:45
Tag(long f, const std::type_info &s)
Definition IInspector.h:46