arsa  2.7
leakHunter.h
Go to the documentation of this file.
1 // Copyright (C) 2013 Michael Zeilfelder
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 __LEAK_HUNTER_INCLUDEED__
6 
7 #include "IrrCompileConfig.h"
8 
9 #ifdef _IRR_COMPILE_WITH_LEAK_HUNTER_
10 
11 #include "irrArray.h"
12 
13 namespace irr
14 {
15  class IReferenceCounted;
16 
18 
23  class LeakHunter
24  {
25  public:
26  friend class IReferenceCounted;
27 
29 
34  static void clearReferenceCountedObjects()
35  {
36  ReferenceCountedObjects.clear();
37  }
38 
40  static inline irr::core::array<const IReferenceCounted*> getReferenceCountedObjects()
41  {
42  return ReferenceCountedObjects;
43  }
44 
45  protected:
46  static inline void addObject(const IReferenceCounted* object)
47  {
48  ReferenceCountedObjects.push_back(object);
49  }
50 
51  static inline void removeObject(const IReferenceCounted* object)
52  {
53  irr::s32 idx = ReferenceCountedObjects.linear_search(object );
54  if ( idx >= 0 )
55  {
56  irr::core::swap( ReferenceCountedObjects[idx], ReferenceCountedObjects.getLast() );
57  ReferenceCountedObjects.erase( ReferenceCountedObjects.size()-1 );
58  }
59  }
60 
61  private:
62  // NOTE: We don't do additional grab()/drop()'s here as we want to supervise reference counted objects and not affect them otherwise.
63  IRRLICHT_API static irr::core::array<const IReferenceCounted*> ReferenceCountedObjects;
64  };
65 } // end namespace irr
66 
67 #endif // _IRR_COMPILE_WITH_LEAK_HUNTER_
68 
69 #endif
#define IRRLICHT_API
Set FPU settings.
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
void push_back(const T &element)
Adds an element at back of array.
Definition: irrArray.h:111
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
void swap(T1 &a, T2 &b)
swaps the content of the passed parameters
Definition: irrMath.h:178
Self reallocating template array (like stl vector) with additional features.
Definition: irrArray.h:22