Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:36:05

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_IINSPECTOR_H
0012 #define GAUDIKERNEL_IINSPECTOR_H
0013 
0014 // STL Include files
0015 #include <string>
0016 #include <typeinfo>
0017 
0018 // Framework Include files
0019 #include "GaudiKernel/IInterface.h"
0020 
0021 /** @class IInspector IInspector.h GaudiKernel/IInspector.h
0022 
0023     Inspector base class
0024 */
0025 class GAUDI_API IInspector : virtual public IInterface {
0026 public:
0027   /// InterfaceID
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   // Referenced implementation of the IInspector interface:
0072   /// Inspect object by Reference
0073   virtual StatusCode inspectByRef( const void* pObj, const Tag& typ, void* pOwner, const Tag& otag,
0074                                    const std::string& comment, long flag ) = 0;
0075   /// Inspect object by Value
0076   virtual StatusCode inspectByValue( IValue* pObj, const Tag& typ, void* pOwner, const Tag& oTag,
0077                                      const std::string& comment ) = 0;
0078   /// Inspect container of objects by reference
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   /// Inspect container of objects by value
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   // User interface of the IInspector interface
0088   /// Inspect single item by its reference (mutable and const)
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   /// Inspect single item by its value (const)
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   /// Inspect container of object items by its reference (mutable and const)
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     // Unfortunately this is not implemented on G++:
0104     // typedef typename T::allocator_type::value_type _TTT;
0105     return inspectContByRef( (void*)pObj, _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment, flag );
0106   }
0107   /// Inspect container of object items by its value (const)
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     // Unfortunately this is not implemented on G++:
0113     // typedef typename T::allocator_type::value_type _TTT;
0114     return inspectContByValue( new _V<T>( obj ), _TT<T>(), _TT<_VVV>(), _TT<_TTT>(), (void*)pOwner, _TT<O>(), comment );
0115   }
0116 };
0117 #endif // GAUDIKERNEL_IINSPECTOR_H