12 #include <boost/function.hpp>
16 #ifdef DT_OBJECT_TRACKING_ENABLED
17 #include <tbb/spin_mutex.h>
23 template <
typename D,
bool Enable = false>
26 template <
typename D,
bool Enable = false>
30 #ifndef DT_OBJECT_DEBUGGING_ENABLED
31 #define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
32 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type)
33 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(type)
36 template <
typename D,
bool Enable>
45 class DtObjectContainer;
51 template <
typename D,
bool Enable>
54 typedef unsigned long long CounterType;
55 typedef std::atomic<CounterType> AtomicType;
57 typedef boost::function<std::string ()> NameFunction;
62 static std::string Print(std::string regex =
"");
63 static std::string PrettyPrintSize(
size_t);
64 static std::string DetectLeaks();
67 explicit DtObjectCounter(
71 const DtObjectContainer* container = 0);
74 explicit DtObjectCounter(
78 const DtObjectContainer* container = 0);
84 CounterType value()
const {
return myCount; }
87 CounterType total()
const {
return myTotal; }
90 size_t size()
const {
return mySize; }
93 size_t totalSize()
const {
return value() *
size(); }
96 const DtObjectContainer* objects()
const {
return myObjects; }
100 CounterType increment() { ++myCount;
return myTotal++; }
103 void decrement() { --myCount; }
106 AtomicType myCount, myTotal;
108 const bool myEnableFlag;
111 const DtObjectContainer* myObjects;
114 DtObjectCounter(
const DtObjectCounter&);
116 void operator=(
const DtObjectCounter&);
119 #ifdef DT_OBJECT_TRACKING_ENABLED
121 class DtObjectTracker;
126 typedef tbb::spin_mutex
Mutex;
127 typedef std::list<const DtObjectTracker*> TrackableList;
128 typedef TrackableList::iterator Handle;
130 typedef boost::function<void (const DtObjectTracker&)> IterateFunction;
132 Handle add(
const DtObjectTracker& obj);
133 void remove(Handle h);
135 void iterate(
const IterateFunction&)
const;
136 void print(std::ostream&,
unsigned width = 0)
const;
139 mutable Mutex myMutex;
140 TrackableList myTrackables;
146 virtual std::string debugText()
const;
148 DtObjectCounter::CounterType objectIndex()
const {
return myObjectIndex; }
151 DtObjectTracker() : myObjectIndex(0) { }
153 virtual ~DtObjectTracker();
156 template <
typename D,
bool Enable>
159 DtObjectContainer::Handle myHandle;
160 DtObjectCounter::CounterType myObjectIndex;
165 class DtObjectTracker { };
169 template <
typename D,
bool Enable>
173 static DtObjectCounter::CounterType ObjectCount()
175 return theStaticCount.value();
178 static const DtObjectContainer* ObjectContainer()
180 return ObjectContainerMutable();
188 #ifdef DT_OBJECT_TRACKING_ENABLED
189 myObjectIndex = theStaticCount.increment();
190 myHandle = ObjectContainerMutable()->add(*
this);
192 theStaticCount.increment();
201 #ifdef DT_OBJECT_TRACKING_ENABLED
202 myObjectIndex = theStaticCount.increment();
203 myHandle = ObjectContainerMutable()->add(*
this);
205 theStaticCount.increment();
212 #ifdef DT_OBJECT_TRACKING_ENABLED
214 ObjectContainerMutable()->remove(myHandle);
218 theStaticCount.decrement();
222 static DtObjectCounter theStaticCount;
224 static DtObjectContainer* ObjectContainerMutable()
226 #ifdef DT_OBJECT_TRACKING_ENABLED
227 static DtObjectContainer theObjectContainer;
228 return &theObjectContainer;
235 template <
typename D>
236 struct DtObjectDebuggerLabel
238 static inline std::string value()
244 template <
typename D,
bool Enabled>
246 &DtObjectDebuggerLabel<D>::value,
251 #define DT_NAME_OBJECT_DEBUGGER(type, name) \
253 struct DtObjectDebuggerLabel< type > \
255 static inline std::string value() \
261 #define DT_DEFINE_OBJECT_DEBUGGER_NAME(type) \
263 struct DtObjectDebuggerLabel< type > \
265 static inline std::string value() \
271 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE(type) \
272 template <typename T> \
273 struct DtObjectDebuggerLabel< type <T> > \
275 static inline std::string value() \
277 std::string name( #type "<" ); \
278 name += DtObjectDebuggerLabel<T>::value(); \
284 #define DT_DEFINE_OBJECT_DEBUGGER_NAME_TEMPLATE2(type) \
285 template <typename T1, typename T2> \
286 struct DtObjectDebuggerLabel< type <T1,T2> > \
288 static inline std::string value() \
290 std::string name( #type "<" ); \
291 name += DtObjectDebuggerLabel<T1>::value(); \
293 name += DtObjectDebuggerLabel<T2>::value(); \
voidpf void uLong size
Definition: ioapi.h:39
Default on in debug, off in release.
Definition: objectCounter.h:27
void print(double **a, int r, int c, const char *str)
DtObjectDebugger()
Definition: objectCounter.h:40
OpenThreads::Mutex Mutex
Definition: DtOsgThreadingUtils.h:12
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34