ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
No Matches
T_Append< TEnumBitwise, TChar > Struct Template Reference


template<typename TEnumBitwise, typename TChar>
struct alib::strings::APPENDABLES::T_Append< TEnumBitwise, TChar >

Templated specialization of functor T_Append makes elements of C++ enumeration type TEnum appendable to AString instances, if

  • Type TEnum is equipped with ALib Enum Records of type ERSerializable (or a derived type derived from ERSerializable), and
  • A specialization of TMP struct T_EnumIsBitwise exists for TEnum . (For non-bitwise types, a different implementation of this functor is given.)
The conditions are evaluated by the compiler using 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 ','.

For technical reasons, the delimiter is not adjustable. In cases a different delimter is to be used, it needs to be replaced in the string after the value is written.

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 :

namespace WindowManager
enum class States
HorizontallyMaximized = (1 << 0),
VerticallyMaximized = (1 << 1),
Hidden = (1 << 2),
ALIB_ENUMS_MAKE_BITWISE( WindowManager::States )

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:

// No state set
"0" "," "Normal" "," "1" ","
// Combined entry. Put before single bits.
"3" "," "Maximized" "," "1" ","
// The corresponding single bit entries.
"1" "," "HMax" "," "1" ","
"2" "," "VMax" "," "1" ","
// Others...
"4" "," "Hidden" "," "1" ) );

That is all that is needed! With this setup, the following code:

States stateNull = States(0);
States stateHM = States::HorizontallyMaximized;
States stateVM = States::VerticallyMaximized;
States stateHMVM = States::HorizontallyMaximized + States::VerticallyMaximized;
States stateHMHidden = States::HorizontallyMaximized + States::Hidden;
cout << "Null: " << stateNull << endl;
cout << "HM: " << stateHM << endl;
cout << "VM: " << stateVM << endl;
cout << "VM+HM: " << stateHMVM << endl;
cout << "HM+Hidden: " << stateHMHidden << endl;

produces this output:

Null: Normal
HM: HMax
VM: VMax
VM+HM: Maximized
HM+Hidden: HMax,Hidden

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).

See also

Reference Documentation

Template Parameters
TEnumThe AString that Append was invoked on.
TCharThe 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)

Method Details:

◆ operator()()

template<typename TEnumBitwise , typename TChar >
void operator() ( TAString< TChar > & target,
TEnum elements )

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).

See also
This struct's documentation for more information and a sample.
targetThe AString that elements is to be appended to.
elementsThe enumeration element to append to target .

Definition at line 459 of file serialization.hpp.

Here is the call graph for this function:

The documentation for this struct was generated from the following file: