implements.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_IMPLEMENTS_H
2 #define GAUDIKERNEL_IMPLEMENTS_H
3 
4 #include "GaudiKernel/IInterface.h"
5 
7 template <typename... Interfaces>
8 struct GAUDI_API implements: virtual public extend_interfaces<Interfaces...> {
10  using base_class = implements<Interfaces...>;
12  using extend_interfaces_base = extend_interfaces<Interfaces...>;
13  using iids = typename extend_interfaces_base::ext_iids;
14 
15 public:
17  void *i_cast(const InterfaceID &tid) const override {
18  return Gaudi::iid_cast(tid,iids{},this);
19  }
21  StatusCode queryInterface(const InterfaceID &ti, void** pp) override {
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  }
29  std::vector<std::string> getInterfaceNames() const override {
30  return Gaudi::getInterfaceNames( iids{} );
31  }
33  implements() = default;
35  implements(const implements& /*other*/) : m_refCount{0} {}
37  implements& operator=(const implements& /*other*/) { return *this; }
39  ~implements() override = default;
40 
41 public:
43  unsigned long addRef() override { return ++m_refCount; }
45  unsigned long release() override {
46  /* Avoid to decrement 0 */
47  auto count = ( m_refCount ? --m_refCount : m_refCount );
48  if (count == 0) delete this;
49  return count;
50  }
52  unsigned long refCount() const override { return m_refCount; }
53 
54 protected:
56  unsigned long m_refCount = 0;
57 };
58 
59 
60 template <typename I1> using implements1 = implements<I1>;
61 template <typename I1,
62  typename I2> using implements2 = implements<I1,I2>;
63 template <typename I1,
64  typename I2,
65  typename I3> using implements3 = implements<I1,I2,I3>;
66 template <typename I1,
67  typename I2,
68  typename I3,
69  typename I4> using implements4 = implements<I1,I2,I3,I4>;
70 
71 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
Base class used to implement the interfaces.
Definition: implements.h:8
#define GAUDI_API
Definition: Kernel.h:107
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is...>)
Definition: IInterface.h:177
Interface ID class.
Definition: IInterface.h:30
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Base class to be used to extend an interface.
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is...>, P *ptr)
Definition: IInterface.h:182