arsa  2.7
Public Member Functions | Protected Member Functions | List of all members
irr::IReferenceCounted Class Reference

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

#include <IReferenceCounted.h>

Inheritance diagram for irr::IReferenceCounted:
irr::gui::ICursorControl irr::gui::IGUIElementFactory irr::gui::IGUIEnvironment irr::gui::IGUIFont irr::gui::IGUIImageList irr::gui::IGUISpriteBank irr::gui::IGUITreeViewNode irr::ILogger irr::io::IArchiveLoader irr::io::IAttributeExchangingObject irr::io::IAttributes irr::io::IFileArchive irr::io::IFileList irr::io::IFileSystem irr::io::IReadFile irr::io::IWriteFile irr::IOSOperator irr::IRandomizer irr::IrrlichtDevice irr::ITimer irr::scene::IAnimationEndCallBack irr::scene::IColladaMeshWriterNames irr::scene::IColladaMeshWriterProperties irr::scene::ICollisionCallback irr::scene::IGeometryCreator irr::scene::IIndexBuffer irr::scene::ILightManager irr::scene::IMesh irr::scene::IMeshBuffer irr::scene::IMeshCache irr::scene::IMeshLoader irr::scene::IMeshManipulator irr::scene::IMeshTextureLoader irr::scene::IMeshWriter irr::scene::ISceneCollisionManager irr::scene::ISceneLoader irr::scene::ISceneManager irr::scene::ISceneNodeAnimatorFactory irr::scene::ISceneNodeFactory irr::scene::ITriangleSelector irr::scene::IVertexBuffer irr::scene::quake3::IShaderManager irr::scene::quake3::SVarGroupList irr::scene::SMD3Mesh irr::scene::SMD3MeshBuffer irr::video::IContextManager irr::video::IImage irr::video::IImageLoader irr::video::IImageWriter irr::video::IMaterialRenderer irr::video::IRenderTarget irr::video::IShaderConstantSetCallBack irr::video::ITexture irr::video::IVideoDriver irr::video::IVideoModeList

Public Member Functions

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

51  : DebugName(0), ReferenceCounter(1)
52  {
53 #ifdef _IRR_COMPILE_WITH_LEAK_HUNTER_
54  LeakHunter::addObject(this);
55 #endif
56  }

◆ ~IReferenceCounted()

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

Destructor.

Definition at line 59 of file IReferenceCounted.h.

60  {
61  #ifdef _IRR_COMPILE_WITH_LEAK_HUNTER_
62  LeakHunter::removeObject(this);
63  #endif
64  }

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.

127  {
128  // someone is doing bad reference counting.
129  _IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0)
130 
131  --ReferenceCounter;
132  if (!ReferenceCounter)
133  {
134  delete this;
135  return true;
136  }
137 
138  return false;
139  }
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185

◆ 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.

153  {
154  return DebugName;
155  }

◆ 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.

144  {
145  return ReferenceCounter;
146  }

◆ 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.

96 { ++ReferenceCounter; }

◆ 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.

164  {
165  DebugName = newName;
166  }

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