File indexing completed on 2025-01-18 09:57:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_IMPLEMENTS_H
0012 #define GAUDIKERNEL_IMPLEMENTS_H
0013
0014 #include "GaudiKernel/IInterface.h"
0015 #include <atomic>
0016
0017
0018 template <typename... Interfaces>
0019 struct GAUDI_API implements : virtual public extend_interfaces<Interfaces...> {
0020
0021 using base_class = implements<Interfaces...>;
0022
0023 using extend_interfaces_base = extend_interfaces<Interfaces...>;
0024 using iids = typename extend_interfaces_base::ext_iids;
0025
0026 public:
0027
0028 void* i_cast( const InterfaceID& tid ) const override { return Gaudi::iid_cast( tid, iids{}, this ); }
0029
0030 StatusCode queryInterface( const InterfaceID& ti, void** pp ) override {
0031 if ( !pp ) return StatusCode::FAILURE;
0032 *pp = Gaudi::iid_cast( ti, iids{}, this );
0033 if ( !*pp ) return StatusCode::FAILURE;
0034 this->addRef();
0035 return StatusCode::SUCCESS;
0036 }
0037
0038 std::vector<std::string> getInterfaceNames() const override { return Gaudi::getInterfaceNames( iids{} ); }
0039
0040 implements() = default;
0041
0042 implements( const implements& ) : m_refCount{ 0 } {}
0043
0044 implements& operator=( const implements& ) { return *this; }
0045
0046 public:
0047
0048 unsigned long addRef() override { return ++m_refCount; }
0049
0050 unsigned long release() override {
0051
0052 auto count = ( m_refCount ? --m_refCount : m_refCount.load() );
0053 if ( count == 0 ) delete this;
0054 return count;
0055 }
0056
0057 unsigned long refCount() const override { return m_refCount.load(); }
0058
0059 protected:
0060
0061 std::atomic_ulong m_refCount = { 0 };
0062 };
0063
0064 template <typename I1>
0065 using implements1 = implements<I1>;
0066 template <typename I1, typename I2>
0067 using implements2 = implements<I1, I2>;
0068 template <typename I1, typename I2, typename I3>
0069 using implements3 = implements<I1, I2, I3>;
0070 template <typename I1, typename I2, typename I3, typename I4>
0071 using implements4 = implements<I1, I2, I3, I4>;
0072
0073 #endif