acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
counter.h
1
// Created on 2021-03-42 16:35 <3ThomasBS_!!
2
#pragma once
3
4
5
#include "acme/platform/acme.h"
6
#include "acme/prototype/collection/map.h"
7
8
9
namespace
heap
10
{
11
12
13
template
<
typename
TYPE >
14
class
counter :
15
virtual
public
::particle
16
{
17
public
:
18
19
class
item
20
{
21
22
public
:
23
24
::string m_strDebug;
25
::i64 m_i32 = 0;
26
27
28
};
29
30
bool
m_bEnabled =
false
;
31
//::i32 m_iMemoryCounters = -1;
32
33
::critical_section
m_criticalsection;
34
35
//::i32 m_iMemoryCountersStartable = 0;
36
37
::map_base < TYPE, item > m_mapCounter;
38
39
40
counter()
41
{
42
43
//m_bEnabled = false;
44
45
}
46
~counter
()
override
47
{
48
49
50
}
51
52
void
on_initialize_particle()
override
53
{
54
::particle::on_initialize_particle();
55
}
56
57
bool
is_enabled()
58
{
59
60
return
m_bEnabled;
61
62
}
63
64
//void increment_by_name(const ::scoped_string & scopedstr);
65
//void decrement_by_name(const ::scoped_string & scopedstr);
66
67
68
//template < typename T >
69
//const_char_pointer memory_counter_id(T* pthis)
70
//{
71
72
// return typeid(*pthis).name();
73
74
//}
75
76
77
::i64 get_counter(
const
TYPE & t)
78
{
79
80
critical_section_lock lock(&m_criticalsection);
81
82
if
(is_enabled())
83
{
84
85
auto
&
item
= m_mapCounter[t];
86
87
return
item
.m_i32;
88
89
}
90
91
return
-1;
92
93
}
94
95
96
97
void
increment_counter(
const
TYPE & t)
98
{
99
100
critical_section_lock lock(&m_criticalsection);
101
102
if
(is_enabled())
103
{
104
105
auto
&
item
= m_mapCounter[t];
106
107
item
.m_i32++;
108
109
}
110
111
}
112
113
114
void
decrement_counter(
const
TYPE & t)
115
{
116
117
critical_section_lock lock(&m_criticalsection);
118
119
if
(is_enabled())
120
{
121
122
auto
& i = m_mapCounter[t];
123
124
i--;
125
126
}
127
128
}
129
130
131
};
132
133
134
}
// namespace heap
135
136
137
138
140
141
142
//CLASS_DECL_ACME void initialize_memory_counter();
143
//CLASS_DECL_ACME void finalize_memory_counter();
144
//CLASS_DECL_ACME ::memory_counter * get_memory_counter();
145
146
147
//template < typename T >
148
//const_char_pointer memory_counter_id(T* pthis);
149
//
150
151
152
//template < typename T >
153
//void memory_counter_increment(T* pthis)
154
//{
155
//
156
// if (this->::system()->m_pmemorycounter)
157
// {
158
//
159
// this->::system()->m_pmemorycounter->memory_counter_increment(pthis);
160
//
161
// }
162
//
163
//}
164
//
165
//
166
//template < typename T >
167
//void memory_counter_decrement(T* pthis)
168
//{
169
//
170
// if (this->::system()->m_pmemorycounter)
171
// {
172
//
173
// this->::system()->m_pmemorycounter->memory_counter_decrement(pthis);
174
//
175
// }
176
//
177
//}
178
//
179
//
180
critical_section
Definition
critical_section.h:9
heap::counter::item
Definition
counter.h:20
heap::counter
Definition
counter.h:16
memory
counter.h
Generated by
1.17.0