- Main Page
- Classes
- Directories
- Related Pages

- Class List
- Class Hierarchy
- Class Members

# Ptr< T > Class Template Reference

Smart pointer template. More...

`#include <ptr.h>`

List of all members.

## Public Member Functions

| Ptr ()
| Construct empty object. Analogy to "null".
| Ptr (TObject *data)
| Start managing reference counting to TObject data.
| Ptr (const Ptr &ptr)
| Copy constructor.
| ~Ptr ()
| Destructor.
| operator T * (void)
| Retype instance to template class.
TObject * | asObject ()
| Return managed object.
bool | isNull () const
| Test if managed object is NULL.
T * | operator-> (void)
| Use for smart acces to methods of managed object.
const T * | operator-> (void) const
| Use for smart acces to methods of managed object.
bool | operator< (const Ptr &ptr) const
| Comparator.
Ptr & | operator= (const Ptr &ptr)
| Assign operator.
Ptr & | operator= (TObject *ptr)
| Assign operator.

## Detailed Description

### template<class T>
class Ptr< T >

Smart pointer template.

Manages reference couting for TObject and its subclasses. Example of usage:

     {
        Ptr<MyClass> myClass=new MyClass();
     }

myClass will be disposed when reference is lost, in our example at the end of the block.

Note:
  Avoid circular references, reference circle will not be disposed until end of the program.

See also:
  TObject

Date:
  01-13-2006

Author:
  Ondrej Svejdar

Todo:

Bug:

## Constructor & Destructor Documentation

template<class T>
Ptr< T >::Ptr | ( | TObject * | data | ) | `[inline]`

| Start managing reference counting to TObject data. If data is not NULL, increase data reference's counter by one.

Parameters:

  | data | pointer to TObject

template<class T>
Ptr< T >::Ptr | ( | const Ptr< T > & | ptr | ) | `[inline]`

| Copy constructor. Set inner pointer to point to the same TObject as in ptr and increase reference's counter by one.

Parameters:

  | ptr | reference to Ptr class

template<class T>
Ptr< T >::~Ptr | ( |  | ) | `[inline]`

| Destructor. Decrease reference counter of managed TObject by one.

Returns:

## Member Function Documentation

template<class T>
TObject* Ptr< T >::asObject | ( |  | ) | `[inline]`

| Return managed object.

Returns:
  managed object

template<class T>
bool Ptr< T >::isNull | ( |  | ) | const`[inline]`

| Test if managed object is NULL.

Returns:
  true if instance is NULL

template<class T>
Ptr< T >::operator T * | ( | void |  | ) | `[inline]`

| Retype instance to template class.

Returns:
  pointer to managed object

template<class T>
const T* Ptr< T >::operator-> | ( | void |  | ) | const`[inline]`

| Use for smart acces to methods of managed object. Example:
     Ptr<MyClass> myClass=new MyClass();
     myClass->foo();

Returns:
  pointer to managed object

template<class T>
T* Ptr< T >::operator-> | ( | void |  | ) | `[inline]`

| Use for smart acces to methods of managed object. Example:
     Ptr<MyClass> myClass=new MyClass();
     myClass->foo();

Returns:
  pointer to managed object

template<class T>
bool Ptr< T >::operator< | ( | const Ptr< T > & | ptr | ) | const`[inline]`

| Comparator. For enable usage of generic Ptr classes in the STL container classes.

Parameters:

  | ptr | reference to Ptr

Returns:
  true if this instance is "less than" ptr

template<class T>
Ptr& Ptr< T >::operator= | ( | TObject * | ptr | ) | `[inline]`

| Assign operator. Decrease reference counter of currently managed object, set managed object to managed object referenced by ptr, and increase it's reference counter.

Parameters:

  | ptr | reference to Ptr

Returns:
  reference to this

template<class T>
Ptr& Ptr< T >::operator= | ( | const Ptr< T > & | ptr | ) | `[inline]`

| Assign operator. Decrease reference counter of currently managed object, set managed object to managed object referenced by ptr, and increase it's reference counter.

Parameters:

  | ptr | reference to Ptr

Returns:
  reference to this

The documentation for this class was generated from the following file:

- H:/projs/dotNET/eda/src/ptr.h