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"
16#if !ALIB_MONOMEM || !ALIB_CONTAINERS
17# include <unordered_map>
19#if !ALIB_MONOMEM && !ALIB_SINGLE_THREADED
42#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
43namespace {
bool inShutdown=
false; }
46#if ALIB_FEAT_SINGLETON_MAPPED && !DOXYGEN
48 # if ALIB_MONOMEM && ALIB_CONTAINERS
60# if !ALIB_MONOMEM && !ALIB_SINGLE_THREADED
61 std::mutex singletonMapMutex;
65void storeSingleton(
const std::type_info& type,
void* theSingleton )
67 #if ALIB_MONOMEM && ALIB_CONTAINERS
68 if( singletonMap.Size() == 0)
70 singletonMap.MaxLoadFactor( 10 );
74 singletonMap.EmplaceUnique( &type, theSingleton );
76 if( singletonMap.size() == 0)
78 singletonMap.max_load_factor( 10 );
79 singletonMap.reserve( 23 );
82 singletonMap.emplace(&type, theSingleton);
86void removeSingleton(
const std::type_info& type )
90 #if ALIB_MONOMEM && ALIB_CONTAINERS
98void* getSingleton (
const std::type_info& type )
100 #if ALIB_MONOMEM && ALIB_CONTAINERS
101 auto entry= singletonMap.Find( &type );
102 if ( entry != singletonMap.end() )
104 void* result= entry->second;
109 auto entry= singletonMap.find( &type );
110 if ( entry != singletonMap.end() )
112 void* result= entry->second;
125 #if ALIB_FEAT_SINGLETON_MAPPED
127 for(
auto& mapPair : hidden::singletonMap)
130 memcpy( &theSingleton, &mapPair.second,
sizeof(
void*) );
133 #if ALIB_MONOMEM && ALIB_CONTAINERS
146#if ALIB_DEBUG && ALIB_FEAT_SINGLETON_MAPPED
151 #if ALIB_MONOMEM && ALIB_CONTAINERS
154 lang::TypeFunctors::Hash,
155 lang::TypeFunctors::EqualTo,
169 for(
auto& it : types )
171 <<
" = 0x" <<
NHex(
reinterpret_cast<uint64_t
>(it.second) )
174 #if ALIB_MONOMEM && ALIB_CONTAINERS
175 return int( types.Size() );
177 return int( types.size() );
ALIB_DLL const char * Get()
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
@ Absolute
Referring to an absolute value.
ALIB_DLL TMonoAllocator< lang::HeapAllocator > GLOBAL_ALLOCATOR
HashMap< MonoAllocator, lang::TypeFunctors::Key, void *, lang::TypeFunctors::Hash, lang::TypeFunctors::EqualTo, lang::Caching::Auto, Recycling::None > & DbgGetSingletons()
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.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
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.