Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::IReferenceCounted Class Reference

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

#include <nirtcpp/core/engine/IReferenceCounted.hpp>

Inherited by nirt::ILogger [virtual], nirt::IOSOperator [virtual], nirt::IRandomizer [virtual], nirt::ITimer [virtual], nirt::NirtcppDevice [virtual], nirt::gui::ICursorControl [virtual], nirt::gui::IGUIElementFactory [virtual], nirt::gui::IGUIEnvironment [virtual], nirt::gui::IGUIFont [virtual], nirt::gui::IGUIImageList [virtual], nirt::gui::IGUISpriteBank [virtual], nirt::gui::IGUITreeViewNode, nirt::io::IArchiveLoader [virtual], nirt::io::IAttributeExchangingObject [virtual], nirt::io::IAttributes [virtual], nirt::io::IFileArchive [virtual], nirt::io::IFileList [virtual], nirt::io::IFileSystem [virtual], nirt::io::IReadFile [virtual], nirt::io::IWriteFile [virtual], nirt::scene::IAnimationEndCallBack [virtual], nirt::scene::IColladaMeshWriterNames [virtual], nirt::scene::IColladaMeshWriterProperties [virtual], nirt::scene::ICollisionCallback [virtual], nirt::scene::IGeometryCreator, nirt::scene::IIndexBuffer [virtual], nirt::scene::ILightManager, nirt::scene::IMesh [virtual], nirt::scene::IMeshBuffer [virtual], nirt::scene::IMeshCache [virtual], nirt::scene::IMeshLoader [virtual], nirt::scene::IMeshManipulator [virtual], nirt::scene::IMeshTextureLoader [virtual], nirt::scene::IMeshWriter [virtual], nirt::scene::ISceneCollisionManager [virtual], nirt::scene::ISceneLoader [virtual], nirt::scene::ISceneManager [virtual], nirt::scene::ISceneNodeAnimatorFactory [virtual], nirt::scene::ISceneNodeFactory [virtual], nirt::scene::ITriangleSelector [virtual], nirt::scene::IVertexBuffer [virtual], nirt::scene::SMD3Mesh, nirt::scene::SMD3MeshBuffer, nirt::scene::quake3::IShaderManager, nirt::scene::quake3::SVarGroupList, nirt::video::IContextManager [virtual], nirt::video::IImage [virtual], nirt::video::IImageLoader [virtual], nirt::video::IImageWriter, nirt::video::IMaterialRenderer [virtual], nirt::video::IRenderTarget [virtual], nirt::video::IShaderConstantSetCallBack [virtual], nirt::video::ITexture [virtual], nirt::video::IVideoDriver [virtual], and nirt::video::IVideoModeList [virtual].

Public Member Functions

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

Protected Member Functions

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

Detailed Description

Base class of most objects of the Nirtcpp 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 Nirtcpp Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Nirtcpp 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.

Member Function Documentation

◆ drop()

bool nirt::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 Nirtcpp Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Nirtcpp 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.

◆ getDebugName()

const c8 * nirt::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();

◆ getReferenceCount()

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

Get the reference count.

Returns
Current value of the reference counter.

◆ grab()

void nirt::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 Nirtcpp Engine are derived from IReferenceCounted, and so they are reference counted.

When you create an object in the Nirtcpp 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.

◆ setDebugName()

void nirt::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.

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

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print