Irrlicht 3D Engine
irr::IReferenceCounted Class Reference

Base class of most objects of the Irrlicht Engine. More...

#include <IReferenceCounted.h>

+ Inheritance diagram for irr::IReferenceCounted:

Public Member Functions

 IReferenceCounted ()
 Constructor. More...
 
virtual ~IReferenceCounted ()
 Destructor. More...
 
bool drop () const
 Drops the object. Decrements the reference counter by one. More...
 
const c8getDebugName () const
 Returns the debug name of the object. More...
 
s32 getReferenceCount () const
 Get the reference count. More...
 
void grab () const
 Grabs the object. Increments the reference counter by one. More...
 

Protected Member Functions

void setDebugName (const c8 *newName)
 Sets the debug name of the object. More...
 

Detailed Description

Base class of most objects of the Irrlicht Engine.

This class provides reference counting through the methods grab() and drop(). It also is able to store a debug string for every instance of an object. Most objects of the Irrlicht Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Irrlicht engine, calling a method which starts with 'create', an object is created, and you get a pointer to the new object. If you no longer need the object, you have to call drop(). This will destroy the object, if grab() was not called in another part of you program, because this part still needs the object. Note, that you only need to call drop() to the object, if you created it, and the method had a 'create' in it.

A simple example:

If you want to create a texture, you may want to call an imaginable method IDriver::createTexture. You call ITexture* texture = driver->createTexture(dimension2d<u32>(128, 128)); If you no longer need the texture, call texture->drop().

If you want to load a texture, you may want to call imaginable method IDriver::loadTexture. You do this like ITexture* texture = driver->loadTexture("example.jpg"); You will not have to drop the pointer to the loaded texture, because the name of the method does not start with 'create'. The texture is stored somewhere by the driver.

Definition at line 45 of file IReferenceCounted.h.

Constructor & Destructor Documentation

◆ IReferenceCounted()

irr::IReferenceCounted::IReferenceCounted ( )
inline

Constructor.

Definition at line 50 of file IReferenceCounted.h.

◆ ~IReferenceCounted()

virtual irr::IReferenceCounted::~IReferenceCounted ( )
inlinevirtual

Destructor.

Definition at line 59 of file IReferenceCounted.h.

Member Function Documentation

◆ drop()

bool irr::IReferenceCounted::drop ( ) const
inline

Drops the object. Decrements the reference counter by one.

The IReferenceCounted class provides a basic reference counting mechanism with its methods grab() and drop(). Most objects of the Irrlicht Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Irrlicht engine, calling a method which starts with 'create', an object is created, and you get a pointer to the new object. If you no longer need the object, you have to call drop(). This will destroy the object, if grab() was not called in another part of you program, because this part still needs the object. Note, that you only need to call drop() to the object, if you created it, and the method had a 'create' in it.

A simple example:

If you want to create a texture, you may want to call an imaginable method IDriver::createTexture. You call ITexture* texture = driver->createTexture(dimension2d<u32>(128, 128)); If you no longer need the texture, call texture->drop(). If you want to load a texture, you may want to call imaginable method IDriver::loadTexture. You do this like ITexture* texture = driver->loadTexture("example.jpg"); You will not have to drop the pointer to the loaded texture, because the name of the method does not start with 'create'. The texture is stored somewhere by the driver.

Returns
True, if the object was deleted.

Definition at line 126 of file IReferenceCounted.h.

References _IRR_DEBUG_BREAK_IF.

Referenced by irr::scene::SMesh::clear(), irr::scene::ISceneNode::cloneMembers(), irr::video::IVideoDriver::createImageFromFile(), irr::scene::quake3::getTextures(), irr::scene::IColladaMeshWriter::setDefaultNameGenerator(), irr::scene::IColladaMeshWriter::setDefaultProperties(), irr::scene::CDynamicMeshBuffer::setIndexBuffer(), irr::scene::IMeshLoader::setMeshTextureLoader(), irr::scene::IColladaMeshWriter::setNameGenerator(), irr::scene::ISceneNode::setParent(), irr::scene::IColladaMeshWriter::setProperties(), irr::scene::ISceneNode::setTriangleSelector(), irr::scene::CDynamicMeshBuffer::setVertexBuffer(), irr::scene::CDynamicMeshBuffer::~CDynamicMeshBuffer(), irr::scene::IColladaMeshWriter::~IColladaMeshWriter(), irr::scene::IMeshLoader::~IMeshLoader(), irr::scene::ISceneNode::~ISceneNode(), irr::scene::SAnimatedMesh::~SAnimatedMesh(), irr::scene::SMD3Mesh::~SMD3Mesh(), and irr::scene::SMesh::~SMesh().

◆ getDebugName()

const c8* irr::IReferenceCounted::getDebugName ( ) const
inline

Returns the debug name of the object.

The Debugname may only be set and changed by the object itself. This method should only be used in Debug mode.

Returns
Returns a string, previously set by setDebugName();

Definition at line 152 of file IReferenceCounted.h.

◆ getReferenceCount()

s32 irr::IReferenceCounted::getReferenceCount ( ) const
inline

Get the reference count.

Returns
Current value of the reference counter.

Definition at line 143 of file IReferenceCounted.h.

◆ grab()

void irr::IReferenceCounted::grab ( ) const
inline

Grabs the object. Increments the reference counter by one.

Someone who calls grab() to an object, should later also call drop() to it. If an object never gets as much drop() as grab() calls, it will never be destroyed. The IReferenceCounted class provides a basic reference counting mechanism with its methods grab() and drop(). Most objects of the Irrlicht Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Irrlicht engine, calling a method which starts with 'create', an object is created, and you get a pointer to the new object. If you no longer need the object, you have to call drop(). This will destroy the object, if grab() was not called in another part of you program, because this part still needs the object. Note, that you only need to call drop() to the object, if you created it, and the method had a 'create' in it.

A simple example:

If you want to create a texture, you may want to call an imaginable method IDriver::createTexture. You call ITexture* texture = driver->createTexture(dimension2d<u32>(128, 128)); If you no longer need the texture, call texture->drop(). If you want to load a texture, you may want to call imaginable method IDriver::loadTexture. You do this like ITexture* texture = driver->loadTexture("example.jpg"); You will not have to drop the pointer to the loaded texture, because the name of the method does not start with 'create'. The texture is stored somewhere by the driver.

Definition at line 96 of file IReferenceCounted.h.

Referenced by irr::scene::ISceneNode::addAnimator(), irr::scene::ISceneNode::addChild(), irr::gui::IGUIElement::addChildToEnd(), irr::scene::SAnimatedMesh::addMesh(), irr::scene::SMesh::addMeshBuffer(), irr::scene::IColladaMeshWriter::setDefaultNameGenerator(), irr::scene::IColladaMeshWriter::setDefaultProperties(), irr::scene::CDynamicMeshBuffer::setIndexBuffer(), irr::scene::IMeshLoader::setMeshTextureLoader(), irr::scene::IColladaMeshWriter::setNameGenerator(), irr::scene::ISceneNode::setParent(), irr::scene::IColladaMeshWriter::setProperties(), irr::scene::ISceneNode::setTriangleSelector(), and irr::scene::CDynamicMeshBuffer::setVertexBuffer().

◆ setDebugName()

void irr::IReferenceCounted::setDebugName ( const c8 newName)
inlineprotected

Sets the debug name of the object.

The Debugname may only be set and changed by the object itself. This method should only be used in Debug mode.

Parameters
newNameNew debug name to set.

Definition at line 163 of file IReferenceCounted.h.

Referenced by irr::scene::CMeshBuffer< T >::CMeshBuffer(), irr::gui::IGUIElement::IGUIElement(), irr::scene::SAnimatedMesh::SAnimatedMesh(), irr::scene::SMesh::SMesh(), irr::scene::SSharedMeshBuffer::SSharedMeshBuffer(), and irr::scene::SSkinMeshBuffer::SSkinMeshBuffer().


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