Open Inventor Release 2024.1.1
 
Loading...
Searching...
No Matches
SoRefCounter Class Reference

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

#include <Inventor/misc/SoRefCounter.h>

+ Inheritance diagram for SoRefCounter:

Public Member Functions

void ref () const
 Adds a reference to an instance.
 
void unref () const
 Removes a reference from an instance.
 
void unrefNoDelete () const
 unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.
 
int getRefCount () const
 Returns current reference count.
 
void lock () const
 lock this instance.
 
void unlock () const
 unlock this instance.
 

Detailed Description

Base class for ref-counted objects.

If a single object or more precisely a pointer to a single object is used at multiple locations in a program there should be some way to detect if the object is still in use or if it can be destroyed.

Reference counting as implemented by this class provides such a way. The behavior is the same as reference counting of Open Inventor nodes except that there is no automatic ref/unref (unless you use SoRef). Manual reference counting means that the user has to call the methods ref() and unref() whenever he wants to use or discard an object. These methods increment or decrement the reference count. The initial reference count is zero. The object is destroyed automatically if the is decremented to zero, i.e., the object isn't in use anymore.

The related class SoRef implements smart pointers to reference counted objects. Such pointers automatically keep track of reference counting and therefore are safer than explicit use of ref() and unref().

SEE ALSO

SoRef

Definition at line 70 of file SoRefCounter.h.

Member Function Documentation

◆ getRefCount()

int SoRefCounter::getRefCount ( ) const
inline

Returns current reference count.

Definition at line 99 of file SoRefCounter.h.

◆ lock()

void SoRefCounter::lock ( ) const
inline

lock this instance.

Definition at line 105 of file SoRefCounter.h.

◆ ref()

void SoRefCounter::ref ( ) const

Adds a reference to an instance.

This is defined to be const so users can call it on any instance, even const ones.

◆ unlock()

void SoRefCounter::unlock ( ) const
inline

unlock this instance.

Definition at line 111 of file SoRefCounter.h.

◆ unref()

void SoRefCounter::unref ( ) const

Removes a reference from an instance.

This method removes a reference from the object. If the reference count goes to zero the object is automatically deleted. This is defined to be const so users can call it on any instance, even const ones.

◆ unrefNoDelete()

void SoRefCounter::unrefNoDelete ( ) const

unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.

This is most useful in returning an object to a zero-reference-count state, like it was when it was created by new. This is defined to be const so users can call it on any instance, even const ones.


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