dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Enum Namespace Reference

Enum string conversion and enumeration utilities. More...

Functions

template<typename E>
std::string_view toStringView (E e) noexcept
 Convert an enum value into a string view.
template<typename E>
std::string toString (E e) noexcept
 Convert an enum value into a string.
template<typename E>
std::optional< E > fromStringView (std::string_view) noexcept=delete
 Convert a string view to an enum value.
template<typename E>
std::optional< E > fromString (std::string const &) noexcept=delete
 Convert a string to an enum value.
template<typename E>
std::unordered_map< std::string, E > const & allValuesMap () noexcept=delete
 Map from label (owned string) to enum value for type E.
template<typename E>
std::unordered_map< std::string_view, E > const & allValuesMapView () noexcept=delete
 Map from label (string_view) to enum value for type E.
template<typename E>
std::vector< E > const & allValues () noexcept=delete
 Return all enum values registered for E, in the order provided to the macro. Deleted by default; provided via macro specialization.
template<typename E>
std::vector< std::string_view > const & allValuesStringView () noexcept=delete
 Return all labels registered for E, in the order provided to the macro. Deleted by default; provided via macro specialization.

Detailed Description

Enum string conversion and enumeration utilities.

The templates in this namespace are declared as deleted by default and are meant to be explicitly specialized by the macros in this file.

Function Documentation

◆ allValues()

template<typename E>
std::vector< E > const & dfx::Enum::allValues ( )
nodiscarddeletenoexcept

Return all enum values registered for E, in the order provided to the macro. Deleted by default; provided via macro specialization.

◆ allValuesMap()

template<typename E>
std::unordered_map< std::string, E > const & dfx::Enum::allValuesMap ( )
nodiscarddeletenoexcept

Map from label (owned string) to enum value for type E.

Deleted by default; provided via macro specialization.

Note
allValuesMap() uses std::string keys and therefore owns the key storage.

◆ allValuesMapView()

template<typename E>
std::unordered_map< std::string_view, E > const & dfx::Enum::allValuesMapView ( )
nodiscarddeletenoexcept

Map from label (string_view) to enum value for type E.

Deleted by default; provided via macro specialization.

Warning
The string_view keys must refer to storage with static lifetime (string literals are expected).

◆ allValuesStringView()

template<typename E>
std::vector< std::string_view > const & dfx::Enum::allValuesStringView ( )
nodiscarddeletenoexcept

Return all labels registered for E, in the order provided to the macro. Deleted by default; provided via macro specialization.

◆ fromString()

template<typename E>
std::optional< E > dfx::Enum::fromString ( std::string const & )
nodiscarddeletenoexcept

Convert a string to an enum value.

Convenience overload calling fromStringView<E>(...). This template is deleted by default; generated by macros.

◆ fromStringView()

template<typename E>
std::optional< E > dfx::Enum::fromStringView ( std::string_view )
nodiscarddeletenoexcept

Convert a string view to an enum value.

This template is deleted by default. Use DECLARE_ENUM_STRING_FUNCTIONS(E) in headers and DEFINE_ENUM_STRING(E, ...) in one .cpp to provide an explicit specialization.

◆ toString()

template<typename E>
std::string dfx::Enum::toString ( E e)
nodiscardnoexcept

Convert an enum value into a string.

◆ toStringView()

template<typename E>
std::string_view dfx::Enum::toStringView ( E e)
nodiscardnoexcept

Convert an enum value into a string view.