1 #ifndef GAUDI_SMARTIF_H 2 #define GAUDI_SMARTIF_H 1 18 template <
class TYPE>
class SmartIF {
27 inline SmartIF(TYPE* ptr): m_interface(ptr) {
28 if (m_interface) m_interface->addRef();
31 template <
class OTHER>
37 if (m_interface) m_interface->addRef();
41 rhs.m_interface =
nullptr;
45 if (m_interface) m_interface->release();
47 rhs.m_interface =
nullptr;
62 inline bool isValid()
const {
return m_interface !=
nullptr; }
64 inline explicit operator bool()
const {
return isValid(); }
77 #if !defined(GAUDI_V22_API) && !defined(NEW_SMARTIF) 78 inline TYPE*&
pRef() {
88 inline void reset(TYPE* ptr =
nullptr) {
89 if (ptr == m_interface)
return;
90 if (m_interface) m_interface->release();
92 if (m_interface) m_interface->addRef();
96 template <
class OTHER>
98 if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface))
return;
99 if (m_interface) m_interface->release();
101 ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
103 m_interface =
nullptr;
109 template <
typename IFace>
142 template <
typename IFace>
146 #endif // GAUDI_SMARTIF_H SmartIF(SmartIF &&rhs)
Move constructor.
Small smart pointer class with automatic reference counting for IInterface.
void reset(OTHER *ptr)
Set the internal pointer to the passed one disposing of the old one.
TYPE & operator*() const
Dereference operator.
~SmartIF()
Standard Destructor.
TYPE * operator->() const
Dereference operator.
TYPE * get() const
Get interface pointer.
SmartIF()=default
Default constructor.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
TYPE * m_interface
Pointer to the instance.
Definition of the basic interface.
SmartIF(const SmartIF &rhs)
Copy constructor.
SmartIF(TYPE *ptr)
Standard constructor from pointer.
bool isValid() const
Allow for check if smart pointer is valid.
SmartIF & operator=(SmartIF &&rhs)
Move assignement.
SmartIF(OTHER *ptr)
Standard constructor from any (IInterface-derived) pointer.
SmartIF(const SmartIF< T > &rhs)
Constructor from another SmartIF, with a different type.
SmartIF< IFace > make_SmartIF(IFace *iface)
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
TYPE *& pRef()
Get reference to the pointer.