12# if ALIB_FEAT_SINGLETON_MAPPED && ALIB_DEBUG
21# if ALIB_MONOMEM && ALIB_CONTAINERS
25# include <unordered_map>
33#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
34namespace {
bool inShutdown=
false; }
40#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
42#if ALIB_MONOMEM && ALIB_CONTAINERS
47 TypeFunctors::EqualTo,
49 Recycling::None > singletonMap;
53 TypeFunctors::EqualTo,
59 TypeFunctors::EqualTo > singletonMap;
62 TypeFunctors::EqualTo > singletonMap;
65extern std::recursive_mutex singletonLock;
66 std::recursive_mutex singletonLock; )
69#include
"alib/lang/callerinfo_functions.hpp"
70void storeSingleton(
const std::type_info& type,
void* theSingleton )
72 #if ALIB_MONOMEM && ALIB_CONTAINERS
73 if( singletonMap.Size() == 0)
75 singletonMap.MaxLoadFactor( 10 );
79 singletonMap.EmplaceUnique( &type, theSingleton );
84 if( singletonMap.size() == 0)
86 singletonMap.max_load_factor( 10 );
87 singletonMap.reserve( 23 );
90 singletonMap.emplace(&type, theSingleton);
97void removeSingleton(
const std::type_info& type )
101 #if ALIB_MONOMEM && ALIB_CONTAINERS
112#if !DOXYGEN && ALIB_FEAT_SINGLETON_MAPPED && ALIB_THREADS
118void* getSingleton (
const std::type_info& type )
120 #if ALIB_MONOMEM && ALIB_CONTAINERS
122 auto entry= singletonMap.Find( &type );
123 if ( entry != singletonMap.end() )
125 void* result= entry->second;
133 auto entry= singletonMap.find( &type );
134 if ( entry != singletonMap.end() )
136 void* result= entry->second;
151 #if ALIB_FEAT_SINGLETON_MAPPED
153 for(
auto mapPair : singletonMap)
156 memcpy( &theSingleton, &mapPair.second,
sizeof(
void*) );
159 #if ALIB_MONOMEM && ALIB_CONTAINERS
172#if ALIB_DEBUG && ALIB_FEAT_SINGLETON_MAPPED
173 #if ALIB_MONOMEM && ALIB_CONTAINERS
186 #if ALIB_STRINGS && ALIB_DEBUG
190 for(
auto& it : types )
192 <<
" = 0x" <<
NFormat::Hex(
reinterpret_cast<uint64_t
>(it.second) )
195 #if ALIB_MONOMEM && ALIB_CONTAINERS
196 return static_cast<int>( types.Size() );
198 return static_cast<int>( types.size() );
ALIB_API const char * Get()
ALIB_API void ReleaseRecursive(ALIB_DBG_TAKE_CI)
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
#define IF_ALIB_THREADS(...)
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_CALLER_PRUNED
@ Absolute
Referring to an absolute value.
ALIB_API MonoAllocator GLOBAL_ALLOCATOR
ALIB_API RecursiveLock GLOBAL_ALLOCATOR_LOCK
ALIB_API HashMap< MonoAllocator, TypeFunctors::Key, void *, TypeFunctors::Hash, TypeFunctors::EqualTo, lang::Caching::Auto, Recycling::None > & DbgGetSingletons()
constexpr NCString NNEW_LINE
A zero-terminated string containing the new-line character sequence.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace alib.
Comparison functor for type const std::type_info*.
Hash code functor for type const std::type_info*.
const ::std::type_info * Key
The key type.