Fovia C++ In-Process API
Public Member Functions | Public Attributes | List of all members
CBComPtr< T > Class Template Reference

Public Member Functions

void Attach (T *p2)
 
 CBComPtr ()
 
 CBComPtr (T *lp)
 
 CBComPtr (const CBComPtr< T > &lp)
 
RRESULT CopyTo (T **ppT)
 
void DecRef ()
 
T * Detach ()
 
bool IsEqualObject (IRoot *pOther)
 
 operator T * () const
 
bool operator! () const
 
T ** operator& ()
 
T & operator* () const
 
_protptr< T > * operator-> () const
 
bool operator< (T *pT) const
 
T * operator= (T *lp)
 
T * operator= (const CBComPtr< T > &lp)
 
bool operator== (T *pT) const
 
 ~CBComPtr ()
 

Public Attributes

T * p
 

Detailed Description

template<class T>
class CBComPtr< T >

Smart pointer class intended to handle the reference counting operations on an IRoot automatically. The following illustrates a typical use case for this object.

{
CBComPtr<ISomeObject> piObject = NULL;
CBComPtr<ISomeObject> piObject2 = NULL;
piLibrary->CreateObject(&CLSID_SomeObject, &piObject); // reference count is 1 upon creation
piObject->SomeFunction();
// the reference count on the interface is increased by 1 here (so it is now 2)
piObject2 = piObject;
} // the reference count on the interface is decreased by 2 here because both piObject and
// piObject2 are out of scope. the interface is deallocated because the reference count becomes 0.

Constructor & Destructor Documentation

template<class T>
CBComPtr< T >::CBComPtr ( )
inline

The default constructor. The internal pointer is set to NULL by default.

template<class T>
CBComPtr< T >::CBComPtr ( T *  lp)
inline

Constructs a new CBComPtr and initializes the internal pointer to lp. If lp is not NULL, the reference count is increased by 1.

Parameters
lpThe pointer to assign to this object. NULL is acceptable here.
template<class T>
CBComPtr< T >::CBComPtr ( const CBComPtr< T > &  lp)
inline

Standard copy constructor. If lp's internal pointer is not NULL, the reference count of the interface is increased by 1.

Parameters
lpThe CBComPtr to assign to this object.

References CBComPtr< T >::p.

template<class T>
CBComPtr< T >::~CBComPtr ( )
inline

Destructs this object. If the internal pointer is not NULL, then its reference count is decreased by 1.

Member Function Documentation

template<class T>
void CBComPtr< T >::Attach ( T *  p2)
inline

Attaches p2 to this object. If this object's internal interface pointer is not NULL, its reference count is decreased by 1 first. p2's reference count is NOT incremented by this operation.

Parameters
p2The interface pointer to attach to this object.
template<class T>
RRESULT CBComPtr< T >::CopyTo ( T **  ppT)
inline

Copies the internal interface pointer to the pointer contained at address ppT. If the internal interface pointer is not NULL, the interface's reference count is incremented by this operation.

Parameters
ppTThe address of the pointer to get this objects interface pointer. NULL will return E_POINTER.
Returns
S_OK upon success, E_POINTER if ppT is NULL.

References BCOM_ASSERT, E_POINTER, CBComPtr< T >::p, and S_OK.

template<class T>
void CBComPtr< T >::DecRef ( )
inline

Explicitly decreases the reference count on the internal pointer by 1 if it is not NULL.

References IRoot::DecRef(), and CBComPtr< T >::p.

template<class T>
T* CBComPtr< T >::Detach ( )
inline

Detaches the internal interface pointer from this object (sets it to NULL) and returns the old value. The reference count of that interface is NOT decremented by this operation.

Returns
The internal interface pointer value before this operation was performed.

References CBComPtr< T >::p.

template<class T>
bool CBComPtr< T >::IsEqualObject ( IRoot pOther)
inline

Compares this object's internal interface pointer with pOther. Returns true if they are both the same or they are both NULL, false otherwise.

Parameters
pOtherThe interface pointer to compare to this object's internal interface pointer.
Returns
true if this object's interface pointer and pOther are both the same or they are both NULL, false otherwise.

References IRoot::AskInterface().

template<class T>
CBComPtr< T >::operator T * ( ) const
inline

Casting this object to its internal interface type will return the internal interface pointer.

Returns
The address of the internal interface pointer.

References CBComPtr< T >::p.

template<class T>
bool CBComPtr< T >::operator! ( ) const
inline

Returns true if this object's internal interface pointer is NULL, false otherwise.

Returns
true if this object's internal interface pointer is NULL, false otherwise.
template<class T>
T** CBComPtr< T >::operator& ( )
inline

Returns the address of the internal interface pointer.

Returns
The address of the internal interface pointer.

References BCOM_ASSERT, and CBComPtr< T >::p.

template<class T>
T& CBComPtr< T >::operator* ( ) const
inline

Dereferencing the object will return a deferencing of the internal interface pointer.

Returns
The internal interface (not a pointer; the actual interface object).

References BCOM_ASSERT, and CBComPtr< T >::p.

template<class T>
_protptr<T>* CBComPtr< T >::operator-> ( ) const
inline

Use this to call a function on the internal interface. For example:

CBComPtr<ISomeInterface> piObject(piSomeInterfacePointer);
piObject->SomeFunction(); // this will call SomeFunction on the ISomeInterface pointer

References BCOM_ASSERT, and CBComPtr< T >::p.

template<class T>
bool CBComPtr< T >::operator< ( T *  pT) const
inline

Returns true if the address of this object's internal interface pointer is less than pT, false otherwise.

Parameters
pTThe interface pointer to compare to this object's interface pointer.
Returns
true if the address of this object's internal interface pointer is less than pT, false otherwise.
template<class T>
T* CBComPtr< T >::operator= ( T *  lp)
inline

Sets the internal interface pointer to lp. NULL is acceptable here.

Parameters
lpThe interface pointer to assign to this object. NULL is acceptable here.
Returns
The internal interface pointer.
template<class T>
T* CBComPtr< T >::operator= ( const CBComPtr< T > &  lp)
inline

Sets the internal interface pointer to the value of the internal interface pointer of lp.

Parameters
lpThe CBComPtr that contains the interface pointer you wish to assign to this object.
Returns
The internal interface pointer of this object.

References CBComPtr< T >::p.

template<class T>
bool CBComPtr< T >::operator== ( T *  pT) const
inline

Returns true if the address of this object's internal interface pointer is equal to pT, false otherwise.

Parameters
pTThe interface pointer to compare to this object's interface pointer. NULL is acceptable here.
Returns
true if the address of this object's internal interface pointer is less than pT, false otherwise.

Member Data Documentation

template<class T>
T* CBComPtr< T >::p