Defines the MAKE_ENUM macro. More...
#include <cassert>#include <exception>#include <string>#include <boost/preprocessor/cat.hpp>#include <boost/preprocessor/seq/for_each.hpp>#include <boost/preprocessor.hpp>#include <istream>#include <ostream>

Go to the source code of this file.
Classes | |
| class | bad_enum_cast |
| class | enum_tag |
Namespaces | |
| make_enum_detail | |
Macros | |
| #define | ADD_PAREN_1(A, B) ((A, B)) ADD_PAREN_2 |
| #define | ADD_PAREN_2(A, B) ((A, B)) ADD_PAREN_1 |
| #define | ADD_PAREN_1_END |
| #define | ADD_PAREN_2_END |
| #define | MAKEPAIRS(INPUT) BOOST_PP_CAT(ADD_PAREN_1 INPUT,_END) |
| #define | PP_SEQ_FOR_EACH_I_PAIR(macro, data, pairs) BOOST_PP_SEQ_FOR_EACH_I(macro, data, MAKEPAIRS(pairs)) |
| #define | CAT2(A, B) A ## B |
| #define | CAT3(A, B, C) A ## B ## C |
| #define | EXPAND_ENUMVALUE_NORMAL(r, data, i, record) BOOST_PP_TUPLE_ELEM(2, 0, record) = i, |
| #define | EXPAND_ENUMFUNC_NORMAL(r, data, i, record) if(data == BOOST_PP_TUPLE_ELEM(2, 1, record)) return BOOST_PP_TUPLE_ELEM(2, 0, record); |
| #define | EXPAND_ENUMPARSE_NORMAL(r, data, i, record) if(data == BOOST_PP_TUPLE_ELEM(2, 1, record)) { *this = BOOST_PP_TUPLE_ELEM(2, 0, record); return true; } |
| #define | EXPAND_ENUMFUNCREV_NORMAL(r, data, i, record) if(data == BOOST_PP_TUPLE_ELEM(2, 0, record)) return BOOST_PP_TUPLE_ELEM(2, 1, record); |
| #define | EXPAND_ENUMFUNCTIONCOUNT(r, data, i, record) + 1 |
| #define | MAKE_ENUM(NAME, CONTENT) |
Functions | |
| void | make_enum_detail::debug_conversion_error (const std::string &temp, const bad_enum_cast &e) |
Defines the MAKE_ENUM macro.
Currently this comes in 1-argument and 2-argument versions.
Example usage:
What it does:
Generates a struct enumname which holds an enum and provides functions to convert to and from string, as well as a constant enumname::count, which is set to the number of possible enum values defined.
It also defines the following stream operations:
In case of a bad string -> enum conversion from istream input, the istream will have its fail bit set. This means that lexical_casts will throw a bad_lexical_cast in the similar scenario; however, note that bad_lexical_cast does not provide any details about the error.
It is recommended to use MAKE_ENUM types with the built-in versions of lexical_cast or lexical_cast_default provided by Wesnoth (see util.hpp). However, if you do not want twml_exception to be thrown under any circumstances, use the string_to_enumname functions instead.
See src/tests/test_make_enum.cpp for example code.
Definition in file make_enum.hpp.
| #define ADD_PAREN_1 | ( | A, | |
| B | |||
| ) | ((A, B)) ADD_PAREN_2 |
Definition at line 128 of file make_enum.hpp.
| #define ADD_PAREN_1_END |
Definition at line 130 of file make_enum.hpp.
| #define ADD_PAREN_2 | ( | A, | |
| B | |||
| ) | ((A, B)) ADD_PAREN_1 |
Definition at line 129 of file make_enum.hpp.
| #define ADD_PAREN_2_END |
Definition at line 131 of file make_enum.hpp.
| #define CAT2 | ( | A, | |
| B | |||
| ) | A ## B |
Definition at line 136 of file make_enum.hpp.
| #define CAT3 | ( | A, | |
| B, | |||
| C | |||
| ) | A ## B ## C |
Definition at line 137 of file make_enum.hpp.
| #define EXPAND_ENUMFUNC_NORMAL | ( | r, | |
| data, | |||
| i, | |||
| record | |||
| ) | if(data == BOOST_PP_TUPLE_ELEM(2, 1, record)) return BOOST_PP_TUPLE_ELEM(2, 0, record); |
Definition at line 144 of file make_enum.hpp.
| #define EXPAND_ENUMFUNCREV_NORMAL | ( | r, | |
| data, | |||
| i, | |||
| record | |||
| ) | if(data == BOOST_PP_TUPLE_ELEM(2, 0, record)) return BOOST_PP_TUPLE_ELEM(2, 1, record); |
Definition at line 148 of file make_enum.hpp.
Definition at line 151 of file make_enum.hpp.
| #define EXPAND_ENUMPARSE_NORMAL | ( | r, | |
| data, | |||
| i, | |||
| record | |||
| ) | if(data == BOOST_PP_TUPLE_ELEM(2, 1, record)) { *this = BOOST_PP_TUPLE_ELEM(2, 0, record); return true; } |
Definition at line 146 of file make_enum.hpp.
Definition at line 140 of file make_enum.hpp.
| #define MAKE_ENUM | ( | NAME, | |
| CONTENT | |||
| ) |
Definition at line 157 of file make_enum.hpp.
| #define MAKEPAIRS | ( | INPUT | ) | BOOST_PP_CAT(ADD_PAREN_1 INPUT,_END) |
Definition at line 132 of file make_enum.hpp.
| #define PP_SEQ_FOR_EACH_I_PAIR | ( | macro, | |
| data, | |||
| pairs | |||
| ) | BOOST_PP_SEQ_FOR_EACH_I(macro, data, MAKEPAIRS(pairs)) |
Definition at line 133 of file make_enum.hpp.
1.8.8