Go to the first, previous, next, last section, table of contents.


CNPtr -- Intelligent pointer to CNRefObjs

SYNOPSIS

#include <CNCL/Ptr.h>

TYPE

CN_PTR

BASE CLASSES

CNObject

DERIVED CLASSES

None

RELATED CLASSES

CNRef, CNRefObj, CNRefNamed

DESCRIPTION

This class provides an intelligent pointer to CNRefObjs, i.e. if you copy one CNPtr to another one, then the reference count of the CNRefObj contained in the source CNPtr is increased automatically and the reference count of the CNRefObj contained in the destination CNPtr is decreased automatically. See example below.


Constructors:

CNPtr();
CNPtr(CNParam *param);
CNPtr(CNRefObj *o);
CNPtr(const CNPtr &p);


In addition to the member functions required by CNCL, CNPtr provides:

CNPtr& operator =(const CNPtr& p)
Intelligent assignment operator. Additionally to copying the CNRefObj data member, the reference count of the CNRefObj data member contained in the source CNPtr is increased automatically and the reference count of the CNRefObj data member contained in the destination CNPtr is decreased automatically.
CNRefObj *operator ->() const
CNRefObj *get_object() const
Returns the CNRefObj data member.


Example:

CNRefObj *source_obj, *dest_obj;
CNPtr    *source, *dest;

source_obj = new CNRefObj;
source_obj->ref();
source = new CNPtr(source_obj);

dest_obj = new CNRefObj;
dest_obj->ref();
dest = new CNPtr(dest_obj);

// ref counts
// source_obj : 1
// dest_obj   : 1

// copy contents of source to dest
// implicitly increase counter of source_obj
// implicitly decrease counter of dest_obj and delete it

*dest = *source;
// ref counts
// source_obj : 2
// dest_obj   : 0 (deleted)

// implicitly decrease counter of source_obj
delete source;
// implicitly decrease counter of source_obj and delete it
delete dest;


Go to the first, previous, next, last section, table of contents.