Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
IReferenceCounted.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_I_IREFERENCE_COUNTED_HPP_INCLUDED
6#define NIRT_I_IREFERENCE_COUNTED_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/nirt_types.hpp>
9
10#ifdef _NIRT_COMPILE_WITH_LEAK_HUNTER_
11 #include <nirtcpp/core/engine/leakHunter.hpp>
12#endif
13
14namespace nirt
15{
16
18
46 {
47 public:
48
51 : DebugName(0), ReferenceCounter(1)
52 {
53#ifdef _NIRT_COMPILE_WITH_LEAK_HUNTER_
54 LeakHunter::addObject(this);
55#endif
56 }
57
60 {
61 #ifdef _NIRT_COMPILE_WITH_LEAK_HUNTER_
62 LeakHunter::removeObject(this);
63 #endif
64 }
65
67
96 void grab() const { ++ReferenceCounter; }
97
99
126 bool drop() const
127 {
128 // someone is doing bad reference counting.
129 NIRT_DEBUG_BREAK_IF(ReferenceCounter <= 0)
130
131 --ReferenceCounter;
132 if (!ReferenceCounter)
133 {
134 delete this;
135 return true;
136 }
137
138 return false;
139 }
140
142
144 {
145 return ReferenceCounter;
146 }
147
149
152 const c8* getDebugName() const
153 {
154 return DebugName;
155 }
156
157 protected:
158
160
163 void setDebugName(const c8* newName)
164 {
165 DebugName = newName;
166 }
167
168 private:
169
171 const c8* DebugName;
172
174 mutable s32 ReferenceCounter;
175 };
176
177} // end namespace nirt
178
179#endif
Base class of most objects of the Nirtcpp Engine.
Definition IReferenceCounted.hpp:46
virtual ~IReferenceCounted()
Destructor.
Definition IReferenceCounted.hpp:59
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.hpp:163
bool drop() const
Drops the object. Decrements the reference counter by one.
Definition IReferenceCounted.hpp:126
s32 getReferenceCount() const
Get the reference count.
Definition IReferenceCounted.hpp:143
const c8 * getDebugName() const
Returns the debug name of the object.
Definition IReferenceCounted.hpp:152
void grab() const
Grabs the object. Increments the reference counter by one.
Definition IReferenceCounted.hpp:96
IReferenceCounted()
Constructor.
Definition IReferenceCounted.hpp:50
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
char c8
8 bit character variable.
Definition irrTypes.hpp:37

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print