ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing_debug.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
16#if ALIB_DEBUG_BOXING
17# if !ALIB_MONOMEM
18# include <unordered_map>
19# include <unordered_set>
20# endif
21# include <vector>
22# include <algorithm>
23#endif // ALIB_DEBUG_BOXING
24
25// =========================================== Module ==========================================
26#if ALIB_C20_MODULES
27 module ALib.Boxing;
28 import ALib.Lang;
29# if ALIB_MONOMEM
30 import ALib.Monomem;
31# endif
32#else
33# include "ALib.Lang.H"
34# include "ALib.Monomem.H"
35# include "ALib.Boxing.H"
36#endif
37// ====================================== Implementation =======================================
38#if ALIB_DEBUG_BOXING
40
42
44{
45 vtable->DbgProduction= productionType;
46 DbgLockMaps(true);
47 if( !vtable->IsArray() )
48 {
49 #if ALIB_MONOMEM
51 DbgKnownVTables.InsertUnique( std::make_pair( &vtable->Type, vtable ) );
52 #else
53 if ( DbgKnownVTables.find( &vtable->Type ) != DbgKnownVTables.end() )
54 {
55 ALIB_ERROR( "BOXING", "Double instantiation of VTable of Type: \"{}\"",
56 vtable->Type )
57 DbgLockMaps(false);
58 return;
59 }
60
61 DbgKnownVTables.insert(std::make_pair( &vtable->Type, vtable ) );
62 #endif
63 }
64 else
65 {
66 #if ALIB_MONOMEM
68 DbgKnownVTablesArray.InsertUnique(std::make_pair( &vtable->ElementType, vtable ) );
69 #else
70 if ( DbgKnownVTablesArray.find( &vtable->ElementType ) != DbgKnownVTablesArray.end() )
71 {
72 ALIB_ERROR( "BOXING", "Double instantiation of VTable of Type: \"{}[]\"",
73 vtable->ElementType )
74 DbgLockMaps(false);
75 return;
76 }
77
78 DbgKnownVTablesArray.insert(std::make_pair( &vtable->ElementType, vtable ) );
79 #endif
80 }
81 DbgLockMaps(false);
82}
83
84
85#if ALIB_STRINGS
86AString& removeNamespaces( AString& string, integer startIndex )
87{
88 for( auto& search: RemovableNamespaces )
89 {
90 integer idx;
91 while( (idx= string.IndexOf(search, startIndex) ) >= 0 )
92 string.Delete( idx, search.Length() );
93 }
94 return string;
95}
96
97std::vector<alib::String> RemovableNamespaces
98{
99 A_CHAR( "alib::boxing::" ),
100 A_CHAR( "alib::" ),
101};
102
103void typeName( const detail::VTable* vtable, AString& result )
104{
105 auto startLength= result.Length();
106 if( !vtable->IsArray() )
107 result << vtable->Type;
108 else
109 result << vtable->ElementType << "[]";
110
111 // MSC adds "class "
112 if( result.StartsWith( A_CHAR("class ") ) )
113 result.DeleteStart( 6 );
114
115 removeNamespaces(result, startLength);
116}
117#endif // ALIB_STRINGS
118
119
120} // namespace [alib::boxing::debug]
121
122# include "ALib.Lang.CIMethods.H"
123
124#endif // ALIB_DEBUG_BOXING
TAString & DeleteStart(integer regionLength)
constexpr integer Length() const
Definition string.inl:318
bool StartsWith(const TString &needle) const
Definition string.inl:772
#define A_CHAR(STR)
#define ALIB_ERROR(domain,...)
Definition alib.inl:1045
#define ALIB_LOCK_RECURSIVE_WITH(lock)
Definition alib.inl:1323
std::vector< alib::String > RemovableNamespaces
See function removeNamespaces. Pre-initialized with "alib::".
AString & removeNamespaces(AString &string, integer startIndex)
void typeName(const detail::VTable *vtable, AString &result)
void DbgRegisterVTable(detail::VTable *vtable, detail::VTable::DbgFactoryType productionType)
ALIB_DLL RecursiveLock GLOBAL_ALLOCATOR_LOCK
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
The custom function hash.
Definition vtable.inl:227
const std::type_info & ElementType
Definition vtable.inl:245
DbgFactoryType DbgProduction
Debug information.
Definition vtable.inl:274
const std::type_info & Type
Definition vtable.inl:241