Go to the previous, next section.

CNRef -- Base class for classes with reference counting

SYNOPSIS

#include <CNCL/Ref.h>

TYPE

BASE CLASSES

None

DERIVED CLASSES

CNRefObj, CNRefNamed

RELATED CLASSES

CNPtr

DESCRIPTION

This class is the base class for classes with reference counting. Note: CNRef is outside of CNCL's inheritance tree and is always used as a further base class of its children, which are also derived from CNObject.

With the help of reference counting you can track all references to instances of CNObject.

See see section CNPtr -- Intelligent pointer to CNRefObjs and the file tRef.c in directory CNCL/lib/misc/test for examples.


Constructors:

CNRef();
Initially the reference counter is set to zero.


CNRef provides:

void ref();
Increase the reference counter by one.

void deref();
Decrease the reference counter by one. If the reference counter already was equal to zero, CNCL aborts with an error message. If the decreased reference counter equals to zero, then the object of this class deletes itself from memory, i.e. delete this;! In this case you cannot access this object any longer.

unsigned long get_count() const;
Returns the number of references.

static void set_debug(bool r, bool = FALSE);
If r is set to TRUE, all calls to ref() and deref() are logged and a respective message is output to cerr. The second parameter has no funcionality, yet.

Go to the previous, next section.