8#ifndef HPP_ALIB_ENUMS_SERIALIZATION
9#define HPP_ALIB_ENUMS_SERIALIZATION 1
11#if !defined(HPP_ALIB_ENUMS_RECORDS)
17#if ALIB_CAMP && !defined(HPP_ALIB_LANG_RESOURCES_RESOURCES)
21#if !defined (HPP_ALIB_ENUMS_BITWISE)
24#if !defined (HPP_ALIB_STRINGS_LOCALSTRING)
28#if ALIB_DEBUG && !defined (HPP_ALIB_STRINGS_FORMAT)
32namespace alib {
namespace enums {
76template<
typename TEnum,
78 Case TSensitivity = Case::Ignore,
84#pragma warning( push )
85#pragma warning( disable : 4127 )
88template<
typename TEnum,
93Parse( strings::TSubstring<TChar>& input, TEnum& result )
98 if constexpr ( TTrimBeforeConsume == lang::Whitespaces::Trim )
102 recordIt !=
EnumRecords<TEnum>().end() ; ++recordIt )
103 if ( input.template ConsumePartOf<TSensitivity>( recordIt->EnumElementName,
104 recordIt->MinimumRecognitionLength ) > 0 )
106 result= recordIt.Enum();
152template<
typename TEnum,
154 Case TSensitivity = Case::Ignore,
155 Whitespaces TTrimBeforeConsume = Whitespaces::Trim,
156 TChar delimiter =
',',
157 bool keepLastDelim =
true >
161template<
typename TEnum,
165 TChar delimiter =
',',
166 bool keepLastDelim =
true >
174 if constexpr ( keepLastDelim )
175 restoreBeforeDelim= input;
181 if ( !Parse<TEnum, TChar, TSensitivity, TTrimBeforeConsume>( input, actEnum ) )
183 if constexpr ( keepLastDelim )
184 input= restoreBeforeDelim;
191 if constexpr ( keepLastDelim )
192 restoreBeforeDelim= input;
194 if( !input.template ConsumeChar<TSensitivity, TTrimBeforeConsume>( delimiter ) )
200#pragma warning( pop )
239template<
typename TEnum,
241 Case TSensitivity = Case::Ignore,
242 Whitespaces TTrimBeforeConsume = Whitespaces::Trim >
249template<
typename TEnum,
260 if( Parse<TEnum, TChar, TSensitivity, TTrimBeforeConsume>( input, result ) )
265 if( enums::Parse<lang::Bool, TChar, TSensitivity, lang::Whitespaces::Keep>( input, boolEnum ) )
284namespace alib {
namespace strings {
288 namespace APPENDABLES {
326template<
typename TEnum,
typename TChar>
329template<typename TEnum, typename TChar>
357 auto* record= enums::TryRecord( element );
358 if( record !=
nullptr )
359 target << record->EnumElementName;
361 target << UnderlyingIntegral( element );
433template<
typename TEnumBitwise,
typename TChar>
436template<typename TEnum, typename TChar>
468 TEnum covered= TEnum(0);
477 if( recordIt.Integral() == 0 )
479 if( elements == TEnum(0) )
481 target << recordIt->EnumElementName;
486 else if( HasBits( elements, recordIt.Enum() )
487 && !HasBits( covered , recordIt.Enum() ) )
489 covered|= recordIt.Enum();
490 target << recordIt->EnumElementName <<
',';
493 len= target.
Length() - len;
501 NString128() <<
"Not all bits have been covered while writing bitset '"
502 <<
NFormat::Bin( elements ) <<
"' of enumeration type <"
507 "Not all bits have been covered while writing a bitset of type <",
508 DbgTypeDemangler(
typeid(TEnum)).Get(),
">." )
TAString & DeleteEnd(integer regionLength)
constexpr integer Length() const
TSubstring & TrimStart(const TCString< TChar > &whiteSpaces=TT_StringConstants< TChar >::DefaultWhitespaces())
#define ALIB_ASSERT_MODULE(modulename)
#define ALIB_IF_CAMP(...)
#define ATMP_VOID_IF(Cond)
#define ATMP_ISOF( T, TBase)
#define ALIB_ASSERT_ERROR(cond,...)
#define ATMP_T_IF(T, Cond)
bool ParseBitwise(strings::TSubstring< TChar > &input, TEnum &result)
bool Parse(strings::TSubstring< TChar > &input, TEnum &result)
bool ParseEnumOrTypeBool(strings::TSubstring< TChar > &input, TEnum &result, TEnum falseValue, TEnum trueValue)
@ Trim
Trim whitespaces away.
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128> .
lang::integer integer
Type alias in namespace alib.
static constexpr ForwardIterator end()
void operator()(TAString< TChar > &target, TEnum elements)
void operator()(TAString< TChar > &target, TEnum element)