openshot-audio  0.1.6
juce_LeakedObjectDetector.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the juce_core module of the JUCE library.
5  Copyright (c) 2015 - ROLI Ltd.
6 
7  Permission to use, copy, modify, and/or distribute this software for any purpose with
8  or without fee is hereby granted, provided that the above copyright notice and this
9  permission notice appear in all copies.
10 
11  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
12  TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
13  NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
15  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16  CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 
18  ------------------------------------------------------------------------------
19 
20  NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
21  All other JUCE modules are covered by a dual GPL/commercial license, so if you are
22  using any other modules, be sure to check that you also comply with their license.
23 
24  For more details, visit www.juce.com
25 
26  ==============================================================================
27 */
28 
29 #ifndef JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED
30 #define JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED
31 
32 
33 //==============================================================================
46 template <class OwnerClass>
48 {
49 public:
50  //==============================================================================
51  LeakedObjectDetector() noexcept { ++(getCounter().numObjects); }
52  LeakedObjectDetector (const LeakedObjectDetector&) noexcept { ++(getCounter().numObjects); }
53 
55  {
56  if (--(getCounter().numObjects) < 0)
57  {
58  DBG ("*** Dangling pointer deletion! Class: " << getLeakedObjectClassName());
59 
72  }
73  }
74 
75 private:
76  //==============================================================================
77  class LeakCounter
78  {
79  public:
80  LeakCounter() noexcept {}
81 
82  ~LeakCounter()
83  {
84  if (numObjects.value > 0)
85  {
86  DBG ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
87 
96  }
97  }
98 
99  Atomic<int> numObjects;
100  };
101 
102  static const char* getLeakedObjectClassName()
103  {
104  return OwnerClass::getLeakedObjectClassName();
105  }
106 
107  static LeakCounter& getCounter() noexcept
108  {
109  static LeakCounter counter;
110  return counter;
111  }
112 };
113 
114 //==============================================================================
115 #if DOXYGEN || ! defined (JUCE_LEAK_DETECTOR)
116  #if (DOXYGEN || JUCE_CHECK_MEMORY_LEAKS)
117 
136  #define JUCE_LEAK_DETECTOR(OwnerClass) \
137  friend class juce::LeakedObjectDetector<OwnerClass>; \
138  static const char* getLeakedObjectClassName() noexcept { return #OwnerClass; } \
139  juce::LeakedObjectDetector<OwnerClass> JUCE_JOIN_MACRO (leakDetector, __LINE__);
140  #else
141  #define JUCE_LEAK_DETECTOR(OwnerClass)
142  #endif
143 #endif
144 
145 
146 #endif // JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED
#define noexcept
Definition: juce_CompilerSupport.h:141
LeakedObjectDetector(const LeakedObjectDetector &) noexcept
Definition: juce_LeakedObjectDetector.h:52
#define jassertfalse
Definition: juce_PlatformDefs.h:141
#define DBG(dbgtext)
Definition: juce_PlatformDefs.h:140
~LeakedObjectDetector()
Definition: juce_LeakedObjectDetector.h:54
Definition: juce_LeakedObjectDetector.h:47
LeakedObjectDetector() noexcept
Definition: juce_LeakedObjectDetector.h:51