Intrusive Pointer

Intrusive pointer ( boost::intrusive_ptr ) is a reference counted pointer which stores the reference count within the pointed object. This naturally limits sensible use of this construct to composite types ( read: classes and structures ). The strong point of the intrusive_ptr is the fact that it is really lightweight, allowing to pass such pointers to functions as argument with very little cost but with most benefits of smart pointers.

TE provides a simple way to use intrusive pointers. 'common' project contains a base class called 'intrudable'. Inheriting from this class gives the derived class the interface for boost::intrusive_ptr to use.

Example:

#include "common/intrudable.hpp"

class some_interesting_class : public intrudable
{
};

class some_other_class : public intrudable
{
};

class composite_class : public some_interesting_class, public some_other_class
{
}

Example shows not only the ease of use but also another important feature. Intrudable is constructed in a way that ensures the 'diamond' inheritance problem. This is important because TE often uses multiple inheritance to interfaces and passes those interfaces via an intrusive_ptr.
When using the 'intrudable' class it has to be noted that instances of classes which derive from it cannot be instantiated in a way different then through boost::intrusive_ptr. Otherwise the reference count goes haywire when one does this:

some_interesting_class instance; // reference count == 0
{
boost::intrusive_ptr< some_interesting_class > local_pointer( &instance );
// reference count == 1;

local_pointer->some_function();
}

instance.some_function();
// gpf because local pointer got
// destroyed and took its instance with it


This behaviour is considered a feature because it forces stricter control over the lifetime of the object.

Intrusive pointers are considered to be the 'standard' smart pointer in TE. Other types - such as shared or scoped pointers are used only when itrusive pointers cannot be due to their concept constraints.