24 #ifndef GEOSX_COMMON_ENUM_HPP_ 25 #define GEOSX_COMMON_ENUM_HPP_ 27 #include "codingUtilities/StringUtilities.hpp" 34 #include <type_traits> 47 template<
typename ... ARGS >
48 constexpr
int countArgs( ARGS ... )
50 return sizeof...( ARGS );
69 #define ENUM_STRINGS( ENUM, ... ) \ 70 static_assert( std::is_enum< ENUM >::value, "Not an enumeration" ); \ 72 inline auto const & getEnumStrings( ENUM const ) \ 74 constexpr int N = internal::countArgs( __VA_ARGS__ ); \ 75 static constexpr std::array< char const *, N > ss{ __VA_ARGS__ }; \ 79 inline std::ostream & operator<<( std::ostream & os, ENUM const e ) \ 81 os << EnumStrings< ENUM >::toString( e ); \ 85 inline std::istream & operator>>( std::istream & is, ENUM & e ) \ 88 e = EnumStrings< ENUM >::fromString( s ); \ 96 template<
typename ENUM >
108 static auto const &
get()
118 static string concat(
string const & delim =
" " )
120 auto const & strings =
get();
121 return ::geosx::stringutilities::strjoin( begin( strings ), end( strings ), delim );
133 auto const & strings =
get();
137 "Valid range is 0.." << strings.size() - 1 );
138 return strings[ index ];
148 auto const & strings =
get();
149 auto const it =
std::find( begin( strings ), end( strings ), s );
152 "Valid options are: \n " << concat(
"\n " ) );
153 enum_type const e =
static_cast< enum_type >( LvArray::integerConversion< base_type >( std::distance( begin( strings ), it ) ) );
167 template<
typename ENUM >
168 struct TypeRegex< ENUM, std::enable_if_t< internal::HasEnumStrings< ENUM > > >
181 #endif //GEOSX_COMMON_ENUM_HPP_
ENUM enum_type
Alias for the enumeration type.
Utility class for querying type names at runtime.
std::ptrdiff_t find(T const *const LVARRAY_RESTRICT ptr, std::ptrdiff_t const size, T const &value, Compare &&comp=Compare())
static string concat(string const &delim=" ")
Get a list of valid options as a delimited string.
#define GEOSX_ERROR_IF_GE_MSG(lhs, rhs, msg)
Raise a hard error if one value compares greater than or equal to the other.
std::underlying_type_t< ENUM > base_type
Alias for enum's underlying fundamental type.
static string toString(enum_type const &e)
Convert enum to string.
static enum_type fromString(string const &s)
Convert string to enum.
Provides enum <-> string conversion facilities.
Extension point for custom types to provide a validation regexp to schema.
std::string string
String type.
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
#define IS_VALID_EXPRESSION(NAME, T,...)
Macro that expands to a static constexpr bool with one template argument which is true only if the ex...