10#ifndef HPP_ALIB_BOXING_BOXING
14#if !defined(HPP_ALIB_COMPATIBILITY_STD_TYPEINFO)
19# if !defined (HPP_ALIB_BOXING_DBGBOXING)
27# if !defined(HPP_ALIB_MONOMEM_HASHMAP)
30# if !defined(HPP_ALIB_MONOMEM_HASHSET)
34# if !defined(_GLIBCXX_UNORDERED_MAP) && !defined(_UNORDERED_MAP_)
35# include <unordered_map>
37# if !defined(_GLIBCXX_UNORDERED_SET) && !defined(_UNORDERED_SET_)
38# include <unordered_set>
44namespace alib {
namespace boxing {
namespace detail {
49 extern HashSet <TypeFunctors::Key, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
50 extern HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
51 extern HashMap <TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
53 extern std::unordered_set<TypeFunctors::Key, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownCustomFunctions;
54 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTables;
55 extern std::unordered_map<TypeFunctors::Key, detail::VTable*, TypeFunctors::Hash, TypeFunctors::EqualTo> DbgKnownVTablesArray;
58extern ALIB_API void DbgLockMaps(
bool doLock );
66 struct CustomFunctionKey
68 const FunctionTable* Parent;
69 const std::type_info&
Type;
71 CustomFunctionKey(
const FunctionTable* parent,
const std::type_info& type )
77 struct CustomFunctionMapped
80ALIB_DBG(uinteger DbgCntInvocations; )
82 CustomFunctionMapped(
void* implementation )
83 : Implementation (implementation)
89 struct CustomFunctionHash
91 std::size_t operator()(
const CustomFunctionKey& key)
const
93 size_t result=
reinterpret_cast<size_t>(key.Parent)
94 ^ key.Type.hash_code();
95 result^= (result << 21 );
96 result^= (result >> 11);
102 struct CustomFunctionEqualTo
104 bool operator()(
const CustomFunctionKey& lhs,
const CustomFunctionKey& rhs)
const
106 return lhs.Parent == rhs.Parent
107 && lhs.Type == rhs.Type;
112 HashMap < CustomFunctionKey, CustomFunctionMapped,
116 std::unordered_map< CustomFunctionKey, CustomFunctionMapped,
118 CustomFunctionEqualTo > customFunctionMap;
135 auto it= customFunctionMap.Find( CustomFunctionKey(
this, rtti) );
137 auto it= customFunctionMap.find( CustomFunctionKey(
this, rtti) );
139 if ( it != customFunctionMap.end() )
142 ++it->second.DbgCntInvocations; )
143 return it->second.Implementation;
150 #if ALIB_DEBUG_BOXING
151 detail::DbgLockMaps(
true);
153 DbgKnownCustomFunctions.InsertIfNotExistent( &rtti );
155 DbgKnownCustomFunctions.emplace( &rtti );
157 detail::DbgLockMaps(
false);
162 customFunctionMap.InsertOrAssign( CustomFunctionKey(
this, rtti), CustomFunctionMapped(impl) );
164 if( customFunctionMap.size() == 0 )
165 customFunctionMap.reserve( 50 );
166 customFunctionMap.insert_or_assign( CustomFunctionKey(
this, rtti), CustomFunctionMapped(impl) );
173using namespace detail;
184 std::vector<detail::VTable*> result;
186 result.reserve(
static_cast<size_t>(
187 DbgKnownVTables .Size()
188 + DbgKnownVTablesArray.Size() ) );
190 result.reserve( DbgKnownVTables .size()
191 + DbgKnownVTablesArray.size() );
194 for(
int type= 0 ; type < 2 ; ++type )
196 auto& map= type == 0 ? DbgKnownVTables
197 : DbgKnownVTablesArray;
198 for(
auto it= map.begin() ; it!= map.end() ; ++it )
199 result.emplace_back( it->second );
208 std::vector<std::pair<const std::type_info*,uinteger>> result;
219 detail::DbgLockMaps(
true);
221 for (
auto* typeIt : detail::DbgKnownCustomFunctions )
224 auto usage= (std::numeric_limits<uinteger>::max)();
231 if( implIt != customFunctionMap.end() )
232 usage= implIt->second.DbgCntInvocations;
234 result.emplace_back( typeIt, usage );
237 detail::DbgLockMaps(
false);
243 std::vector<std::pair<const std::type_info*,uinteger>>& output )
258 for(
auto funcIt= customFunctionMap.begin() ; funcIt != customFunctionMap.end() ; ++funcIt )
259 if( funcIt->first.Parent == &functionTable )
260 output.emplace_back( &funcIt->first.Type , funcIt->second.DbgCntInvocations );
265#if ALIB_MONOMEM && ALIB_DEBUG_MONOMEM
288DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DEFINE_1])
290DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DEFINE_1])
293#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
308 #if ALIB_SIZEOF_INTEGER == 8
316#if ALIB_SIZEOF_LONGDOUBLE_REPORTED <= 2 * ALIB_SIZEOF_INTEGER
319#if ALIB_FEAT_BOXING_BIJECTIVE_FLOATS
323#if !ALIB_FEAT_BOXING_BIJECTIVE_CHARACTERS
332DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DEFINE_2])
334DOX_MARKER([DOX_ALIB_BOXING_OPTIMIZE_DEFINE_2])
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_IF_STRINGS(...)
#define ALIB_IF_MONOMEM(...)
#define ALIB_BOXING_VTABLE_DEFINE_ARRAYTYPE(TMapped, Identifier)
FunctionTable DEFAULT_FUNCTIONS
const alib::boxing::Box & Type
AString DbgDumpDistribution(const THashtable &hashtable, bool detailedBucketList)
MonoAllocator GlobalAllocator(8 *1024)
monomem::HashMap< TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace alib. See type definition alib::monomem::HashMap.
static ALIB_API std::vector< std::pair< const std::type_info *, uinteger > > GetKnownFunctionTypes()
static ALIB_API void DumpCustomFunctionHashMapMetrics(AString &target, bool detailedBucketList)
static ALIB_API void getFunctionTypes(const detail::FunctionTable &input, std::vector< std::pair< const std::type_info *, uinteger > > &output)
static ALIB_API std::vector< detail::VTable * > GetKnownVTables()
uinteger DbgCntInvocationsFHashcode
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFIsNotNull
Debug-compilation counter for the number of invocations.
FIsLess::Signature fIsLess
Entry for built-in function FIsLess .
ALIB_API void * getCustom(const std::type_info &rtti, bool isInvocation) const
uinteger DbgCntInvocationsFIsLess
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFClone
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFAppend
Debug-compilation counter for the number of invocations.
uinteger DbgCntInvocationsFIsTrue
Debug-compilation counter for the number of invocations.
ALIB_API void setCustom(const std::type_info &rtti, void *implementation)
uinteger DbgCntInvocationsFEquals
Debug-compilation counter for the number of invocations.
FClone::Signature fClone
Entry for built-in function FClone .
FHashcode::Signature fHashcode
Entry for built-in function FHashcode .
FIsTrue::Signature fIsTrue
Entry for built-in function FIsTrue .
FAppend< character >::Signature fAppend
Entry for built-in function FAppend .
FEquals::Signature fEquals
Entry for built-in function FEquals .
FIsNotNull::Signature fIsNotNull
Entry for built-in function FIsNotNull .