Graphite  Version 3
An experimental 3D geometry processing program
GEO::Counted Class Reference

Base class for reference-counted objects. More...

#include <geogram/basic/counted.h>

Inheritance diagram for GEO::Counted:
GEO::Factory< FactoryCreator1< Type, Param1 > > GEO::Factory< FactoryCreator0< Type > > GEO::AttributeStoreCreator GEO::CSGMesh GEO::Colormap GEO::Command GEO::CommandInvoker GEO::Delaunay GEO::Environment GEO::Factory< FactoryCreator > GEO::FileSystem::Node GEO::FullScreenEffectImpl GEO::Image GEO::ImageSerializer GEO::IntegrationSimplex GEO::MeshIOHandler GEO::NearestNeighborSearch GEO::Optimizer GEO::ProgressClient GEO::RestrictedVoronoiDiagram GEO::Thread GEO::ThreadManager OGF::BasicFactory< BASE > OGF::BasicFactoryWithArg< BASE, ARG > OGF::Factory OGF::LifeCycle OGF::Module OGF::Object OGF::RenderingContext OGF::Serializer OGF::Texture

Public Member Functions

void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Public Member Functions

static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Protected Member Functions

 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Detailed Description

Base class for reference-counted objects.

Reference counted objects implement shared ownership with a simple mechanism: objects willing to share ownership on a Counted object must call ref() on this object and call unref() when they no longer need it. The object is destroyed when no more objects hold a reference on it (when the last holder calls unref()).

Objects can benefit reference counted sharing simply by deriving from Counted and implementing the virtual destructor.

Reference acquisition and release can be done manually by explicitly calling ref() or unref() on the reference counted objects, or can be done automatically by using SmartPointer<T>.

See also
SmartPointer

Definition at line 71 of file counted.h.

Constructor & Destructor Documentation

◆ Counted()

GEO::Counted::Counted ( )
inlineprotected

Creates a reference counted object.

This initializes the reference count to 0 (zero).

Definition at line 142 of file counted.h.

◆ ~Counted()

virtual GEO::Counted::~Counted ( )
protectedvirtual

Destroys a reference counted object.

The destructor is never called directly but indirectly through unref(). If the reference counter is not null when the destructor is called the program dies with an assertion failure.

Member Function Documentation

◆ is_shared()

bool GEO::Counted::is_shared ( ) const
inline

Check if the object is shared.

An object is considered as shared if at least 2 client objects have called ref() on this object.

Returns
true if the object is shared, false otherwise

Definition at line 103 of file counted.h.

◆ nb_refs()

int GEO::Counted::nb_refs ( ) const
inline

Gets the number of references that point to this object.

Returns
the number of references.

Definition at line 111 of file counted.h.

◆ ref() [1/2]

void GEO::Counted::ref ( ) const
inline

Increments the reference count.

This function must be called to share ownership on this object. Calling ref() will prevent this object from being deleted when someone else releases ownership.

Definition at line 79 of file counted.h.

◆ ref() [2/2]

static void GEO::Counted::ref ( const Counted counted)
inlinestatic

Increments the reference count.

This calls ref() on object counted if it is not null.

Parameters
[in]countedreference object to reference.

Definition at line 120 of file counted.h.

◆ unref() [1/2]

void GEO::Counted::unref ( ) const
inline

Decrements the reference count.

This function must be called to release ownership on this object when it's no longer needed. Whwen the reference count reaches the value of 0 (zero), the object is simply deleted.

Definition at line 89 of file counted.h.

◆ unref() [2/2]

static void GEO::Counted::unref ( const Counted counted)
inlinestatic

Decrements the reference count.

This calls unref() on object counted if it is not null.

Parameters
[in]countedreference object to dereference.

Definition at line 131 of file counted.h.


The documentation for this class was generated from the following file: