From a550f66bc565584955463ec056fc09819c639b98 Mon Sep 17 00:00:00 2001 From: Fabian Peller <fabian.peller-konrad@kit.edu> Date: Mon, 27 Mar 2023 15:36:02 +0200 Subject: [PATCH] fix codegeneratio of extending objects. Make toAron and fromAron methods virtual. Add special base classes for objects and enums which allow template calling of toAron and fromAron methods --- .../codegenerator/codewriter/cpp/Writer.cpp | 24 ++-- .../codewriter/cpp/generator/Generator.cpp | 10 +- .../cpp/generator/toplevel/ObjectClass.cpp | 18 +-- .../codegenerator/helper/ReaderInfo.h | 2 +- .../codegenerator/helper/WriterInfo.h | 2 +- .../aron/codegeneration/test/CMakeLists.txt | 18 +++ .../test/aronConversionTest.cpp | 97 +++++++++++++++ .../libraries/aron/core/CMakeLists.txt | 2 + .../codegeneration/cpp/AronGeneratedIntEnum.h | 68 +++++++++++ .../codegeneration/cpp/AronGeneratedObject.h | 111 ++++++++++++++++++ .../core/type/variant/container/Object.cpp | 7 ++ 11 files changed, 329 insertions(+), 30 deletions(-) create mode 100644 source/RobotAPI/libraries/aron/codegeneration/test/aronConversionTest.cpp create mode 100644 source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedIntEnum.h create mode 100644 source/RobotAPI/libraries/aron/core/codegeneration/cpp/AronGeneratedObject.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 a597e8ecc..c65402434 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 @@ -306,10 +314,6 @@ namespace armarx::aron::codegenerator::cpp c->addInclude(info.include); } - if (type->getExtends() != nullptr) - { - info.extends = true; - } CppMethodPtr convert = generator.toSpecializedDataWriterMethod(info); c->addPublicMethod(convert); } @@ -344,10 +348,6 @@ namespace armarx::aron::codegenerator::cpp c->addInclude(info.include); } - if (type->getExtends() != nullptr) - { - info.extends = true; - } CppMethodPtr convert = generator.toSpecializedDataReaderMethod(info); c->addPublicMethod(convert); } @@ -391,7 +391,7 @@ 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())); @@ -563,6 +563,8 @@ 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())); 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 a0715b220..d3c61320d 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,10 +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"; - const std::string fin = info.extends ? " final" : ""; - const std::string virt = info.extends ? "" : "virtual "; - - CppMethodPtr m = CppMethodPtr(new CppMethod(virt + info.returnType + " " + info.methodName + "() const" + fin, 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 + ";"); @@ -334,10 +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"; - const std::string fin = info.extends ? " final" : ""; - const std::string virt = info.extends ? "" : "virtual "; - - CppMethodPtr m = CppMethodPtr(new CppMethod(virt + "void " + info.methodName + "(const " + info.argumentType + "& input)" + fin, 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 + ");"); 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 e3af89daa..605c7b865 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 58dda6381..486a57879 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/ReaderInfo.h @@ -37,7 +37,7 @@ namespace armarx::aron::codegenerator std::string include; std::string enforceConversion = ""; std::string enforceMemberAccess = ""; - bool extends = false; + 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 d3cff5ef8..c7dc87033 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/helper/WriterInfo.h @@ -37,6 +37,6 @@ namespace armarx::aron::codegenerator std::string include; std::string enforceConversion = ""; std::string enforceMemberAccess = ""; - bool extends = false; + bool override = false; }; } diff --git a/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/codegeneration/test/CMakeLists.txt index d7add84ad..3b05caec2 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 000000000..636f9bde6 --- /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 e17910e7f..2fb890b86 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 000000000..f173775da --- /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 000000000..17d94831b --- /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>; +} diff --git a/source/RobotAPI/libraries/aron/core/type/variant/container/Object.cpp b/source/RobotAPI/libraries/aron/core/type/variant/container/Object.cpp index 1b26bd769..526cc9f05 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/container/Object.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/container/Object.cpp @@ -88,6 +88,13 @@ namespace armarx::aron::type std::map<std::string, VariantPtr> Object::getMemberTypes() const { std::map<std::string, VariantPtr> ret = memberTypes; + if (extends) + { + for (const auto& [key, t] : extends->getMemberTypes()) + { + ret.insert({key, t}); + } + } return ret; } -- GitLab