Reference Namespace Reference

Contains two basic classes that simplify dynamic memory management. More...

Classes

class  Able
 Manages Reference::To references to the instance. More...
 
class  HeapTracked
 Determines if the instance was dynamically allocated on the heap. More...
 
class  To
 Template class manages Reference::Able objects. More...
 
class  Vector
 A smart pointer that gets invalidated when its target is destroyed. More...
 

Functions

template<typename T >
std::ostream & operator<< (std::ostream &ostr, const To< T > &e)
 
template<typename T >
std::istream & operator>> (std::istream &istr, To< T > &e)
 

Variables

bool verbose = false
 Verbosity flag. More...
 

Detailed Description

Contains two basic classes that simplify dynamic memory management.

The Reference::Able mixin base class and Reference::To template class jointly implement a hybrid set of dynamic memory management features. Proper use of these classes will reduce the chances of memory leaks and dangling references.

A Reference::To object behaves very much like a normal pointer, except that it can only be used to refer to objects that inherit Reference::Able. For instance, if:

class klass: public Reference::Able { [...] };

then

klass* kp = new klass;

may be replaced with:

Reference::To<klass> kp = new klass;

Multiple Reference::To objects may point to a single Reference::Able instance. However, no single Reference::To instance manages that Reference::Able object. Instead, the number of Reference::To objects that point to the Reference::Able object are counted. Note that reference counting is used only to eliminate ownership tracking, and no high-level resource sharing is implemented.

The reference count is decremented whenever a Reference::To object is re-assigned or detroyed. When the reference count reaches zero, the Reference::Able object is automatically deleted. By noting which Reference::Able objects have been dynamcially allocated on the heap, static instances will not be automatically deleted. Therefore, the Reference::To class may also be safely used as follows:

klass instance; Reference::To<klass> kp =

Alternatively, if the Reference::Able object is deleted before its reference count reaches zero, all Reference::To instances that remain pointing to this object will be automatically invalidated.

If an attempt is made to dereference an invalid Reference::To<klass> instance, a Reference::To<klass>::invalid exception will be thrown.

Variable Documentation

◆ verbose

bool Reference::verbose = false

Verbosity flag.

Method verbosity flag.


Generated using doxygen 1.8.17