Templated specialization of functor T_Append makes elements of C++ enumeration type TEnum appendable to AString instances, if
std::enable_if
on optional template parameter TEnableIf of unspecialized T_Append .Member operator() writes all value names corresponding to the bits set in src , separated by delimiter character ','
.
If the underlying integral value of a given enum element may be become 0
, a corresponding enum record associated to such non-bit value will be used if existent.
Furthermore, with bitwise type enums, the defined enum records may contain entries that represent combinations of more than one integral bit. Such combination entries are supported but have to be registered with class EnumRecords prior to the standard single bit entries! If combined bit values are matched, the corresponding element names that represent the single bit values will not be written.
As a sample, lets consider a window manager software which has a scoped enum type representing window states. Because a window might have more than one state, macro ALIB_ENUMS_MAKE_BITWISE is used to specialize TMP struct T_EnumIsBitwise . Next, macro ALIB_ENUMS_ASSIGN_RECORD used to associate the type with enum record type ERSerializable :
A window that is both, vertically and horizontally maximized, is considered to be "just" maximized. Therefore, during bootstrap of the software, enum records that fetch that the combination of states are defined prior to the single-state records:
That is all that is needed! With this setup, the following code:
produces this output:
If furthermore TMP struct T_Resourced is specialized for type TEnum and an externalizd resouce string exists according to the specification described with methods ResourcedType::TypeNamePrefix and ResourcedType::TypeNamePostfix then these resourced strings are written prior and after the enumeration element name(s).
TEnum | The AString that Append was invoked on. |
TChar | The character type of the target AString. |
Definition at line 434 of file serialization.hpp.
#include <serialization.hpp>
Public Method Index: | |
void | operator() (TAString< TChar > &target, TEnum elements) |
|
inline |
Writes a comma-separated list of element names of the bitwise defined enumeration TEnum to target .
In debug builds, the method asserts that at least one record is defined for TEnum . It is furthermore asserted that all bits contained in elements have been "covered" by corresponding names.
The enum records defined may aggregate several bits. Aggregations have to be defined prior to records that represent the corresponding single bits (or another subset of those).
target | The AString that elements is to be appended to. |
elements | The enumeration element to append to target . |
Definition at line 459 of file serialization.hpp.