ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
enumrecordmap.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the module \alib_enumrecords of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace enumrecords { namespace detail {
9
10//==================================================================================================
11/// The key-type of the central hash table that stores all enum records.
12/// Contains inner functors for hashing and comparing.
13//==================================================================================================
15 /// Runtime type information on the enumeration type
16 const std::type_info& RTTI;
17
18 /// Integral value of the enumeration element.
20
21 /// Constructor.
22 /// @param rtti Assigned to #".RTTI".
23 /// @param element Assigned to #".Element".
24 EnumRecordKey(const std::type_info& rtti, integer element)
25 : RTTI (rtti)
26 , Element(element) {}
27
28 /// Hash functor for this key type.
29 struct Hash {
30 /// Calculate hash code.
31 /// @param key The key to calculate a hash value for.
32 /// @return A hash code for this key.
33 std::size_t operator()( const EnumRecordKey & key ) const {
34 size_t result= key.RTTI.hash_code()
35 ^ size_t(key.Element);
36 #if ALIB_SIZEOF_INTEGER == 4
37 result^= (result >> 17);
38 #else
39 result^= (result >> 33);
40 #endif
41 return result;
42 }
43 };
44
45 /// Compare functor for this key type.
46 struct EqualTo {
47 /// Compares two keys.
48 /// @param lhs The left-hand side value.
49 /// @param rhs The right-hand side value.
50 /// @return \c true if the two keys are equal, \c false otherwise.
51 bool operator()( const EnumRecordKey & lhs,
52 const EnumRecordKey & rhs ) const
53 {
54 return lhs.RTTI == rhs.RTTI
55 && lhs.Element == rhs.Element;
56 }
57 };
58}; // EnumRecordKey
59
60
61#if ALIB_MONOMEM && ALIB_CONTAINERS
62//==================================================================================================
63/// This detail function returns \e the central hash table that stores enum records of all types.
64/// A constant reference is returned, which is in alignment with the general contract of this
65/// concept that considers enum records as static data which must not be modified after
66/// bootstrapping a process.
67///
68/// Consequently, there are no mechanisms to protect parallel access, because after bootstrap
69/// only read operations are allowed.
70///
71/// Before bootstrapping, the returned map may be <c>const_cast</c>'ed to a mutable reference
72/// for the sake of modifying the base- and maximum load factors as well as for reserving
73/// a certain element capacity. The default values are already raised to \c 3.0 and \c 6.0,
74/// as the retrieval of enumeration records is not considered to be done in time-critical
75/// code units.
76///
77/// Direct access to this map is not recommended, and useful only in seldom cases.
78///
79/// A good sample for its use, is to provide debug-output of all defined records for a type in the
80/// case that a record for a certain enumeration element of that type was not found, and such
81/// output is required to be performed in a code unit that has lost (templated) compile-time type
82/// information.
83///
84/// \note
85/// Runtime access to single records is provided with function
86/// #"detail::getEnumRecord(const std::type_info& rtti; integer)" and encapsulated
87/// in type #"boxing::Enum" of the module \alib_boxing.
88///
89/// \attention
90/// In the absence of the module \alib_monomem in an \alibbuild, the returned type changes to
91/// <c>std::unordered_map</c>.
92///
93/// @return A constant reference to the internal hash map storing all enum records.
94//==================================================================================================
96 EnumRecordKey, const void*,
97 EnumRecordKey::Hash,
98 EnumRecordKey::EqualTo >& getInternalRecordMap();
99#else
100std::unordered_map< EnumRecordKey, const void*,
101 EnumRecordKey::Hash,
102 EnumRecordKey::EqualTo >& getInternalRecordMap();
103#endif
104
105}}} // namespace [alib::enumrecords::detail]
#define ALIB_EXPORT
Details of namespace #"alib::enumrecords;2".
HashMap< MonoAllocator, EnumRecordKey, const void *, EnumRecordKey::Hash, EnumRecordKey::EqualTo > & getInternalRecordMap()
Definition records.cpp:50
Definition alox.cpp:14
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
lang::integer integer
Type alias in namespace #"%alib".
Definition integers.hpp:149
containers::HashMap< TAllocator, TKey, TMapped, THash, TEqual, THashCaching, TRecycling > HashMap
Type alias in namespace #"%alib".
bool operator()(const EnumRecordKey &lhs, const EnumRecordKey &rhs) const
std::size_t operator()(const EnumRecordKey &key) const
EnumRecordKey(const std::type_info &rtti, integer element)
const std::type_info & RTTI
Runtime type information on the enumeration type.
integer Element
Integral value of the enumeration element.