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


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.
static void ref(CNRef* aRef);
Static interface to ref(). Calls aRef->ref(), if aRef is non-NIL.
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.
static void deref(CNRef* aRef);
Static interface to deref(). Calls aRef->deref(), if aRef is non-NIL.
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.
static void decrease(CNRef* aRef);
Static function, which decreases the reference counter, if aRef is non-NIL, and does not delete aRef, if the reference counter equals to zero.
static void del(CNRef* aRef);
Static function, which decreases the reference counter, if aRef is non-NIL and the reference counter greater than zero, and which deletes aRef, if the reference counter equals to 0.


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