7#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
8namespace {
bool inShutdown=
false; }
11#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
13 # if ALIB_MONOMEM && ALIB_CONTAINERS
25# if !ALIB_MONOMEM && !ALIB_SINGLE_THREADED
26 std::mutex singletonMapMutex;
30void storeSingleton(
const std::type_info& type,
void* theSingleton )
32 #if ALIB_MONOMEM && ALIB_CONTAINERS
33 if( singletonMap.Size() == 0)
35 singletonMap.MaxLoadFactor( 10 );
39 singletonMap.EmplaceUnique( &type, theSingleton );
41 if( singletonMap.size() == 0)
43 singletonMap.max_load_factor( 10 );
44 singletonMap.reserve( 23 );
47 singletonMap.emplace(&type, theSingleton);
51void removeSingleton(
const std::type_info& type )
55 #if ALIB_MONOMEM && ALIB_CONTAINERS
63void* getSingleton (
const std::type_info& type )
65 #if ALIB_MONOMEM && ALIB_CONTAINERS
66 auto entry= singletonMap.Find( &type );
67 if ( entry != singletonMap.end() )
69 void* result= entry->second;
74 auto entry= singletonMap.find( &type );
75 if ( entry != singletonMap.end() )
77 void* result= entry->second;
89 #if ALIB_FEAT_SINGLETON_MAPPED
91 for(
auto& mapPair : hidden::singletonMap) {
93 memcpy( &theSingleton, &mapPair.second,
sizeof(
void*) );
96 #if ALIB_MONOMEM && ALIB_CONTAINERS
109#if ALIB_DEBUG && ALIB_FEAT_SINGLETON_MAPPED
114 #if ALIB_MONOMEM && ALIB_CONTAINERS
117 lang::TypeFunctors::Hash,
118 lang::TypeFunctors::EqualTo,
132 for(
auto& it : types )
134 <<
" = 0x" <<
NHex(
reinterpret_cast<uint64_t
>(it.second) )
137 #if ALIB_MONOMEM && ALIB_CONTAINERS
138 return int( types.Size() );
140 return int( types.size() );
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
@ Absolute
Referring to an absolute value.
TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
HashMap< MonoAllocator, lang::TypeFunctors::Key, void *, lang::TypeFunctors::Hash, lang::TypeFunctors::EqualTo, lang::Caching::Auto, Recycling::None > & DbgGetSingletons()
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
strings::TAString< nchar, lang::HeapAllocator > NAString
Type alias in namespace #"%alib".
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace #"%alib".
constexpr NCString NNEW_LINE
A zero-terminated string containing the new-line character sequence.
strings::THex< nchar > NHex
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.