Irrlicht 3D Engine
IReferenceCounted.h
Go to the documentation of this file.
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 irrlicht.h
4 
5 #ifndef __I_IREFERENCE_COUNTED_H_INCLUDED__
6 #define __I_IREFERENCE_COUNTED_H_INCLUDED__
7 
8 #include "irrTypes.h"
9 
10 namespace irr
11 {
12 
14 
42  {
43  public:
44 
47  : DebugName(0), ReferenceCounter(1)
48  {
49  }
50 
53  {
54  }
55 
57 
86  void grab() const { ++ReferenceCounter; }
87 
89 
116  bool drop() const
117  {
118  // someone is doing bad reference counting.
119  _IRR_DEBUG_BREAK_IF(ReferenceCounter <= 0)
120 
121  --ReferenceCounter;
122  if (!ReferenceCounter)
123  {
124  delete this;
125  return true;
126  }
127 
128  return false;
129  }
130 
132 
134  {
135  return ReferenceCounter;
136  }
137 
139 
142  const c8* getDebugName() const
143  {
144  return DebugName;
145  }
146 
147  protected:
148 
150 
153  void setDebugName(const c8* newName)
154  {
155  DebugName = newName;
156  }
157 
158  private:
159 
161  const c8* DebugName;
162 
164  mutable s32 ReferenceCounter;
165  };
166 
167 } // end namespace irr
168 
169 #endif
170 
bool drop() const
Drops the object. Decrements the reference counter by one.
virtual ~IReferenceCounted()
Destructor.
char c8
8 bit character variable.
Definition: irrTypes.h:31
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
signed int s32
32 bit signed variable.
Definition: irrTypes.h:66
s32 getReferenceCount() const
Get the reference count.
IReferenceCounted()
Constructor.
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:178
const c8 * getDebugName() const
Returns the debug name of the object.
void grab() const
Grabs the object. Increments the reference counter by one.
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Base class of most objects of the Irrlicht Engine.