28 #include <SimoxUtility/algorithm/string.h>
29 #include <SimoxUtility/meta/type_name.h>
55 const static std::map<std::string, std::string> ESCAPE_ACCESSORS = {{
"->",
"_ptr_"},
63 std::string escaped_accessor = accessor;
64 for (
const auto& [key,
value] : ESCAPE_ACCESSORS)
66 escaped_accessor = simox::alg::replace_all(escaped_accessor, key,
value);
68 return escaped_accessor;
76 return cpp->getInstantiatedCppTypename();
79 std::vector<std::string>
82 std::vector<std::string>
ret;
83 for (
const auto&
v : n)
90 std::unique_ptr<Generator>
93 return FACTORY->create(n, n.
getPath());
98 const std::string& classCppTypename,
99 const std::string& aronDataTypename,
100 const std::string& aronTypeTypename) :
101 instantiatedCppTypename(instantiatedCppTypename),
102 classCppTypename(classCppTypename),
103 aronDataTypename(aronDataTypename),
104 aronTypeTypename(aronTypeTypename)
112 return instantiatedCppTypename;
122 case type::Maybe::OPTIONAL:
124 case type::Maybe::RAW_PTR:
126 case type::Maybe::SHARED_PTR:
128 case type::Maybe::UNIQUE_PTR:
132 "Received unknown maybe enum",
145 case type::Maybe::OPTIONAL:
147 case type::Maybe::RAW_PTR:
149 case type::Maybe::SHARED_PTR:
151 case type::Maybe::UNIQUE_PTR:
155 "Received unknown maybe enum",
164 return classCppTypename;
174 case type::Maybe::OPTIONAL:
176 case type::Maybe::RAW_PTR:
178 case type::Maybe::SHARED_PTR:
180 case type::Maybe::UNIQUE_PTR:
184 "Received unknown maybe enum",
196 if (b->size() > 0 || initList.second)
199 c->addInitListEntries(initList.first);
214 if (b->size() > 0 || initList.second)
218 c->addInitListEntries(initList.first);
237 m->setEnforceBlockGeneration(
true);
242 m->setEnforceBlockGeneration(
false);
249 std::stringstream doc;
250 doc <<
"@brief resetSoft() - This method resets all member variables with respect to the "
251 "current parameterization. \n";
252 doc <<
"@return - nothing";
259 m->setEnforceBlockGeneration(
true);
266 std::stringstream doc;
267 doc <<
"@brief resetHard() - This method resets member variables according to the XML type "
269 doc <<
"@return - nothing";
276 m->setEnforceBlockGeneration(
true);
283 std::stringstream doc;
284 doc <<
"@brief writeType() - This method returns a new type from the class structure using "
285 "a type writer implementation. This function is static. \n";
286 doc <<
"@return - the result of the writer implementation";
289 "template<class WriterT>\nstatic typename WriterT::ReturnType writeType(WriterT& " +
293 " = ::armarx::aron::type::Maybe::NONE, const ::armarx::aron::Path& " +
297 b->addLine(
"using _Aron_T [[maybe_unused]] = typename WriterT::ReturnType;");
303 m->setEnforceBlockGeneration(
true);
310 std::stringstream doc;
311 doc <<
"@brief write() - This method returns a new type from the member data types using a "
312 "data writer implementation. \n";
313 doc <<
"@param w - The writer implementation\n";
314 doc <<
"@return - the result of the writer implementation";
317 new CppMethod(
"template<class WriterT>\ntypename WriterT::ReturnType write(WriterT& " +
322 b->addLine(
"using _Aron_T [[maybe_unused]] = typename WriterT::ReturnType;");
328 b->addLineAsBlock(
"throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, "
329 "std::string(\"An error occured during the write method of an aron "
330 "generated class. The full error log was:\\n\") + " +
334 m->setEnforceBlockGeneration(
true);
341 std::stringstream doc;
342 doc <<
"@brief read() - This method sets the struct members to new values given in a data "
343 "reader implementation. \n";
344 doc <<
"@param r - The reader implementation\n";
345 doc <<
"@return - nothing";
349 ", typename ReaderT::InputType& input)",
352 b->addLine(
"using _Aron_T [[maybe_unused]] = typename ReaderT::InputType;");
353 b->addLine(
"using _Aron_TNonConst [[maybe_unused]] = typename ReaderT::InputTypeNonConst;");
355 b->addLine(
"this->resetSoft();");
357 ".readNull(input), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, "
358 "\"The input to the read method must not be null.\"));");
363 b->addLineAsBlock(
"throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, "
364 "std::string(\"An error occured during the read method of an aron "
365 "generated class. The full error log was:\\n\") + " +
369 m->setEnforceBlockGeneration(
true);
376 std::stringstream doc;
378 <<
"() - This method returns a new data from the member data types using a writer "
379 "implementation. \n";
380 doc <<
"@return - the result of the writer implementation";
390 m->setEnforceBlockGeneration(
true);
397 std::stringstream doc;
399 <<
" - This method sets the struct members to new values given in a reader "
400 "implementation. \n";
401 doc <<
"@return - nothing";
405 "& input)" + (info.
override ?
" override" :
""),
411 m->setEnforceBlockGeneration(
true);
418 std::stringstream doc;
420 <<
"() - This method sets the struct members to new values given in a reader "
421 "implementation. \n";
422 doc <<
"@return - nothing";
429 m->addLine(
"t.fromAron(input);");
430 m->addLine(
"return t;");
432 m->setEnforceBlockGeneration(
true);
439 std::stringstream doc;
441 <<
"() - This method returns a new type from the member data types using a writer "
442 "implementation. \n";
443 doc <<
"@return - the result of the writer implementation";
451 m->setEnforceBlockGeneration(
true);
458 std::stringstream doc;
459 doc <<
"@brief operator==() - This method checks whether all values equal another "
461 doc <<
"@param i - The other instance\n";
462 doc <<
"@return - true, if all members are the same, false otherwise";
467 b->addLine(
"return true;");
470 m->setEnforceBlockGeneration(
true);
475 std::vector<std::string>
481 std::vector<CppFieldPtr>
488 std::pair<std::vector<std::pair<std::string, std::string>>,
bool>
497 return std::make_shared<CppBlock>();
500 std::pair<std::vector<std::pair<std::string, std::string>>,
bool>
504 if (t.getMaybe() == type::Maybe::UNIQUE_PTR)
519 return std::make_shared<CppBlock>();
525 return std::make_shared<CppBlock>();
531 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
540 auto block_if_data = std::make_shared<CppBlock>();
548 const std::string& otherInstanceAccessor)
const
550 CppBlockPtr block_if_data = std::make_shared<CppBlock>();
552 std::string other_instance_resolved_accessor =
555 block_if_data->addLine(
"if (not (" + resolved_accessor +
556 " == " + other_instance_resolved_accessor +
"))");
557 block_if_data->addLineAsBlock(
"return false;");
566 if (t.getMaybe() == type::Maybe::OPTIONAL)
568 return s +
".value()";
570 if (t.getMaybe() == type::Maybe::RAW_PTR || t.getMaybe() == type::Maybe::SHARED_PTR ||
571 t.getMaybe() == type::Maybe::UNIQUE_PTR)
582 if (t.getMaybe() == type::Maybe::OPTIONAL)
586 if (t.getMaybe() == type::Maybe::RAW_PTR)
590 if (t.getMaybe() == type::Maybe::SHARED_PTR)
594 if (t.getMaybe() == type::Maybe::UNIQUE_PTR)
607 return s +
" = " + gen +
";";
616 switch (type.getMaybe())
620 case type::Maybe::OPTIONAL:
621 case type::Maybe::RAW_PTR:
622 case type::Maybe::SHARED_PTR:
623 case type::Maybe::UNIQUE_PTR:
627 "Received unknown maybe enum",
636 switch (type.getMaybe())
638 case type::Maybe::RAW_PTR:
640 case type::Maybe::SHARED_PTR:
641 case type::Maybe::UNIQUE_PTR:
642 return cppAccessor +
".get()";
645 case type::Maybe::OPTIONAL:
649 "Received invalid maybe enum (not a pointer?)",
656 const std::string& cppAccessor)
const
659 if (type.getMaybe() == type::Maybe::OPTIONAL)
662 b->addLine(cppAccessor +
" = std::nullopt;");
665 else if (type.getMaybe() == type::Maybe::RAW_PTR ||
666 type.getMaybe() == type::Maybe::SHARED_PTR ||
667 type.getMaybe() == type::Maybe::UNIQUE_PTR)
670 b->addLine(cppAccessor +
" = nullptr;");
673 return block_if_data;
678 const std::string& cppAccessor)
const
681 if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR ||
682 type.getMaybe() == type::Maybe::SHARED_PTR ||
683 type.getMaybe() == type::Maybe::UNIQUE_PTR)
686 b->addLine(
"if (" + cppAccessor +
") // if " + cppAccessor +
" contains data");
687 b->addBlock(block_if_data);
690 return block_if_data;
695 const std::string& cppAccessor)
const
698 if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR ||
699 type.getMaybe() == type::Maybe::SHARED_PTR ||
700 type.getMaybe() == type::Maybe::UNIQUE_PTR)
703 b->addLine(
"if (" + cppAccessor +
") // if " + cppAccessor +
" contains data");
704 b->addBlock(block_if_data);
707 return block_if_data;
712 const std::string& cppAccessor,
713 const std::string& variantAccessor)
const
716 if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR ||
717 type.getMaybe() == type::Maybe::SHARED_PTR ||
718 type.getMaybe() == type::Maybe::UNIQUE_PTR)
722 "))) // if aron contains data");
726 ifb->appendBlock(block_if_data);
731 return block_if_data;
736 const std::string& accessor,
737 const std::string& otherInstanceAccessor)
const
740 if (type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR)
743 b->addLine(
"if (not (static_cast<bool>(" + accessor +
") == static_cast<bool>(" + otherInstanceAccessor +
"))) // check if both contain data");
744 b->addLineAsBlock(
"return false;");
745 b->addLine(
"if (static_cast<bool>(" + accessor +
") && static_cast<bool>(" + otherInstanceAccessor +
"))");
746 b->addBlock(block_if_data);
750 if (type.getMaybe() == type::Maybe::OPTIONAL)
753 b->addLine(
"if (not ( " + accessor +
".has_value() == " + otherInstanceAccessor +
".has_value())) // check if both contain data");
754 b->addLineAsBlock(
"return false;");
755 b->addLine(
"if ( " + accessor +
".has_value() && " + otherInstanceAccessor +
".has_value())");
756 b->addBlock(block_if_data);
759 return block_if_data;