| The Gaudi Framework v32r1 (f65d50dc)

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 #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...>;
14 using iids = typename extend_interfaces_base::ext_iids;
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 if ( !pp ) return StatusCode::FAILURE;
22 *pp = Gaudi::iid_cast( ti, iids{}, this );
23 if ( !*pp ) return StatusCode::FAILURE; /* cast failed */
24 this->addRef();
25 return StatusCode::SUCCESS;
26 }
28 std::vector<std::string> getInterfaceNames() const override { return Gaudi::getInterfaceNames( iids{} ); }
30 implements() = default;
32 implements( const implements& /*other*/ ) : m_refCount{0} {}
34 implements& operator=( const implements& /*other*/ ) { return *this; }
35
36 public:
38 unsigned long addRef() override { return ++m_refCount; }
40 unsigned long release() override {
41 /* Avoid to decrement 0 */
42 auto count = ( m_refCount ? --m_refCount : m_refCount.load() );
43 if ( count == 0 ) delete this;
44 return count;
45 }
47 unsigned long refCount() const override { return m_refCount.load(); }
48
49 protected:
51 std::atomic_ulong m_refCount = {0};
52 };
53
54 template <typename I1>
55 using implements1 = implements<I1>;
56 template <typename I1, typename I2>
57 using implements2 = implements<I1, I2>;
58 template <typename I1, typename I2, typename I3>
59 using implements3 = implements<I1, I2, I3>;
60 template <typename I1, typename I2, typename I3, typename I4>
61 using implements4 = implements<I1, I2, I3, I4>;
62
63 #endif /* GAUDIKERNEL_IMPLEMENTS_H_ */
implements
Base class used to implement the interfaces.
Definition: implements.h:9
extend_interfaces< Interfaces... >::ext_iids
typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type ext_iids
take union of the ext_iids of all Interfaces...
Definition: extend_interfaces.h:16
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
implements::implements
implements(const implements &)
Copy constructor (zero the reference count)
Definition: implements.h:32
implements::refCount
unsigned long refCount() const override
Current reference count.
Definition: implements.h:47
implements< IInterface >::iids
typename extend_interfaces_base::ext_iids iids
Definition: implements.h:14
implements::getInterfaceNames
std::vector< std::string > getInterfaceNames() const override
Implementation of IInterface::getInterfaceNames.
Definition: implements.h:28
implements::operator=
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition: implements.h:34
InterfaceID
Interface ID class.
Definition: IInterface.h:29
implements::addRef
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:38
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
extend_interfaces
Base class to be used to extend an interface.
Definition: extend_interfaces.h:5
implements::i_cast
void * i_cast(const InterfaceID &tid) const override
Implementation of IInterface::i_cast.
Definition: implements.h:18
std::vector< std::string >
compareOutputFiles.pp
pp
Definition: compareOutputFiles.py:495
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::getInterfaceNames
std::vector< std::string > getInterfaceNames(Gaudi::interface_list< Is... >)
Definition: IInterface.h:180
implements::queryInterface
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:20
Gaudi::iid_cast
void * iid_cast(const InterfaceID &tid, Gaudi::interface_list< Is... >, P *ptr)
Definition: IInterface.h:185
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
IInterface.h
implements::release
unsigned long release() override
Release Interface instance.
Definition: implements.h:40