2 #ifndef GAUDI_SMARTIF_H
3 #define GAUDI_SMARTIF_H 1
19 template <
class TYPE>
class SmartIF {
28 inline SmartIF(TYPE* ptr): m_interface(ptr) {
29 if (m_interface) m_interface->addRef();
32 template <
class OTHER>
33 inline SmartIF(OTHER* ptr): m_interface(0) {
38 if (m_interface) m_interface->addRef();
51 inline bool isValid()
const {
return m_interface != 0; }
63 #if !defined(GAUDI_V22_API) && !defined(NEW_SMARTIF)
64 inline TYPE*&
pRef() {
74 inline void reset(TYPE* ptr = 0) {
75 if (ptr == m_interface)
return;
76 if (m_interface) m_interface->release();
79 m_interface->addRef();
86 template <
class OTHER>
88 if (static_cast<IInterface*>(ptr) == static_cast<IInterface*>(m_interface))
return;
89 if (m_interface) m_interface->release();
91 ptr->queryInterface(TYPE::interfaceID(), pp_cast<void>(&m_interface)).ignore();
122 #if defined(_MSC_VER) && (_MSC_VER < 1500)
123 template <
class TYPE>
132 return rhs ==
reinterpret_cast<TYPE*
>(lhs);
141 template <
class TYPE>
143 return rhs !=
reinterpret_cast<TYPE*
>(lhs);
146 #endif // GAUDI_SMARTIF_H
bool operator!=(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
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.
TYPE * m_interface
Pointer to the instance.
bool operator==(const GaudiUtils::Allocator< T1 > &, const GaudiUtils::Allocator< T2 > &)
SmartIF & operator=(IInterface *ptr)
Assignment operator from IInterface pointer.
Definition of the basic interface.
SmartIF()
Default constructor.
SmartIF(const SmartIF &rhs)
Copy constructor.
void reset(TYPE *ptr=0)
Set the internal pointer to the passed one disposing of the old one.
SmartIF(TYPE *ptr)
Standard constructor from pointer.
bool isValid() const
Allow for check if smart pointer is valid.
SmartIF(OTHER *ptr)
Standard constructor from any (IInterface-derived) pointer.
SmartIF(const SmartIF< T > &rhs)
Constructor from another SmartIF, with a different type.
TYPE *& pRef()
Get reference to the pointer.