1 #ifndef GAUDI_SMARTIF_H 2 #define GAUDI_SMARTIF_H 1 30 inline SmartIF( TYPE* ptr ) : m_interface( ptr )
32 if ( m_interface ) m_interface->addRef();
35 template <
class OTHER>
38 if ( ptr )
reset( ptr );
43 if ( m_interface ) m_interface->addRef();
46 inline SmartIF(
SmartIF&& rhs ) : m_interface( rhs.m_interface ) { rhs.m_interface =
nullptr; }
50 if ( m_interface ) m_interface->release();
52 rhs.m_interface =
nullptr;
68 inline bool isValid()
const {
return m_interface !=
nullptr; }
70 inline explicit operator bool()
const {
return isValid(); }
83 #if !defined( GAUDI_V22_API ) && !defined( NEW_SMARTIF ) 92 inline void reset( TYPE* ptr =
nullptr )
94 if ( ptr == m_interface )
return;
95 if ( m_interface ) m_interface->release();
97 if ( m_interface ) m_interface->addRef();
101 template <
class OTHER>
104 if ( static_cast<IInterface*>( ptr ) == static_cast<IInterface*>( m_interface ) )
return;
105 if ( m_interface ) m_interface->release();
107 ptr->queryInterface( TYPE::interfaceID(), pp_cast<void>( &m_interface ) ).ignore();
109 m_interface =
nullptr;
114 template <
typename IFace>
151 template <
typename IFace>
157 #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.