next up previous contents index
Next: Converting code using traditional Up: Graph serialisation Previous: Graph serialisation   Contents   Index


Ref is a reference counted shared smart pointer implementation. When all references to an object are destroyed, the object it references is also destroyed. It is somewhat equivalent in functionality to Boosts shared_ptr or intrusive_ptr. Boost, however, is a big library, so the decision was made to avoid any dependencies of Classdesc or Eco Lab on Boost.

Ref performs entire object life cycle management. Initialising it with an object makes a copy, it does not pass control of the object to the ref. As such, it requires that its target type has a default constructor. Assigning, or copying a ref object duplicates the reference to a single object. Dereferencing works as with traditional pointers.


template <class T>
class ref
  ref(); // unitialised refs are NULL
  ref(const ref& x);
  ref(const T& x);  //copies x
  ref& operator=(const ref& x);
  ref& operator=(const T& x);  //copies x
  T* operator->();  //dereference operators
  T& operator*(); 
  void nullify();  //set reference to NULL
  bool nullref();  //returns true if invalid
  operator bool (); //returns true if valid
  bool operator==(const ref& x);
  bool operator==(const T* x); //true if x points to this's target
  bool operator==(const T& x); //true if x==this's target

Packing a ref object automatically invokes the pack_graph algorithm.

Russell Standish 2016-09-02