The Gaudi Framework  v29r0 (ff2e7097)
implements.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_IMPLEMENTS_H
2 #define GAUDIKERNEL_IMPLEMENTS_H
3 
5 #include <atomic>
6 
8 template <typename... Interfaces>
9 struct GAUDI_API implements : virtual public extend_interfaces<Interfaces...> {
11  using base_class = implements<Interfaces...>;
13  using extend_interfaces_base = extend_interfaces<Interfaces...>;
15 
16 public:
18  void* i_cast( const InterfaceID& tid ) const override { return Gaudi::iid_cast( tid, iids{}, this ); }
20  StatusCode queryInterface( const InterfaceID& ti, void** pp ) override
21  {
22  if ( !pp ) return StatusCode::FAILURE;
23  *pp = Gaudi::iid_cast( ti, iids{}, this );
24  if ( !*pp ) return StatusCode::FAILURE; /* cast failed */
25  this->addRef();
26  return StatusCode::SUCCESS;
27  }
31  implements() = default;
33  implements( const implements& /*other*/ ) : m_refCount{0} {}
35  implements& operator=( const implements& /*other*/ ) { return *this; }
37  ~implements() override = default;
38 
39 public:
41  unsigned long addRef() override { return ++m_refCount; }
43  unsigned long release() override
44  {
45  /* Avoid to decrement 0 */
46  auto count = ( m_refCount ? --m_refCount : m_refCount.load() );
47  if ( count == 0 ) delete this;
48  return count;
49  }
51  unsigned long refCount() const override { return m_refCount.load(); }
52 
53 protected:
55  std::atomic_ulong m_refCount = {0};
56 };
57 
58 template <typename I1>
60 template <typename I1, typename I2>
62 template <typename I1, typename I2, typename I3>
64 template <typename I1, typename I2, typename I3, typename I4>
66 
67 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
Base class used to implement the interfaces.
Definition: implements.h:9
typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type ext_iids
take union of the ext_iids of all Interfaces...
void * i_cast(const InterfaceID &tid) const override
Implementation of IInterface::i_cast.
Definition: implements.h:18
implements(const implements &)
Copy constructor (zero the reference count)
Definition: implements.h:33
typename extend_interfaces_base::ext_iids iids
Definition: implements.h:14
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition: implements.h:35
Interface ID class.
Definition: IInterface.h:29
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:41
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Base class to be used to extend an interface.
std::vector< std::string > getInterfaceNames() const override
Implementation of IInterface::getInterfaceNames.
Definition: implements.h:29
unsigned long refCount() const override
Current reference count.
Definition: implements.h:51
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
Definition: IInterface.h:206
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:20
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
Definition: IInterface.h:212
#define GAUDI_API
Definition: Kernel.h:110
unsigned long release() override
Release Interface instance.
Definition: implements.h:43