@@ -35,9 +35,9 @@ namespace utils {
3535/* *
3636 * @brief This macro creates a Custom Enumeration with auxiliary functions and variables.
3737 *
38- * An enumeration built with ENUEMERATION_BUILDER has:
38+ * An enumeration built with ENUMERATION_BUILDER has:
3939 * - enum class with name \c enumeration_name and N values, one for each extra argument, and with that exact name.
40- * - array called \c nammes_ <enumeration_name> with the names of each element of the enumeration
40+ * - array called \c NAMES_ <enumeration_name> with the names of each element of the enumeration
4141 * as strings of the enum value.
4242 * - \c to_string method to get the string associated with an enumeration value.
4343 * - \c from_string_<enumeration_name> method that gives enumeration value from string name.
@@ -55,42 +55,41 @@ namespace utils {
5555 * my_value = from_string_CustomEnum("el2"); // Set my_value as el2 = 1
5656 * to_string(my_value); // = "el2"
5757 */
58- #define ENUMERATION_BUILDER (enumeration_name, ...) \
59- \
60- /* Forbid empty enumerations */ \
61- static_assert ( COUNT_ARGUMENTS (__VA_ARGS__), " Empty Enumerations are not allowed." ); \
62- \
63- /* Declare enumeration */ \
64- enum class enumeration_name {__VA_ARGS__ \
65- }; \
66- \
67- /* Initialize name arrays */ \
68- const std::array<std::string, COUNT_ARGUMENTS (__VA_ARGS__)> names_ ## enumeration_name = \
69- { APPLY_MACRO_FOR_EACH (STRINGIFY_WITH_COMMA , __VA_ARGS__) }; \
70- \
71- /* To string method */ \
72- inline const std::string& to_string (const enumeration_name& e) \
73- { return names_ ## enumeration_name[static_cast <int >(e)]; } \
74- \
75- inline std::vector<std::string> string_vector_ ## enumeration_name() \
76- { return std::vector<std::string> (names_ ## enumeration_name.begin (), names_ ## enumeration_name.end ()); } \
77- \
78- /* From string */ \
79- inline enumeration_name from_string_ ## enumeration_name(const std::string& s) \
80- { \
81- for (int i = 0 ; i < COUNT_ARGUMENTS (__VA_ARGS__); i++) \
82- if (names_ ## enumeration_name[i] == s)return static_cast <enumeration_name>(i); \
83- throw eprosima::utils::InitializationException ( \
84- STR_ENTRY << " Not correct name " << s << " for Enum " << STRINGIFY (enumeration_name) << " ." ); \
85- } \
86- \
87- /* Serialization operation */ \
88- inline std::ostream& operator <<(std::ostream& os, const enumeration_name& e) \
89- { os << to_string (e); return os; } \
90- \
91- /* Number of elements in enumeration */ \
58+ #define ENUMERATION_BUILDER (enumeration_name, ...) \
59+ \
60+ /* Forbid empty enumerations */ \
61+ static_assert ( COUNT_ARGUMENTS (__VA_ARGS__), " Empty Enumerations are not allowed." ); \
62+ \
63+ /* Declare enumeration */ \
64+ enum class enumeration_name {__VA_ARGS__ \
65+ }; \
66+ \
67+ /* Initialize name arrays */ \
68+ const std::array<std::string, COUNT_ARGUMENTS (__VA_ARGS__)> NAMES_ ## enumeration_name = \
69+ { APPLY_MACRO_FOR_EACH (STRINGIFY_WITH_COMMA , __VA_ARGS__) }; \
70+ \
71+ /* To string method */ \
72+ inline const std::string& to_string (const enumeration_name& e) \
73+ { return NAMES_ ## enumeration_name[static_cast <int >(e)]; } \
74+ \
75+ inline std::vector<std::string> string_vector_ ## enumeration_name() \
76+ { return std::vector<std::string> (NAMES_ ## enumeration_name.begin (), NAMES_ ## enumeration_name.end ()); } \
77+ \
78+ /* From string */ \
79+ inline enumeration_name from_string_ ## enumeration_name(const std::string& s) \
80+ { \
81+ for (int i = 0 ; i < COUNT_ARGUMENTS (__VA_ARGS__); i++) \
82+ if (NAMES_ ## enumeration_name[i] == s)return static_cast <enumeration_name>(i); \
83+ throw eprosima::utils::InitializationException ( \
84+ STR_ENTRY << " Not correct name " << s << " for Enum " << STRINGIFY (enumeration_name) << " ." ); \
85+ } \
86+ \
87+ /* Serialization operation */ \
88+ inline std::ostream& operator <<(std::ostream& os, const enumeration_name& e) \
89+ { os << to_string (e); return os; } \
90+ \
91+ /* Number of elements in enumeration */ \
9292 constexpr const unsigned int N_VALUES_ ## enumeration_name = COUNT_ARGUMENTS (__VA_ARGS__)
9393
94-
9594} /* namespace utils */
9695} /* namespace eprosima */
0 commit comments