Embedded Template Library  1.0
debug_count.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2017 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_DEBUG_COUNT_INCLUDED
32 #define ETL_DEBUG_COUNT_INCLUDED
33 
34 #include <stdint.h>
35 #include <assert.h>
36 
37 #include "platform.h"
38 
41 
42 #if defined(ETL_DEBUG_COUNT)
43 
44 #define ETL_DECLARE_DEBUG_COUNT etl::debug_count etl_debug_count;
45 #define ETL_INCREMENT_DEBUG_COUNT ++etl_debug_count;
46 #define ETL_DECREMENT_DEBUG_COUNT --etl_debug_count;
47 #define ETL_ADD_DEBUG_COUNT(n) etl_debug_count += (n);
48 #define ETL_SUBTRACT_DEBUG_COUNT(n) etl_debug_count -= (n);
49 #define ETL_RESET_DEBUG_COUNT etl_debug_count.clear();
50 #define ETL_OBJECT_RESET_DEBUG_COUNT(object) object.etl_debug_count.clear();
51 
52 namespace etl
53 {
54  //***************************************************************************
60  //***************************************************************************
61  class debug_count
62  {
63  public:
64 
65  inline debug_count()
66  : count(0)
67  {
68  }
69 
70  inline ~debug_count()
71  {
72  assert(count == 0);
73  }
74 
75  inline debug_count& operator ++()
76  {
77  ++count;
78  return *this;
79  }
80 
81  inline debug_count& operator --()
82  {
83  --count;
84  assert(count >= 0);
85  return *this;
86  }
87 
88  template <typename T>
89  inline debug_count& operator +=(T n)
90  {
91  count += int32_t(n);
92  return *this;
93  }
94 
95  template <typename T>
96  inline debug_count& operator -=(T n)
97  {
98  count -= int32_t(n);
99  return *this;
100  }
101 
102  inline operator int32_t()
103  {
104  return count;
105  }
106 
107  inline void clear()
108  {
109  count = 0;
110  }
111 
112  private:
113 
114  int32_t count;
115  };
116 
117 }
118 
119 #else
120  #define ETL_DECLARE_DEBUG_COUNT
121  #define ETL_INCREMENT_DEBUG_COUNT
122  #define ETL_DECREMENT_DEBUG_COUNT
123  #define ETL_ADD_DEBUG_COUNT(n)
124  #define ETL_SUBTRACT_DEBUG_COUNT(n)
125  #define ETL_RESET_DEBUG_COUNT
126  #define ETL_OBJECT_RESET_DEBUG_COUNT(object)
127 #endif // ETL_DEBUG_COUNT
128 
129 #endif
Definition: absolute.h:37