10#include <boost/preprocessor.hpp>
12#ifdef ENUMS_FOR_PYTHON
16#define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) \
18 return BOOST_PP_STRINGIZE(elem);
20#define X_DEFINE_ENUM_FOR_PYTHON_VALUE(r, data, elem) .value(BOOST_PP_STRINGIZE(elem), elem)
22#define X_DEFINE_ENUM_ADD_VALUE(r, data, elem) values.emplace_back(BOOST_PP_STRINGIZE(elem));
24#ifdef ENUMS_FOR_PYTHON
25#define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) \
26 enum name { BOOST_PP_SEQ_ENUM(enumerators) }; \
28 static inline const char *toString(name v) \
31 BOOST_PP_SEQ_FOR_EACH(X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, name, enumerators) \
33 return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \
37 static inline std::vector<std::string> valueList(name) \
39 std::vector<std::string> values; \
40 BOOST_PP_SEQ_FOR_EACH(X_DEFINE_ENUM_ADD_VALUE, name, enumerators) \
44 template<class Scope> \
45 static inline void enumForPython_##name(const Scope &scope, const char *pythonName) \
47 namespace py = pybind11; \
48 py::enum_<name>(scope, pythonName) BOOST_PP_SEQ_FOR_EACH(X_DEFINE_ENUM_FOR_PYTHON_VALUE, name, enumerators) \
52#define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) \
53 enum name { BOOST_PP_SEQ_ENUM(enumerators) }; \
55 static inline const char *toString(name v) \
58 BOOST_PP_SEQ_FOR_EACH(X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, name, enumerators) \
60 return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \
64 static inline std::vector<std::string> valueList(name) \
66 std::vector<std::string> values; \
67 BOOST_PP_SEQ_FOR_EACH(X_DEFINE_ENUM_ADD_VALUE, name, enumerators) \
72#define V_ENUM_OUTPUT_OP(name, scope) \
73 inline std::ostream &operator<<(std::ostream &s, scope::name v) \
75 s << scope::toString(v) << " (" << (int)v << ")"; \
79#define V_ENUM_SET_CHOICES_SCOPE(param, name, scope) setParameterChoices(param, scope::valueList((scope::name)0))
81#define V_ENUM_SET_CHOICES(param, name) setParameterChoices(param, valueList((name)0))