10# if !defined(HPP_ALIB_SINGLETONS_SINGLETON)
14# if !defined(HPP_ALIB_COMPATIBILITY_STD_TYPEINFO)
18# if ALIB_FEAT_SINGLETON_MAPPED && ALIB_DEBUG
19# if !defined(HPP_ALIB_SINGLETONS_DBGSINGLETONS)
22# if ALIB_STRINGS && !defined (HPP_ALIB_STRINGS_FORMAT)
28# if !defined (HPP_ALIB_STRINGS_ASTRING)
34# if !defined(HPP_ALIB_MONOMEM_HASHMAP)
37# if !defined(HPP_ALIB_MONOMEM_HASHSET)
41# if !defined(_GLIBCXX_UNORDERED_MAP) && !defined(_UNORDERED_MAP_)
42# include <unordered_map>
44# if !defined (_GLIBCXX_MUTEX) && !defined(_MUTEX_)
47# if !defined (_GLIBCXX_CSTRING) && !defined(_CSTRING_)
56#if ALIB_FEAT_SINGLETON_MAPPED && !defined(ALIB_DOX)
57namespace {
bool inShutdown=
false; }
67#if ALIB_FEAT_SINGLETON_MAPPED && !defined(ALIB_DOX)
72 TypeFunctors::EqualTo > singletonMap;
79 TypeFunctors::EqualTo > singletonMap;
82 TypeFunctors::EqualTo > singletonMap;
85 extern std::recursive_mutex singletonLock;
86 std::recursive_mutex singletonLock; )
89void storeSingleton(
const std::type_info& type,
void* theSingleton )
92 if( singletonMap.Size() == 0)
94 singletonMap.MaxLoadFactor( 10 );
98 singletonMap.EmplaceUnique( &type, theSingleton );
103 if( singletonMap.size() == 0)
105 singletonMap.max_load_factor( 10 );
106 singletonMap.reserve( 23 );
109 singletonMap.emplace(&type, theSingleton);
116void removeSingleton(
const std::type_info& type )
123 monomem::ReleaseGlobalAllocator();
132void* getSingleton (
const std::type_info& type )
136 auto entry= singletonMap.Find( &type );
137 if ( entry != singletonMap.end() )
139 void* result= entry->second;
148 auto entry= singletonMap.find( &type );
149 if ( entry != singletonMap.end() )
151 void* result= entry->second;
166 #if ALIB_FEAT_SINGLETON_MAPPED
168 for(
auto mapPair : singletonMap)
171 memcpy( &theSingleton, &mapPair.second,
sizeof(
void*) );
179#if ALIB_DEBUG && ALIB_FEAT_SINGLETON_MAPPED
190 #if ALIB_STRINGS && ALIB_DEBUG
194 for(
auto& it : types )
196 <<
" = 0x" <<
NFormat::Hex(
reinterpret_cast<uint64_t
>(it.second) )
200 return static_cast<int>( types.Size() );
202 return static_cast<int>( types.size() );
ALIB_API const char * Get()
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
#define ALIB_IF_THREADS(...)
#define ALIB_CALLER_PRUNED
@ Absolute
Referring to an absolute value.
void ReleaseGlobalAllocator()
MonoAllocator GlobalAllocator(8 *1024)
MonoAllocator & AcquireGlobalAllocator(const NCString &dbgFile, int dbgLine, const NCString &dbgFunc)
ALIB_API HashMap< TypeFunctors::Key, void *, TypeFunctors::Hash, TypeFunctors::EqualTo > & DbgGetSingletons()
constexpr NCString NNewLine()
monomem::HashMap< TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace alib. See type definition alib::monomem::HashMap.
const ::std::type_info * Key