26 #ifndef CASADI_ENUM_HPP
27 #define CASADI_ENUM_HPP
32 #include "exception.hpp"
34 #include <casadi/core/casadi_export.h>
42 static const size_t n_enum =
static_cast<size_t>(T::NUMEL);
49 for (
size_t i = 0; i < enum_traits<T>::n_enum; ++i) {
50 if (s ==
to_string(
static_cast<T>(i)))
return true;
58 T to_enum(
const std::string& s,
const std::string& s_def =
"") {
60 if (s.empty() && !s_def.empty())
return to_enum<T>(s_def);
62 for (
size_t i = 0; i < enum_traits<T>::n_enum; ++i) {
63 if (s ==
to_string(
static_cast<T>(i)))
return static_cast<T>(i);
67 ss <<
"No such enum: '" << s <<
"'. Permitted values: ";
68 for (
size_t i = 0; i < enum_traits<T>::n_enum; ++i) {
70 if (i > 0) ss <<
", ";
72 ss <<
"'" <<
to_string(
static_cast<T>(i)) <<
"'";
74 casadi_error(ss.str());
82 for (
size_t i = 0; i < enum_traits<T>::n_enum; ++i)
T to_enum(const std::string &s, const std::string &s_def="")
Helper function: Convert string to enum.
std::vector< std::string > enum_names()
Helper function: Get all fields.
bool has_enum(const std::string &s)
Helper function: Check if enum exists.
std::string to_string(TypeFmi2 v)
Helper class: Specify number of entries in an enum.
static const size_t n_enum