27 #include <SimoxUtility/meta/type_name.h>
43 "Somehow the maybe flag of a top level int enum "
44 "declaration is set. This is not valid!",
50 std::vector<CppFieldPtr>
53 std::vector<CppFieldPtr> fields;
54 std::stringstream enum_to_name;
55 std::stringstream name_to_enum;
56 std::stringstream enum_to_value;
57 std::stringstream value_to_enum;
61 std::make_shared<CppField>(
"using",
62 std::string(IMPL_ENUM),
63 simox::alg::to_lower(className) +
"_details::Enum",
64 "Legacy typedef of enum"));
68 enum_to_name <<
"{" << std::endl;
69 name_to_enum <<
"{" << std::endl;
70 enum_to_value <<
"{" << std::endl;
71 value_to_enum <<
"{" << std::endl;
74 std::string enumKeyWithNamespace = std::string(IMPL_ENUM) +
"::" + key;
75 fields.push_back(std::make_shared<CppField>(
76 "static constexpr " + std::string(IMPL_ENUM), key +
" = " + enumKeyWithNamespace));
78 enum_to_name <<
"\t\t{" << enumKeyWithNamespace <<
", \"" << key <<
"\"}," << std::endl;
79 name_to_enum <<
"\t\t{\"" << key <<
"\", " << enumKeyWithNamespace <<
"}," << std::endl;
81 enum_to_value <<
"\t\t{" << enumKeyWithNamespace <<
", " <<
value <<
"}," << std::endl;
82 value_to_enum <<
"\t\t{" <<
value <<
", " << enumKeyWithNamespace <<
"}," << std::endl;
85 enum_to_name <<
"\t}";
86 name_to_enum <<
"\t}";
87 enum_to_value <<
"\t}";
88 value_to_enum <<
"\t}";
90 fields.push_back(std::make_shared<CppField>(
"static inline const std::map<" +
91 std::string(IMPL_ENUM) +
", std::string>",
94 "Mapping enum values to readable strings"));
95 fields.push_back(std::make_shared<CppField>(
"static inline const std::map<std::string, " +
96 std::string(IMPL_ENUM) +
">",
99 "Mapping readable strings to enum values"));
100 fields.push_back(std::make_shared<CppField>(
"static inline const std::map<" +
101 std::string(IMPL_ENUM) +
", int>",
104 "Mapping enum values to a int value"));
105 fields.push_back(std::make_shared<CppField>(
"static inline const std::map<int, " +
106 std::string(IMPL_ENUM) +
">",
109 "Mapping int values to a enum"));
111 fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM),
114 "The current value of the enum object"));
122 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
123 block_if_data->addLine(
"value = {};");
124 return block_if_data;
130 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
131 block_if_data->addLine(
"value = {};");
132 return block_if_data;
145 std::vector<std::string> map_initializer;
150 b->addLine(
"std::map<std::string, int> " + INT_ENUM_VALUE_MAP +
" = {" +
161 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
166 return block_if_data;
174 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
175 block_if_data->addLine(
"int " + INT_ENUM_TMP_VALUE +
";");
177 ", " + INT_ENUM_TMP_VALUE +
"); // of top level enum " +
180 block_if_data->addLine(
"auto valueToEnumMap_iterator = ValueToEnumMap.find(" +
181 INT_ENUM_TMP_VALUE +
");");
182 block_if_data->addLine(
183 "ARMARX_CHECK_AND_THROW(valueToEnumMap_iterator != ValueToEnumMap.end(), "
184 "::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing enum for value "
185 "'\" + std::to_string(" +
187 block_if_data->addLine(
"value = valueToEnumMap_iterator->second;");
188 return block_if_data;
193 const std::string& otherInstanceAccessor)
const
195 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
196 block_if_data->addLine(
"if (not (value == " + otherInstanceAccessor +
".value))");
197 block_if_data->addLineAsBlock(
"return false;");
198 return block_if_data;
213 CppCtorPtr c = std::make_shared<CppCtor>(name +
"(const " + std::string(IMPL_ENUM) +
" e)");
214 std::vector<std::pair<std::string, std::string>> initList = {{
"value",
"e"}};
215 c->addInitListEntries(initList);
216 c->setBlock(std::make_shared<CppBlock>());
220 std::vector<CppEnumFieldPtr>
223 std::vector<CppEnumFieldPtr> e;
226 e.push_back(std::make_shared<CppEnumField>(key));
234 std::stringstream doc;
235 doc <<
"@brief int() - Converts the internally stored value to int representation \n";
236 doc <<
"@return - the int representation";
240 b->addLine(
"return EnumToValueMap.at(value);");
248 std::stringstream doc;
249 doc <<
"@brief operator=() - Assignment operator for copy \n";
250 doc <<
"@return - nothing";
257 b->addLine(
"value = c.value;");
258 b->addLine(
"return *this;");
266 std::stringstream doc;
267 doc <<
"@brief operator=() - Assignment operator for the internally defined enum \n";
268 doc <<
"@return - nothing";
274 b->addLine(
"value = v;");
275 b->addLine(
"return *this;");
283 std::stringstream doc;
284 doc <<
"@brief operator=() - Assignment operator for the internally defined enum \n";
285 doc <<
"@return - nothing";
290 b->addLine(
"if (auto it = ValueToEnumMap.find(v); it == ValueToEnumMap.end())");
292 b2->addLine(
"throw armarx::LocalException(\"The input int is not valid. Could net set the "
293 "enum to value '\" + std::to_string(v) + \"'\");");
297 b3->addLine(
"value = it->second;");
299 b->addLine(
"return *this;");
307 std::stringstream doc;
308 doc <<
"@brief toString() - Converts the internally stored value to string \n";
309 doc <<
"@return - the name of the enum";
313 b->addLine(
"return EnumToStringMap.at(value);");
321 std::stringstream doc;
322 doc <<
"@brief fromString() - sets the internally stored value to the corrsponding enum of "
324 doc <<
"@return - nothing";
329 b->addLine(
"if (auto it = StringToEnumMap.find(str); it == StringToEnumMap.end())");
331 b2->addLine(
"throw armarx::LocalException(\"The input name is not valid. Could net set the "
332 "enum to value '\" + str + \"'\");");
336 b3->addLine(
"value = it->second;");