IrrIMGUI  0.3.1
Public Member Functions | Private Attributes | List of all members
IrrIMGUI::IReferenceCounter Class Reference

A class to count references. More...

#include <IReferenceCounter.h>

Inheritance diagram for IrrIMGUI::IReferenceCounter:
Inheritance graph
[legend]

Public Member Functions

 IReferenceCounter (void)
 Constructor. More...
 
virtual ~IReferenceCounter (void)
 Destructor. More...
 
virtual void grab (void)
 Call this method to grab an instance. More...
 
virtual void drop (void)
 Call this method to drop an instance. If you drop the last used instance, the object is destroyed. More...
 
virtual irr::u32 getReferenceCount (void) const
 

Private Attributes

irr::u32 mReferences
 The reference counter of this class. More...
 

Detailed Description

A class to count references.

This class can be used in the same way like the reference counter of Irrlicht: When this class is created, it's counter is set to 1. When this class is destroyed it will print a warning, when the counter is not equal to 1, because this means another class still uses a reference to it. You can increase the counter by calling IReferenceCounter::grab(). By calling IReferenceCounter::drop() you can decrease the counter. If the counter reaches 0 in that way, the instance is destroyed automatically. Thus you don't need to call destroy manually, just call IReferenceCounter::drop() and it will be destroyed automatically when no other reference is currently in use. The big difference of the Irrlicht implementation is, that this implementation uses virtual methods. Thus you can easily mock classes that are derived from this reference counter. However this comes with a drawback: Creating and destroying such classes is not as fast as in the Irrlicht library. Outside of the main-loop this is not an issue, because spending some nanoseconds more a single time is not bad, when you gain a better testability. But when you create and destroy objects every frame, then it could become an issue. Please use in such cases the high performance inline implementation from Irrlicht!

Definition at line 58 of file IReferenceCounter.h.

Constructor & Destructor Documentation

IrrIMGUI::IReferenceCounter::IReferenceCounter ( void  )

Constructor.

Definition at line 41 of file IReferenceCounter.cpp.

IrrIMGUI::IReferenceCounter::~IReferenceCounter ( void  )
virtual

Destructor.

Definition at line 47 of file IReferenceCounter.cpp.

Member Function Documentation

void IrrIMGUI::IReferenceCounter::drop ( void  )
virtual

Call this method to drop an instance. If you drop the last used instance, the object is destroyed.

Definition at line 65 of file IReferenceCounter.cpp.

irr::u32 IrrIMGUI::IReferenceCounter::getReferenceCount ( void  ) const
virtual
Returns
Returns the current reference count.

Definition at line 80 of file IReferenceCounter.cpp.

void IrrIMGUI::IReferenceCounter::grab ( void  )
virtual

Call this method to grab an instance.

Definition at line 59 of file IReferenceCounter.cpp.

Member Data Documentation

irr::u32 IrrIMGUI::IReferenceCounter::mReferences
private

The reference counter of this class.

Definition at line 78 of file IReferenceCounter.h.


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