26 #include <SimoxUtility/algorithm/string.h>
42 std::string result =
"";
46 char c = std::tolower(
str[0]);
51 for (
unsigned int i = 1; i <
str.length(); i++) {
58 if (std::isupper(ch)) {
59 result = result +
'_';
60 result+=char(std::tolower(ch));
74 Writer::Writer(
const std::string& producerName,
const std::vector<std::string>& additionalIncludesFromXMLFile) :
75 CodeWriter(producerName, additionalIncludesFromXMLFile)
87 toAron.methodName =
"toAron";
88 toAron.returnType =
"armarx::aron::data::DictPtr";
89 toAron.writerClassType =
"armarx::aron::data::writer::VariantWriter";
91 "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>";
92 toAron.enforceConversion =
"armarx::aron::data::Dict::DynamicCastAndCheck";
99 toAronDTO.
returnType =
"armarx::aron::data::dto::DictPtr";
100 toAronDTO.
writerClassType =
"armarx::aron::data::writer::VariantWriter";
102 "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>";
112 ToAronType.
returnType =
"armarx::aron::type::ObjectPtr";
113 ToAronType.
writerClassType =
"armarx::aron::type::writer::VariantWriter";
115 "<RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h>";
116 ToAronType.
enforceConversion =
"armarx::aron::type::Object::DynamicCastAndCheck";
123 ToAronTypeDTO.
returnType =
"armarx::aron::type::dto::AronObjectPtr";
124 ToAronTypeDTO.
writerClassType =
"armarx::aron::type::writer::VariantWriter";
126 "<RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h>";
127 ToAronTypeDTO.
enforceConversion =
"armarx::aron::type::Object::DynamicCastAndCheck";
137 toAron.methodName =
"toAron";
138 toAron.returnType =
"armarx::aron::data::IntPtr";
139 toAron.writerClassType =
"armarx::aron::data::writer::VariantWriter";
141 "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>";
142 toAron.enforceConversion =
"armarx::aron::data::Int::DynamicCastAndCheck";
149 toAronDTO.
returnType =
"armarx::aron::data::dto::AronIntPtr";
150 toAronDTO.
writerClassType =
"armarx::aron::data::writer::VariantWriter";
152 "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>";
162 ToAronType.
returnType =
"armarx::aron::type::IntEnumPtr";
163 ToAronType.
writerClassType =
"armarx::aron::type::writer::VariantWriter";
165 "<RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h>";
166 ToAronType.
enforceConversion =
"armarx::aron::type::IntEnum::DynamicCastAndCheck";
173 ToAronTypeDTO.
returnType =
"armarx::aron::type::dto::IntEnumPtr";
174 ToAronTypeDTO.
writerClassType =
"armarx::aron::type::writer::VariantWriter";
176 "<RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h>";
177 ToAronTypeDTO.
enforceConversion =
"armarx::aron::type::IntEnum::DynamicCastAndCheck";
191 fromAron.argumentType =
"armarx::aron::data::DictPtr";
192 fromAron.returnType = OWN_TYPE_NAME;
198 fromAronDTO.
argumentType =
"armarx::aron::data::dto::DictPtr";
205 fromAron.argumentType =
"armarx::aron::data::DictPtr";
206 fromAron.readerClassType =
"armarx::aron::data::reader::VariantReader";
207 fromAron.include =
"<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>";
214 fromAronDTO.
argumentType =
"armarx::aron::data::dto::DictPtr";
215 fromAronDTO.
readerClassType =
"armarx::aron::data::reader::VariantReader";
216 fromAronDTO.
include =
"<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>";
228 fromAron.argumentType =
"armarx::aron::data::IntPtr";
229 fromAron.returnType = OWN_TYPE_NAME;
235 fromAronDTO.
argumentType =
"armarx::aron::data::dto::AronIntPtr";
242 fromAron.argumentType =
"armarx::aron::data::IntPtr";
243 fromAron.readerClassType =
"armarx::aron::data::reader::VariantReader";
244 fromAron.include =
"<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>";
251 fromAronDTO.
argumentType =
"armarx::aron::data::dto::AronIntPtr";
252 fromAronDTO.
readerClassType =
"armarx::aron::data::reader::VariantReader";
254 "<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>";
265 for (
const auto& publicGenerateObjectType : generateObjects)
267 const auto type = publicGenerateObjectType.correspondingType;
279 if (!type->getTemplates().empty())
281 std::vector<std::string> tmpl;
282 std::vector<std::string> tmpl_requires;
283 for (
auto& t : type->getTemplates())
285 tmpl_requires.push_back(
"armarx::aron::cpp::isAronGeneratedObject<" + t +
">");
286 tmpl.push_back(
"class " + t);
288 std::string templateDef =
"template <" + simox::alg::join(tmpl,
", ") +
">";
289 std::string requiresDef =
"requires " + simox::alg::join(tmpl_requires,
" && ");
290 c->setTemplates(templateDef +
"\n" + requiresDef);
294 if (type->getExtends() !=
nullptr)
307 if (info.returnType == OWN_TYPE_NAME)
312 if (!info.include.empty())
314 c->addInclude(info.include);
325 if (info.returnType == OWN_TYPE_NAME)
329 if (info.argumentType == OWN_TYPE_NAME)
341 if (info.argumentType == OWN_TYPE_NAME)
346 if (!info.include.empty())
348 c->addInclude(info.include);
358 if (info.returnType == OWN_TYPE_NAME)
363 if (!info.include.empty())
365 c->addInclude(info.include);
377 for (
const auto& publicGenerateIntEnumType : generateIntEnums)
379 const auto& nav = publicGenerateIntEnumType.correspondingType;
390 c->addInclude(
"<RobotAPI/libraries/aron/core/data/variant/primitive/Int.h>");
403 c->addPublicMethod(fromString);
406 c->addPublicMethod(intConversion);
409 c->addPublicMethod(enumAssignment);
412 c->addPublicMethod(enumAssignment2);
415 c->addPublicMethod(enumAssignment3);
420 if (info.returnType == OWN_TYPE_NAME)
425 if (!info.include.empty())
427 c->addInclude(info.include);
438 if (info.returnType == OWN_TYPE_NAME)
442 if (info.argumentType == OWN_TYPE_NAME)
454 if (info.argumentType == OWN_TYPE_NAME)
459 if (!info.include.empty())
461 c->addInclude(info.include);
470 if (info.returnType == OWN_TYPE_NAME)
475 if (!info.include.empty())
477 c->addInclude(info.include);
489 const auto& type = gen.
getType();
500 namespaces.push_back(simox::alg::to_lower(
camelToSnake(rawObjectName)) +
"_details");
502 std::string enumdoc =
"The enum definition of the enum of the auogenerated class '" + gen.
getFullClassCppTypename() +
"'.";
503 CppEnumPtr e = std::make_shared<CppEnum>(namespaces,
"Enum");
508 for (
const auto& field : enumFields)
518 const auto& type = gen.
getType();
530 CppClassPtr c = std::make_shared<CppClass>(namespaces, rawObjectName);
532 std::string classDoc =
"******************************************\n"
533 "* AUTOGENERATED CLASS. Please do NOT edit.\n"
534 "******************************************\n";
542 c->addClassDoc(classDoc);
558 c->addInclude(simox::alg::replace_last(
s,
".aron.generated.codesuffix",
".aron.generated.h"));
563 c->addInclude(
"<RobotAPI/libraries/aron/core/aron_conversions.h>");
564 c->addInclude(
"<RobotAPI/libraries/aron/core/rw.h>");
565 c->addInclude(
"<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedClass.h>");
566 c->addInclude(
"<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.h>");
567 c->addInclude(
"<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h>");
570 c->addCtor(gen.
toCtor(
c->getName()));
574 c->addPublicMethod(gen.
toDtor(
c->getName()));
579 c->addPublicMethod(equals);
583 c->addPublicMethod(resetHard);
587 c->addPublicMethod(resetSoft);
591 c->addPublicMethod(writeType);
595 c->addPublicMethod(
write);
599 c->addPublicMethod(
read);
606 for (
const auto& f : publicFields)
608 if (
auto it = doc_members.find(f->getName()); it != doc_members.end())
610 f->setDoc(
"@brief " + it->second);
612 c->addPublicField(f);
619 for (
const auto& f : publicFields)
621 if (
auto it = doc_members.find(f->getName()); it != doc_members.end())
623 f->setDoc(
"@brief " + it->second);
625 c->addPublicField(f);