AGX Dynamics  2.37.3.2
ReferencedManager.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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()
23 #include <agx/agxPhysics_export.h>
24 
25 
26 
27 // hashtable would be better but causes problems with includes
28 #include <map>
29 #include <iostream>
30 
31 namespace 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.