SoRefCounter Class Reference
[General]

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

#include <Inventor/misc/SoRefCounter.h>

Inheritance diagram for SoRefCounter:
SbStructuredQuadrilateralMesh SoBase SoBufferAsyncNotifierInterface SoBufferObject SoCameraInteractor SoDeviceContext SoDeviceContextSharedGroup SoEngineDialogViewer SoInputReader SoLicensedProduct SoLicenseProperty SoMemoryObject SoNodeDependencies SoOffscreenRenderArea SoRenderAreaCore SoSystemTimer SoSystemTimerTask

List of all members.

Classes

struct  OnDeleteCB

Public Member Functions

void ref () const
void unref () const
void unrefNoDelete () const
int getRefCount () const
void lock () const
void unlock () const

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


Member Function Documentation

int SoRefCounter::getRefCount (  )  const [inline]

Returns current reference count.

void SoRefCounter::lock (  )  const [inline]

lock this instance.

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.

void SoRefCounter::unlock (  )  const [inline]

unlock this instance.

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.

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:

Open Inventor Toolkit reference manual, generated on 15 Mar 2023
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/