1 #ifndef GAUDI_SMARTIF_H 2 #define GAUDI_SMARTIF_H 1 29 inline SmartIF( TYPE* ptr ) : m_interface( ptr ) {
30 if ( m_interface ) m_interface->addRef();
33 template <
class OTHER>
35 if ( ptr )
reset( ptr );
39 if ( m_interface ) m_interface->addRef();
42 inline SmartIF(
SmartIF&& rhs ) : m_interface( rhs.m_interface ) { 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 ) 86 inline void reset( TYPE* ptr =
nullptr ) {
87 if ( ptr == m_interface )
return;
88 if ( m_interface ) m_interface->release();
90 if ( m_interface ) m_interface->addRef();
94 template <
class OTHER>
95 inline void reset( OTHER* ptr ) {
96 if ( static_cast<IInterface*>( ptr ) == static_cast<IInterface*>( m_interface ) )
return;
97 if ( m_interface ) m_interface->release();
99 ptr->queryInterface( TYPE::interfaceID(), pp_cast<void>( &m_interface ) ).ignore();
101 m_interface =
nullptr;
106 template <
typename IFace>
139 template <
typename IFace>
144 #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.
SmartIF & operator=(IInterface *ptr)
Assignment operator from IInterface pointer.
Definition of the basic interface.
SmartIF & operator=(const SmartIF< T > &rhs)
Assignment operator from a different SmartIF.
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=(const SmartIF &rhs)
Assignment operator.
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.