acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
reference_referer.h
1// Created by camilo on 2023-11-25 21:15 <3ThomasBorregaardSorensen!!
2#pragma once
3
4
5#if REFERENCING_DEBUGGING
6
7
8CLASS_DECL_ACME bool refdbg_add_top_track(::subparticle* pparticle);
9CLASS_DECL_ACME void refdbg_erase_top_track(::subparticle* pparticle);
10
11
12CLASS_DECL_ACME::subparticle* refdbg_get_track_allocation();
13CLASS_DECL_ACME::reference_referer* refdbg_get_top_referer();
14CLASS_DECL_ACME::reference_referer* refdbg_get_top_releaser();
15
16CLASS_DECL_ACME void __check_refdbg
17
18
19//#include "acme/platform/_c.h"
20#include "acme/prototype/prototype/interlocked_count.h"
21#include "acme/prototype/string/c_string.h"
22
23
24CLASS_DECL_ACME ::i64 new_reference_referer_serial();
25
26
27class CLASS_DECL_ACME reference_referer
28{
29public:
30
31 //bool m_bConstructor;
32 //::subparticle * m_psubparticleExisting;
33 ::subparticle * m_psubparticle;
34 void * m_p;
35 ::i64 m_iSerial;
36 ::c::string m_cstringType;
37 ::c::string m_cstringFunctionName;
38 ::c::string m_cstringDebug;
39 //::reference_referer * m_preferencerefererNext = nullptr;
40
41 static ::i64 new_serial() { return new_reference_referer_serial(); }
42 reference_referer(const_char_pointer pszType = nullptr, const_char_pointer pszFunctionName = nullptr, const_char_pointer pszDebug = nullptr) :
43 //m_bConstructor(true),
44 //m_psubparticleExisting(nullptr),
45 m_psubparticle(nullptr),
46 m_p(nullptr),
47 m_cstringType(pszType),
48 m_cstringFunctionName(pszFunctionName),
49 m_cstringDebug(pszDebug),
50 m_iSerial(new_serial())
51 {
52 common_construct();
53 }
54 reference_referer(const reference_referer & referer) :
55 //m_bConstructor(referer.m_bConstructor),
56 //m_psubparticleExisting(referer.m_psubparticleExisting),
57 m_psubparticle(referer.m_psubparticle),
58 m_cstringType(referer.m_cstringType),
59 m_cstringFunctionName(referer.m_cstringFunctionName),
60 m_cstringDebug(referer.m_cstringDebug),
61 m_p(referer.m_p),
62 m_iSerial(referer.m_iSerial)
63 {
64 common_construct();
65 }
66 reference_referer(reference_referer && referer) :
67 //m_bConstructor(referer.m_bConstructor),
68 //m_psubparticleExisting(referer.m_psubparticleExisting),
69 m_psubparticle(referer.m_psubparticle),
70 m_cstringType(::transfer(referer.m_cstringType)),
71 m_cstringFunctionName(::transfer(referer.m_cstringFunctionName)),
72 m_cstringDebug(::transfer(referer.m_cstringDebug)),
73 m_p(referer.m_p),
74 m_iSerial(referer.m_iSerial)
75 {
76 //referer.m_psubparticleExisting = nullptr;
77 referer.m_psubparticle = nullptr;
78 referer.m_p = nullptr;
79 referer.m_iSerial = -1;
80 //referer.m_preferencerefererNext = nullptr;
81 common_construct();
82 }
83 template < prototype_subparticle A_SUBPARTICLE >
84 //reference_referer(::subparticle * psubparticleExisting, A_SUBPARTICLE * pparticle, const_char_pointer pszFunctionName = nullptr, const_char_pointer pszDebug = nullptr) :
85 reference_referer(A_SUBPARTICLE * pparticle, const_char_pointer pszFunctionName = nullptr, const_char_pointer pszDebug = nullptr) :
86 //m_bConstructor(!psubparticleExisting),
87 //m_psubparticleExisting(psubparticleExisting),
88 m_psubparticle(pparticle),
89 m_cstringType(typeid(*pparticle).name()),
90 m_cstringFunctionName(pszFunctionName),
91 m_cstringDebug(pszDebug),
92 m_p(nullptr),
93 m_iSerial(new_serial())
94 {
95 common_construct();
96 }
97 template < non_primitive_subparticle NON_SUBPARTICLE >
98 //reference_referer(::subparticle * psubparticleExisting, NON_SUBPARTICLE * p, const_char_pointer pszFunctionName, const_char_pointer pszDebug = nullptr) :
99 reference_referer(NON_SUBPARTICLE * p, const_char_pointer pszFunctionName, const_char_pointer pszDebug = nullptr) :
100 //m_bConstructor(!psubparticleExisting),
101 //m_psubparticleExisting(psubparticleExisting),
102 m_psubparticle(nullptr),
103 m_cstringType(typeid(*p).name()),
104 m_cstringFunctionName(pszFunctionName),
105 m_cstringDebug(pszDebug),
106 m_p(p),
107 m_iSerial(new_serial())
108 {
109 common_construct();
110 }
111 ~reference_referer()
112 {
113 destroy();
114 }
115 void destroy()
116 {
117 //m_bConstructor = false;
118 m_p = nullptr;
119 m_cstringType.destroy();
120 m_cstringFunctionName.destroy();
121 m_cstringDebug.destroy();
122 m_psubparticle = nullptr;
123 m_iSerial = -1;
124 }
125 bool operator ==(const reference_referer & referer) const
126 {
127 return m_iSerial == referer.m_iSerial;
128 }
129 void reset(const_char_pointer pszType = nullptr, const_char_pointer pszFunctionName = nullptr, const_char_pointer pszDebug = nullptr)
130 {
131 destroy();
132 m_cstringType = pszType;
133 m_cstringFunctionName = pszFunctionName;
134 m_cstringDebug = pszDebug;
135 }
136 reference_referer & operator=(const reference_referer & referer)
137 {
138 if (this != &referer)
139 {
140 destroy();
141 //m_bConstructor = referer.m_bConstructor;
142 //m_psubparticleExisting = referer.m_psubparticleExisting;
143 m_psubparticle = referer.m_psubparticle;
144 m_cstringType = referer.m_cstringType;
145 m_cstringFunctionName = referer.m_cstringFunctionName;
146 m_cstringDebug = referer.m_cstringDebug;
147 m_p = referer.m_p;
148 m_iSerial = referer.m_iSerial;
149 //m_preferencerefererNext = referer.m_preferencerefererNext;
150 }
151 return *this;
152 }
153 reference_referer & operator =(reference_referer && referer) noexcept
154 {
155 if (this != &referer)
156 {
157 destroy();
158 //m_bConstructor = referer.m_bConstructor;
159 //m_psubparticleExisting = referer.m_psubparticleExisting;
160 m_psubparticle = referer.m_psubparticle;
161 m_cstringType = ::transfer(referer.m_cstringType);
162 m_cstringFunctionName = ::transfer(referer.m_cstringFunctionName);
163 m_cstringDebug = ::transfer(referer.m_cstringDebug);
164 //m_preferencerefererNext = referer.m_preferencerefererNext;
165 m_p = referer.m_p;
166 m_iSerial = referer.m_iSerial;
167 //referer.m_bConstructor = false;
168 //referer.m_psubparticleExisting = nullptr;
169 referer.m_psubparticle = nullptr;
170 referer.m_p = nullptr;
171 referer.m_iSerial = -1;
172 //referer.m_preferencerefererNext = nullptr;
173 }
174 return *this;
175 }
176 bool operator!() const
177 {
178 return m_p == nullptr && m_psubparticle == nullptr;
179
180 }
181 explicit operator bool() const
182 {
183 return !this->operator!();
184 }
185
186 void common_construct();
187
188};
189
190
191#endif // REFERENCING_DEBUGGING
192
193
194
195class __new_site
196{
197public:
198
199
200#if REFERENCING_DEBUGGING
201
202
203 ::reference_referer* m_preferer;
204
205
206 __new_site(const ::reference_referer& referer, ::reference_referer** pprefererGet = nullptr)
207 {
208
209 ASSERT(!::allocator::is_suppressing_referencing_debugging());
210
211 if (!::allocator::is_suppressing_referencing_debugging())
212 {
213
214 m_preferer = ::allocator::push_referer(referer);
215
216 if (pprefererGet)
217 {
218
219 *pprefererGet = m_preferer;
220
221 }
222
223 }
224
225 }
226
227
228#else
229
230
231 __new_site()
232 {
233
234
235 }
236
237
238#endif
239
240 template < prototype_subparticle T >
241 T* operator << (T* p)
242 {
243
244
245#if REFERENCING_DEBUGGING
246
247
248 p->on_after_construct(m_preferer);
249
250
251#endif
252
253
254 return p;
255
256
257 }
258
259
260 template < non_primitive_subparticle T >
261 T * operator << (T * p)
262 {
263
264
265#if REFERENCING_DEBUGGING
266
267
268// p->on_after_construct(m_preferer);
269 ::allocator::__on_after_construct_non_subparticle();
270
271
272#endif
273
274
275 return p;
276
277
278 }
279
280};
281
282
283
284class __raw_new_site
285{
286public:
287
288
289 bool m_bOldSuppressingReferencingDebugging;
290
291
292 __raw_new_site()
293 {
294
295#if REFERENCING_DEBUGGING
296
297 m_bOldSuppressingReferencingDebugging = ::allocator::is_suppressing_referencing_debugging();
298
299 if (!m_bOldSuppressingReferencingDebugging)
300 {
301
302 ::allocator::start_suppressing_referencing_debugging();
303
304 }
305
306#endif
307
308 }
309
310
311 template < prototype_subparticle T >
312 T* operator << (T* p)
313 {
314
315#if REFERENCING_DEBUGGING
316
317 if (!m_bOldSuppressingReferencingDebugging)
318 {
319
320 ::allocator::cease_referencing_debugging_suppression();
321
322 }
323
324 p->on_after_construct(nullptr);
325
326#endif
327
328 return p;
329
330 }
331
332
333 template < non_primitive_subparticle T >
334 T* operator << (T* p)
335 {
336
337#if REFERENCING_DEBUGGING
338
339 if (!m_bOldSuppressingReferencingDebugging)
340 {
341
342 ::allocator::cease_referencing_debugging_suppression();
343
344 }
345
346 ::allocator::__on_after_construct_non_subparticle();
347
348#endif
349
350 return p;
351
352 }
353
354
355};
356
357
358class __new_refdbg_continuation_site
359{
360public:
361
362
363#if REFERENCING_DEBUGGING
364
365 ::reference_referer * m_preferencerefererTransferStack;
366
367#endif
368
369
370 __new_refdbg_continuation_site()
371 {
372
373#if REFERENCING_DEBUGGING
374
375 if(::allocator::get_top_referer())
376 {
377
378 m_preferencerefererTransferStack = ::allocator::get_top_referer();
379
380 }
381
382#endif
383
384 }
385
386
387 template < prototype_subparticle T >
388 T* operator << (T* p)
389 {
390
391#if REFERENCING_DEBUGGING
392
393 p->on_after_construct(nullptr);
394
395 p->m_prefererTransfer2 = m_preferencerefererTransferStack;
396
397#endif
398
399 return p;
400
401 }
402
403
404 template < non_primitive_subparticle T >
405 T* operator << (T* p)
406 {
407
408#if REFERENCING_DEBUGGING
409
410 ::allocator::__on_after_construct_non_subparticle();
411
412#endif
413
414 return p;
415
416 }
417
418
419};
420
421
422
423class __delete_site
424{
425public:
426
427#if REFERENCING_DEBUGGING
428 ::reference_referer* m_preferer;
429 __delete_site(::reference_referer * preferer)
430 {
431 m_preferer = preferer;
432 }
433#else
434 __delete_site()
435 {
436 }
437#endif
438
439 template < typename T >
440 T* operator << (T* p)
441 {
442#if REFERENCING_DEBUGGING
443 p->add_referer(m_preferer);
444#endif
445 return p;
446
447 }
448
449};
450
Definition subparticle.h:78