AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ReferencedManager.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_REFERENCEDMANAGER_H
18#define AGX_REFERENCEDMANAGER_H
19
20#include <agx/config/AGX_DEBUG_TRACK_REFERENCED_OBJECTS.h>
21
22#if AGX_DEBUG_TRACK_REFERENCED_OBJECTS()
24
25
26
27// hashtable would be better but causes problems with includes
28#include <map>
29#include <iostream>
30
31namespace agx {
32
33
34 class AGXPHYSICS_EXPORT ReferencedManager {
35
36 public:
37 static ReferencedManager* instance();
38
39 inline void ref() const
40 {
41 _refCount++;
42 }
43
44 inline void unref() const
45 {
46 _refCount--;
47 if ( _refCount == 0 )
48 {
49 delete this;
50 _refCount = 0;
51 }
52 }
53
54 inline void add(const void *p)
55 {
56 ++m_added;
57 if ( m_referencedObjects.find(p) != m_referencedObjects.end() )
58 {
59 std::cout << "Duplicate: " << p << std::endl;
60 }
61 m_referencedObjects.insert( std::make_pair(p, 1) );
62 }
63
64 inline void remove(const void *p)
65 {
66 ++m_removed;
67 m_referencedObjects.erase(p);
68 }
69
70 void report();
71
72 protected:
73 ReferencedManager() : m_added(0), m_removed(0) {}
74 private:
75 ~ReferencedManager();
76 int m_added;
77 int m_removed;
78 mutable int _refCount;
79 // void* _observers;
80
81 std::map<const void*,int> m_referencedObjects;
82 };
83
84}
85
86
87#endif
88#endif
89
#define AGXPHYSICS_EXPORT
The agx namespace contains the dynamics/math part of the AGX Dynamics API.