ALib C++ Library
Library Version: 2510 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 module \alib_enumrecords, which provides the
21/// 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{
33 const void* result= enumrecords::detail::getEnumRecord( e.TypeID(), e.Integral() );
34 ALIB_ASSERT_ERROR( result != nullptr, "BOXING", "Enum Record for type <{}>({}) not found.",
35 &e.TypeID(), e.Integral() )
36
37 return *reinterpret_cast<const TRecord*>( result );
38}
39
40/// Returns a pointer to the \ref alib_enums_records "ALib Enum Record" associated with this
41/// the enumeration element represented by this instance.
42/// If no enum record was is defined, \c nullptr is returned.
43///
44/// \see
45/// - Namespace function \alib{enumrecords::TryRecord} of module \alib_enumrecords, which provides the
46/// standard way of accessing enum records for enum elements known at compile-time.
47/// - Sibling method #GetRecord.
48///
49/// @tparam TRecord The enumeration record type associated with the enum type.
50/// This has to be explicitly provided.
51/// It is the caller's obligation to ensure that the requested type equals
52/// the one associated. Otherwise this method produces undefined behavior.
53/// @param e The enumeration element, boxed in class \b %Enum.
54///
55/// @return A pointer to the record that is associated with this enumeration element,
56/// respectively \c nullptr if no record was found.
57template<typename TRecord>
58const TRecord* TryRecord(Enum e){
59 return reinterpret_cast<const TRecord*>( enumrecords::detail::getEnumRecord( e.TypeID(),
60 e.Integral() ) );
61}
62
63#include "ALib.Lang.CIMethods.H"
64
65} // namespace [alib::boxing]
66#endif //ALIB_BOXING
#define ALIB_EXPORT
Definition alib.inl:488
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
const TRecord * TryRecord(Enum e)
const TRecord & GetRecord(Enum e)
const void * getEnumRecord(const std::type_info &rtti, integer elementValue)
Definition records.cpp:71
integer Integral() const
Definition enum.inl:87
const std::type_info & TypeID() const
Definition box.inl:827