Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

upf::Ptr< T > Class Template Reference

#include <cxx_ptr.h>

List of all members.


Detailed Description

template<class T>
class upf::Ptr< T >

UPF's smart pointer.

upf::Ptr<T> holds pointer of type T* and overrides operator-> so that it can be used as if it were T*. upf::Ptr's function is two-fold:

Parameters:
T  interface type. This must be interface, not implementation class type!
A simple example is here:
    {
        upf::Ptr<IFoo> foo = upf::create("MyFooImpl");
        upf::Ptr<upf::IClassInfo> x = foo; 
        // x == NULL now because IFoo does not implement upf::IClassInfo
        {
            upf::Ptr<upf::IObject> base = foo;  // foo's ref count increased by 1 (to 2)
            // 'base' contains valid pointer, every interface implements IObject
        } // 'base' ptr destroyed, ref cnt decreased to 1
    } // 'foo' ptr destroyed, ref cnt decreased to 0, the object itself is deleted

See also:
Reference Counting


Public Methods

 Ptr ()
 Default ctor.

 Ptr (const Ptr &ptr)
 Copy ctor.

template<class O>  Ptr (const Ptr< O > &ptr)
 "Copy" ctor from non-T smart pointer.

 Ptr (IObject *obj)
 Ctor from non-T ordinary pointer.

 Ptr (T *obj)
 Ctor (doesn't call upf::queryInterface).

 ~Ptr ()
 Destructor.

T * operator-> () const
 operator-> allows us to use Ptr as ordinary pointers

const Ptr & operator= (IObject *obj)
 operator= for non-T types.

const Ptr & operator= (const Ptr &ptr)
 Fast version of operator= that does not call upf::queryInterface.

template<class O> const Ptr & operator= (const Ptr< O > &ptr)
 operator= for non-T types.

const Ptr & operator= (T *obj)
 Fast version of operator= that does not call upf::queryInterface.

 operator T * () const
 Cast to T*.


Constructor & Destructor Documentation

template<class T>
template<class O>
upf::Ptr< T >::Ptr const Ptr< O > &    ptr [inline]
 

"Copy" ctor from non-T smart pointer.

upf::queryInterface is called to determine if interface T is supported by ptr. If it is not, the pointer is assigned NULL value instead of ptr.

template<class T>
upf::Ptr< T >::Ptr IObject   obj [inline]
 

Ctor from non-T ordinary pointer.

upf::queryInterface is called to determine if interface T is supported by obj. If it is not, the pointer is assigned NULL value instead of obj.


Member Function Documentation

template<class T>
template<class O>
const Ptr& upf::Ptr< T >::operator= const Ptr< O > &    ptr [inline]
 

operator= for non-T types.

upf::queryInterface is called to determine if interface T is supported by the object hold in ptr. If it is not, the pointer is assigned NULL value instead of ptr.

template<class T>
const Ptr& upf::Ptr< T >::operator= IObject   obj [inline]
 

operator= for non-T types.

upf::queryInterface is called to determine if interface T is supported by obj. If it is not, the pointer is assigned NULL value instead of obj.


Generated on Wed Jan 15 23:10:56 2003 for Universal Plugins Framework by doxygen1.2.18