diff --git a/source/RobotAPI/applications/AronCodeGenerator/main.cpp b/source/RobotAPI/applications/AronCodeGenerator/main.cpp index f7e39ceefaefdc1bc131d075bd419fcd3fd20ba1..05185cc8d7c1a244a9797668f91481a8d2357d5e 100644 --- a/source/RobotAPI/applications/AronCodeGenerator/main.cpp +++ b/source/RobotAPI/applications/AronCodeGenerator/main.cpp @@ -177,7 +177,39 @@ int main(int argc, char* argv[]) } } - auto w = CppWriterPtr(new CppWriter()); + std::time_t current_time = std::time(0); + std::tm* now = std::localtime(¤t_time); + std::string current_year = std::to_string(now->tm_year + 1900); + + std::string fileDoc = std::string("* This file is part of ArmarX. \n") + +"* \n" + +"* Copyright (C) 2012-" + current_year + ", High Performance Humanoid Technologies (H2T), \n" + +"* Karlsruhe Institute of Technology (KIT), all rights reserved. \n" + +"* \n" + +"* ArmarX is free software; you can redistribute it and/or modify \n" + +"* it under the terms of the GNU General Public License version 2 as \n" + +"* published by the Free Software Foundation. \n" + +"* \n" + +"* ArmarX is distributed in the hope that it will be useful, but \n" + +"* WITHOUT ANY WARRANTY; without even the implied warranty of \n" + +"* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" + +"* GNU General Public License for more details. \n" + +"* \n" + +"* You should have received a copy of the GNU General Public License \n" + +"* along with this program. If not, see <http://www.gnu.org/licenses/>. \n" + +"* \n" + +"* @copyright http://www.gnu.org/licenses/gpl-2.0.txt \n" + +"* GNU General Public License \n" + +"* *********************************************************************** \n" + +"* WARNING: This file is autogenerated. \n" + +"* Original file: " + filename + " \n" + +"* Please do not edit since your changes may be overwritten on the next generation \n" + +"* If you have any questions please contact: Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) \n" + +"* ***********************************************************************"; + + auto w = CppWriterPtr(new CppWriter(true, fileDoc)); + w->header.line(); + w->header.line(); // Generate enums at top of generated header file std::vector<MetaEnumPtr> enums = writer.getTypeEnums(); @@ -186,7 +218,12 @@ int main(int argc, char* argv[]) std::cout << "Now exporting enums..." << std::endl; } + w->body.line("/*************************************************************************"); + w->body.line(" * ALL GENERATED ENUMS ***************************************************"); + w->body.line(" ************************************************************************/"); MetaEnum::Write(enums, w); + w->body.line(); + w->body.line(); std::string enum_file_generation_content = w->getString(); @@ -208,7 +245,12 @@ int main(int argc, char* argv[]) std::cout << "Now exporting classes..." << std::endl; } + w->body.line("/* ************************************************************************"); + w->body.line(" * ALL GENERATED CLASSES *************************************************"); + w->body.line(" * ***********************************************************************/"); CppClass::Write(classes, w); + w->body.line(); + w->body.line(); std::string class_file_generation_content = simox::alg::remove_prefix(w->getString(), enum_file_generation_content); @@ -223,39 +265,7 @@ int main(int argc, char* argv[]) exit(1); } - std::time_t current_time = std::time(0); - std::tm* now = std::localtime(¤t_time); - std::string current_year = std::to_string(now->tm_year + 1900); - std::string new_file_header = "\ -/* \n\ - * This file is part of ArmarX. \n\ - * \n\ - * Copyright (C) 2012-" + current_year + ", High Performance Humanoid Technologies (H2T), \n\ - * Karlsruhe Institute of Technology (KIT), all rights reserved. \n\ - * \n\ - * ArmarX is free software; you can redistribute it and/or modify \n\ - * it under the terms of the GNU General Public License version 2 as \n\ - * published by the Free Software Foundation. \n\ - * \n\ - * ArmarX is distributed in the hope that it will be useful, but \n\ - * WITHOUT ANY WARRANTY; without even the implied warranty of \n\ - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n\ - * GNU General Public License for more details. \n\ - * \n\ - * You should have received a copy of the GNU General Public License \n\ - * along with this program. If not, see <http://www.gnu.org/licenses/>. \n\ - * \n\ - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt \n\ - * GNU General Public License \n\ - ************************************************************************* \n\ - * WARNING: This file is autogenerated. \n\ - * Original file: " + filename + " \n\ - * Please do not edit since your changes may be overwritten on the next generation \n\ - * If you have any questions please contact: Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) \n\ - ************************************************************************* \n\ - */\n\n\n"; - - std::string new_file_full_content = new_file_header + w->getString(); + std::string new_file_full_content = w->getString(); std::string new_name_with_extension = input_file.filename().replace_extension("").string(); new_name_with_extension += ".aron.generated.h"; diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp index 64d17347e586e80613ef571f8d22d9489d0b522e..c65402434f631f9d26f34c15b6f12d818e1b4a43 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/Writer.cpp @@ -90,6 +90,7 @@ namespace armarx::aron::codegenerator::cpp toAron.include = "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>"; toAron.enforceConversion = "armarx::aron::data::Dict::DynamicCastAndCheck"; + toAron.override = true; dictDataWriters.push_back(toAron); } { @@ -101,6 +102,7 @@ namespace armarx::aron::codegenerator::cpp "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>"; toAronDTO.enforceConversion = "armarx::aron::data::Dict::DynamicCastAndCheck"; toAronDTO.enforceMemberAccess = "->toAronDictDTO()"; + toAronDTO.override = true; dictDataWriters.push_back(toAronDTO); } { @@ -138,6 +140,7 @@ namespace armarx::aron::codegenerator::cpp toAron.include = "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>"; toAron.enforceConversion = "armarx::aron::data::Int::DynamicCastAndCheck"; + toAron.override = true; intEnumDataWriters.push_back(toAron); } { @@ -149,6 +152,7 @@ namespace armarx::aron::codegenerator::cpp "<RobotAPI/libraries/aron/core/data/rw/writer/variant/VariantWriter.h>"; toAronDTO.enforceConversion = "armarx::aron::data::Int::DynamicCastAndCheck"; toAronDTO.enforceMemberAccess = "->toAronIntDTO()"; + toAronDTO.override = true; intEnumDataWriters.push_back(toAronDTO); } { @@ -201,6 +205,7 @@ namespace armarx::aron::codegenerator::cpp fromAron.argumentType = "armarx::aron::data::DictPtr"; fromAron.readerClassType = "armarx::aron::data::reader::VariantReader"; fromAron.include = "<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>"; + fromAron.override = true; dictDataReaders.push_back(fromAron); } { @@ -210,6 +215,7 @@ namespace armarx::aron::codegenerator::cpp fromAronDTO.readerClassType = "armarx::aron::data::reader::VariantReader"; fromAronDTO.include = "<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>"; fromAronDTO.enforceConversion = "std::make_shared<armarx::aron::data::Dict>"; + fromAronDTO.override = true; dictDataReaders.push_back(fromAronDTO); } } @@ -236,6 +242,7 @@ namespace armarx::aron::codegenerator::cpp fromAron.argumentType = "armarx::aron::data::IntPtr"; fromAron.readerClassType = "armarx::aron::data::reader::VariantReader"; fromAron.include = "<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>"; + fromAron.override = true; intEnumDataReaders.push_back(fromAron); } { @@ -246,6 +253,7 @@ namespace armarx::aron::codegenerator::cpp fromAronDTO.include = "<RobotAPI/libraries/aron/core/data/rw/reader/variant/VariantReader.h>"; fromAronDTO.enforceConversion = "std::make_shared<armarx::aron::data::Int>"; + fromAronDTO.override = true; intEnumDataReaders.push_back(fromAronDTO); } } @@ -274,7 +282,7 @@ namespace armarx::aron::codegenerator::cpp std::vector<std::string> tmpl_requires; for (auto& t : type->getTemplates()) { - tmpl_requires.push_back("armarx::aron::cpp::isAronGeneratedClass<" + t + ">"); + tmpl_requires.push_back("armarx::aron::cpp::isAronGeneratedObject<" + t + ">"); tmpl.push_back("class " + t); } std::string templateDef = "template <" + simox::alg::join(tmpl, ", ") + ">"; @@ -290,7 +298,7 @@ namespace armarx::aron::codegenerator::cpp } else { - c->addInherit("public armarx::aron::cpp::AronGeneratedClass"); + c->addInherit("public armarx::aron::cpp::AronGeneratedObject<" + generator.getFullClassCppTypename() + ">"); } // Writermethods @@ -305,8 +313,9 @@ namespace armarx::aron::codegenerator::cpp { c->addInclude(info.include); } + CppMethodPtr convert = generator.toSpecializedDataWriterMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Add methods to set the member variables @@ -323,7 +332,7 @@ namespace armarx::aron::codegenerator::cpp } CppMethodPtr convert = generator.toSpecializedStaticDataReaderMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Add methods to set the member variables @@ -338,8 +347,9 @@ namespace armarx::aron::codegenerator::cpp { c->addInclude(info.include); } + CppMethodPtr convert = generator.toSpecializedDataReaderMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Typewritermethods @@ -355,7 +365,7 @@ namespace armarx::aron::codegenerator::cpp c->addInclude(info.include); } CppMethodPtr convert = generator.toSpecializedTypeWriterMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } typeClasses.push_back(c); @@ -381,28 +391,28 @@ namespace armarx::aron::codegenerator::cpp setupMemberFields(c, publicGenerateIntEnumType.doc_values, generator); - c->addInherit("public armarx::aron::cpp::AronGeneratedClass"); + c->addInherit("public armarx::aron::cpp::AronGeneratedIntEnum<" + generator.getFullClassCppTypename() + ">"); // ctor c->addCtor(generator.toEnumCtor(c->getName())); CppMethodPtr toString = generator.toToStringMethod(); - c->addMethod(toString); + c->addPublicMethod(toString); CppMethodPtr fromString = generator.toFromStringMethod(); - c->addMethod(fromString); + c->addPublicMethod(fromString); CppMethodPtr intConversion = generator.toIntMethod(); - c->addMethod(intConversion); + c->addPublicMethod(intConversion); CppMethodPtr enumAssignment = generator.toEnumAssignmentMethod(); - c->addMethod(enumAssignment); + c->addPublicMethod(enumAssignment); CppMethodPtr enumAssignment2 = generator.toCopyAssignmentMethod(); - c->addMethod(enumAssignment2); + c->addPublicMethod(enumAssignment2); CppMethodPtr enumAssignment3 = generator.toIntAssignmentMethod(); - c->addMethod(enumAssignment3); + c->addPublicMethod(enumAssignment3); // Writermethods for (codegenerator::WriterInfo info : intEnumDataWriters) @@ -416,8 +426,9 @@ namespace armarx::aron::codegenerator::cpp { c->addInclude(info.include); } + CppMethodPtr convert = generator.toSpecializedDataWriterMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Add methods to set the member variables @@ -434,7 +445,7 @@ namespace armarx::aron::codegenerator::cpp } CppMethodPtr convert = generator.toSpecializedStaticDataReaderMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Add methods to set the member variables @@ -450,7 +461,7 @@ namespace armarx::aron::codegenerator::cpp c->addInclude(info.include); } CppMethodPtr convert = generator.toSpecializedDataReaderMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } // Typewritermethods @@ -466,7 +477,7 @@ namespace armarx::aron::codegenerator::cpp c->addInclude(info.include); } CppMethodPtr convert = generator.toSpecializedTypeWriterMethod(info); - c->addMethod(convert); + c->addPublicMethod(convert); } typeClasses.push_back(c); @@ -492,6 +503,8 @@ namespace armarx::aron::codegenerator::cpp CppEnumPtr e = std::make_shared<CppEnum>(namespaces, "Enum"); auto enumFields = gen.toEnumFields(); + ARMARX_CHECK(enumFields.size() > 0); + for (const auto& field : enumFields) { e->addField(field); @@ -527,7 +540,6 @@ namespace armarx::aron::codegenerator::cpp } c->addClassDoc(classDoc); - c->setPragmaOnceIncludeGuard(true); // add generator includes (e.g. coming from dto types) for (const auto& s : gen.getRequiredIncludes()) @@ -551,38 +563,40 @@ namespace armarx::aron::codegenerator::cpp c->addInclude("<RobotAPI/libraries/aron/core/aron_conversions.h>"); c->addInclude("<RobotAPI/libraries/aron/core/rw.h>"); c->addInclude("<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedClass.h>"); + c->addInclude("<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.h>"); + c->addInclude("<RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h>"); // ctor c->addCtor(gen.toCtor(c->getName())); c->addCtor(gen.toCopyCtor(c->getName())); // dtor - c->addMethod(gen.toDtor(c->getName())); + c->addPublicMethod(gen.toDtor(c->getName())); // Generic methods //std::cout << "Generate equals method" << std::endl; CppMethodPtr equals = gen.toEqualsMethod(); - c->addMethod(equals); + c->addPublicMethod(equals); //std::cout << "Generate reset method" << std::endl; CppMethodPtr resetHard = gen.toResetHardMethod(); - c->addMethod(resetHard); + c->addPublicMethod(resetHard); //std::cout << "Generate init method" << std::endl; CppMethodPtr resetSoft = gen.toResetSoftMethod(); - c->addMethod(resetSoft); + c->addPublicMethod(resetSoft); //std::cout << "Generate writeInit method" << std::endl; CppMethodPtr writeType = gen.toWriteTypeMethod(); - c->addMethod(writeType); + c->addPublicMethod(writeType); //std::cout << "Generate write method" << std::endl; CppMethodPtr write = gen.toWriteMethod(); - c->addMethod(write); + c->addPublicMethod(write); //std::cout << "Generate read method" << std::endl; CppMethodPtr read = gen.toReadMethod(); - c->addMethod(read); + c->addPublicMethod(read); return c; } diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp index be87200f51f745b314ef7f3f7c2a67beb18d332a..d3c61320d0bd8d1f57fd03531edf1f79df5754f2 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/Generator.cpp @@ -317,7 +317,7 @@ namespace armarx::aron::codegenerator::cpp doc << "@brief " << info.methodName << "() - This method returns a new data from the member data types using a writer implementation. \n"; doc << "@return - the result of the writer implementation"; - CppMethodPtr m = CppMethodPtr(new CppMethod(info.returnType + " " + info.methodName + "() const", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod(info.returnType + " " + info.methodName + "() const" + (info.override ? " override" : ""), doc.str())); m->addLine(info.writerClassType + " writer;"); m->addLine("return " + info.enforceConversion + "(this->write(writer))" + info.enforceMemberAccess + ";"); @@ -331,7 +331,7 @@ namespace armarx::aron::codegenerator::cpp doc << "@brief " << info.methodName << " - This method sets the struct members to new values given in a reader implementation. \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod("void " + info.methodName + "(const " + info.argumentType + "& input)", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod("void " + info.methodName + "(const " + info.argumentType + "& input)" + (info.override ? " override" : ""), doc.str())); m->addLine(info.readerClassType + " reader;"); m->addLine("this->read(reader, " + info.enforceConversion + "(input)" + info.enforceMemberAccess + ");"); @@ -395,9 +395,9 @@ namespace armarx::aron::codegenerator::cpp return {field}; } - std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCtorInitializers(const std::string&) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCtorInitializers(const std::string& name) const { - return {{}, false}; + return {{{name, "{}"}}, false}; } CppBlockPtr Generator::getCtorBlock(const std::string&) const @@ -408,7 +408,7 @@ namespace armarx::aron::codegenerator::cpp std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCopyCtorInitializers(const std::string& name) const { const auto& t = getType(); - if (t.getMaybe() == type::Maybe::UNIQUE_PTR || t.getMaybe() == type::Maybe::RAW_PTR) + if (t.getMaybe() == type::Maybe::UNIQUE_PTR) // unique ptrs cant be copied { return {{{name, ARON_OTHER_ACCESSOR + "." + name + " ? " + resolveMaybeGenerator("*" + ARON_OTHER_ACCESSOR + "." + name) + " : nullptr"}}, true}; } diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp index ce2bbb8dd8df9bfc0fe5c8482e4a7921b42fdfa7..0cddfd33161dcd0bf5f398fa87f4c0a88ec0a447 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.cpp @@ -55,6 +55,8 @@ namespace armarx::aron::codegenerator::cpp::generator // add legacy typedef fields.push_back(std::make_shared<CppField>("using", std::string(IMPL_ENUM), simox::alg::to_lower(className) + "_details::Enum", "Legacy typedef of enum")); + ARMARX_CHECK(type.getAcceptedValueMap().size() > 0); + enum_to_name << "{" << std::endl; name_to_enum << "{" << std::endl; enum_to_value << "{" << std::endl; @@ -81,7 +83,7 @@ namespace armarx::aron::codegenerator::cpp::generator fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", int>", "EnumToValueMap", enum_to_value.str(), "Mapping enum values to a int value")); fields.push_back(std::make_shared<CppField>("static inline const std::map<int, " + std::string(IMPL_ENUM) + ">", "ValueToEnumMap", value_to_enum.str(), "Mapping int values to a enum")); - fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", "", "The current value of the enum object")); + fields.push_back(std::make_shared<CppField>(std::string(IMPL_ENUM), "value", type.getAcceptedValueNames()[0], "The current value of the enum object")); return fields; } @@ -162,11 +164,6 @@ namespace armarx::aron::codegenerator::cpp::generator return c; }*/ - std::pair<std::vector<std::pair<std::string, std::string>>, bool> IntEnumClass::getCopyCtorInitializers(const std::string&) const - { - return {{{"value", ARON_OTHER_ACCESSOR + ".value"}}, false}; - } - CppCtorPtr IntEnumClass::toEnumCtor(const std::string& name) const { CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + std::string(IMPL_ENUM) + " e)"); diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.h index 53e9dd4a31143ad193e29fa59aec0aed351860a5..fb5e22671ba678ea69072e7b97fee54dbdd395e9 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/IntEnumClass.h @@ -43,8 +43,6 @@ namespace armarx::aron::codegenerator::cpp::generator // virtual implementations std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const final; - std::pair<std::vector<std::pair<std::string, std::string>>, bool> getCopyCtorInitializers(const std::string&) const final; - CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final; diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp index e3af89daa12ecc2de2f4fe60d9269dd48f729c9a..605c7b8655db3accb2dd1999d7c62e1cfc48730e 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.cpp @@ -47,7 +47,7 @@ namespace armarx::aron::codegenerator::cpp::generator std::vector<std::string> ObjectClass::getRequiredIncludes() const { std::vector<std::string> ret; - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { (void) key; auto child_s = FromAronType(*child); @@ -59,7 +59,7 @@ namespace armarx::aron::codegenerator::cpp::generator std::vector<CppFieldPtr> ObjectClass::getPublicVariableDeclarations(const std::string&) const { std::vector<CppFieldPtr> fields; - for (const auto& [key, member] : type.getMemberTypes()) + for (const auto& [key, member] : type.getDirectMemberTypes()) { auto member_s = FromAronType(*member); std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key); @@ -77,7 +77,7 @@ namespace armarx::aron::codegenerator::cpp::generator block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetSoft();"); } - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { auto child_s = FromAronType(*child); CppBlockPtr b2 = child_s->getResetSoftBlock(key); @@ -95,7 +95,7 @@ namespace armarx::aron::codegenerator::cpp::generator block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::resetHard();"); } - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { const auto child_s = FromAronType(*child); CppBlockPtr b2 = child_s->getResetHardBlock(key); @@ -127,7 +127,7 @@ namespace armarx::aron::codegenerator::cpp::generator } b->addLine("// members of " + this->getFullInstantiatedCppTypename()); - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { const auto child_s = FromAronType(*child); std::string child_return_variant; @@ -176,7 +176,7 @@ namespace armarx::aron::codegenerator::cpp::generator } block_if_data->addLine("// members of " + this->getFullInstantiatedCppTypename()); - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { const auto child_s = FromAronType(*child); std::string child_return_variant; @@ -210,7 +210,7 @@ namespace armarx::aron::codegenerator::cpp::generator block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readDict("+variantAccessor+", "+OBJECT_MEMBERS_ACCESSOR+"); // of top level object " + getInstantiatedCppTypename()); - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { const auto child_s = FromAronType(*child); std::string child_accessor = OBJECT_MEMBERS_ACCESSOR + "_" + key + "_iterator"; @@ -230,7 +230,7 @@ namespace armarx::aron::codegenerator::cpp::generator block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + "::operator== (" + otherInstanceAccessor + ")))"); block_if_data->addLineAsBlock("return false;"); } - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { auto child_s = FromAronType(*child); CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key); @@ -250,7 +250,7 @@ namespace armarx::aron::codegenerator::cpp::generator } bool anyComplex = false; - for (const auto& [key, child] : type.getMemberTypes()) + for (const auto& [key, child] : type.getDirectMemberTypes()) { auto child_s = FromAronType(*child); auto initList = child_s->getCopyCtorInitializers(key); diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h index 3bda10de7b14849fe6e18da11f7201704c2f3670..486a57879e42fa1eaced1d76231bf63f181a7312 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h @@ -37,6 +37,7 @@ namespace armarx::aron::codegenerator std::string include; std::string enforceConversion = ""; std::string enforceMemberAccess = ""; + bool override = false; }; diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h index 1989ac5de9e93ee5ddda8ac66cfa1e65edeab98b..c7dc87033b6fe87356e2b79a42b477ed8bd37b3d 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h @@ -37,5 +37,6 @@ namespace armarx::aron::codegenerator std::string include; std::string enforceConversion = ""; std::string enforceMemberAccess = ""; + bool override = false; }; } diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt index d7add84ada2fcafe2c8bf8f9f9a8d2c40e663c7d..3b05caec20fae2d7a43b406f043e4c2da703923c 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt @@ -106,6 +106,24 @@ armarx_add_test( ${Simox_INCLUDE_DIR} ) +###################### +# ARON CONVERSION TEST +###################### +armarx_add_test( + TEST_NAME + aronConversionTest + TEST_FILE + aronConversionTest.cpp + LIBS + SimoxUtility # Simox::SimoxUtility + ArmarXCore + RobotAPI::aron + ARON_FILES + aron/HumanPoseTest.xml + INCLUDE_DIRECTORIES + ${Simox_INCLUDE_DIR} +) + ###################### # ARON JSON EXPORT TEST ###################### diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/aronConversionTest.cpp b/source/RobotAPI/libraries/aron/codegeneration/test/aronConversionTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..636f9bde6472fb9596a0a1a07d6343f3690da808 --- /dev/null +++ b/source/RobotAPI/libraries/aron/codegeneration/test/aronConversionTest.cpp @@ -0,0 +1,97 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::aron + * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu ) + * @date 2019 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#define BOOST_TEST_MODULE RobotAPI::ArmarXLibraries::aron + +#define ARMARX_BOOST_TEST + +// STD/STL +#include <iostream> +#include <cstdlib> +#include <ctime> +#include <numeric> + +// Test +#include <RobotAPI/Test.h> + +// Aron +#include <RobotAPI/libraries/aron/core/data/variant/All.h> +#include <RobotAPI/libraries/aron/codegeneration/test/aron/HumanPoseTest.aron.generated.h> + + +using namespace armarx; +using namespace aron; + +namespace armarx +{ + class HumanPoseBO + { + public: + std::vector<float> jointValues; + bool reached; + + HumanPoseBO() = default; + + void fromAron(const HumanPoseTest& aron) + { + jointValues = aron.jointValues; + reached = aron.reached; + } + + HumanPoseTest toAron() + { + HumanPoseTest aron; + aron.jointValues = jointValues; + aron.reached = reached; + return aron; + } + }; + + void fromAron(const HumanPoseTest& aron, HumanPoseBO& bo) + { + bo.jointValues = aron.jointValues; + bo.reached = aron.reached; + } + + void toAron(HumanPoseTest& aron, const HumanPoseBO& bo) + { + aron.jointValues = bo.jointValues; + aron.reached = bo.reached; + } + + BOOST_AUTO_TEST_CASE(AronAssignmentTest) + { + armarx::HumanPoseTest aron; + aron.jointValues = {1,2,3,4}; + aron.reached = true; + + HumanPoseBO bo; + aron.to(bo); + + BOOST_CHECK((aron.jointValues == bo.jointValues)); + + HumanPoseBO bo2; + aron.to(bo, &fromAron); + + BOOST_CHECK((aron.jointValues == bo2.jointValues)); + } +} diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt index e17910e7f15989afc0c99c8284469074c1f88f34..2fb890b86fb3c9e1bd26bee37f879922c3d6bcd5 100644 --- a/source/RobotAPI/libraries/aron/core/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -107,6 +107,8 @@ set(LIB_HEADERS Path.h codegeneration/cpp/AronGeneratedClass.h + codegeneration/cpp/AronGeneratedObject.h + codegeneration/cpp/AronGeneratedIntEnum.h aron_conversions.h rw.h diff --git a/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h b/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h new file mode 100644 index 0000000000000000000000000000000000000000..f173775dabfd4faf404ea47564f3e74183e32de8 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h @@ -0,0 +1,68 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include "AronGeneratedClass.h" + + +namespace armarx::aron::cpp +{ + class AronGeneratedIntEnumBase : public AronGeneratedClass + { + public: + AronGeneratedIntEnumBase() = default; + virtual ~AronGeneratedIntEnumBase() = default; + + /// Convert the current bo to an aron variant data dict + virtual armarx::aron::data::IntPtr toAron() const = 0; + + /// Convert the current bo to the ice representation of an aron variant data dict + virtual armarx::aron::data::dto::AronIntPtr toAronDTO() const = 0; + + /// Set all members of the current bo according to the aron variant data dict + virtual void fromAron(const armarx::aron::data::IntPtr& input) = 0; + + /// Set all members of the current bo according to the ice representation of an aron variant data dict + virtual void fromAron(const armarx::aron::data::dto::AronIntPtr& input) = 0; + }; + + template <class Derived> + class AronGeneratedIntEnum : + public AronGeneratedIntEnumBase + { + public: + + }; + + template <class T> + concept isAronGeneratedIntEnum = std::is_base_of<AronGeneratedIntEnumBase, T>::value; +} + +namespace armarx::aron::codegenerator::cpp +{ + using AronGeneratedIntEnumBase = aron::cpp::AronGeneratedIntEnumBase; + + template <class Derived> + using AronGeneratedIntEnum = aron::cpp::AronGeneratedIntEnum<Derived>; +} diff --git a/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.h b/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.h new file mode 100644 index 0000000000000000000000000000000000000000..17d94831b41120c40dbb56932427e003fe3de1fd --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.h @@ -0,0 +1,111 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include "AronGeneratedClass.h" + + +namespace armarx::aron::cpp +{ + + class AronGeneratedObjectBase : + public AronGeneratedClass + { + public: + AronGeneratedObjectBase() = default; + virtual ~AronGeneratedObjectBase() = default; + + /// Convert the current bo to an aron variant data dict + virtual armarx::aron::data::DictPtr toAron() const = 0; + + /// Convert the current bo to the ice representation of an aron variant data dict + virtual armarx::aron::data::dto::DictPtr toAronDTO() const = 0; + + /// Set all members of the current bo according to the aron variant data dict + virtual void fromAron(const armarx::aron::data::DictPtr& input) = 0; + + /// Set all members of the current bo according to the ice representation of an aron variant data dict + virtual void fromAron(const armarx::aron::data::dto::DictPtr& input) = 0; + }; + + template <class Derived> + class AronGeneratedObject : + public AronGeneratedObjectBase + { + public: + AronGeneratedObject() = default; + virtual ~AronGeneratedObject() = default; + + template <class T> + void to(T& t) const + { + const Derived* d = dynamic_cast<const Derived*>(this); + if (d) + { + t.fromAron(*d); + } + } + + template <class T> + void from(const T& t) + { + Derived* d = dynamic_cast<Derived*>(this); + if (d) + { + t.toAron(*d); + } + } + + template <class T> + void to(T& t, void(*fromAron)(const Derived&, T&)) const + { + const Derived* d = dynamic_cast<const Derived*>(this); + if (d) + { + fromAron(*d, t); + } + } + + template <class T> + void from(const T& t, void(*toAron)(Derived&, const T&)) + { + Derived* d = dynamic_cast<Derived*>(this); + if (d) + { + toAron(*d, t); + } + } + }; + + template <class T> + concept isAronGeneratedObject = std::is_base_of<AronGeneratedObjectBase, T>::value; +} + +namespace armarx::aron::codegenerator::cpp +{ + using AronGeneratedObjectBase = aron::cpp::AronGeneratedObjectBase; + + template <class Derived> + using AronGeneratedObject = aron::cpp::AronGeneratedObject<Derived>; +}