ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
boxing_enums.inl
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/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#if ALIB_BOXING
10
12
13/// Returns the \ref alib_enums_records "ALib Enum Record" associated with the given instance of
14/// class \alib{boxing;Enum}, which is defined in module \alib_boxing.
15///
16/// In debug-compilations an \alib_assertion is raised if no enum record was defined for
17/// the enumeration element represented by this instance.
18///
19/// \see
20/// - Namespace function \alib{enumrecords::GetRecord} of the module \alib_enumrecords, which
21/// provides the standard way of accessing enum records for enum elements known at compile-time.
22/// - Sibling method #TryRecord.
23///
24/// @tparam TRecord The enumeration record type associated with the enum type.
25/// This has to be explicitly provided.
26/// It is the caller's obligation to ensure that the requested type equals
27/// the one associated. Otherwise, this method produces undefined behavior.
28/// @param e The enumeration element, boxed in class \b %Enum.
29/// @return The record that is associated with this enumeration element.
30template<typename TRecord>
31const TRecord& GetRecord(Enum e) {
32 const void* result= enumrecords::detail::getEnumRecord( e.TypeID(), e.Integral() );
33 ALIB_ASSERT_ERROR( result != nullptr, "BOXING", "Enum Record for type <{}>({}) not found.",
34 &e.TypeID(), e.Integral() )
35
36 return *reinterpret_cast<const TRecord*>( result );
37}
38
39/// Returns a pointer to the \ref alib_enums_records "ALib Enum Record" associated with this
40/// enumeration element represented by this instance.
41/// If no enum record was is defined, \c nullptr is returned.
42///
43/// \see
44/// - Namespace function \alib{enumrecords::TryRecord} of module \alib_enumrecords, which provides the
45/// standard way of accessing enum records for enum elements known at compile-time.
46/// - Sibling method #GetRecord.
47///
48/// @tparam TRecord The enumeration record type associated with the enum type.
49/// This has to be explicitly provided.
50/// It is the caller's obligation to ensure that the requested type equals
51/// the one associated. Otherwise this method produces undefined behavior.
52/// @param e The enumeration element, boxed in class \b %Enum.
53///
54/// @return A pointer to the record that is associated with this enumeration element,
55/// respectively \c nullptr if no record was found.
56template<typename TRecord>
57const TRecord* TryRecord(Enum e){
58 return reinterpret_cast<const TRecord*>( enumrecords::detail::getEnumRecord( e.TypeID(),
59 e.Integral() ) );
60}
61
62#include "ALib.Lang.CIMethods.H"
63
64} // namespace [alib::boxing]
65#endif //ALIB_BOXING
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
const TRecord * TryRecord(Enum e)
const TRecord & GetRecord(Enum e)
const void * getEnumRecord(const std::type_info &rtti, integer elementValue)
Definition records.cpp:70
integer Integral() const
Definition enum.inl:86
const std::type_info & TypeID() const
Definition box.inl:780