ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
enums_serialization.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the module \alib_resources 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 !DOXYGEN
10
11ALIB_EXPORT namespace alib::strings {
12
13template<typename TEnum, typename TChar, typename TAllocator>
14requires ( enumrecords::IsSerializable<TEnum> && !enumops::IsBitwise<TEnum> )
16{
17 void operator()( TAString<TChar,TAllocator>& target, TEnum element ) {
18 ALIB_ASSERT_ERROR( EnumRecords<TEnum>().begin() != EnumRecords<TEnum>().end(), "ENUMS",
19 "No Enum Records for type <{}> found.", &typeid(TEnum) )
20
21// CHANGE 1 (compared to original implementation, without module Resources in the ALib Build)
22 target << ResourcedType<TEnum>::TypeNamePrefix();
23 auto* record= enumrecords::TryRecord( element );
24 if( record != nullptr )
25 target << record->EnumElementName;
26 else
27 target << UnderlyingIntegral( element );
28// CHANGE 1 (compared to original implementation, without module Resources in the ALib Build)
29 target << ResourcedType<TEnum>::TypeNamePostfix();
30 }
31};
32
33
34template<typename TBitwiseEnum, typename TChar, typename TAllocator>
35requires ( alib::enumrecords::IsSerializable<TBitwiseEnum>
36 && alib::enumops::IsBitwise <TBitwiseEnum> )
38
39 void operator()( TAString<TChar,TAllocator>& target, TBitwiseEnum elements ) {
41 "ENUMS", "No Enum Records for type <{}> found.", &typeid(TBitwiseEnum) )
42
43// CHANGE 1 (compared to original implementation, without module Resources in the ALib Build)
44 target << ResourcedType<TBitwiseEnum>::TypeNamePrefix();
45
46 // check what has been covered and omit double entries
47 TBitwiseEnum covered= TBitwiseEnum(0);
48
49 // loop over entry 2 to end, check bit
50 integer len= target.Length();
51
52 for( auto recordIt= EnumRecords<TBitwiseEnum>().begin() ;
53 recordIt != EnumRecords<TBitwiseEnum>().end() ; ++recordIt )
54 {
55 // no bits are set and this entry does not contain bits, then stop here
56 if( recordIt.Integral() == 0 ) {
57 if( elements == TBitwiseEnum(0) ) {
58 target << recordIt->EnumElementName;
59// CHANGE 2 (compared to original implementation, without module Resources in the ALib Build)
60 target << ResourcedType<TBitwiseEnum>::TypeNamePostfix();
61 return;
62 } }
63 else if( HasBits( elements, recordIt.Enum() )
64 && !HasBits( covered , recordIt.Enum() ) )
65 {
66 covered|= recordIt.Enum();
67 target << recordIt->EnumElementName << ',';
68 } }
69 len= target.Length() - len;
70
71 // remove the last comma
72 if( len != 0 )
73 target.DeleteEnd( 1 );
74
75 ALIB_ASSERT_ERROR( covered == elements, "ENUMS",
76 "Not all bits have been covered while writing bitset '{}' of enumeration type <{}>. "
77 "Remaining bits are '{}'.", NString(NString128(NBin( elements ))),
78 &typeid(TBitwiseEnum), NString(NString128(NBin( covered & elements ))) )
79
80// CHANGE 3 (compared to original implementation, without module Resources in the ALib Build)
81 target << ResourcedType<TBitwiseEnum>::TypeNamePostfix();
82 }
83};
84
85} // namespace [alib::strings]
86#include "ALib.Lang.CIMethods.H"
87
88#endif // !DOXYGEN
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
constexpr bool HasBits(TEnum element, TEnum selection) noexcept
Definition bitwise.inl:325
std::underlying_type_t< TEnum > constexpr UnderlyingIntegral(TEnum element) noexcept
const RecordsTraits< TEnum >::Type * TryRecord(TEnum element)
Definition records.inl:214
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
lang::integer integer
Type alias in namespace alib.
Definition integers.inl:149
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
enumrecords::EnumRecords< TEnum > EnumRecords
Type alias in namespace alib.
Definition records.inl:482
strings::TBin< nchar > NBin
Type alias in namespace alib.
Definition format.inl:571