Reactions  0.1.2
Handling reaction trees and decays
Classes | Namespaces | Macros | Functions
pow_enum.hpp File Reference

Contains macros to define smart enumeration types. More...

#include <cstdlib>
#include <string>
#include <utility>
Include dependency graph for pow_enum.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  reactions::pow_enum::string_tpl< C >
 String as a template of characters. More...
 
struct  reactions::pow_enum::string_builder< lambda_str_type >
 Helper struct to convert strings to templates of strings. More...
 
struct  reactions::pow_enum::string_builder< lambda_str_type >::produce< indices >
 
struct  reactions::pow_enum::apply_range< count, meta_functor, indices >
 Transform a template of characters into a string. More...
 
struct  reactions::pow_enum::apply_range< 0, meta_functor, indices... >
 Transform a template of characters into a string. More...
 
struct  reactions::pow_enum::string_group< S >
 Group of string templates. More...
 

Namespaces

 reactions::pow_enum
 Utilities to define smart enumeration types.
 

Macros

#define REACTIONS_POW_ENUM(enum_name, ...)
 
#define REACTIONS_POW_ENUM_WITH_UNKNOWN(enum_name, ...)
 

Functions

template<class... Strings, char... C>
constexpr auto reactions::pow_enum::parse_string_impl (string_group< Strings... >, string_tpl< C... >, string_tpl<>)
 Implementation of the function to parse a string. More...
 
template<class... Strings, char... Cp, char C0, char... C>
constexpr auto reactions::pow_enum::parse_string_impl (string_group< Strings... >, string_tpl< Cp... >, string_tpl< C0, C... >)
 Implementation of the function to parse a string. More...
 
template<char... C>
constexpr auto reactions::pow_enum::parse_string (string_tpl< C... > s)
 Parse a string template and return it as an array of strings. More...
 

Detailed Description

Contains macros to define smart enumeration types.

The macro REACTIONS_POW_ENUM_WITH_UNKNOWN is provided in this file, which defines a class containing an enumeration type, and several functions and constant objects to iterate over the enumeration values and convert/parse them to/from strings.

Macro Definition Documentation

◆ REACTIONS_POW_ENUM

#define REACTIONS_POW_ENUM (   enum_name,
  ... 
)
Value:
enum enum_name : int { __VA_ARGS__ }; \
\
struct enum_name##_properties { \
\
static constexpr std::size_t size = \
std::initializer_list{__VA_ARGS__}.size(); \
\
static constexpr enum_name list[size] = {__VA_ARGS__}; \
\
template <enum_name E, std::size_t I = 0> \
static constexpr auto index_impl() { \
static_assert(I < size); \
if constexpr (list[I] == E) \
return I; \
else \
return index_impl<E, I + 1>(); \
} \
\
template <enum_name E> static constexpr auto index() { \
return index_impl<E>(); \
} \
}
T size(T... args)

This macro defines a new class with the given name, which itself defines an enum and a series of elements to facilitate operations with them.

  • enum_type: type of the enumeration
  • size: number of elements defined
  • list: elements as an array

◆ REACTIONS_POW_ENUM_WITH_UNKNOWN

#define REACTIONS_POW_ENUM_WITH_UNKNOWN (   enum_name,
  ... 
)

This macro defines a new class with the given name, which itself defines an enum and a series of elements to facilitate operations with them.

  • enum_type: type of the enumeration
  • size: number of elements defined
  • list: elements as an array
  • from_string: get the element associated to the given string (return unknown if not found)
  • to_string: represent an element as a string