10#if !defined(HPP_ALIB_BOXING_BOXING)
18# if !defined(HPP_ALIB_BOXING_DBGBOXING)
21# if !defined(HPP_ALIB_COMPATIBILITY_STD_TYPEINFO)
25# if ALIB_THREADS && !defined(HPP_ALIB_THREADS_THREADLOCK)
30# if !defined (HPP_ALIB_STRINGS_FORMAT)
35# if !defined(HPP_ALIB_MONOMEM_HASHMAP)
38# if !defined(HPP_ALIB_MONOMEM_HASHSET)
42# if !defined(_GLIBCXX_UNORDERED_MAP) && !defined(_UNORDERED_MAP_)
43# include <unordered_map>
45# if !defined(_GLIBCXX_UNORDERED_SET) && !defined(_UNORDERED_SET_)
46# include <unordered_set>
52#if !defined (_GLIBCXX_ALGORITHM) && !defined(_ALGORITHM_)
56namespace alib {
namespace boxing {
namespace detail {
61 extern HashSet <TypeFunctors::Key , TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
62 HashSet <TypeFunctors::Key , TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions(&
monomem::GlobalAllocator);
63 extern HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
64 HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables(&
monomem::GlobalAllocator);
65 extern HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
66 HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray(&
monomem::GlobalAllocator);
68 extern std::unordered_set<TypeFunctors::Key , TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
69 std::unordered_set<TypeFunctors::Key , TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
70 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
71 std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
72 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
73 std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
80 void DbgLockMaps(
bool doLock );
81 void DbgLockMaps(
bool doLock )
104 DbgKnownVTables.InsertUnique( std::make_pair( &vtable->
Type, vtable ) );
106 if ( DbgKnownVTables.find( &vtable->
Type ) != DbgKnownVTables.end() )
108 ALIB_ERROR(
"BOXING",
"Double instantiation of VTable of Type: \"",
109 DbgTypeDemangler( vtable->
Type ).Get(),
"\"" )
114 DbgKnownVTables.insert(std::make_pair( &vtable->
Type, vtable ) );
121 DbgKnownVTablesArray.InsertUnique(std::make_pair( &vtable->
ElementType, vtable ) );
123 if ( DbgKnownVTablesArray.find( &vtable->
ElementType ) != DbgKnownVTablesArray.end() )
125 ALIB_ERROR(
"BOXING",
"Double instantiation of VTable of Type: \"",
126 DbgTypeDemangler( vtable->
ElementType ).Get(),
"[]\"" )
131 DbgKnownVTablesArray.insert(std::make_pair( &vtable->
ElementType, vtable ) );
150 while( (idx=
string.IndexOf(search, startIndex) ) >= 0 )
151 string.Delete( idx, search.Length() );
158 A_CHAR(
"alib::boxing::" ),
164 auto startLength= result.
Length();
166 result << vtable->
Type;
189 bool isValueTypeCustomized,
190 bool isPointerTypeCustomized,
191 bool fitsToPlaceholder,
192 bool copyConstructible,
193 bool triviallyDestructible,
206 target << indent <<
"Mapped Type: ";
typeName(vtable, target ); target <<
" (Enumeration)" <<
NewLine();
207 target << indent <<
"Customized: Not customizable (always boxed as enum value type)" <<
NewLine();
213 bool arrayBoxing = vtable->
IsArray();
214 bool srcIsValue = !srcIsPointer;
216 target << indent <<
"Mapped Type: ";
typeName(vtable, target ); target <<
NewLine();
218 target <<indent <<
"Customized T: " << isValueTypeCustomized <<
NewLine();
219 target <<indent <<
"Customized T*: " << isPointerTypeCustomized <<
NewLine();
220 target <<indent <<
"Is Unboxable: "
222 ? ( srcIsValue && valueBoxing && isValueTypeCustomized
223 ?
"Yes (By customization)"
225 : srcIsValue && valueBoxing && !isValueTypeCustomized
226 ?
"Yes (Value fits in placeholder and is copy constructible)"
228 : srcIsPointer && pointerBoxing && isPointerTypeCustomized
229 ?
"Yes (By customization)"
231 : srcIsPointer && pointerBoxing && !isPointerTypeCustomized && (!copyConstructible || !triviallyDestructible)
232 ?
"Yes (Value would not be copy-constructible or trivially destructible)"
234 : srcIsPointer && pointerBoxing && !isPointerTypeCustomized && !fitsToPlaceholder
235 ?
"Yes (Value would not fit to placeholder)"
237 : srcIsValue && arrayBoxing && isValueTypeCustomized
238 ?
"Yes (Custom unboxing from array type)"
240 : srcIsValue && arrayBoxing && isPointerTypeCustomized
241 ?
"Yes (Unboxing from array type, customized with pointer type)"
243 : srcIsPointer && arrayBoxing && isPointerTypeCustomized
244 ?
"Yes (Custom unboxing from array type)"
246 : srcIsPointer && arrayBoxing && isValueTypeCustomized
247 ?
"Yes (Unboxing from array type, customized with value type)"
249 :
"INTERNAL ERROR IN DBG METHDO: CASE NOT MATCHED (E1)"
252 srcIsValue && isValueTypeCustomized
253 ?
"Forbidden (By customization)"
255 : srcIsValue && pointerBoxing && isPointerTypeCustomized
256 ?
"Not as value (Pointer type is customized)"
258 : srcIsValue && pointerBoxing && !isPointerTypeCustomized && (!copyConstructible || !triviallyDestructible)
259 ?
"Not as value (Not copy-constructible or trivially destructible)"
261 : srcIsValue && pointerBoxing && !isPointerTypeCustomized && !fitsToPlaceholder
262 ?
"Not as value (Does not fit to placeholder)"
264 : srcIsPointer && isPointerTypeCustomized
265 ?
"Forbidden (By customization)"
267 : srcIsPointer && valueBoxing && isValueTypeCustomized
268 ?
"Not as pointer (Value type is customized)"
270 : srcIsPointer && valueBoxing && !isValueTypeCustomized
271 ?
"Not as pointer (Value fits in placeholder and is copy constructible and trivially destructible)"
273 :
"INTERNAL ERROR IN DBG METHOd: CASE NOT MATCHED (E2)"
279 ?
"INTERNAL ERROR IN DBG METHOD: STATIC VTABLE NOT REGISTERED"
281 ?
"Dynamic Singleton"
282 :
"Static Singleton (Specialized T_VTableFactory)"
289 "BOXING",
"Error occurred describing type" )
294 String256 headline; headline <<
'\n' << indent <<
"Associated Specialized Functions:";
295 String256 indent2; indent2 << indent << indent;
296 dumpFunctions( functions, target, headline, indent2, tmpStrings );
313 for(
int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs )
316 dumpFunctions( input, result, headline, indent, tmpStrings );
318 formatter->Release();
331 for(
auto& type : input )
334 std::sort( tmpStrings.begin(), tmpStrings.end(),
335 [] (std::tuple<String, uinteger>& a,
336 std::tuple<String, uinteger>& b )
338 return std::get<0>(a).template CompareTo<true, lang::Case::Ignore>( std::get<0>(b) ) < 0;
343 output << headline <<
NewLine();
347 args.
Add( indent,
"{} {!ATab5}{:>2})\n",
nullptr,
'(',
nullptr );
348 for(
auto& nameAndUse : tmpStrings )
350 args[2]= std::get<0>(nameAndUse);
351 args[4]= std::get<1>(nameAndUse) != (std::numeric_limits<uinteger>::max)()
352 ?
Box( std::get<1>(nameAndUse) )
353 :
Box(
"No default implementation" );
354 formatter->FormatArgs( output, args );
356 formatter->Release();
373 for(
int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs )
378 dumpVTables( result, vtableNames, staticVtables , includeFunctions );
381 formatter->Release();
389 bool includeFunctions )
394 result << ( staticVtables ?
A_CHAR(
"Mapped types with static VTables")
395 :
A_CHAR(
"Mapped types with dynamic VTables") );
396 if( includeFunctions )
397 result <<
A_CHAR(
" and their associated specialized functions");
404 detail::DbgLockMaps(
true);
405 for(
int i= 0 ; i < 2; ++i )
406 for(
auto& it : ( i == 0 ? detail::DbgKnownVTables : detail::DbgKnownVTablesArray) )
418 temp <<
" ATTENTION: Unregistered customized VTable!!! This is an Error";
420 vtableNames.
Add( temp, it.second );
423 detail::DbgLockMaps(
false);
425 std::sort( vtableNames.begin(), vtableNames.end(),
430 Substring lhs= std::get<0>(a); lhs.TrimStart().ConsumeToken(
' '); lhs.TrimStart();
431 Substring rhs= std::get<0>(b); rhs.TrimStart().ConsumeToken(
' '); rhs.TrimStart();
432 return lhs.CompareTo<true, lang::Case::Ignore>( rhs ) < 0;
438 std::vector<std::pair<const std::type_info*,uinteger>> tempFunctions;
439 for(
auto& vtable: vtableNames )
441 result << std::get<0>(vtable) <<
NewLine();
442 if( includeFunctions )
449 formatter->Release();
462 for(
int theSakeOfAutoTabs= 0 ; theSakeOfAutoTabs < 2 ; ++theSakeOfAutoTabs )
472 (result <<
"Known Function Declarators And Usage Of Default Implementation:"
476 #if ALIB_DEBUG_MONOMEM
477 (result <<
NewLine() <<
"Metrics Of Custom Function Implementation HashMap: "
484 formatter->Release();
ALIB_API void Reset(const Snapshot &snapshot=Snapshot())
TAString & DeleteStart(integer regionLength)
integer IndexOf(TChar needle, integer startIdx=0) const
constexpr bool IsNotEmpty() const
constexpr integer Length() const
bool StartsWith(const TString &needle) const
#define ALIB_IF_THREADS(...)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_CALLER_PRUNED
#define ALIB_LOCK_WITH(lock)
void DbgRegisterVTable(detail::VTable *vtable, detail::VTable::DbgFactoryType productionType)
@ Left
Chooses left alignment.
ALIB_API ThreadLock GlobalAllocatorLock
MonoAllocator GlobalAllocator(8 *1024)
LocalString< 64 > String64
Type alias name for TLocalString<character,64> .
constexpr CString NewLine()
void DbgCheckSingleThreaded()
constexpr String NullString()
std::shared_ptr< lang::format::Formatter > SPFormatter
threads::ThreadLock ThreadLock
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
static ALIB_API void dumpVTables(AString &target, detail::DbgStringTable< const detail::VTable * > &vtableNames, bool staticVtables, bool includeFunctions)
static ALIB_API AString & removeNamespaces(AString &string, integer startIndex)
static ALIB_API std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
static std::vector< std::pair< const std::type_info *, uinteger > > GetSpecificFunctionTypes(const detail::VTable *vtable)
static ALIB_API void DumpCustomFunctionHashMapMetrics(AString &target, bool detailedBucketList)
static ALIB_API void typeInfo(AString &target, const detail::VTable *vtable, const String &indent, bool srcIsPointer, bool isValueTypeCustomized, bool isPointerTypeCustomized, bool fitsToPlaceholder, bool copyConstructible, bool triviallyDestructible, bool isUnboxable)
static ALIB_API alib::AString DumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, const String &headline=EmptyString(), const String &indent=EmptyString())
static ALIB_API void dumpFunctions(const std::vector< std::pair< const std::type_info *, uinteger > > &input, AString &output, const String &headline, const String &indent, detail::DbgStringTable< uinteger > &tmpStrings)
static ALIB_API void getFunctionTypes(const detail::FunctionTable &input, std::vector< std::pair< const std::type_info *, uinteger > > &output)
static ALIB_API void typeName(const detail::VTable *vtable, AString &result)
static ALIB_API AString DumpAll()
static ALIB_API std::vector< String > RemovableNamespaces
static ALIB_API AString DumpVTables(bool staticVtables, bool includeFunctions=false)
String & Add(const String &src, TArgs &&... args)
std::tuple< String, TAssociatedTypes... > ElementType
DbgFactoryType DbgProduction
const std::type_info & Type
@ Static
A static VTable is in place.
@ Unregistered
Not registered, yet.
@ Dynamic
The VTable is created dynamically from templated type VTableTT.
const MappingType Mapping
const std::type_info & ElementType