diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml index 4efce411b680ce9a91afceff7da5523b8f67d6cc..d204c95fac16b40f110555729049a5da632d8846 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml +++ b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml @@ -20,13 +20,13 @@ An example data containing different native ARON types. <GenerateTypes> <Object name='armarx::armem::example::InnerClass'> <ObjectChild key='element_int'> - <Int /> + <int32 default="42" /> </ObjectChild> <ObjectChild key='element_float'> - <Float /> + <float32 default="666.66" /> </ObjectChild> <ObjectChild key='element_string'> - <String /> + <String default="foobar" /> </ObjectChild> </Object> diff --git a/source/RobotAPI/interface/aron/Aron.ice b/source/RobotAPI/interface/aron/Aron.ice index fb412c46c2409c60ac236ba7579c64fe795dff28..f88037e31290655397624cfd23d0eadc42a293e5 100644 --- a/source/RobotAPI/interface/aron/Aron.ice +++ b/source/RobotAPI/interface/aron/Aron.ice @@ -8,10 +8,10 @@ #include <ArmarXCore/interface/core/BasicTypes.ice> -#define ARON_MAJOR "1" -#define ARON_MINOR "1" -#define ARON_PATCH "2" -#define ARON_VERSION "1.1.2" +#define ARON_MAJOR "2" +#define ARON_MINOR "0" +#define ARON_PATCH "0" +#define ARON_VERSION "2.0.0" module armarx { @@ -96,42 +96,104 @@ module armarx module dto { - class GenericType { + class GenericType + { string VERSION = ARON_VERSION; Maybe maybe = Maybe::NONE; - } - sequence<GenericType> GenericTypeSeq; + } sequence<GenericType> GenericTypeSeq; + dictionary<string, GenericType> GenericTypeDict; /* ***** Container types ***** */ - class List extends GenericType { GenericType acceptedType; } - class Tuple extends GenericType { GenericTypeSeq elementTypes; } - class Pair extends GenericType { GenericType acceptedType1; GenericType acceptedType2; } - class AronObject extends GenericType { AronObject parent; Ice::StringSeq templates; string objectName; Ice::StringSeq templateInstantiations; GenericTypeDict elementTypes; } - class Dict extends GenericType { GenericType acceptedType; } + class List extends GenericType + { + GenericType acceptedType; + } class Tuple extends GenericType + + { + GenericTypeSeq elementTypes; + } class Pair extends GenericType + { + GenericType acceptedType1; + GenericType acceptedType2; + } class AronObject extends GenericType + { + AronObject parent; + Ice::StringSeq templates; + string objectName; + Ice::StringSeq templateInstantiations; + GenericTypeDict elementTypes; + } class Dict extends GenericType + { + GenericType acceptedType; + } /* ***** Complex Types (serialize to ndarray) ***** */ - class NDArray extends GenericType { int ndimensions; ndarray::ElementType elementType; } - class Matrix extends GenericType { int rows; int cols; matrix::ElementType elementType; } - class Quaternion extends GenericType { quaternion::ElementType elementType; } - class Image extends GenericType { image::PixelType pixelType; } - class PointCloud extends GenericType { pointcloud::VoxelType voxelType; } + class NDArray extends GenericType + { + int ndimensions; + ndarray::ElementType elementType; + } class Matrix extends GenericType + { + int rows; + int cols; + matrix::ElementType elementType; + } class Quaternion extends GenericType + { + quaternion::ElementType elementType; + } class Image extends GenericType + { + image::PixelType pixelType; + } class PointCloud extends GenericType + { + pointcloud::VoxelType voxelType; + } /* ***** Enum types ***** */ - class IntEnum extends GenericType { string enumName; StringIntDict acceptedValues; } + class IntEnum extends GenericType + { + string enumName; + StringIntDict acceptedValues; + string defaultValue; + } //class FloatEnum extends GenericType { string enumName; StringFloatDict acceptedValues; } //class StringEnum extends GenericType { string enumName; StringStringDict acceptedValues; } /* ***** Any Types ***** */ - class AnyObject extends GenericType { }; + class AnyObject extends GenericType + { + }; /* ***** Primitive Types ***** */ - class AronInt extends GenericType { }; - class AronLong extends GenericType { }; - class AronDouble extends GenericType { }; - class AronFloat extends GenericType { }; - class AronString extends GenericType { }; - class AronBool extends GenericType { }; + class AronInt extends GenericType + { + int defaultValue; + }; + + class AronLong extends GenericType + { + long defaultValue; + }; + + class AronDouble extends GenericType + { + double defaultValue; + }; + + class AronFloat extends GenericType + { + float defaultValue; + }; + + class AronString extends GenericType + { + string defaultValue; + }; + + class AronBool extends GenericType + { + bool defaultValue; + }; }; }; @@ -143,30 +205,68 @@ module armarx { module dto { - class GenericData { + class GenericData + { string VERSION = ARON_VERSION; }; + sequence<GenericData> GenericDataSeq; dictionary<string, GenericData> GenericDataDict; /* ***** Container Data ***** */ - class List extends GenericData { GenericDataSeq elements; }; - class Dict extends GenericData { GenericDataDict elements; }; + class List extends GenericData + { + GenericDataSeq elements; + }; + + class Dict extends GenericData + { + GenericDataDict elements; + }; /* ***** Complex Data ***** */ // The NDArray contains more or less the same information as an AronType, but there is no other way to do it // Especially, note the difference between the type's typeName (e.g. "GRAY_SCALE_IMAGE" => language dependent) and the data's type ("0") // Further, note the difference between the type's dimensions (e.g. 128x128) and the data's dimensions (128x128x3 for RGB) - class NDArray extends GenericData { Ice::IntSeq shape; string type; Ice::ByteSeq data; } + class NDArray extends GenericData + { + Ice::IntSeq shape; + string type; + Ice::ByteSeq data; + } /* ***** Primitive Data ***** */ - class AronInt extends GenericData { int value; }; - class AronLong extends GenericData { long value; }; - class AronDouble extends GenericData { double value; }; - class AronFloat extends GenericData { float value; }; - class AronString extends GenericData { string value; }; - class AronBool extends GenericData { bool value; }; + class AronInt extends GenericData + + { + int value; + }; + + class AronLong extends GenericData + { + long value; + }; + + class AronDouble extends GenericData + { + double value; + }; + + class AronFloat extends GenericData + { + float value; + }; + + class AronString extends GenericData + { + string value; + }; + + class AronBool extends GenericData + { + bool value; + }; // useful for memory ice_conversions sequence<Dict> AronDictSeq; 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 d3c61320d0bd8d1f57fd03531edf1f79df5754f2..59e1b9eb46c1f680e16b73a63a51511cf7140f4a 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 @@ -24,40 +24,41 @@ // STD/STL #include "Generator.h" -#include "Factory.h" -#include <SimoxUtility/meta/type_name.h> #include <SimoxUtility/algorithm/string.h> +#include <SimoxUtility/meta/type_name.h> +#include "Factory.h" namespace armarx::aron::codegenerator::cpp { // constantes const std::string Generator::ARON_VARIABLE_PREFIX = "aron"; - const std::string Generator::ARON_MAYBE_TYPE_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_maybeType"; + const std::string Generator::ARON_MAYBE_TYPE_ACCESSOR = + Generator::ARON_VARIABLE_PREFIX + "_maybeType"; const std::string Generator::ARON_READER_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_r"; const std::string Generator::ARON_WRITER_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_w"; - const std::string Generator::ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_tmpls"; - const std::string Generator::ARON_VARIANT_RETURN_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_variant"; + const std::string Generator::ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR = + Generator::ARON_VARIABLE_PREFIX + "_tmpls"; + const std::string Generator::ARON_VARIANT_RETURN_ACCESSOR = + Generator::ARON_VARIABLE_PREFIX + "_variant"; const std::string Generator::ARON_PATH_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_p"; const std::string Generator::ARON_OTHER_ACCESSOR = Generator::ARON_VARIABLE_PREFIX + "_o"; const SerializerFactoryPtr Generator::FACTORY = SerializerFactoryPtr(new GeneratorFactory()); // static methods - std::string Generator::EscapeAccessor(const std::string& accessor) + std::string + Generator::EscapeAccessor(const std::string& accessor) { - const static std::map<std::string, std::string> ESCAPE_ACCESSORS = - { - {"->", "_ptr_"}, - {".", "_dot_"}, - {"[", "_lbrC_"}, - {"]", "_rbrC_"}, - {"(", "_lbrR_"}, - {")", "_rbrR_"}, - {"*", "_ast_"} - }; + const static std::map<std::string, std::string> ESCAPE_ACCESSORS = {{"->", "_ptr_"}, + {".", "_dot_"}, + {"[", "_lbrC_"}, + {"]", "_rbrC_"}, + {"(", "_lbrR_"}, + {")", "_rbrR_"}, + {"*", "_ast_"}}; std::string escaped_accessor = accessor; for (const auto& [key, value] : ESCAPE_ACCESSORS) @@ -67,13 +68,16 @@ namespace armarx::aron::codegenerator::cpp return escaped_accessor; } - std::string Generator::ExtractCppTypename(const type::Variant& n) + std::string + Generator::ExtractCppTypename(const type::Variant& n) { auto cpp = Generator::FromAronType(n); ARMARX_CHECK_NOT_NULL(cpp); return cpp->getInstantiatedCppTypename(); } - std::vector<std::string> Generator::ExtractCppTypenames(const std::vector<type::VariantPtr>& n) + + std::vector<std::string> + Generator::ExtractCppTypenames(const std::vector<type::VariantPtr>& n) { std::vector<std::string> ret; for (const auto& v : n) @@ -83,29 +87,33 @@ namespace armarx::aron::codegenerator::cpp return ret; } - std::unique_ptr<Generator> Generator::FromAronType(const type::Variant& n) + std::unique_ptr<Generator> + Generator::FromAronType(const type::Variant& n) { return FACTORY->create(n, n.getPath()); } - // constructors - Generator::Generator(const std::string& instantiatedCppTypename, const std::string& classCppTypename, const std::string& aronDataTypename, const std::string& aronTypeTypename) : + Generator::Generator(const std::string& instantiatedCppTypename, + const std::string& classCppTypename, + const std::string& aronDataTypename, + const std::string& aronTypeTypename) : instantiatedCppTypename(instantiatedCppTypename), classCppTypename(classCppTypename), aronDataTypename(aronDataTypename), aronTypeTypename(aronTypeTypename) { - } // public methods - std::string Generator::getInstantiatedCppTypename() const + std::string + Generator::getInstantiatedCppTypename() const { return instantiatedCppTypename; } - std::string Generator::getFullInstantiatedCppTypename() const + std::string + Generator::getFullInstantiatedCppTypename() const { switch (getType().getMaybe()) { @@ -120,11 +128,15 @@ namespace armarx::aron::codegenerator::cpp case type::Maybe::UNIQUE_PTR: return "std::unique_ptr<" + getInstantiatedCppTypename() + ">"; default: - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Received unknown maybe enum", std::to_string((int) getType().getMaybe()), getType().getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Received unknown maybe enum", + std::to_string((int)getType().getMaybe()), + getType().getPath()); } } - std::string Generator::getFullInstantiatedCppTypenameGenerator() const + std::string + Generator::getFullInstantiatedCppTypenameGenerator() const { switch (getType().getMaybe()) { @@ -139,16 +151,21 @@ namespace armarx::aron::codegenerator::cpp case type::Maybe::UNIQUE_PTR: return "std::make_unique<" + getInstantiatedCppTypename() + ">"; default: - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Received unknown maybe enum", std::to_string((int) getType().getMaybe()), getType().getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Received unknown maybe enum", + std::to_string((int)getType().getMaybe()), + getType().getPath()); } } - std::string Generator::getClassCppTypename() const + std::string + Generator::getClassCppTypename() const { return classCppTypename; } - std::string Generator::getFullClassCppTypename() const + std::string + Generator::getFullClassCppTypename() const { switch (getType().getMaybe()) { @@ -163,11 +180,15 @@ namespace armarx::aron::codegenerator::cpp case type::Maybe::UNIQUE_PTR: return "std::unique_ptr<" + getClassCppTypename() + ">"; default: - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Received unknown maybe enum", std::to_string((int) getType().getMaybe()), getType().getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Received unknown maybe enum", + std::to_string((int)getType().getMaybe()), + getType().getPath()); } } - CppCtorPtr Generator::toCtor(const std::string& name) const + CppCtorPtr + Generator::toCtor(const std::string& name) const { CppBlockPtr b = this->getCtorBlock(""); auto initList = this->getCtorInitializers(""); @@ -184,24 +205,28 @@ namespace armarx::aron::codegenerator::cpp return c; } - CppCtorPtr Generator::toCopyCtor(const std::string& name) const + CppCtorPtr + Generator::toCopyCtor(const std::string& name) const { CppBlockPtr b = this->getCopyCtorBlock(""); auto initList = this->getCopyCtorInitializers(""); if (b->size() > 0 || initList.second) { - CppCtorPtr c = CppCtorPtr(new CppCtor(name + "(const " + name + "& " + ARON_OTHER_ACCESSOR + ")")); + CppCtorPtr c = + CppCtorPtr(new CppCtor(name + "(const " + name + "& " + ARON_OTHER_ACCESSOR + ")")); c->addInitListEntries(initList.first); c->setBlock(b); return c; } - CppCtorPtr c = CppCtorPtr(new CppCtor(name + "(const " + name + "& " + ARON_OTHER_ACCESSOR + ") = default;")); + CppCtorPtr c = CppCtorPtr( + new CppCtor(name + "(const " + name + "& " + ARON_OTHER_ACCESSOR + ") = default;")); return c; } - CppMethodPtr Generator::toDtor(const std::string& name) const + CppMethodPtr + Generator::toDtor(const std::string& name) const { CppBlockPtr b = this->getDtorBlock(""); if (b->size() > 0) @@ -218,13 +243,16 @@ namespace armarx::aron::codegenerator::cpp return m; } - CppMethodPtr Generator::toResetSoftMethod() const + CppMethodPtr + Generator::toResetSoftMethod() const { std::stringstream doc; - doc << "@brief resetSoft() - This method resets all member variables with respect to the current parameterization. \n"; + doc << "@brief resetSoft() - This method resets all member variables with respect to the " + "current parameterization. \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void resetSoft() override", doc.str())); + CppMethodPtr m = + CppMethodPtr(new CppMethod("virtual void resetSoft() override", doc.str())); CppBlockPtr b = this->getResetSoftBlock(""); m->setBlock(b); @@ -232,13 +260,16 @@ namespace armarx::aron::codegenerator::cpp return m; } - CppMethodPtr Generator::toResetHardMethod() const + CppMethodPtr + Generator::toResetHardMethod() const { std::stringstream doc; - doc << "@brief resetHard() - This method resets member variables according to the XML type description. \n"; + doc << "@brief resetHard() - This method resets member variables according to the XML type " + "description. \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void resetHard() override", doc.str())); + CppMethodPtr m = + CppMethodPtr(new CppMethod("virtual void resetHard() override", doc.str())); CppBlockPtr b = this->getResetHardBlock(""); m->setBlock(b); @@ -246,13 +277,22 @@ namespace armarx::aron::codegenerator::cpp return m; } - CppMethodPtr Generator::toWriteTypeMethod() const + CppMethodPtr + Generator::toWriteTypeMethod() const { std::stringstream doc; - doc << "@brief writeType() - This method returns a new type from the class structure using a type writer implementation. This function is static. \n"; + doc << "@brief writeType() - This method returns a new type from the class structure using " + "a type writer implementation. This function is static. \n"; doc << "@return - the result of the writer implementation"; - CppMethodPtr m = CppMethodPtr(new CppMethod("template<class WriterT>\nstatic typename WriterT::ReturnType writeType(WriterT& " + ARON_WRITER_ACCESSOR + ", std::vector<std::string> " + ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR + " = {}, armarx::aron::type::Maybe "+ ARON_MAYBE_TYPE_ACCESSOR +" = ::armarx::aron::type::Maybe::NONE, const ::armarx::aron::Path& "+ARON_PATH_ACCESSOR+" = ::armarx::aron::Path())", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod( + "template<class WriterT>\nstatic typename WriterT::ReturnType writeType(WriterT& " + + ARON_WRITER_ACCESSOR + ", std::vector<std::string> " + + ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR + " = {}, armarx::aron::type::Maybe " + + ARON_MAYBE_TYPE_ACCESSOR + + " = ::armarx::aron::type::Maybe::NONE, const ::armarx::aron::Path& " + + ARON_PATH_ACCESSOR + " = ::armarx::aron::Path())", + doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("using _Aron_T [[maybe_unused]] = typename WriterT::ReturnType;"); @@ -264,14 +304,20 @@ namespace armarx::aron::codegenerator::cpp return m; } - CppMethodPtr Generator::toWriteMethod() const + CppMethodPtr + Generator::toWriteMethod() const { std::stringstream doc; - doc << "@brief write() - This method returns a new type from the member data types using a data writer implementation. \n"; + doc << "@brief write() - This method returns a new type from the member data types using a " + "data writer implementation. \n"; doc << "@param w - The writer implementation\n"; doc << "@return - the result of the writer implementation"; - CppMethodPtr m = CppMethodPtr(new CppMethod("template<class WriterT>\ntypename WriterT::ReturnType write(WriterT& " + ARON_WRITER_ACCESSOR + ", const ::armarx::aron::Path& "+ARON_PATH_ACCESSOR+" = armarx::aron::Path()) const", doc.str())); + CppMethodPtr m = CppMethodPtr( + new CppMethod("template<class WriterT>\ntypename WriterT::ReturnType write(WriterT& " + + ARON_WRITER_ACCESSOR + ", const ::armarx::aron::Path& " + + ARON_PATH_ACCESSOR + " = armarx::aron::Path()) const", + doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("using _Aron_T [[maybe_unused]] = typename WriterT::ReturnType;"); @@ -279,73 +325,106 @@ namespace armarx::aron::codegenerator::cpp std::string dummy; b->addBlock(this->getWriteBlock("", Path(), dummy)); b->addLine("catch(const std::exception& " + ARON_VARIABLE_PREFIX + "_e)"); - b->addLineAsBlock("throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, std::string(\"An error occured during the write method of an aron generated class. The full error log was:\\n\") + " + ARON_VARIABLE_PREFIX + "_e.what());"); + b->addLineAsBlock("throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, " + "std::string(\"An error occured during the write method of an aron " + "generated class. The full error log was:\\n\") + " + + ARON_VARIABLE_PREFIX + "_e.what());"); m->setBlock(b); m->setEnforceBlockGeneration(true); return m; } - CppMethodPtr Generator::toReadMethod() const + CppMethodPtr + Generator::toReadMethod() const { std::stringstream doc; - doc << "@brief read() - This method sets the struct members to new values given in a data reader implementation. \n"; + doc << "@brief read() - This method sets the struct members to new values given in a data " + "reader implementation. \n"; doc << "@param r - The reader implementation\n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod("template<class ReaderT>\nvoid read(ReaderT& " + ARON_READER_ACCESSOR + ", typename ReaderT::InputType& input)", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod("template<class ReaderT>\nvoid read(ReaderT& " + + ARON_READER_ACCESSOR + + ", typename ReaderT::InputType& input)", + doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("using _Aron_T [[maybe_unused]] = typename ReaderT::InputType;"); b->addLine("using _Aron_TNonConst [[maybe_unused]] = typename ReaderT::InputTypeNonConst;"); b->addLine("this->resetSoft();"); - b->addLine("ARMARX_CHECK_AND_THROW(!" + ARON_READER_ACCESSOR + ".readNull(input), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"The input to the read method must not be null.\"));"); + b->addLine("ARMARX_CHECK_AND_THROW(!" + ARON_READER_ACCESSOR + + ".readNull(input), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, " + "\"The input to the read method must not be null.\"));"); b->addLine("try"); b->addBlock(this->getReadBlock("", "input")); b->addLine("catch(const std::exception& " + ARON_VARIABLE_PREFIX + "_e)"); - b->addLineAsBlock("throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, std::string(\"An error occured during the read method of an aron generated class. The full error log was:\\n\") + " + ARON_VARIABLE_PREFIX + "_e.what());"); + b->addLineAsBlock("throw ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, " + "std::string(\"An error occured during the read method of an aron " + "generated class. The full error log was:\\n\") + " + + ARON_VARIABLE_PREFIX + "_e.what());"); m->setBlock(b); m->setEnforceBlockGeneration(true); return m; } - CppMethodPtr Generator::toSpecializedDataWriterMethod(const WriterInfo& info) const + CppMethodPtr + Generator::toSpecializedDataWriterMethod(const WriterInfo& info) const { std::stringstream doc; - doc << "@brief " << info.methodName << "() - This method returns a new data from the member data types using a writer implementation. \n"; + 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" + (info.override ? " override" : ""), 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 + ";"); + m->addLine("return " + info.enforceConversion + "(this->write(writer))" + + info.enforceMemberAccess + ";"); m->setEnforceBlockGeneration(true); return m; } - CppMethodPtr Generator::toSpecializedDataReaderMethod(const ReaderInfo& info) const + CppMethodPtr + Generator::toSpecializedDataReaderMethod(const ReaderInfo& info) const { std::stringstream doc; - doc << "@brief " << info.methodName << " - This method sets the struct members to new values given in a reader implementation. \n"; + 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)" + (info.override ? " override" : ""), 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 + ");"); + m->addLine("this->read(reader, " + info.enforceConversion + "(input)" + + info.enforceMemberAccess + ");"); m->setEnforceBlockGeneration(true); return m; } - CppMethodPtr Generator::toSpecializedStaticDataReaderMethod(const StaticReaderInfo& info) const + CppMethodPtr + Generator::toSpecializedStaticDataReaderMethod(const StaticReaderInfo& info) const { std::stringstream doc; - doc << "@brief " << info.methodName << "() - This method sets the struct members to new values given in a reader implementation. \n"; + 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("static " + info.returnType + " " + info.methodName + "(const " + info.argumentType + "& input)", doc.str())); + CppMethodPtr m = + CppMethodPtr(new CppMethod("static " + info.returnType + " " + info.methodName + + "(const " + info.argumentType + "& input)", + doc.str())); m->addLine(info.returnType + " t;"); m->addLine("t.fromAron(input);"); m->addLine("return t;"); @@ -354,28 +433,36 @@ namespace armarx::aron::codegenerator::cpp return m; } - CppMethodPtr Generator::toSpecializedTypeWriterMethod(const WriterInfo& info) const + CppMethodPtr + Generator::toSpecializedTypeWriterMethod(const WriterInfo& info) const { std::stringstream doc; - doc << "@brief " << info.methodName << "() - This method returns a new type from the member data types using a writer implementation. \n"; + doc << "@brief " << info.methodName + << "() - This method returns a new type from the member data types using a writer " + "implementation. \n"; doc << "@return - the result of the writer implementation"; - CppMethodPtr m = CppMethodPtr(new CppMethod("static " + info.returnType + " " + info.methodName + "()", doc.str())); + CppMethodPtr m = CppMethodPtr( + new CppMethod("static " + info.returnType + " " + info.methodName + "()", doc.str())); m->addLine(info.writerClassType + " writer;"); - m->addLine("return " + info.enforceConversion + "(writeType(writer))" + info.enforceMemberAccess + ";"); + m->addLine("return " + info.enforceConversion + "(writeType(writer))" + + info.enforceMemberAccess + ";"); m->setEnforceBlockGeneration(true); return m; } - CppMethodPtr Generator::toEqualsMethod() const + CppMethodPtr + Generator::toEqualsMethod() const { std::stringstream doc; - doc << "@brief operator==() - This method checks whether all values equal another instance. \n"; + doc << "@brief operator==() - This method checks whether all values equal another " + "instance. \n"; doc << "@param i - The other instance\n"; doc << "@return - true, if all members are the same, false otherwise"; - CppMethodPtr m = CppMethodPtr(new CppMethod("bool operator==(const " + this->getFullClassCppTypename() + "& i) const", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod( + "bool operator==(const " + this->getFullClassCppTypename() + "& i) const", doc.str())); CppBlockPtr b = this->getEqualsBlock("", "i"); b->addLine("return true;"); m->setBlock(b); @@ -385,89 +472,111 @@ namespace armarx::aron::codegenerator::cpp } // defaulted implementations of the blocks - std::vector<std::string> Generator::getRequiredIncludes() const + std::vector<std::string> + Generator::getRequiredIncludes() const { return {}; } - std::vector<CppFieldPtr> Generator::getPublicVariableDeclarations(const std::string& name) const + + std::vector<CppFieldPtr> + Generator::getPublicVariableDeclarations(const std::string& name) const { auto field = std::make_shared<CppField>(this->getFullInstantiatedCppTypename(), name); return {field}; } - std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCtorInitializers(const std::string& name) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Generator::getCtorInitializers(const std::string& name) const { - return {{{name, "{}"}}, false}; + return {{}, false}; } - CppBlockPtr Generator::getCtorBlock(const std::string&) const + CppBlockPtr + Generator::getCtorBlock(const std::string&) const { return std::make_shared<CppBlock>(); } - std::pair<std::vector<std::pair<std::string, std::string>>, bool> Generator::getCopyCtorInitializers(const std::string& name) const + 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) // unique ptrs cant be copied { - return {{{name, ARON_OTHER_ACCESSOR + "." + name + " ? " + resolveMaybeGenerator("*" + ARON_OTHER_ACCESSOR + "." + name) + " : nullptr"}}, true}; + return {{{name, + ARON_OTHER_ACCESSOR + "." + name + " ? " + + resolveMaybeGenerator("*" + ARON_OTHER_ACCESSOR + "." + name) + + " : nullptr"}}, + true}; } return {{{name, ARON_OTHER_ACCESSOR + "." + name}}, false}; } - CppBlockPtr Generator::getCopyCtorBlock(const std::string&) const + CppBlockPtr + Generator::getCopyCtorBlock(const std::string&) const { return std::make_shared<CppBlock>(); } - CppBlockPtr Generator::getDtorBlock(const std::string&) const + CppBlockPtr + Generator::getDtorBlock(const std::string&) const { return std::make_shared<CppBlock>(); } - CppBlockPtr Generator::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Generator::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); - block_if_data->addLine(cppAccessor + " = " + this->getFullInstantiatedCppTypename() + "();"); + block_if_data->addLine(cppAccessor + " = " + this->getFullInstantiatedCppTypename() + + "();"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Generator::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Generator::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); - block_if_data->addLine(cppAccessor + " = " + this->getFullInstantiatedCppTypename() + "();"); + block_if_data->addLine(cppAccessor + " = " + this->getFullInstantiatedCppTypename() + + "();"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } - CppBlockPtr Generator::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + CppBlockPtr + Generator::getEqualsBlock(const std::string& accessor, + const std::string& otherInstanceAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); std::string resolved_accessor = this->resolveMaybeAccessor(accessor); - std::string other_instance_resolved_accessor = this->resolveMaybeAccessor(otherInstanceAccessor); + std::string other_instance_resolved_accessor = + this->resolveMaybeAccessor(otherInstanceAccessor); - block_if_data->addLine("if (not (" + resolved_accessor + " == " + other_instance_resolved_accessor + "))"); + block_if_data->addLine("if (not (" + resolved_accessor + + " == " + other_instance_resolved_accessor + "))"); block_if_data->addLineAsBlock("return false;"); return resolveMaybeEqualsBlock(block_if_data, accessor, otherInstanceAccessor); } - // Helper methods - std::string Generator::resolveMaybeAccessor(const std::string& s) const + std::string + Generator::resolveMaybeAccessor(const std::string& s) const { const auto& t = getType(); if (t.getMaybe() == type::Maybe::OPTIONAL) { return s + ".value()"; } - if (t.getMaybe() == type::Maybe::RAW_PTR || t.getMaybe() == type::Maybe::SHARED_PTR || t.getMaybe() == type::Maybe::UNIQUE_PTR) + if (t.getMaybe() == type::Maybe::RAW_PTR || t.getMaybe() == type::Maybe::SHARED_PTR || + t.getMaybe() == type::Maybe::UNIQUE_PTR) { return "*" + s; } return s; } - std::string Generator::resolveMaybeGenerator(const std::string& args) const + std::string + Generator::resolveMaybeGenerator(const std::string& args) const { const auto& t = getType(); if (t.getMaybe() == type::Maybe::OPTIONAL) @@ -487,10 +596,10 @@ namespace armarx::aron::codegenerator::cpp return "std::make_unique<" + getInstantiatedCppTypename() + ">(" + args + ")"; } return ""; - } - std::string Generator::resolveMaybeGeneratorWithSetter(const std::string& s, const std::string& args) const + std::string + Generator::resolveMaybeGeneratorWithSetter(const std::string& s, const std::string& args) const { auto gen = resolveMaybeGenerator(args); if (!gen.empty()) @@ -500,7 +609,8 @@ namespace armarx::aron::codegenerator::cpp return ""; } - std::string Generator::nextEl() const + std::string + Generator::nextEl() const { const auto& type = getType(); switch (type.getMaybe()) @@ -513,10 +623,14 @@ namespace armarx::aron::codegenerator::cpp case type::Maybe::UNIQUE_PTR: return "->"; } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Received unknown maybe enum", std::to_string((int) type.getMaybe()), type.getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Received unknown maybe enum", + std::to_string((int)type.getMaybe()), + type.getPath()); } - std::string Generator::toPointerAccessor(const std::string& cppAccessor) const + std::string + Generator::toPointerAccessor(const std::string& cppAccessor) const { const auto& type = getType(); switch (type.getMaybe()) @@ -528,12 +642,18 @@ namespace armarx::aron::codegenerator::cpp return cppAccessor + ".get()"; case type::Maybe::NONE: //[[fallthrough]]; - case type::Maybe::OPTIONAL: break; + case type::Maybe::OPTIONAL: + break; } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Received invalid maybe enum (not a pointer?)", std::to_string((int) type.getMaybe()), type.getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Received invalid maybe enum (not a pointer?)", + std::to_string((int)type.getMaybe()), + type.getPath()); } - CppBlockPtr Generator::resolveMaybeResetHardBlock(const CppBlockPtr& block_if_data, const std::string& cppAccessor) const + CppBlockPtr + Generator::resolveMaybeResetHardBlock(const CppBlockPtr& block_if_data, + const std::string& cppAccessor) const { const auto& type = getType(); if (type.getMaybe() == type::Maybe::OPTIONAL) @@ -542,7 +662,9 @@ namespace armarx::aron::codegenerator::cpp b->addLine(cppAccessor + " = std::nullopt;"); return b; } - else if (type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR) + else if (type.getMaybe() == type::Maybe::RAW_PTR || + type.getMaybe() == type::Maybe::SHARED_PTR || + type.getMaybe() == type::Maybe::UNIQUE_PTR) { CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine(cppAccessor + " = nullptr;"); @@ -551,10 +673,14 @@ namespace armarx::aron::codegenerator::cpp return block_if_data; } - CppBlockPtr Generator::resolveMaybeResetSoftBlock(const CppBlockPtr& block_if_data, const std::string& cppAccessor) const + CppBlockPtr + Generator::resolveMaybeResetSoftBlock(const CppBlockPtr& block_if_data, + const std::string& cppAccessor) const { const auto& type = getType(); - if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR) + if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || + type.getMaybe() == type::Maybe::SHARED_PTR || + type.getMaybe() == type::Maybe::UNIQUE_PTR) { CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("if (" + cppAccessor + ") // if " + cppAccessor + " contains data"); @@ -564,10 +690,14 @@ namespace armarx::aron::codegenerator::cpp return block_if_data; } - CppBlockPtr Generator::resolveMaybeWriteBlock(const CppBlockPtr& block_if_data, const std::string& cppAccessor) const + CppBlockPtr + Generator::resolveMaybeWriteBlock(const CppBlockPtr& block_if_data, + const std::string& cppAccessor) const { const auto& type = getType(); - if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR) + if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || + type.getMaybe() == type::Maybe::SHARED_PTR || + type.getMaybe() == type::Maybe::UNIQUE_PTR) { CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("if (" + cppAccessor + ") // if " + cppAccessor + " contains data"); @@ -577,13 +707,19 @@ namespace armarx::aron::codegenerator::cpp return block_if_data; } - CppBlockPtr Generator::resolveMaybeReadBlock(const CppBlockPtr& block_if_data, const std::string& cppAccessor, const std::string& variantAccessor) const + CppBlockPtr + Generator::resolveMaybeReadBlock(const CppBlockPtr& block_if_data, + const std::string& cppAccessor, + const std::string& variantAccessor) const { const auto& type = getType(); - if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR) + if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || + type.getMaybe() == type::Maybe::SHARED_PTR || + type.getMaybe() == type::Maybe::UNIQUE_PTR) { CppBlockPtr b = std::make_shared<CppBlock>(); - b->addLine("if (not (" + ARON_READER_ACCESSOR + ".readNull(" + variantAccessor + "))) // if aron contains data"); + b->addLine("if (not (" + ARON_READER_ACCESSOR + ".readNull(" + variantAccessor + + "))) // if aron contains data"); { CppBlockPtr ifb = std::make_shared<CppBlock>(); ifb->addLine(resolveMaybeGeneratorWithSetter(cppAccessor)); @@ -595,13 +731,19 @@ namespace armarx::aron::codegenerator::cpp return block_if_data; } - CppBlockPtr Generator::resolveMaybeEqualsBlock(const CppBlockPtr& block_if_data, const std::string& accessor, const std::string& otherInstanceAccessor) const + CppBlockPtr + Generator::resolveMaybeEqualsBlock(const CppBlockPtr& block_if_data, + const std::string& accessor, + const std::string& otherInstanceAccessor) const { const auto& type = getType(); - if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || type.getMaybe() == type::Maybe::SHARED_PTR || type.getMaybe() == type::Maybe::UNIQUE_PTR) + if (type.getMaybe() == type::Maybe::OPTIONAL || type.getMaybe() == type::Maybe::RAW_PTR || + type.getMaybe() == type::Maybe::SHARED_PTR || + type.getMaybe() == type::Maybe::UNIQUE_PTR) { CppBlockPtr b = std::make_shared<CppBlock>(); - b->addLine("if (not ((bool) " + accessor + " == (bool) " + otherInstanceAccessor + ")) // check if both contain data"); + b->addLine("if (not ((bool) " + accessor + " == (bool) " + otherInstanceAccessor + + ")) // check if both contain data"); b->addLineAsBlock("return false;"); b->addLine("if ((bool) " + accessor + " && (bool) " + otherInstanceAccessor + ")"); b->addBlock(block_if_data); @@ -609,4 +751,4 @@ namespace armarx::aron::codegenerator::cpp } return block_if_data; } -} +} // namespace armarx::aron::codegenerator::cpp diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.cpp index 00a9ab35d7f52eb757963c97355403377459737e..dbff73cdf796524958269d256c5100ff95c304b9 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.cpp @@ -26,7 +26,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { // constructors @@ -35,18 +34,27 @@ namespace armarx::aron::codegenerator::cpp::generator e.getEnumName(), e.getEnumName(), simox::meta::get_type_name<data::dto::NDArray>(), - simox::meta::get_type_name<type::dto::IntEnum>(), e) + simox::meta::get_type_name<type::dto::IntEnum>(), + e) + { + } + + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + IntEnum::getCtorInitializers(const std::string& name) const { + return {{{name, type.getDefaultValueName()}}, true}; } - CppBlockPtr IntEnum::getResetSoftBlock(const std::string& accessor) const + CppBlockPtr + IntEnum::getResetSoftBlock(const std::string& accessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(accessor + nextEl() + "resetSoft();"); return this->resolveMaybeResetSoftBlock(block_if_data, accessor); } - CppBlockPtr IntEnum::getResetHardBlock(const std::string& accessor) const + CppBlockPtr + IntEnum::getResetHardBlock(const std::string& accessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); if (type.getMaybe() != type::Maybe::NONE) @@ -60,39 +68,51 @@ namespace armarx::aron::codegenerator::cpp::generator return this->resolveMaybeResetHardBlock(b, accessor); } - CppBlockPtr IntEnum::getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const + CppBlockPtr + IntEnum::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(cppAccessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto "+variantAccessor+" = " +getInstantiatedCppTypename() + "::writeType(" + ARON_WRITER_ACCESSOR + ", " + - "{}, " + - conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + cppAccessor); + b->addLine("auto " + variantAccessor + " = " + getInstantiatedCppTypename() + + "::writeType(" + ARON_WRITER_ACCESSOR + ", " + "{}, " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + cppAccessor); return b; } - CppBlockPtr IntEnum::getWriteBlock(const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const + CppBlockPtr + IntEnum::getWriteBlock(const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(cppAccessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - block_if_data->addLine(variantAccessor+" = " + cppAccessor + nextEl() + "write(" + ARON_WRITER_ACCESSOR + ", "+ - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + cppAccessor); + block_if_data->addLine(variantAccessor + " = " + cppAccessor + nextEl() + "write(" + + ARON_WRITER_ACCESSOR + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + cppAccessor); return resolveMaybeWriteBlock(block_if_data, cppAccessor); } - CppBlockPtr IntEnum::getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const + CppBlockPtr + IntEnum::getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); if (const auto reset = resolveMaybeGeneratorWithSetter(cppAccessor); !reset.empty()) { block_if_data->addLine(reset); } - block_if_data->addLine(cppAccessor + nextEl() + "read(" + ARON_READER_ACCESSOR + ", " + variantAccessor + ");"); + block_if_data->addLine(cppAccessor + nextEl() + "read(" + ARON_READER_ACCESSOR + ", " + + variantAccessor + ");"); return resolveMaybeReadBlock(block_if_data, cppAccessor, variantAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.h index cd5b36bcef8300bbb57b88abdf14ca2bde9bc911..4fc6383beebab99aaf334b21a26498d3dfcb00ca 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/enum/IntEnum.h @@ -23,20 +23,18 @@ #pragma once -#include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/SpecializedGenerator.h> -#include <RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h> - #include <map> #include <string> +#include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/SpecializedGenerator.h> +#include <RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h> namespace armarx::aron::codegenerator::cpp::generator { class IntEnum; typedef std::shared_ptr<IntEnum> IntEnumSerializerPtr; - class IntEnum : - public detail::SpecializedGeneratorBase<type::IntEnum, IntEnum> + class IntEnum : public detail::SpecializedGeneratorBase<type::IntEnum, IntEnum> { public: // constructors @@ -44,10 +42,18 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~IntEnum() = default; // virtual implementations + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string& name) 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; - CppBlockPtr getWriteBlock(const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final; - CppBlockPtr getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path&, + std::string& variantAccessor) const final; + CppBlockPtr getWriteBlock(const std::string& cppAccessor, + const Path&, + std::string& variantAccessor) const final; + CppBlockPtr getReadBlock(const std::string& cppAccessor, + const std::string& variantAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.cpp index 7dcadbb33ae84d70a180e89763ca37a634946268..0dad3b9e12a65c73d41d390db1029e50c70f8a90 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.cpp @@ -25,7 +25,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ @@ -34,33 +33,49 @@ namespace armarx::aron::codegenerator::cpp::generator "bool", "bool", simox::meta::get_type_name<data::dto::AronBool>(), - simox::meta::get_type_name<type::dto::AronBool>(), e) + simox::meta::get_type_name<type::dto::AronBool>(), + e) { } /* virtual implementations */ - CppBlockPtr Bool::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Bool::getCtorInitializers(const std::string& name) const + { + return {{{name, std::to_string(type.getDefaultValue())}}, true}; + } + + CppBlockPtr + Bool::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeBool(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeBool(" + + std::to_string(type.getDefaultValue()) + ", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr Bool::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Bool::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = false;"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Bool::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Bool::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = false;"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.h index 381adec7bc759c7a20aedd54229dd499253110d1..f218b9938bbc57d3595542c7915e021ebc386de7 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Bool.h @@ -23,24 +23,29 @@ #pragma once -#include "../detail/PrimitiveGenerator.h" - #include <RobotAPI/libraries/aron/core/type/variant/primitive/Bool.h> +#include "../detail/PrimitiveGenerator.h" namespace armarx::aron::codegenerator::cpp::generator { - class Bool : - public detail::PrimitiveGenerator<type::Bool, Bool> + class Bool : public detail::PrimitiveGenerator<type::Bool, Bool> { public: + static const constexpr bool DEFAULT_DEFAULT = false; + /* constructors */ Bool(const type::Bool& e); virtual ~Bool() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.cpp index 735f3ad9dc4efdf0f00a34093671644aebb0eb3f..149050164efeae441132e2e2608f57321d3ef3e8 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.cpp @@ -25,7 +25,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ @@ -40,28 +39,43 @@ namespace armarx::aron::codegenerator::cpp::generator } /* virtual implementations */ - CppBlockPtr Double::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Double::getCtorInitializers(const std::string& name) const + { + return {{{name, std::to_string(type.getDefaultValue())}}, true}; + } + + CppBlockPtr + Double::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeDouble(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeDouble(" + + std::to_string(type.getDefaultValue()) + ", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr Double::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Double::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0.0;"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Double::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Double::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0.0;"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.h index b9a96a077e225aad5b0871882e86e20f85fb3685..2ff98312264d0cfbd611544c13d3cfedddb3e884 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Double.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/PrimitiveGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/primitive/Double.h> - namespace armarx::aron::codegenerator::cpp::generator { - class Double : - public detail::PrimitiveGenerator<type::Double, Double> + class Double : public detail::PrimitiveGenerator<type::Double, Double> { public: /* constructors */ @@ -38,8 +36,13 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~Double() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.cpp index d3d27ea6c34713b3d81074c1ab64e37ed696d69c..76c71a6431ca9368811c11ed516d6486c636a9ee 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.cpp @@ -25,7 +25,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ @@ -40,28 +39,43 @@ namespace armarx::aron::codegenerator::cpp::generator } /* virtual implementations */ - CppBlockPtr Float::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Float::getCtorInitializers(const std::string& name) const + { + return {{{name, std::to_string(type.getDefaultValue())}}, true}; + } + + CppBlockPtr + Float::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeFloat(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeFloat(" + + std::to_string(type.getDefaultValue()) + ", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr Float::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Float::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0.0f;"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Float::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Float::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0.0f;"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.h index f1c88c502f92b7d86afc7668eda0710f0f3351b7..7cb65fc6d2712107ea2c932d189f96532d5c04f9 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Float.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/PrimitiveGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/primitive/Float.h> - namespace armarx::aron::codegenerator::cpp::generator { - class Float : - public detail::PrimitiveGenerator<type::Float, Float> + class Float : public detail::PrimitiveGenerator<type::Float, Float> { public: /* constructors */ @@ -38,8 +36,13 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~Float() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.cpp index 7a976bd83fffa4ad52bec05c2a5392bbf7400798..635cab4dee34bfd7f26232e43c80a0d0b98c73c1 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.cpp @@ -25,43 +25,56 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ Int::Int(const type::Int& e) : - detail::PrimitiveGenerator<type::Int, Int>( - "int", - "int", - simox::meta::get_type_name<data::dto::AronInt>(), - simox::meta::get_type_name<type::dto::AronInt>(), - e) + detail::PrimitiveGenerator<type::Int, Int>("int", + "int", + simox::meta::get_type_name<data::dto::AronInt>(), + simox::meta::get_type_name<type::dto::AronInt>(), + e) { } /* virtual implementations */ - CppBlockPtr Int::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Int::getCtorInitializers(const std::string& name) const + { + return {{{name, std::to_string(type.getDefaultValue())}}, true}; + } + + CppBlockPtr + Int::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeInt(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeInt(" + + std::to_string(type.getDefaultValue()) + ", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr Int::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Int::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0;"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Int::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Int::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0;"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.h index b21abee9cef1850a1d55da0369a530b65585c210..d552f34ea914baba72f3a7c886c9ebce99d0658b 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Int.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/PrimitiveGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/primitive/Int.h> - namespace armarx::aron::codegenerator::cpp::generator { - class Int : - public detail::PrimitiveGenerator<type::Int, Int> + class Int : public detail::PrimitiveGenerator<type::Int, Int> { public: /* constructors */ @@ -38,8 +36,13 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~Int() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.cpp index fe6cd5e87f6f3db26873c351987f91d86556d27b..9b61ee5f607b3cc1f4816252b40582bfdb92fae8 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.cpp @@ -25,7 +25,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ @@ -40,28 +39,43 @@ namespace armarx::aron::codegenerator::cpp::generator } /* virtual implementations */ - CppBlockPtr Long::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + Long::getCtorInitializers(const std::string& name) const + { + return {{{name, std::to_string(type.getDefaultValue())}}, true}; + } + + CppBlockPtr + Long::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeLong(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeLong(" + + std::to_string(type.getDefaultValue()) + ", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr Long::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + Long::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0;"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr Long::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + Long::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = 0;"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.h index 09d923e487108a7c2c0927156af77c21fddf79ec..8dd002ecb4680f40660bc6dc39c0583c556cf730 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/Long.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/PrimitiveGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/primitive/Long.h> - namespace armarx::aron::codegenerator::cpp::generator { - class Long : - public detail::PrimitiveGenerator<type::Long, Long> + class Long : public detail::PrimitiveGenerator<type::Long, Long> { public: /* constructors */ @@ -38,8 +36,13 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~Long() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.cpp b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.cpp index d51ee9ed159a5abb82442a5501ffebb3500aad15..e1649b982a053830e7b65e3f763298f9b7c01b61 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.cpp @@ -25,7 +25,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { /* constructors */ @@ -40,28 +39,43 @@ namespace armarx::aron::codegenerator::cpp::generator } /* virtual implementations */ - CppBlockPtr String::getWriteTypeBlock(const std::string& typeAccessor, const std::string& accessor, const Path& p, std::string& variantAccessor) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + String::getCtorInitializers(const std::string& name) const + { + return {{{name, "\"" + type.getDefaultValue() + "\""}}, true}; + } + + CppBlockPtr + String::getWriteTypeBlock(const std::string& typeAccessor, + const std::string& accessor, + const Path& p, + std::string& variantAccessor) const { CppBlockPtr b = std::make_shared<CppBlock>(); std::string escaped_accessor = EscapeAccessor(accessor); variantAccessor = ARON_VARIANT_RETURN_ACCESSOR + "_" + escaped_accessor; - b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeString(" + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + - "armarx::aron::Path("+ARON_PATH_ACCESSOR+", {"+simox::alg::join(p.getPath(), ", ")+"})); // of " + typeAccessor); + b->addLine("auto " + variantAccessor + " = " + ARON_WRITER_ACCESSOR + ".writeString(\"" + + type.getDefaultValue() + "\", " + + conversion::Maybe2CppString.at(type.getMaybe()) + ", " + "armarx::aron::Path(" + + ARON_PATH_ACCESSOR + ", {" + simox::alg::join(p.getPath(), ", ") + + "})); // of " + typeAccessor); return b; } - CppBlockPtr String::getResetHardBlock(const std::string& cppAccessor) const + CppBlockPtr + String::getResetHardBlock(const std::string& cppAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = \"\";"); return resolveMaybeResetHardBlock(block_if_data, cppAccessor); } - CppBlockPtr String::getResetSoftBlock(const std::string& cppAccessor) const + CppBlockPtr + String::getResetSoftBlock(const std::string& cppAccessor) const { auto block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine(cppAccessor + " = \"\";"); return this->resolveMaybeResetSoftBlock(block_if_data, cppAccessor); } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.h index fd854ccee807d549fbe1448643eb31a4f069bcc8..628f0af2552d732a5a1e39bd6eefc684030723af 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/primitive/String.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/PrimitiveGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/primitive/String.h> - namespace armarx::aron::codegenerator::cpp::generator { - class String : - public detail::PrimitiveGenerator<type::String, String> + class String : public detail::PrimitiveGenerator<type::String, String> { public: /* constructors */ @@ -38,8 +36,13 @@ namespace armarx::aron::codegenerator::cpp::generator virtual ~String() = default; /* virtual implementations */ - CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, const std::string& cppAccessor, const Path& p, std::string& variantAccessor) const final; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(const std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path& p, + std::string& variantAccessor) const final; CppBlockPtr getResetSoftBlock(const std::string& cppAccessor) const final; CppBlockPtr getResetHardBlock(const std::string& cppAccessor) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator 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 0cddfd33161dcd0bf5f398fa87f4c0a88ec0a447..ade0f0ef42f57366ab2944014ecb2245eed29587 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 @@ -26,7 +26,6 @@ #include <SimoxUtility/meta/type_name.h> - namespace armarx::aron::codegenerator::cpp::generator { // constructors @@ -40,11 +39,16 @@ namespace armarx::aron::codegenerator::cpp::generator { if (type.getMaybe() != type::Maybe::NONE) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Somehow the maybe flag of a top level int enum declaration is set. This is not valid!", std::to_string((int) type.getMaybe()), type.getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Somehow the maybe flag of a top level int enum " + "declaration is set. This is not valid!", + std::to_string((int)type.getMaybe()), + type.getPath()); } } - std::vector<CppFieldPtr> IntEnumClass::getPublicVariableDeclarations(const std::string& className) const + std::vector<CppFieldPtr> + IntEnumClass::getPublicVariableDeclarations(const std::string& className) const { std::vector<CppFieldPtr> fields; std::stringstream enum_to_name; @@ -53,7 +57,11 @@ namespace armarx::aron::codegenerator::cpp::generator std::stringstream value_to_enum; // 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")); + 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); @@ -64,7 +72,8 @@ namespace armarx::aron::codegenerator::cpp::generator for (const auto& [key, value] : type.getAcceptedValueMap()) { std::string enumKeyWithNamespace = std::string(IMPL_ENUM) + "::" + key; - fields.push_back(std::make_shared<CppField>("static constexpr " + std::string(IMPL_ENUM), key + " = " + enumKeyWithNamespace)); + fields.push_back(std::make_shared<CppField>( + "static constexpr " + std::string(IMPL_ENUM), key + " = " + enumKeyWithNamespace)); enum_to_name << "\t\t{" << enumKeyWithNamespace << ", \"" << key << "\"}," << std::endl; name_to_enum << "\t\t{\"" << key << "\", " << enumKeyWithNamespace << "}," << std::endl; @@ -78,31 +87,56 @@ namespace armarx::aron::codegenerator::cpp::generator enum_to_value << "\t}"; value_to_enum << "\t}"; - fields.push_back(std::make_shared<CppField>("static inline const std::map<" + std::string(IMPL_ENUM) + ", std::string>", "EnumToStringMap", enum_to_name.str(), "Mapping enum values to readable strings")); - fields.push_back(std::make_shared<CppField>("static inline const std::map<std::string, " + std::string(IMPL_ENUM) + ">", "StringToEnumMap", name_to_enum.str(), "Mapping readable strings to enum values")); - 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", type.getAcceptedValueNames()[0], "The current value of the enum object")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<" + + std::string(IMPL_ENUM) + ", std::string>", + "EnumToStringMap", + enum_to_name.str(), + "Mapping enum values to readable strings")); + fields.push_back(std::make_shared<CppField>("static inline const std::map<std::string, " + + std::string(IMPL_ENUM) + ">", + "StringToEnumMap", + name_to_enum.str(), + "Mapping readable strings to enum values")); + 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", + type.getAcceptedValueNames()[0], + "The current value of the enum object")); return fields; } - CppBlockPtr IntEnumClass::getResetSoftBlock(const std::string& accessor) const + CppBlockPtr + IntEnumClass::getResetSoftBlock(const std::string& accessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine("value = {};"); return block_if_data; } - CppBlockPtr IntEnumClass::getResetHardBlock(const std::string& accessor) const + CppBlockPtr + IntEnumClass::getResetHardBlock(const std::string& accessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine("value = {};"); return block_if_data; } - CppBlockPtr IntEnumClass::getWriteTypeBlock(const std::string&, const std::string&, const Path& p, std::string&) const + CppBlockPtr + IntEnumClass::getWriteTypeBlock(const std::string&, + const std::string&, + const Path& p, + std::string&) const { static const std::string INT_ENUM_VALUE_MAP = ARON_VARIABLE_PREFIX + "_str2ValueMap"; @@ -113,40 +147,50 @@ namespace armarx::aron::codegenerator::cpp::generator { map_initializer.push_back("{\"" + key + "\", " + std::to_string(value) + "}"); } - b->addLine("std::map<std::string, int> " + INT_ENUM_VALUE_MAP + " = {" + simox::alg::to_string(map_initializer, ", ") + "};"); - b->addLine("return " + ARON_WRITER_ACCESSOR + ".writeIntEnum(\"" + type.getEnumName() + "\", " + - INT_ENUM_VALUE_MAP + ", " + - ARON_MAYBE_TYPE_ACCESSOR + ", " + - ARON_PATH_ACCESSOR + ");"); - return b; - + b->addLine("std::map<std::string, int> " + INT_ENUM_VALUE_MAP + " = {" + + simox::alg::to_string(map_initializer, ", ") + "};"); + b->addLine("return " + ARON_WRITER_ACCESSOR + ".writeIntEnum(\"" + type.getEnumName() + + "\", " + INT_ENUM_VALUE_MAP + ", " + "\"" + type.getDefaultValueName() + "\", " + + ARON_MAYBE_TYPE_ACCESSOR + ", " + ARON_PATH_ACCESSOR + ");"); return b; } - CppBlockPtr IntEnumClass::getWriteBlock(const std::string&, const Path& p, std::string&) const + CppBlockPtr + IntEnumClass::getWriteBlock(const std::string&, const Path& p, std::string&) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); - block_if_data->addLine("return " + ARON_WRITER_ACCESSOR + ".writePrimitive(EnumToValueMap.at(value), " + - ARON_PATH_ACCESSOR + "); // of top level enum " + getInstantiatedCppTypename()); + block_if_data->addLine("return " + ARON_WRITER_ACCESSOR + + ".writePrimitive(EnumToValueMap.at(value), " + ARON_PATH_ACCESSOR + + "); // of top level enum " + getInstantiatedCppTypename()); return block_if_data; } - CppBlockPtr IntEnumClass::getReadBlock(const std::string&, const std::string& variantAccessor) const + CppBlockPtr + IntEnumClass::getReadBlock(const std::string&, const std::string& variantAccessor) const { static const std::string INT_ENUM_TMP_VALUE = ARON_VARIABLE_PREFIX + "_tmpValue"; CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine("int " + INT_ENUM_TMP_VALUE + ";"); - block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readPrimitive("+variantAccessor+", "+INT_ENUM_TMP_VALUE+"); // of top level enum " + getInstantiatedCppTypename()); - - block_if_data->addLine("auto valueToEnumMap_iterator = ValueToEnumMap.find("+INT_ENUM_TMP_VALUE+");"); - block_if_data->addLine("ARMARX_CHECK_AND_THROW(valueToEnumMap_iterator != ValueToEnumMap.end(), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing enum for value '\" + std::to_string(" + INT_ENUM_TMP_VALUE + ") + \"' in aron enum '" + getFullClassCppTypename() + "'.\"))"); + block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readPrimitive(" + variantAccessor + + ", " + INT_ENUM_TMP_VALUE + "); // of top level enum " + + getInstantiatedCppTypename()); + + block_if_data->addLine("auto valueToEnumMap_iterator = ValueToEnumMap.find(" + + INT_ENUM_TMP_VALUE + ");"); + block_if_data->addLine( + "ARMARX_CHECK_AND_THROW(valueToEnumMap_iterator != ValueToEnumMap.end(), " + "::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing enum for value " + "'\" + std::to_string(" + + INT_ENUM_TMP_VALUE + ") + \"' in aron enum '" + getFullClassCppTypename() + "'.\"))"); block_if_data->addLine("value = valueToEnumMap_iterator->second;"); return block_if_data; } - CppBlockPtr IntEnumClass::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + CppBlockPtr + IntEnumClass::getEqualsBlock(const std::string& accessor, + const std::string& otherInstanceAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); block_if_data->addLine("if (not (value == " + otherInstanceAccessor + ".value))"); @@ -154,7 +198,6 @@ namespace armarx::aron::codegenerator::cpp::generator return block_if_data; } - /*CppCtorPtr IntEnumClass::toCopyCtor(const std::string& name) const { CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + getFullInstantiatedCppTypename() + "& i)"); @@ -164,7 +207,8 @@ namespace armarx::aron::codegenerator::cpp::generator return c; }*/ - CppCtorPtr IntEnumClass::toEnumCtor(const std::string& name) const + CppCtorPtr + IntEnumClass::toEnumCtor(const std::string& name) const { CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + std::string(IMPL_ENUM) + " e)"); std::vector<std::pair<std::string, std::string>> initList = {{"value", "e"}}; @@ -173,7 +217,8 @@ namespace armarx::aron::codegenerator::cpp::generator return c; } - std::vector<CppEnumFieldPtr> IntEnumClass::toEnumFields() const + std::vector<CppEnumFieldPtr> + IntEnumClass::toEnumFields() const { std::vector<CppEnumFieldPtr> e; for (const auto& [key, value] : type.getAcceptedValueMap()) @@ -183,7 +228,8 @@ namespace armarx::aron::codegenerator::cpp::generator return e; } - CppMethodPtr IntEnumClass::toIntMethod() const + CppMethodPtr + IntEnumClass::toIntMethod() const { std::stringstream doc; doc << "@brief int() - Converts the internally stored value to int representation \n"; @@ -196,13 +242,17 @@ namespace armarx::aron::codegenerator::cpp::generator return m; } - CppMethodPtr IntEnumClass::toCopyAssignmentMethod() const + CppMethodPtr + IntEnumClass::toCopyAssignmentMethod() const { std::stringstream doc; doc << "@brief operator=() - Assignment operator for copy \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod(getFullInstantiatedCppTypename() + "& operator=(const " + getFullInstantiatedCppTypename() + "& c)", doc.str())); + CppMethodPtr m = + CppMethodPtr(new CppMethod(getFullInstantiatedCppTypename() + "& operator=(const " + + getFullInstantiatedCppTypename() + "& c)", + doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("value = c.value;"); b->addLine("return *this;"); @@ -210,13 +260,16 @@ namespace armarx::aron::codegenerator::cpp::generator return m; } - CppMethodPtr IntEnumClass::toEnumAssignmentMethod() const + CppMethodPtr + IntEnumClass::toEnumAssignmentMethod() const { std::stringstream doc; doc << "@brief operator=() - Assignment operator for the internally defined enum \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod(getFullInstantiatedCppTypename() + "& operator=(" + std::string(IMPL_ENUM) + " v)", doc.str())); + CppMethodPtr m = CppMethodPtr(new CppMethod( + getFullInstantiatedCppTypename() + "& operator=(" + std::string(IMPL_ENUM) + " v)", + doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("value = v;"); b->addLine("return *this;"); @@ -224,17 +277,20 @@ namespace armarx::aron::codegenerator::cpp::generator return m; } - CppMethodPtr IntEnumClass::toIntAssignmentMethod() const + CppMethodPtr + IntEnumClass::toIntAssignmentMethod() const { std::stringstream doc; doc << "@brief operator=() - Assignment operator for the internally defined enum \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod(getFullInstantiatedCppTypename() + "& operator=(int v)", doc.str())); + CppMethodPtr m = CppMethodPtr( + new CppMethod(getFullInstantiatedCppTypename() + "& operator=(int v)", doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("if (auto it = ValueToEnumMap.find(v); it == ValueToEnumMap.end())"); CppBlockPtr b2 = std::make_shared<CppBlock>(); - b2->addLine("throw armarx::LocalException(\"The input int is not valid. Could net set the enum to value '\" + std::to_string(v) + \"'\");"); + b2->addLine("throw armarx::LocalException(\"The input int is not valid. Could net set the " + "enum to value '\" + std::to_string(v) + \"'\");"); b->addBlock(b2); b->addLine("else"); CppBlockPtr b3 = std::make_shared<CppBlock>(); @@ -245,7 +301,8 @@ namespace armarx::aron::codegenerator::cpp::generator return m; } - CppMethodPtr IntEnumClass::toToStringMethod() const + CppMethodPtr + IntEnumClass::toToStringMethod() const { std::stringstream doc; doc << "@brief toString() - Converts the internally stored value to string \n"; @@ -258,17 +315,21 @@ namespace armarx::aron::codegenerator::cpp::generator return m; } - CppMethodPtr IntEnumClass::toFromStringMethod() const + CppMethodPtr + IntEnumClass::toFromStringMethod() const { std::stringstream doc; - doc << "@brief fromString() - sets the internally stored value to the corrsponding enum of the input str \n"; + doc << "@brief fromString() - sets the internally stored value to the corrsponding enum of " + "the input str \n"; doc << "@return - nothing"; - CppMethodPtr m = CppMethodPtr(new CppMethod("void fromString(const std::string& str)", doc.str())); + CppMethodPtr m = + CppMethodPtr(new CppMethod("void fromString(const std::string& str)", doc.str())); CppBlockPtr b = std::make_shared<CppBlock>(); b->addLine("if (auto it = StringToEnumMap.find(str); it == StringToEnumMap.end())"); CppBlockPtr b2 = std::make_shared<CppBlock>(); - b2->addLine("throw armarx::LocalException(\"The input name is not valid. Could net set the enum to value '\" + str + \"'\");"); + b2->addLine("throw armarx::LocalException(\"The input name is not valid. Could net set the " + "enum to value '\" + str + \"'\");"); b->addBlock(b2); b->addLine("else"); CppBlockPtr b3 = std::make_shared<CppBlock>(); @@ -278,4 +339,4 @@ namespace armarx::aron::codegenerator::cpp::generator m->setBlock(b); return m; } -} +} // namespace armarx::aron::codegenerator::cpp::generator 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 fb5e22671ba678ea69072e7b97fee54dbdd395e9..555f1e48be7600da97ec828fbff4e07c77333df2 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 @@ -23,17 +23,15 @@ #pragma once -#include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/SpecializedGenerator.h> -#include <RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h> - #include <map> -#include <utility> // std::pair +#include <utility> // std::pair +#include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/SpecializedGenerator.h> +#include <RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h> namespace armarx::aron::codegenerator::cpp::generator { - class IntEnumClass : - public detail::SpecializedGeneratorBase<type::IntEnum, IntEnumClass> + class IntEnumClass : public detail::SpecializedGeneratorBase<type::IntEnum, IntEnumClass> { public: // constructors @@ -45,9 +43,15 @@ namespace armarx::aron::codegenerator::cpp::generator 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; - CppBlockPtr getWriteBlock(const std::string& cppAccessor, const Path&, std::string& variantAccessor) const final; - CppBlockPtr getReadBlock(const std::string& cppAccessor, const std::string& variantAccessor) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path&, + std::string& variantAccessor) const final; + CppBlockPtr getWriteBlock(const std::string& cppAccessor, + const Path&, + std::string& variantAccessor) const final; + CppBlockPtr getReadBlock(const std::string& cppAccessor, + const std::string& variantAccessor) const final; CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const final; // TODO: Move some of those methods to upper class for enums (if we want to support multiple enums) @@ -66,4 +70,4 @@ namespace armarx::aron::codegenerator::cpp::generator static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; static constexpr const char* IMPL_ENUM = "ImplEnum"; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator 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 605c7b8655db3accb2dd1999d7c62e1cfc48730e..6bfc0100f0738f06ea16052a666893c774f19868 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 @@ -24,9 +24,8 @@ // Header #include "ObjectClass.h" -#include <SimoxUtility/meta/type_name.h> #include <SimoxUtility/algorithm/vector.hpp> - +#include <SimoxUtility/meta/type_name.h> namespace armarx::aron::codegenerator::cpp::generator { @@ -36,27 +35,54 @@ namespace armarx::aron::codegenerator::cpp::generator e.getObjectNameWithTemplateInstantiations(), // should be similar to the object name e.getObjectNameWithTemplates(), simox::meta::get_type_name<data::dto::Dict>(), - simox::meta::get_type_name<type::dto::AronObject>(), e) + simox::meta::get_type_name<type::dto::AronObject>(), + e) { if (type.getMaybe() != type::Maybe::NONE) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Somehow the maybe flag of a top level object declaration is set. This is not valid!", std::to_string((int) type.getMaybe()) + " aka " + type::defaultconversion::string::Maybe2String.at(type.getMaybe()), type.getPath()); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, + "Somehow the maybe flag of a top level object declaration is set. This is not " + "valid!", + std::to_string((int)type.getMaybe()) + " aka " + + type::defaultconversion::string::Maybe2String.at(type.getMaybe()), + type.getPath()); + } + } + + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + ObjectClass::getCtorInitializers(const std::string& name) const + { + std::vector<std::pair<std::string, std::string>> ret; + bool any = false; + for (const auto& [key, child] : type.getDirectMemberTypes()) + { + auto child_s = FromAronType(*child); + auto p = child_s->getCtorInitializers(key); + for (const auto& el : p.first) + { + ret.push_back(el); + } + any = any or p.second; } + return {ret, any}; } - std::vector<std::string> ObjectClass::getRequiredIncludes() const + std::vector<std::string> + ObjectClass::getRequiredIncludes() const { std::vector<std::string> ret; for (const auto& [key, child] : type.getDirectMemberTypes()) { - (void) key; + (void)key; auto child_s = FromAronType(*child); ret = simox::alg::appended(ret, child_s->getRequiredIncludes()); } return ret; } - std::vector<CppFieldPtr> ObjectClass::getPublicVariableDeclarations(const std::string&) const + std::vector<CppFieldPtr> + ObjectClass::getPublicVariableDeclarations(const std::string&) const { std::vector<CppFieldPtr> fields; for (const auto& [key, member] : type.getDirectMemberTypes()) @@ -68,7 +94,8 @@ namespace armarx::aron::codegenerator::cpp::generator return fields; } - CppBlockPtr ObjectClass::getResetSoftBlock(const std::string& accessor) const + CppBlockPtr + ObjectClass::getResetSoftBlock(const std::string& accessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); if (type.getExtends() != nullptr) @@ -86,7 +113,8 @@ namespace armarx::aron::codegenerator::cpp::generator return block_if_data; } - CppBlockPtr ObjectClass::getResetHardBlock(const std::string& accessor) const + CppBlockPtr + ObjectClass::getResetHardBlock(const std::string& accessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); if (type.getExtends() != nullptr) @@ -104,7 +132,11 @@ namespace armarx::aron::codegenerator::cpp::generator return block_if_data; } - CppBlockPtr ObjectClass::getWriteTypeBlock(const std::string&, const std::string&, const Path& p, std::string&) const + CppBlockPtr + ObjectClass::getWriteTypeBlock(const std::string&, + const std::string&, + const Path& p, + std::string&) const { static const std::string OBJECT_MEMBERS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectMembers"; static const std::string OBJECT_EXTENDS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectExtends"; @@ -116,10 +148,11 @@ namespace armarx::aron::codegenerator::cpp::generator { const auto extends_s = FromAronType(*type.getExtends()); b->addLine("// get base class of " + this->getFullInstantiatedCppTypename()); - b->addLine("auto " + OBJECT_EXTENDS_ACCESSOR + " = " + extends_s->getFullInstantiatedCppTypename() + "::writeType(" + - ARON_WRITER_ACCESSOR + ", " + - "{" + simox::alg::join(type.getExtends()->getTemplateInstantiations(), ", ") + "}, " + - "::armarx::aron::type::Maybe::NONE);"); + b->addLine("auto " + OBJECT_EXTENDS_ACCESSOR + " = " + + extends_s->getFullInstantiatedCppTypename() + "::writeType(" + + ARON_WRITER_ACCESSOR + ", " + "{" + + simox::alg::join(type.getExtends()->getTemplateInstantiations(), ", ") + + "}, " + "::armarx::aron::type::Maybe::NONE);"); } else { @@ -132,9 +165,11 @@ namespace armarx::aron::codegenerator::cpp::generator const auto child_s = FromAronType(*child); std::string child_return_variant; Path nextPath = p.withElement(key, true); - CppBlockPtr child_b = child_s->getWriteTypeBlock(child_s->getFullInstantiatedCppTypename(), key, nextPath, child_return_variant); + CppBlockPtr child_b = child_s->getWriteTypeBlock( + child_s->getFullInstantiatedCppTypename(), key, nextPath, child_return_variant); b->appendBlock(child_b); - b->addLine(OBJECT_MEMBERS_ACCESSOR + ".emplace(\"" + key + "\", " + child_return_variant + ");"); + b->addLine(OBJECT_MEMBERS_ACCESSOR + ".emplace(\"" + key + "\", " + + child_return_variant + ");"); } std::vector<std::string> templatesQuoted; std::vector<std::string> templateIntantiationsQuoted; @@ -147,18 +182,19 @@ namespace armarx::aron::codegenerator::cpp::generator templateIntantiationsQuoted.push_back("\"" + t + "\""); } - b->addLine("return " + ARON_WRITER_ACCESSOR + ".writeObject(\"" + type.getObjectName() + "\", " + - "{" + simox::alg::join(templatesQuoted, ", ") + "}, " + - ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR + ", " + - OBJECT_MEMBERS_ACCESSOR + ", " + - OBJECT_EXTENDS_ACCESSOR + ", " + - ARON_MAYBE_TYPE_ACCESSOR + ", " + - ARON_PATH_ACCESSOR + "); // of top level object " + getInstantiatedCppTypename());; + b->addLine("return " + ARON_WRITER_ACCESSOR + ".writeObject(\"" + type.getObjectName() + + "\", " + "{" + simox::alg::join(templatesQuoted, ", ") + "}, " + + ARON_TEMPLATE_INSTANTIATIONS_ACCESSOR + ", " + OBJECT_MEMBERS_ACCESSOR + ", " + + OBJECT_EXTENDS_ACCESSOR + ", " + ARON_MAYBE_TYPE_ACCESSOR + ", " + + ARON_PATH_ACCESSOR + "); // of top level object " + + getInstantiatedCppTypename()); + ; return b; } - CppBlockPtr ObjectClass::getWriteBlock(const std::string&, const Path& p, std::string&) const + CppBlockPtr + ObjectClass::getWriteBlock(const std::string&, const Path& p, std::string&) const { static const std::string OBJECT_MEMBERS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectMembers"; static const std::string OBJECT_EXTENDS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectExtends"; @@ -171,8 +207,11 @@ namespace armarx::aron::codegenerator::cpp::generator if (type.getExtends() != nullptr) { const auto extends_s = FromAronType(*type.getExtends()); - block_if_data->addLine("// write base class of " + this->getFullInstantiatedCppTypename()); - block_if_data->addLine(OBJECT_EXTENDS_ACCESSOR + " = " + extends_s->getFullInstantiatedCppTypename() + "::write(" + ARON_WRITER_ACCESSOR + ");"); + block_if_data->addLine("// write base class of " + + this->getFullInstantiatedCppTypename()); + block_if_data->addLine(OBJECT_EXTENDS_ACCESSOR + " = " + + extends_s->getFullInstantiatedCppTypename() + "::write(" + + ARON_WRITER_ACCESSOR + ");"); } block_if_data->addLine("// members of " + this->getFullInstantiatedCppTypename()); @@ -183,51 +222,67 @@ namespace armarx::aron::codegenerator::cpp::generator Path nextPath = p.withElement(key, true); CppBlockPtr child_b = child_s->getWriteBlock(key, nextPath, child_return_variant); - block_if_data->addLine("auto " + child_return_variant + " = " + ARON_WRITER_ACCESSOR + ".writeNull();"); + block_if_data->addLine("auto " + child_return_variant + " = " + ARON_WRITER_ACCESSOR + + ".writeNull();"); block_if_data->appendBlock(child_b); - block_if_data->addLine(OBJECT_MEMBERS_ACCESSOR + ".emplace(\"" + key + "\", " + child_return_variant + ");"); + block_if_data->addLine(OBJECT_MEMBERS_ACCESSOR + ".emplace(\"" + key + "\", " + + child_return_variant + ");"); } - block_if_data->addLine("return " + ARON_WRITER_ACCESSOR + ".writeDict("+OBJECT_MEMBERS_ACCESSOR+", " + - OBJECT_EXTENDS_ACCESSOR + ", "+ - ARON_PATH_ACCESSOR + "); // of top level object " + getInstantiatedCppTypename()); + block_if_data->addLine("return " + ARON_WRITER_ACCESSOR + ".writeDict(" + + OBJECT_MEMBERS_ACCESSOR + ", " + OBJECT_EXTENDS_ACCESSOR + ", " + + ARON_PATH_ACCESSOR + "); // of top level object " + + getInstantiatedCppTypename()); return block_if_data; } - CppBlockPtr ObjectClass::getReadBlock(const std::string&, const std::string& variantAccessor) const + CppBlockPtr + ObjectClass::getReadBlock(const std::string&, const std::string& variantAccessor) const { static const std::string OBJECT_MEMBERS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectMembers"; static const std::string OBJECT_EXTENDS_ACCESSOR = ARON_VARIABLE_PREFIX + "_objectExtends"; CppBlockPtr block_if_data = std::make_shared<CppBlock>(); - block_if_data->addLine("std::map<std::string, _Aron_TNonConst> " + OBJECT_MEMBERS_ACCESSOR + ";"); + block_if_data->addLine("std::map<std::string, _Aron_TNonConst> " + OBJECT_MEMBERS_ACCESSOR + + ";"); if (type.getExtends() != nullptr) { const auto extends_s = FromAronType(*type.getExtends()); - block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::read(" + ARON_READER_ACCESSOR + ", "+variantAccessor+");"); + block_if_data->addLine(extends_s->getFullInstantiatedCppTypename() + "::read(" + + ARON_READER_ACCESSOR + ", " + variantAccessor + ");"); } - block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readDict("+variantAccessor+", "+OBJECT_MEMBERS_ACCESSOR+"); // of top level object " + getInstantiatedCppTypename()); + block_if_data->addLine("" + ARON_READER_ACCESSOR + ".readDict(" + variantAccessor + ", " + + OBJECT_MEMBERS_ACCESSOR + "); // of top level object " + + getInstantiatedCppTypename()); for (const auto& [key, child] : type.getDirectMemberTypes()) { const auto child_s = FromAronType(*child); std::string child_accessor = OBJECT_MEMBERS_ACCESSOR + "_" + key + "_iterator"; - block_if_data->addLine("auto " + child_accessor + " = " + OBJECT_MEMBERS_ACCESSOR + ".find(\"" + key + "\");"); - block_if_data->addLine("ARMARX_CHECK_AND_THROW(" + child_accessor + " != " + OBJECT_MEMBERS_ACCESSOR + ".end(), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing member '" + key + "' in aron object '" + getFullClassCppTypename() + "'.\"));"); + block_if_data->addLine("auto " + child_accessor + " = " + OBJECT_MEMBERS_ACCESSOR + + ".find(\"" + key + "\");"); + block_if_data->addLine( + "ARMARX_CHECK_AND_THROW(" + child_accessor + " != " + OBJECT_MEMBERS_ACCESSOR + + ".end(), ::armarx::aron::error::AronException(__PRETTY_FUNCTION__, \"Missing " + "member '" + + key + "' in aron object '" + getFullClassCppTypename() + "'.\"));"); block_if_data->appendBlock(child_s->getReadBlock(key, child_accessor + "->second")); } return block_if_data; } - CppBlockPtr ObjectClass::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + CppBlockPtr + ObjectClass::getEqualsBlock(const std::string& accessor, + const std::string& otherInstanceAccessor) const { CppBlockPtr block_if_data = std::make_shared<CppBlock>(); if (type.getExtends() != nullptr) { const auto extends_s = FromAronType(*type.getExtends()); - block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + "::operator== (" + otherInstanceAccessor + ")))"); + block_if_data->addLine("if (not (" + extends_s->getFullInstantiatedCppTypename() + + "::operator== (" + otherInstanceAccessor + ")))"); block_if_data->addLineAsBlock("return false;"); } for (const auto& [key, child] : type.getDirectMemberTypes()) @@ -239,7 +294,8 @@ namespace armarx::aron::codegenerator::cpp::generator return block_if_data; } - std::pair<std::vector<std::pair<std::string, std::string>>, bool> ObjectClass::getCopyCtorInitializers(const std::string&) const + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + ObjectClass::getCopyCtorInitializers(const std::string&) const { std::vector<std::pair<std::string, std::string>> ret; @@ -259,4 +315,4 @@ namespace armarx::aron::codegenerator::cpp::generator } return {ret, anyComplex}; } -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.h b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.h index 772d138cb7cc521753ce6bd3086bb076d475b462..34d0f16c058cca25a7fd2905e0c43f926ea365b7 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.h +++ b/source/RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/toplevel/ObjectClass.h @@ -26,11 +26,9 @@ #include <RobotAPI/libraries/aron/codegeneration/codegenerator/codewriter/cpp/generator/detail/SpecializedGenerator.h> #include <RobotAPI/libraries/aron/core/type/variant/container/Object.h> - namespace armarx::aron::codegenerator::cpp::generator { - class ObjectClass : - public detail::SpecializedGeneratorBase<type::Object, ObjectClass> + class ObjectClass : public detail::SpecializedGeneratorBase<type::Object, ObjectClass> { public: // constructors @@ -41,13 +39,20 @@ namespace armarx::aron::codegenerator::cpp::generator std::vector<std::string> getRequiredIncludes() const final; 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; + std::pair<std::vector<std::pair<std::string, std::string>>, bool> + getCtorInitializers(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; - CppBlockPtr getWriteBlock(const std::string& cppAccessor, const Path&, std::string&) const final; + CppBlockPtr getWriteTypeBlock(const std::string& typeAccessor, + const std::string& cppAccessor, + const Path&, + std::string& variantAccessor) const final; + CppBlockPtr + getWriteBlock(const std::string& cppAccessor, const Path&, std::string&) const final; CppBlockPtr getReadBlock(const std::string& cppAccessor, const std::string&) const final; CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const final; }; -} +} // namespace armarx::aron::codegenerator::cpp::generator diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp index 925582621433aa3f679dccee50af2b7e2dcad6d7..0efac9317644bafad00dbe97e3129a3b58deab86 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.cpp @@ -24,12 +24,13 @@ #include "Data.h" #include <SimoxUtility/algorithm/string/string_tools.h> + #include <RobotAPI/libraries/aron/core/Exception.h> namespace armarx::aron::typereader::xml { - - std::optional<RapidXmlReaderNode> util::GetFirstNodeWithTag(const RapidXmlReaderNode& node, const std::string& name) + std::optional<RapidXmlReaderNode> + util::GetFirstNodeWithTag(const RapidXmlReaderNode& node, const std::string& name) { for (const auto& n : node.nodes()) { @@ -42,26 +43,35 @@ namespace armarx::aron::typereader::xml return std::nullopt; } - void util::EnforceAttribute(const RapidXmlReaderNode& node, const std::string& att) + void + util::EnforceAttribute(const RapidXmlReaderNode& node, const std::string& att) { if (!HasAttribute(node, att)) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "A <" + node.name() + ">-tag does not have the '"+att+"' attribute", simox::alg::to_string(node.get_all_attributes())); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "A <" + node.name() + ">-tag does not have the '" + + att + "' attribute", + simox::alg::to_string(node.get_all_attributes())); } } - bool util::HasAttribute(const RapidXmlReaderNode& node, const std::string& att) + bool + util::HasAttribute(const RapidXmlReaderNode& node, const std::string& att) { return node.has_attribute(att.c_str()); } - std::string util::GetAttribute(const RapidXmlReaderNode& node, const std::string& att) + std::string + util::GetAttribute(const RapidXmlReaderNode& node, const std::string& att) { EnforceAttribute(node, att); return node.attribute_value(att.c_str()); } - std::string util::GetAttributeWithDefault(const armarx::RapidXmlReaderNode& node, const std::string& att, const std::string& def) + std::string + util::GetAttributeWithDefault(const armarx::RapidXmlReaderNode& node, + const std::string& att, + const std::string& def) { if (!(HasAttribute(node, att))) { @@ -70,7 +80,8 @@ namespace armarx::aron::typereader::xml return node.attribute_value(att.c_str()); } - bool util::AttributeIsTrue(const armarx::RapidXmlReaderNode& node, const std::string& att) + bool + util::AttributeIsTrue(const armarx::RapidXmlReaderNode& node, const std::string& att) { if (HasAttribute(node, att)) { @@ -83,20 +94,24 @@ namespace armarx::aron::typereader::xml return false; } - bool util::HasTagName(const armarx::RapidXmlReaderNode& node, const std::string& name) + bool + util::HasTagName(const armarx::RapidXmlReaderNode& node, const std::string& name) { return (simox::alg::to_lower(name) == simox::alg::to_lower(node.name())); } - void util::EnforceTagName(const armarx::RapidXmlReaderNode& node, const std::string& name) + void + util::EnforceTagName(const armarx::RapidXmlReaderNode& node, const std::string& name) { if (!(HasTagName(node, name))) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node has the wrong tag. Expected: " + name, node.name()); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "The node has the wrong tag. Expected: " + name, node.name()); } } - void util::EnforceTagNames(const RapidXmlReaderNode& node, const std::vector<std::string>& names) + void + util::EnforceTagNames(const RapidXmlReaderNode& node, const std::vector<std::string>& names) { for (const auto& name : names) { @@ -105,57 +120,86 @@ namespace armarx::aron::typereader::xml return; } } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node has the wrong tag. Expected one of: " + simox::alg::to_string(names, ", "), node.name()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node has the wrong tag. Expected one of: " + + simox::alg::to_string(names, ", "), + node.name()); } - std::string util::GetTagName(const armarx::RapidXmlReaderNode& node) + std::string + util::GetTagName(const armarx::RapidXmlReaderNode& node) { return simox::alg::to_lower(node.name()); } - void util::EnforceChildSizeSmaller(const RapidXmlReaderNode& node, const size_t size) + void + util::EnforceChildSizeSmaller(const RapidXmlReaderNode& node, const size_t size) { const size_t s = node.nodes().size(); if (s >= size) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong number of children", std::to_string(s), std::to_string(size)); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node <" + node.name() + + "> has the wrong number of children", + std::to_string(s), + std::to_string(size)); } } - void util::EnforceChildSizeSmallerEqual(const RapidXmlReaderNode& node, const size_t size) + void + util::EnforceChildSizeSmallerEqual(const RapidXmlReaderNode& node, const size_t size) { const size_t s = node.nodes().size(); if (s > size) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong number of children", std::to_string(s), std::to_string(size)); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node <" + node.name() + + "> has the wrong number of children", + std::to_string(s), + std::to_string(size)); } } - void util::EnforceChildSize(const armarx::RapidXmlReaderNode& node, const size_t size) + void + util::EnforceChildSize(const armarx::RapidXmlReaderNode& node, const size_t size) { const size_t s = node.nodes().size(); if (s != size) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong number of children", std::to_string(s), std::to_string(size)); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node <" + node.name() + + "> has the wrong number of children", + std::to_string(s), + std::to_string(size)); } } - void util::EnforceChildSizeGreaterEqual(const RapidXmlReaderNode& node, const size_t size) + void + util::EnforceChildSizeGreaterEqual(const RapidXmlReaderNode& node, const size_t size) { const size_t s = node.nodes().size(); if (s < size) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong number of children", std::to_string(s), std::to_string(size)); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node <" + node.name() + + "> has the wrong number of children", + std::to_string(s), + std::to_string(size)); } } - void util::EnforceChildSizeGreater(const RapidXmlReaderNode& node, const size_t size) + void + util::EnforceChildSizeGreater(const RapidXmlReaderNode& node, const size_t size) { const size_t s = node.nodes().size(); if (s <= size) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The node <" + node.name() + "> has the wrong number of children", std::to_string(s), std::to_string(size)); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The node <" + node.name() + + "> has the wrong number of children", + std::to_string(s), + std::to_string(size)); } } -} +} // namespace armarx::aron::typereader::xml diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h index bc557478142396f30a2d92191b469e2f7fcf438f..fb8106874d5b0eba3460f4a0fd0c0934f842b6d3 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Data.h @@ -41,70 +41,71 @@ namespace armarx::aron::typereader::xml namespace constantes { // Definition tags - const std::string TYPE_DEFINITION_TAG = "arontypedefinition"; + const constexpr auto TYPE_DEFINITION_TAG = "arontypedefinition"; - const std::string CODE_INCLUDES_TAG = "codeincludes"; - const std::string ARON_INCLUDES_TAG = "aronincludes"; - const std::string INCLUDES_TAG = "includes"; - const std::string SYSTEM_INCLUDE_TAG = "systeminclude"; - const std::string PACKAGE_PATH_TAG = "packagepath"; - const std::string INCLUDE_TAG = "include"; - const std::string GENERATE_TYPES_TAG = "generatetypes"; + const constexpr auto CODE_INCLUDES_TAG = "codeincludes"; + const constexpr auto ARON_INCLUDES_TAG = "aronincludes"; + const constexpr auto INCLUDES_TAG = "includes"; + const constexpr auto SYSTEM_INCLUDE_TAG = "systeminclude"; + const constexpr auto PACKAGE_PATH_TAG = "packagepath"; + const constexpr auto INCLUDE_TAG = "include"; + const constexpr auto GENERATE_TYPES_TAG = "generatetypes"; // Attribute names - const std::string ARON_ATTRIBUTE_NAME = "aron"; - const std::string CODE_ATTRIBUTE_NAME = "code"; - const std::string METHOD_ATTRIBUTE_NAME = "method"; - const std::string RETURN_ATTRIBUTE_NAME = "return"; - const std::string ARGUMENT_TYPE_ATTRIBUTE_NAME = "argumenttype"; - const std::string INCLUDE_ATTRIBUTE_NAME = "include"; - const std::string READER_ATTRIBUTE_NAME = "reader"; - const std::string WRITER_ATTRIBUTE_NAME = "writer"; - const std::string EXTENDS_ATTRIBUTE_NAME = "extends"; - const std::string NAME_ATTRIBUTE_NAME = "name"; - const std::string VALUE_ATTRIBUTE_NAME = "value"; - const std::string TEMPLATE_ATTRIBUTE_NAME = "template"; - const std::string KEY_ATTRIBUTE_NAME = "key"; - const std::string TYPE_ATTRIBUTE_NAME = "type"; - const std::string WIDTH_ATTRIBUTE_NAME = "width"; - const std::string HEIGHT_ATTRIBUTE_NAME = "height"; - const std::string ROWS_ATTRIBUTE_NAME = "rows"; - const std::string COLS_ATTRIBUTE_NAME = "cols"; - const std::string DIMENSIONS_ATTRIBUTE_NAME = "dimensions"; - const std::string SHAPE_ATTRIBUTE_NAME = "shape"; - const std::string OPTIONAL_ATTRIBUTE_NAME = "optional"; - const std::string RAW_PTR_ATTRIBUTE_NAME = "raw_ptr"; - const std::string SHARED_PTR_ATTRIBUTE_NAME = "shared_ptr"; - const std::string UNIQUE_PTR_ATTRIBUTE_NAME = "unique_ptr"; - const std::string PACKAGE_ATTRIBUTE_NAME = "package"; - const std::string DOC_BRIEF_ATTRIBUTE_NAME = "doc-brief"; - const std::string DOC_AUTHOR_ATTRIBUTE_NAME = "doc-author"; - const std::string DOC_PARAM_ATTRIBUTE_NAME = "doc-param"; - const std::string PATH_ATTRIBUTE_NAME = "path"; + const constexpr auto ARON_ATTRIBUTE_NAME = "aron"; + const constexpr auto CODE_ATTRIBUTE_NAME = "code"; + const constexpr auto METHOD_ATTRIBUTE_NAME = "method"; + const constexpr auto RETURN_ATTRIBUTE_NAME = "return"; + const constexpr auto ARGUMENT_TYPE_ATTRIBUTE_NAME = "argumenttype"; + const constexpr auto INCLUDE_ATTRIBUTE_NAME = "include"; + const constexpr auto READER_ATTRIBUTE_NAME = "reader"; + const constexpr auto WRITER_ATTRIBUTE_NAME = "writer"; + const constexpr auto EXTENDS_ATTRIBUTE_NAME = "extends"; + const constexpr auto NAME_ATTRIBUTE_NAME = "name"; + const constexpr auto VALUE_ATTRIBUTE_NAME = "value"; + const constexpr auto TEMPLATE_ATTRIBUTE_NAME = "template"; + const constexpr auto KEY_ATTRIBUTE_NAME = "key"; + const constexpr auto TYPE_ATTRIBUTE_NAME = "type"; + const constexpr auto WIDTH_ATTRIBUTE_NAME = "width"; + const constexpr auto HEIGHT_ATTRIBUTE_NAME = "height"; + const constexpr auto ROWS_ATTRIBUTE_NAME = "rows"; + const constexpr auto COLS_ATTRIBUTE_NAME = "cols"; + const constexpr auto DIMENSIONS_ATTRIBUTE_NAME = "dimensions"; + const constexpr auto SHAPE_ATTRIBUTE_NAME = "shape"; + const constexpr auto OPTIONAL_ATTRIBUTE_NAME = "optional"; + const constexpr auto RAW_PTR_ATTRIBUTE_NAME = "raw_ptr"; + const constexpr auto SHARED_PTR_ATTRIBUTE_NAME = "shared_ptr"; + const constexpr auto UNIQUE_PTR_ATTRIBUTE_NAME = "unique_ptr"; + const constexpr auto PACKAGE_ATTRIBUTE_NAME = "package"; + const constexpr auto DOC_BRIEF_ATTRIBUTE_NAME = "doc-brief"; + const constexpr auto DOC_AUTHOR_ATTRIBUTE_NAME = "doc-author"; + const constexpr auto DOC_PARAM_ATTRIBUTE_NAME = "doc-param"; + const constexpr auto PATH_ATTRIBUTE_NAME = "path"; + const constexpr auto DEFAULT_ATTRIBUTE_NAME = "default"; // Second level tags. Only important if in specific top level tag - const std::string OBJECT_CHILD_TAG = "objectchild"; - const std::string ENUM_VALUE_TAG = "enumvalue"; + const constexpr auto OBJECT_CHILD_TAG = "objectchild"; + const constexpr auto ENUM_VALUE_TAG = "enumvalue"; // Top Level type tags - const std::string LIST_TAG = "list"; - const std::string DICT_TAG = "dict"; - const std::string OBJECT_TAG = "object"; - const std::string PAIR_TAG = "pair"; - const std::string TUPLE_TAG = "tuple"; - const std::string INT_ENUM_TAG = "intenum"; - const std::string NDARRAY_TAG = "ndarray"; - const std::string MATRIX_TAG = "matrix"; - const std::string QUATERNION_TAG = "quaternion"; - const std::string IMAGE_TAG = "image"; - const std::string POINT_CLOUD_TAG = "pointcloud"; - const std::string INT_TAG = "int32"; - const std::string LONG_TAG = "int64"; - const std::string FLOAT_TAG = "float32"; - const std::string DOUBLE_TAG = "float64"; - const std::string STRING_TAG = "string"; - const std::string BOOL_TAG = "bool"; - const std::string ANY_OBJECT_TAG = "anyobject"; + const constexpr auto LIST_TAG = "list"; + const constexpr auto DICT_TAG = "dict"; + const constexpr auto OBJECT_TAG = "object"; + const constexpr auto PAIR_TAG = "pair"; + const constexpr auto TUPLE_TAG = "tuple"; + const constexpr auto INT_ENUM_TAG = "intenum"; + const constexpr auto NDARRAY_TAG = "ndarray"; + const constexpr auto MATRIX_TAG = "matrix"; + const constexpr auto QUATERNION_TAG = "quaternion"; + const constexpr auto IMAGE_TAG = "image"; + const constexpr auto POINT_CLOUD_TAG = "pointcloud"; + const constexpr auto INT_TAG = "int32"; + const constexpr auto LONG_TAG = "int64"; + const constexpr auto FLOAT_TAG = "float32"; + const constexpr auto DOUBLE_TAG = "float64"; + const constexpr auto STRING_TAG = "string"; + const constexpr auto BOOL_TAG = "bool"; + const constexpr auto ANY_OBJECT_TAG = "anyobject"; // others const std::vector<std::string> WHATEVER_VALUES = {"?"}; @@ -118,64 +119,59 @@ namespace armarx::aron::typereader::xml // Replacements ({tagName, {replacementsTag, additionalAronDTOXMLIncludePackagePath}, deprecationwarning}) const std::map<std::string, Replacement> REPLACEMENTS = { - {"int", - {"<int32 />", {}, "The <int />-tag is deprecated. Please use <int32 /> instead."}}, + {"int", {"int32", {}, "The <int />-tag is deprecated. Please use <int32 /> instead."}}, {"long", - {"<int64 />", {}, "The <long />-tag is deprecated. Please use <int64 /> instead."}}, + {"int64", {}, "The <long />-tag is deprecated. Please use <int64 /> instead."}}, {"float", - {"<float32 />", - {}, - "The <float />-tag is deprecated. Please use <float32 /> instead."}}, + {"float32", {}, "The <float />-tag is deprecated. Please use <float32 /> instead."}}, {"double", - {"<float64 />", - {}, - "The <double />-tag is deprecated. Please use <float64 /> instead."}}, + {"float64", {}, "The <double />-tag is deprecated. Please use <float64 /> instead."}}, // should that be deprecated? - {"position", {"<matrix rows='3' cols='1' type='float32' />", {}, ""}}, - {"pose", {"<matrix rows='4' cols='4' type='float32' />", {}, ""}}, - {"orientation", {"<quaternion type='float32' />", {}, ""}}, + {"position", {"matrix rows='3' cols='1' type='float32'", {}, ""}}, + {"pose", {"matrix rows='4' cols='4' type='float32'", {}, ""}}, + {"orientation", {"quaternion type='float32'", {}, ""}}, // values similar to eigen - {"quaternionf", {"<quaternion type='float32' />", {}, ""}}, - {"quaterniond", {"<quaternion type='float64' />", {}, ""}}, - {"vector2f", {"<matrix rows='2' cols='1' type='float32' />", {}, ""}}, - {"vector2d", {"<matrix rows='2' cols='1' type='float64' />", {}, ""}}, - {"vector3f", {"<matrix rows='3' cols='1' type='float32' />", {}, ""}}, - {"vector3d", {"<matrix rows='3' cols='1' type='float64' />", {}, ""}}, - {"vector4f", {"<matrix rows='4' cols='1' type='float32' />", {}, ""}}, - {"vector4d", {"<matrix rows='4' cols='1' type='float64' />", {}, ""}}, - {"matrix2f", {"<matrix rows='2' cols='2' type='float32' />", {}, ""}}, - {"matrix2d", {"<matrix rows='2' cols='2' type='float64' />", {}, ""}}, - {"matrix3f", {"<matrix rows='3' cols='3' type='float32' />", {}, ""}}, - {"matrix3d", {"<matrix rows='3' cols='3' type='float64' />", {}, ""}}, - {"matrix4f", {"<matrix rows='4' cols='4' type='float32' />", {}, ""}}, - {"matrix4d", {"<matrix rows='4' cols='4' type='float64' />", {}, ""}}, + {"quaternionf", {"quaternion type='float32'", {}, ""}}, + {"quaterniond", {"quaternion type='float64'", {}, ""}}, + {"vector2f", {"matrix rows='2' cols='1' type='float32'", {}, ""}}, + {"vector2d", {"matrix rows='2' cols='1' type='float64'", {}, ""}}, + {"vector3f", {"matrix rows='3' cols='1' type='float32'", {}, ""}}, + {"vector3d", {"matrix rows='3' cols='1' type='float64'", {}, ""}}, + {"vector4f", {"matrix rows='4' cols='1' type='float32'", {}, ""}}, + {"vector4d", {"matrix rows='4' cols='1' type='float64'", {}, ""}}, + {"matrix2f", {"matrix rows='2' cols='2' type='float32'", {}, ""}}, + {"matrix2d", {"matrix rows='2' cols='2' type='float64'", {}, ""}}, + {"matrix3f", {"matrix rows='3' cols='3' type='float32'", {}, ""}}, + {"matrix3d", {"matrix rows='3' cols='3' type='float64'", {}, ""}}, + {"matrix4f", {"matrix rows='4' cols='4' type='float32'", {}, ""}}, + {"matrix4d", {"matrix rows='4' cols='4' type='float64'", {}, ""}}, // You can also add replacements for arondtos here! // structure: {xml-identifier, {replacement, auto-include}, deprecationwarning} {"datetime", - {"<armarx::arondto::DateTime />", + {"armarx::arondto::DateTime", {"RobotAPI", "libraries/aron/common/aron/time.xml"}, ""}}, {"time", - {"<armarx::arondto::DateTime />", + {"armarx::arondto::DateTime", {"RobotAPI", "libraries/aron/common/aron/time.xml"}, ""}}, {"duration", - {"<armarx::arondto::Duration />", + {"armarx::arondto::Duration", {"RobotAPI", "libraries/aron/common/aron/time.xml"}, ""}}, {"framedposition", - {"<armarx::arondto::FramedPosition />", + {"armarx::arondto::FramedPosition", {"RobotAPI", "libraries/aron/common/aron/framed.xml"}, ""}}, {"framedorientation", - {"<armarx::arondto::FramedOrientation />", + {"armarx::arondto::FramedOrientation", {"RobotAPI", "libraries/aron/common/aron/framed.xml"}, ""}}, {"framedpose", - {"<armarx::arondto::FramedPose />", + {"armarx::arondto::FramedPose", {"RobotAPI", "libraries/aron/common/aron/framed.xml"}, ""}}}; } // namespace constantes diff --git a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp index 8409c87ba128e86bab38cf78f0994d34f35844fe..cf6e1731d7c900bb3067368542feb1e2db672b64 100644 --- a/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp +++ b/source/RobotAPI/libraries/aron/codegeneration/typereader/xml/Factory.cpp @@ -31,20 +31,33 @@ // ArmarX #include <ArmarXCore/core/time/DateTime.h> + #include <RobotAPI/libraries/aron/core/type/variant/All.h> + #include "Data.h" namespace armarx::aron::typereader::xml { - void printDeprecationWarning(const std::string& warning) + void + printDeprecationWarning(const std::string& warning) { - std::cout << "\033[1;33mAron deprecation warning: " << warning << "\033[0m" << std::endl; + std::cout + << "\033[1;33m[**Aron v" + armarx::aron::VERSION + " deprecation warning**]: " + << warning + << "\nPlease note that a future version of aron might not support this anymore.\033[0m" + << std::endl; } - type::VariantPtr ReaderFactory::create(const RapidXmlReaderNode& node, const Path& path) + void + printWarning(const std::string& warning) { - static const std::map<std::string, type::Descriptor> String2Descriptor = - { + std::cout << "\033[1;33m[**Aron warning**]: " << warning << "\033[0m" << std::endl; + } + + type::VariantPtr + ReaderFactory::create(const RapidXmlReaderNode& node, const Path& path) + { + static const std::map<std::string, type::Descriptor> String2Descriptor = { {constantes::LIST_TAG, type::Descriptor::LIST}, {constantes::OBJECT_TAG, type::Descriptor::OBJECT}, {constantes::TUPLE_TAG, type::Descriptor::TUPLE}, @@ -62,13 +75,13 @@ namespace armarx::aron::typereader::xml {constantes::DOUBLE_TAG, type::Descriptor::DOUBLE}, {constantes::STRING_TAG, type::Descriptor::STRING}, {constantes::BOOL_TAG, type::Descriptor::BOOL}, - {constantes::ANY_OBJECT_TAG, type::Descriptor::ANY_OBJECT} - }; + {constantes::ANY_OBJECT_TAG, type::Descriptor::ANY_OBJECT}}; RapidXmlReaderNode nodeToUse = node; // check for replacement - if (auto it = constantes::REPLACEMENTS.find(simox::alg::to_lower(nodeToUse.name())); it != constantes::REPLACEMENTS.end()) + if (auto it = constantes::REPLACEMENTS.find(simox::alg::to_lower(nodeToUse.name())); + it != constantes::REPLACEMENTS.end()) { auto replacement = it->second; if (!replacement.deprecatedWarning.empty()) @@ -76,47 +89,75 @@ namespace armarx::aron::typereader::xml printDeprecationWarning(replacement.deprecatedWarning); } + std::string tag = replacement.replacementTag; + if (util::HasAttribute(nodeToUse, constantes::DEFAULT_ATTRIBUTE_NAME)) + { + tag += " " + std::string(constantes::DEFAULT_ATTRIBUTE_NAME) + "\"" + + util::GetAttribute(nodeToUse, constantes::DEFAULT_ATTRIBUTE_NAME) + "\""; + } + // We make the system believe there is another string in the xml - RapidXmlReaderPtr reader = RapidXmlReader::FromXmlString(replacement.replacementTag); + RapidXmlReaderPtr reader = RapidXmlReader::FromXmlString("<" + tag + " />"); nodeToUse = reader->getRoot(); } auto it = String2Descriptor.find(simox::alg::to_lower(nodeToUse.name())); auto descriptor = (it == String2Descriptor.end() ? type::Descriptor::UNKNOWN : it->second); - switch(descriptor) - { - case type::Descriptor::LIST: return createList(nodeToUse, path); - case type::Descriptor::DICT: return createDict(nodeToUse, path); - case type::Descriptor::OBJECT: return createObject(nodeToUse, path); - case type::Descriptor::TUPLE: return createTuple(nodeToUse, path); - case type::Descriptor::PAIR: return createPair(nodeToUse, path); - case type::Descriptor::NDARRAY: return createNDArray(nodeToUse, path); - case type::Descriptor::MATRIX: return createMatrix(nodeToUse, path); - case type::Descriptor::QUATERNION: return createQuaternion(nodeToUse, path); - case type::Descriptor::IMAGE: return createImage(nodeToUse, path); - case type::Descriptor::POINTCLOUD: return createPointCloud(nodeToUse, path); - case type::Descriptor::INT_ENUM: return createIntEnum(nodeToUse, path); - case type::Descriptor::INT: return createInt(nodeToUse, path); - case type::Descriptor::LONG: return createLong(nodeToUse, path); - case type::Descriptor::FLOAT: return createFloat(nodeToUse, path); - case type::Descriptor::DOUBLE: return createDouble(nodeToUse, path); - case type::Descriptor::STRING: return createString(nodeToUse, path); - case type::Descriptor::BOOL: return createBool(nodeToUse, path); - case type::Descriptor::ANY_OBJECT: return createAnyObject(nodeToUse, path); - case type::Descriptor::UNKNOWN: return findExistingObject(nodeToUse.name(), path); + switch (descriptor) + { + case type::Descriptor::LIST: + return createList(nodeToUse, path); + case type::Descriptor::DICT: + return createDict(nodeToUse, path); + case type::Descriptor::OBJECT: + return createObject(nodeToUse, path); + case type::Descriptor::TUPLE: + return createTuple(nodeToUse, path); + case type::Descriptor::PAIR: + return createPair(nodeToUse, path); + case type::Descriptor::NDARRAY: + return createNDArray(nodeToUse, path); + case type::Descriptor::MATRIX: + return createMatrix(nodeToUse, path); + case type::Descriptor::QUATERNION: + return createQuaternion(nodeToUse, path); + case type::Descriptor::IMAGE: + return createImage(nodeToUse, path); + case type::Descriptor::POINTCLOUD: + return createPointCloud(nodeToUse, path); + case type::Descriptor::INT_ENUM: + return createIntEnum(nodeToUse, path); + case type::Descriptor::INT: + return createInt(nodeToUse, path); + case type::Descriptor::LONG: + return createLong(nodeToUse, path); + case type::Descriptor::FLOAT: + return createFloat(nodeToUse, path); + case type::Descriptor::DOUBLE: + return createDouble(nodeToUse, path); + case type::Descriptor::STRING: + return createString(nodeToUse, path); + case type::Descriptor::BOOL: + return createBool(nodeToUse, path); + case type::Descriptor::ANY_OBJECT: + return createAnyObject(nodeToUse, path); + case type::Descriptor::UNKNOWN: + return findExistingObject(nodeToUse.name(), path); } throw aron::error::AronEOFException(__PRETTY_FUNCTION__); } - type::VariantPtr ReaderFactory::findExistingObject(const std::string& name, const Path& path) const + type::VariantPtr + ReaderFactory::findExistingObject(const std::string& name, const Path& path) const { const auto public_intenum_it = allGeneratedPublicIntEnums.find(name); if (public_intenum_it != allGeneratedPublicIntEnums.end()) { // copy the navigator - auto v = type::Variant::FromAronDTO(*public_intenum_it->second.correspondingType->toAronDTO(), path); + auto v = type::Variant::FromAronDTO( + *public_intenum_it->second.correspondingType->toAronDTO(), path); return v; } @@ -124,31 +165,44 @@ namespace armarx::aron::typereader::xml if (public_obj_it != allGeneratedPublicObjects.end()) { // copy the navigator and set instantiation template args - auto v = type::Variant::FromAronDTO(*public_obj_it->second.correspondingType->toAronDTO(), path); + auto v = type::Variant::FromAronDTO( + *public_obj_it->second.correspondingType->toAronDTO(), path); return v; } - const auto public_known_it = std::find(allPreviouslyKnownPublicTypes.begin(), allPreviouslyKnownPublicTypes.end(), name); - if(public_known_it != allPreviouslyKnownPublicTypes.end()) + const auto public_known_it = std::find( + allPreviouslyKnownPublicTypes.begin(), allPreviouslyKnownPublicTypes.end(), name); + if (public_known_it != allPreviouslyKnownPublicTypes.end()) { // create an empty navigator - auto v = std::make_shared<aron::type::Object>(*public_known_it, std::vector<std::string>(), std::vector<std::string>(), std::map<std::string, type::VariantPtr>(), path); + auto v = std::make_shared<aron::type::Object>(*public_known_it, + std::vector<std::string>(), + std::vector<std::string>(), + std::map<std::string, type::VariantPtr>(), + path); return v; } // only works during generation process (not for top-level). Used for templates. - const auto private_known_it = std::find(allPreviouslyKnownPrivateTypes.begin(), allPreviouslyKnownPrivateTypes.end(), name); - if(private_known_it != allPreviouslyKnownPrivateTypes.end()) + const auto private_known_it = std::find( + allPreviouslyKnownPrivateTypes.begin(), allPreviouslyKnownPrivateTypes.end(), name); + if (private_known_it != allPreviouslyKnownPrivateTypes.end()) { // create an empty navigator - auto v = std::make_shared<aron::type::Object>(*private_known_it, std::vector<std::string>(), std::vector<std::string>(), std::map<std::string, type::VariantPtr>(), path); + auto v = std::make_shared<aron::type::Object>(*private_known_it, + std::vector<std::string>(), + std::vector<std::string>(), + std::map<std::string, type::VariantPtr>(), + path); return v; } - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Cannot find a valid object.", name); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "Cannot find a valid object.", name); } - type::Maybe ReaderFactory::getMaybe(const RapidXmlReaderNode& n) const + type::Maybe + ReaderFactory::getMaybe(const RapidXmlReaderNode& n) const { if (util::AttributeIsTrue(n, constantes::OPTIONAL_ATTRIBUTE_NAME)) { @@ -169,35 +223,51 @@ namespace armarx::aron::typereader::xml return type::Maybe::NONE; } - void ReaderFactory::checkObjectMemberName(const std::string& s) const + void + ReaderFactory::checkObjectMemberName(const std::string& s) const { if (simox::alg::starts_with(s, "_") || simox::alg::ends_with(s, "_")) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "You used an invalid membername - '_' as starting or ending char is not allowed.", s); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, + "You used an invalid membername - '_' as starting or ending char is not allowed.", + s); } if (simox::alg::starts_with(s, "aron")) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "You used an invalid membername - The prefix 'aron' is used for codegeneration.", s); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, + "You used an invalid membername - The prefix 'aron' is used for codegeneration.", + s); } } - type::VariantPtr ReaderFactory::createObject(const RapidXmlReaderNode& node, const Path& path) + type::VariantPtr + ReaderFactory::createObject(const RapidXmlReaderNode& node, const Path& path) { if (path.hasElement()) { - throw error::AronException(__PRETTY_FUNCTION__, "Having an inner class is not supported anymore since Aron Version 'beta 0.2.3'. Please move the inner class definition to the <" + constantes::GENERATE_TYPES_TAG + ">-tag."); + throw error::AronException( + __PRETTY_FUNCTION__, + "Having an inner class is not supported anymore since Aron Version 'beta 0.2.3'. " + "Please move the inner class definition to the <" + + std::string(constantes::GENERATE_TYPES_TAG) + ">-tag."); } // ensured we are toplevel! const std::string name = util::GetAttribute(node, constantes::NAME_ATTRIBUTE_NAME); - const std::string extends = util::GetAttributeWithDefault(node, constantes::EXTENDS_ATTRIBUTE_NAME, ""); - auto templates = simox::alg::split(util::GetAttributeWithDefault(node, constantes::TEMPLATE_ATTRIBUTE_NAME, ""), ","); + const std::string extends = + util::GetAttributeWithDefault(node, constantes::EXTENDS_ATTRIBUTE_NAME, ""); + auto templates = simox::alg::split( + util::GetAttributeWithDefault(node, constantes::TEMPLATE_ATTRIBUTE_NAME, ""), ","); auto newObjectInfo = typereader::GenerateObjectInfo(); newObjectInfo.typeName = name; - newObjectInfo.doc_brief = util::GetAttributeWithDefault(node, constantes::DOC_BRIEF_ATTRIBUTE_NAME, ""); - newObjectInfo.doc_author = util::GetAttributeWithDefault(node, constantes::DOC_AUTHOR_ATTRIBUTE_NAME, ""); + newObjectInfo.doc_brief = + util::GetAttributeWithDefault(node, constantes::DOC_BRIEF_ATTRIBUTE_NAME, ""); + newObjectInfo.doc_author = + util::GetAttributeWithDefault(node, constantes::DOC_AUTHOR_ATTRIBUTE_NAME, ""); // reset private known types allPreviouslyKnownPrivateTypes = templates; @@ -219,7 +289,8 @@ namespace armarx::aron::typereader::xml if (util::HasAttribute(objectChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)) { - newObjectInfo.doc_members.insert({key, util::GetAttribute(objectChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); + newObjectInfo.doc_members.insert( + {key, util::GetAttribute(objectChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); } std::vector<RapidXmlReaderNode> children = objectChild.nodes(); @@ -230,7 +301,10 @@ namespace armarx::aron::typereader::xml if (childNavigator->getDescriptor() == aron::type::Descriptor::OBJECT) { // check if template args are present - std::vector<std::string> templates = simox::alg::split(util::GetAttributeWithDefault(children[0], constantes::TEMPLATE_ATTRIBUTE_NAME, ""), ","); + std::vector<std::string> templates = + simox::alg::split(util::GetAttributeWithDefault( + children[0], constantes::TEMPLATE_ATTRIBUTE_NAME, ""), + ","); auto obj = aron::type::Object::DynamicCastAndCheck(childNavigator); for (const auto& t : templates) { @@ -243,7 +317,8 @@ namespace armarx::aron::typereader::xml } // set the new object - auto aronObjectType = std::make_shared<type::Object>(name, templates, std::vector<std::string>(), members, objPath); + auto aronObjectType = std::make_shared<type::Object>( + name, templates, std::vector<std::string>(), members, objPath); if (extends != "") { @@ -258,7 +333,8 @@ namespace armarx::aron::typereader::xml return aronObjectType; } - type::VariantPtr ReaderFactory::createList(const RapidXmlReaderNode &node, const Path &path) + type::VariantPtr + ReaderFactory::createList(const RapidXmlReaderNode& node, const Path& path) { util::EnforceChildSize(node, 1); @@ -271,7 +347,8 @@ namespace armarx::aron::typereader::xml return o; } - type::VariantPtr ReaderFactory::createDict(const RapidXmlReaderNode &node, const Path &path) + type::VariantPtr + ReaderFactory::createDict(const RapidXmlReaderNode& node, const Path& path) { util::EnforceChildSize(node, 1); @@ -284,7 +361,8 @@ namespace armarx::aron::typereader::xml return o; } - type::VariantPtr ReaderFactory::createTuple(const RapidXmlReaderNode& node, const Path& path) + type::VariantPtr + ReaderFactory::createTuple(const RapidXmlReaderNode& node, const Path& path) { util::EnforceChildSizeGreater(node, 1); @@ -308,7 +386,8 @@ namespace armarx::aron::typereader::xml return o; } - type::VariantPtr ReaderFactory::createPair(const RapidXmlReaderNode& node, const Path& path) + type::VariantPtr + ReaderFactory::createPair(const RapidXmlReaderNode& node, const Path& path) { util::EnforceChildSize(node, 2); @@ -326,10 +405,10 @@ namespace armarx::aron::typereader::xml return o; } - type::VariantPtr ReaderFactory::createNDArray(const RapidXmlReaderNode& node, const Path& path) const + type::VariantPtr + ReaderFactory::createNDArray(const RapidXmlReaderNode& node, const Path& path) const { - static const std::map<std::string, type::ndarray::ElementType> String2NDArrayType = - { + static const std::map<std::string, type::ndarray::ElementType> String2NDArrayType = { {"int8", type::ndarray::ElementType::INT8}, {"int16", type::ndarray::ElementType::INT16}, {"int32", type::ndarray::ElementType::INT32}, @@ -337,22 +416,20 @@ namespace armarx::aron::typereader::xml {"uint16", type::ndarray::ElementType::UINT16}, {"uint32", type::ndarray::ElementType::UINT32}, {"float32", type::ndarray::ElementType::FLOAT32}, - {"float64", type::ndarray::ElementType::FLOAT64} - }; + {"float64", type::ndarray::ElementType::FLOAT64}}; return nullptr; } - type::VariantPtr ReaderFactory::createMatrix(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createMatrix(const RapidXmlReaderNode& node, const Path& path) const { - static const std::map<std::string, type::matrix::ElementType> String2MatrixType = - { + static const std::map<std::string, type::matrix::ElementType> String2MatrixType = { {"int16", type::matrix::ElementType::INT16}, {"int32", type::matrix::ElementType::INT32}, {"int64", type::matrix::ElementType::INT64}, {"float32", type::matrix::ElementType::FLOAT32}, - {"float64", type::matrix::ElementType::FLOAT64} - }; + {"float64", type::matrix::ElementType::FLOAT64}}; auto o = std::make_shared<type::Matrix>(path); util::EnforceChildSize(node, 0); @@ -361,18 +438,23 @@ namespace armarx::aron::typereader::xml auto rows_str = util::GetAttributeWithDefault(node, constantes::ROWS_ATTRIBUTE_NAME, "4"); auto cols_str = util::GetAttributeWithDefault(node, constantes::COLS_ATTRIBUTE_NAME, "4"); - if (std::find(constantes::WHATEVER_VALUES.begin(), constantes::WHATEVER_VALUES.end(), simox::alg::to_lower(rows_str)) != constantes::WHATEVER_VALUES.end()) + if (std::find(constantes::WHATEVER_VALUES.begin(), + constantes::WHATEVER_VALUES.end(), + simox::alg::to_lower(rows_str)) != constantes::WHATEVER_VALUES.end()) { rows_str = "-1"; } - if (std::find(constantes::WHATEVER_VALUES.begin(), constantes::WHATEVER_VALUES.end(), simox::alg::to_lower(cols_str)) != constantes::WHATEVER_VALUES.end()) + if (std::find(constantes::WHATEVER_VALUES.begin(), + constantes::WHATEVER_VALUES.end(), + simox::alg::to_lower(cols_str)) != constantes::WHATEVER_VALUES.end()) { cols_str = "-1"; } const int rows = std::stoi(rows_str); const int cols = std::stoi(cols_str); - std::string type = util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); + std::string type = + util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); o->setRows(rows); o->setCols(cols); @@ -382,24 +464,25 @@ namespace armarx::aron::typereader::xml } catch (std::out_of_range& e) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The type tag is not valid", type); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "The type tag is not valid", type); } return o; } - type::VariantPtr ReaderFactory::createQuaternion(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createQuaternion(const RapidXmlReaderNode& node, const Path& path) const { - static const std::map<std::string, type::quaternion::ElementType> String2QuaternionType = - { + static const std::map<std::string, type::quaternion::ElementType> String2QuaternionType = { {"float32", type::quaternion::ElementType::FLOAT32}, - {"float64", type::quaternion::ElementType::FLOAT64} - }; + {"float64", type::quaternion::ElementType::FLOAT64}}; auto o = std::make_shared<type::Quaternion>(path); util::EnforceChildSize(node, 0); util::EnforceAttribute(node, constantes::TYPE_ATTRIBUTE_NAME); - std::string type = util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); + std::string type = + util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); try { @@ -407,25 +490,24 @@ namespace armarx::aron::typereader::xml } catch (std::out_of_range& e) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The type tag is not valid", type); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "The type tag is not valid", type); } return o; } - - type::VariantPtr ReaderFactory::createImage(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createImage(const RapidXmlReaderNode& node, const Path& path) const { - static const std::map<std::string, type::image::PixelType> String2PixelType = - { - {"rgb24", type::image::PixelType::RGB24}, - {"depth32", type::image::PixelType::DEPTH32} - }; + static const std::map<std::string, type::image::PixelType> String2PixelType = { + {"rgb24", type::image::PixelType::RGB24}, {"depth32", type::image::PixelType::DEPTH32}}; auto o = std::make_shared<type::Image>(path); util::EnforceChildSize(node, 0); util::EnforceAttribute(node, constantes::TYPE_ATTRIBUTE_NAME); - std::string type = util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); + std::string type = + util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); try { @@ -433,45 +515,52 @@ namespace armarx::aron::typereader::xml } catch (std::out_of_range& e) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The type tag is not valid", type); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "The type tag is not valid", type); } return o; } - type::VariantPtr ReaderFactory::createPointCloud(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createPointCloud(const RapidXmlReaderNode& node, const Path& path) const { - static const std::map<std::string, type::pointcloud::VoxelType> String2VoxelType = - { + static const std::map<std::string, type::pointcloud::VoxelType> String2VoxelType = { {"pointxyz", type::pointcloud::VoxelType::POINT_XYZ}, {"pointxyzi", type::pointcloud::VoxelType::POINT_XYZI}, {"pointxyzl", type::pointcloud::VoxelType::POINT_XYZL}, {"pointxyzrgb", type::pointcloud::VoxelType::POINT_XYZRGB}, {"pointxyzrgbl", type::pointcloud::VoxelType::POINT_XYZRGBL}, {"pointxyzrgba", type::pointcloud::VoxelType::POINT_XYZRGBA}, - {"pointxyzhsv", type::pointcloud::VoxelType::POINT_XYZHSV} - }; + {"pointxyzhsv", type::pointcloud::VoxelType::POINT_XYZHSV}}; auto o = std::make_shared<type::PointCloud>(path); util::EnforceChildSize(node, 0); util::EnforceAttribute(node, constantes::TYPE_ATTRIBUTE_NAME); - std::string type = util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); + std::string type = + util::GetAttributeWithDefault(node, constantes::TYPE_ATTRIBUTE_NAME, "???"); try { o->setVoxelType(String2VoxelType.at(simox::alg::to_lower(type))); } catch (std::out_of_range& e) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The type tag is not valid", type); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "The type tag is not valid", type); } return o; } - type::VariantPtr ReaderFactory::createIntEnum(const RapidXmlReaderNode& node, const Path& path) + type::VariantPtr + ReaderFactory::createIntEnum(const RapidXmlReaderNode& node, const Path& path) { if (path.hasElement()) { - throw error::AronException(__PRETTY_FUNCTION__, "Having an inner int-enum is not supported anymore since Aron Version 'beta 0.2.3'. Please move the inner int-enum definition to the <" + constantes::GENERATE_TYPES_TAG + ">-tag."); + throw error::AronException( + __PRETTY_FUNCTION__, + "Having an inner int-enum is not supported anymore since Aron Version 'beta " + "0.2.3'. Please move the inner int-enum definition to the <" + + std::string(constantes::GENERATE_TYPES_TAG) + ">-tag."); } // ensured we are top-level! @@ -482,6 +571,10 @@ namespace armarx::aron::typereader::xml allPreviouslyKnownPrivateTypes.clear(); + std::string defaultValue = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, ""); + + // get accepted values std::map<std::string, int> acceptedValues; for (const RapidXmlReaderNode& valueChild : node.nodes()) { @@ -492,18 +585,40 @@ namespace armarx::aron::typereader::xml if (util::HasAttribute(valueChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)) { - newEnumInfo.doc_values.insert({key, util::GetAttribute(valueChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); + newEnumInfo.doc_values.insert( + {key, util::GetAttribute(valueChild, constantes::DOC_BRIEF_ATTRIBUTE_NAME)}); } - const std::string value = util::GetAttribute(valueChild, constantes::VALUE_ATTRIBUTE_NAME); + const std::string value = + util::GetAttribute(valueChild, constantes::VALUE_ATTRIBUTE_NAME); + + // Overwrite default value if child is tagged as default + if (util::HasAttribute(valueChild, constantes::DEFAULT_ATTRIBUTE_NAME)) + { + defaultValue = key; + } acceptedValues.emplace(key, std::stoi(value)); } + if (acceptedValues.size() == 0) + { + printWarning("Found enum '" + name + "' without any members..."); + } + + // check default value + if (not defaultValue.empty() and not acceptedValues.contains(defaultValue)) + { + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "An int enum has a non existing default value set", + defaultValue); + } + + // create the int enum aron::Path enumPath = path; // copy, just in case there are special things set enumPath.setRootIdentifier(name); // set the root identifier to the obj name - auto o = std::make_shared<type::IntEnum>(name, acceptedValues, enumPath); + auto o = std::make_shared<type::IntEnum>(name, acceptedValues, defaultValue, enumPath); newEnumInfo.correspondingType = o; allGeneratedPublicIntEnums.emplace(newEnumInfo.typeName, newEnumInfo); @@ -512,38 +627,57 @@ namespace armarx::aron::typereader::xml return o; } - type::VariantPtr ReaderFactory::createInt(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createInt(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::Int>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, "0"); + return std::make_shared<type::Int>(simox::alg::to_<int>(def), path); } - type::VariantPtr ReaderFactory::createLong(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createLong(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::Long>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, "0"); + return std::make_shared<type::Long>(simox::alg::to_<long>(def), path); } - type::VariantPtr ReaderFactory::createFloat(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createFloat(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::Float>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, "0.0"); + return std::make_shared<type::Float>(simox::alg::to_<float>(def), path); } - type::VariantPtr ReaderFactory::createDouble(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createDouble(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::Double>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, "0.0"); + return std::make_shared<type::Double>(simox::alg::to_<double>(def), path); } - type::VariantPtr ReaderFactory::createString(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createString(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::String>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, ""); + return std::make_shared<type::String>(def, path); } - type::VariantPtr ReaderFactory::createBool(const RapidXmlReaderNode &node, const Path &path) const + type::VariantPtr + ReaderFactory::createBool(const RapidXmlReaderNode& node, const Path& path) const { - return std::make_shared<type::Bool>(path); + const std::string def = + util::GetAttributeWithDefault(node, constantes::DEFAULT_ATTRIBUTE_NAME, "false"); + return std::make_shared<type::Bool>(simox::alg::to_<bool>(def), path); } - type::VariantPtr ReaderFactory::createAnyObject(const RapidXmlReaderNode& node, const Path& path) const + type::VariantPtr + ReaderFactory::createAnyObject(const RapidXmlReaderNode& node, const Path& path) const { return std::make_shared<type::AnyObject>(path); } -} +} // namespace armarx::aron::typereader::xml diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt index 2fb890b86fb3c9e1bd26bee37f879922c3d6bcd5..6e3ef85cf5ef086450a9896003476d788bcfa69f 100644 --- a/source/RobotAPI/libraries/aron/core/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -83,6 +83,9 @@ set(LIB_FILES type/rw/reader/variant/VariantReader.cpp type/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp + type/rw/json/Data.cpp + data/rw/json/Data.cpp + data/visitor/Visitor.cpp data/visitor/RecursiveVisitor.cpp data/visitor/variant/VariantVisitor.cpp diff --git a/source/RobotAPI/libraries/aron/core/Exception.h b/source/RobotAPI/libraries/aron/core/Exception.h index fc080bafd09e2d7424bf0fc18538539f680329da..3bc7ea7f0264a6a3442b050d131790931c28bd94 100644 --- a/source/RobotAPI/libraries/aron/core/Exception.h +++ b/source/RobotAPI/libraries/aron/core/Exception.h @@ -26,36 +26,39 @@ // STD/STL // ArmarX +#include <ArmarXCore/core/exceptions/Exception.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <ArmarXCore/core/logging/Logging.h> + #include <RobotAPI/interface/aron.h> -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/core/Path.h> #include <RobotAPI/libraries/aron/core/Descriptor.h> - +#include <RobotAPI/libraries/aron/core/Path.h> namespace armarx::aron::error { /** * @brief A base class for aron exceptions. All aron exceptions inherit from this class */ - class AronException : - public armarx::LocalException + class AronException : public armarx::LocalException { public: AronException() = delete; + AronException(const std::string& prettymethod, const std::string& reason) : LocalException(prettymethod + ": " + reason + ".") { } - AronException(const std::string& prettymethod, const std::string& reason, const Path& path) : + AronException(const std::string& prettymethod, + const std::string& reason, + const Path& path) : LocalException(prettymethod + ": " + reason + ". The path was: " + path.toString()) { } /// call operator to append a message to the exception. Used by ARMARX_CHECK_AND_THROW - AronException& operator()(const std::string& additionalMessage = "") + AronException& + operator()(const std::string& additionalMessage = "") { auto currentReason = getReason(); setReason(currentReason + ". Additional Message: " + additionalMessage); @@ -63,16 +66,15 @@ namespace armarx::aron::error } }; - /** - * @brief A base class for aron exceptions. All aron exceptions inherit from this class - */ - class AronEOFException : - public AronException + class AronEOFException : public AronException { public: AronEOFException() = delete; + AronEOFException(const std::string& prettymethod) : - AronException(prettymethod, "REACHED THE END OF A NON VOID METHOD. PERHAPS YOU FORGOT TO ADD A VALUE TO SOME SWITCH-CASE STATEMEMT?.") + AronException(prettymethod, + "REACHED THE END OF A NON VOID METHOD. PERHAPS YOU FORGOT TO ADD A VALUE " + "TO SOME SWITCH-CASE STATEMEMT?.") { } }; @@ -80,11 +82,11 @@ namespace armarx::aron::error /** * @brief The NotImplementedYetException class */ - class NotImplementedYetException : - public AronException + class NotImplementedYetException : public AronException { public: NotImplementedYetException() = delete; + NotImplementedYetException(const std::string& prettymethod) : AronException(prettymethod, "This method is not yet implemented!") { @@ -94,66 +96,86 @@ namespace armarx::aron::error /** * @brief The AronNotValidException class. Takes a dto object as input */ - class AronNotValidException : - public AronException + class AronNotValidException : public AronException { public: AronNotValidException() = delete; - AronNotValidException(const std::string& prettymethod, const std::string& reason, const data::dto::GenericDataPtr& data) : + + AronNotValidException(const std::string& prettymethod, + const std::string& reason, + const data::dto::GenericDataPtr& data) : AronException(prettymethod, reason + ". The ice_id of the data was: " + data->ice_id()) { - } - AronNotValidException(const std::string& prettymethod, const std::string& reason, const data::dto::GenericDataPtr& data, const Path& path) : - AronException(prettymethod, reason + ". The ice_id of the data was: " + data->ice_id(), path) + AronNotValidException(const std::string& prettymethod, + const std::string& reason, + const data::dto::GenericDataPtr& data, + const Path& path) : + AronException(prettymethod, + reason + ". The ice_id of the data was: " + data->ice_id(), + path) { - } - AronNotValidException(const std::string& prettymethod, const std::string& reason, const type::dto::GenericTypePtr& type) : + AronNotValidException(const std::string& prettymethod, + const std::string& reason, + const type::dto::GenericTypePtr& type) : AronException(prettymethod, reason + ". The ice_id of the type was: " + type->ice_id()) { - } - AronNotValidException(const std::string& prettymethod, const std::string& reason, const type::dto::GenericTypePtr& type, const Path& path) : - AronException(prettymethod, reason + ". The ice_id of the type was: " + type->ice_id(), path) + AronNotValidException(const std::string& prettymethod, + const std::string& reason, + const type::dto::GenericTypePtr& type, + const Path& path) : + AronException(prettymethod, + reason + ". The ice_id of the type was: " + type->ice_id(), + path) { - } }; /** * @brief The ValueNotValidException class. Only takes strings as input (convert before) */ - class ValueNotValidException : - public AronException + class ValueNotValidException : public AronException { public: ValueNotValidException() = delete; - ValueNotValidException(const std::string& prettymethod, const std::string& reason, const std::string& input) : + + ValueNotValidException(const std::string& prettymethod, + const std::string& reason, + const std::string& input) : AronException(prettymethod, reason + ". Got: " + input) { - } - ValueNotValidException(const std::string& prettymethod, const std::string& reason, const std::string& input, const Path& path) : + ValueNotValidException(const std::string& prettymethod, + const std::string& reason, + const std::string& input, + const Path& path) : AronException(prettymethod, reason + ". Got: " + input, path) { - } - ValueNotValidException(const std::string& prettymethod, const std::string& reason, const std::string& input, const std::string& expectation) : + ValueNotValidException(const std::string& prettymethod, + const std::string& reason, + const std::string& input, + const std::string& expectation) : AronException(prettymethod, reason + ". Got: " + input + ". Expected: " + expectation) { - } - ValueNotValidException(const std::string& prettymethod, const std::string& reason, const std::string& input, const std::string& expectation, const Path& path) : - AronException(prettymethod, reason + ". Got: " + input + ". Expected: " + expectation, path) + ValueNotValidException(const std::string& prettymethod, + const std::string& reason, + const std::string& input, + const std::string& expectation, + const Path& path) : + AronException(prettymethod, + reason + ". Got: " + input + ". Expected: " + expectation, + path) { - } }; -} +} // namespace armarx::aron::error diff --git a/source/RobotAPI/libraries/aron/core/Path.cpp b/source/RobotAPI/libraries/aron/core/Path.cpp index 8d15ca0c810a94fb2972c451ca87cf01758088f7..c80e00f53c989b8aadd4618757aaa3c6a588dc4a 100644 --- a/source/RobotAPI/libraries/aron/core/Path.cpp +++ b/source/RobotAPI/libraries/aron/core/Path.cpp @@ -235,4 +235,38 @@ namespace armarx::aron ret.setDelimeter(delimeter); return ret; } + + bool + Path::hasPrefix(const Path& e) const + { + const auto& p = e.getPath(); + + if (path.size() < p.size()) + { + // prefix is impossible + return false; + } + + int i = 0; + for (const auto& el : path) + { + if (el != path[i++]) + { + return false; + } + } + + return true; + } + + bool + Path::hasDirectPrefix(const Path& e) const + { + const auto& p = e.getPath(); + if (p.size() + 1 != path.size()) + { + return false; + } + return hasPrefix(e); + } } // namespace armarx::aron diff --git a/source/RobotAPI/libraries/aron/core/Path.h b/source/RobotAPI/libraries/aron/core/Path.h index a88a00d84317ee20526d06334ebac5e829020591..888327fd929309cde7575133be27649b1a57bcd9 100644 --- a/source/RobotAPI/libraries/aron/core/Path.h +++ b/source/RobotAPI/libraries/aron/core/Path.h @@ -80,6 +80,9 @@ namespace armarx::aron Path withDetachedLastElement() const; Path getWithoutPrefix(const Path&) const; + bool hasPrefix(const Path&) const; + bool hasDirectPrefix(const Path&) const; + private: void append(const std::string&); diff --git a/source/RobotAPI/libraries/aron/core/data/rw/json/Data.cpp b/source/RobotAPI/libraries/aron/core/data/rw/json/Data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df60876fbdd629f5c43d7a3fd2efb3f2a28ba1f0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/data/rw/json/Data.cpp @@ -0,0 +1,21 @@ +/* +* 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/>. +* +* @author Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#include "Data.h" diff --git a/source/RobotAPI/libraries/aron/core/data/variant/Variant.h b/source/RobotAPI/libraries/aron/core/data/variant/Variant.h index 1fab338ab2df57c267c841ac9297c533632bc46a..cc01ef83979306defb363ce9bdbf0089920ad747 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/Variant.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/Variant.h @@ -30,10 +30,9 @@ // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/core/Path.h> -#include <RobotAPI/libraries/aron/core/Exception.h> #include <RobotAPI/libraries/aron/core/Descriptor.h> - +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Path.h> #include <RobotAPI/libraries/aron/core/type/variant/Variant.h> namespace armarx::aron::data @@ -66,16 +65,19 @@ namespace armarx::aron::data public: // constructors Variant() = delete; + Variant(const data::Descriptor& descriptor, const Path& path) : - descriptor(descriptor), - path(path) + descriptor(descriptor), path(path) { } + virtual ~Variant() = default; // operators virtual bool operator==(const Variant& other) const = 0; - bool operator==(const VariantPtr& other) const + + bool + operator==(const VariantPtr& other) const { if (!other) { @@ -90,25 +92,29 @@ namespace armarx::aron::data static VariantPtr FromAronDTO(const data::dto::GenericDataPtr&, const Path& = Path()); /// create a list of variants from a list of dto objects - static std::vector<VariantPtr> FromAronDTO(const std::vector<data::dto::GenericDataPtr>&, const Path& = Path()); + static std::vector<VariantPtr> FromAronDTO(const std::vector<data::dto::GenericDataPtr>&, + const Path& = Path()); /// return a list of dto objects from a list of variant objects static std::vector<data::dto::GenericDataPtr> ToAronDTO(const std::vector<VariantPtr>&); /// getter for the descriptor enum - data::Descriptor getDescriptor() const + data::Descriptor + getDescriptor() const { return descriptor; } /// get the path - Path getPath() const + Path + getPath() const { return path; } /// get the path as string - std::string pathToString() const + std::string + pathToString() const { return path.toString(); } @@ -116,6 +122,7 @@ namespace armarx::aron::data // virtual definitions /// get a pointer to a copy of this variant virtual VariantPtr cloneAsVariant() const = 0; + virtual VariantPtr cloneAsVariant(const Path& newPath) const = 0; /// get the children of a data variant virtual std::vector<VariantPtr> getChildren() const = 0; @@ -154,4 +161,4 @@ namespace armarx::aron::data template <class T> concept isVariant = std::is_base_of<Variant, T>::value; -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.cpp b/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.cpp index 483088aa7ffaf706271072d5e13d55f26b8e4ec4..dbe828b0e92797b427b6f6f10ef16b5d46eb551d 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.cpp @@ -35,23 +35,31 @@ namespace armarx::aron::data { // constructors NDArray::NDArray(const Path& path) : - detail::ComplexVariant<data::dto::NDArray, NDArray>::ComplexVariant(data::Descriptor::NDARRAY, path) + detail::ComplexVariant<data::dto::NDArray, NDArray>::ComplexVariant( + data::Descriptor::NDARRAY, + path) { - } NDArray::NDArray(const data::dto::NDArrayPtr& o, const Path& path) : - detail::ComplexVariant<data::dto::NDArray, NDArray>::ComplexVariant(o, data::Descriptor::NDARRAY, path) + detail::ComplexVariant<data::dto::NDArray, NDArray>::ComplexVariant( + o, + data::Descriptor::NDARRAY, + path) { } - NDArray::NDArray(const std::vector<int>& dim, const std::string& t, const std::vector<unsigned char>& data, const Path& path) : + NDArray::NDArray(const std::vector<int>& dim, + const std::string& t, + const std::vector<unsigned char>& data, + const Path& path) : NDArray(data::dto::NDArrayPtr(new data::dto::NDArray(aron::VERSION, dim, t, data)), path) { } // operators - bool NDArray::operator==(const NDArray& other) const + bool + NDArray::operator==(const NDArray& other) const { const auto otherAron = other.toNDArrayDTO(); if (aron->shape != otherAron->shape) @@ -69,7 +77,9 @@ namespace armarx::aron::data } return true; } - bool NDArray::operator==(const NDArrayPtr& other) const + + bool + NDArray::operator==(const NDArrayPtr& other) const { if (!other) { @@ -78,8 +88,16 @@ namespace armarx::aron::data return *this == *other; } + NDArrayPtr + NDArray::clone(const Path& p) const + { + NDArrayPtr ret(new NDArray(getShape(), getType(), getDataAsVector(), p)); + return ret; + } + // static methods - NDArrayPtr NDArray::FromNDArrayDTO(const data::dto::NDArrayPtr& aron) + NDArrayPtr + NDArray::FromNDArrayDTO(const data::dto::NDArrayPtr& aron) { if (!aron) { @@ -88,13 +106,15 @@ namespace armarx::aron::data return std::make_shared<NDArray>(aron); } - data::dto::NDArrayPtr NDArray::ToNDArrayDTO(const NDArrayPtr& variant) + data::dto::NDArrayPtr + NDArray::ToNDArrayDTO(const NDArrayPtr& variant) { return variant ? variant->toNDArrayDTO() : nullptr; } // public member functions - DictPtr NDArray::getAsDict() const + DictPtr + NDArray::getAsDict() const { auto dict = std::make_shared<Dict>(); auto copy_this = FromAronDTO(toAronDTO(), getPath()); @@ -102,43 +122,51 @@ namespace armarx::aron::data return dict; } - unsigned char* NDArray::getData() const + unsigned char* + NDArray::getData() const { return aron->data.data(); } - void NDArray::setData(unsigned int elements, const unsigned char* src) + void + NDArray::setData(unsigned int elements, const unsigned char* src) { aron->data = std::vector<unsigned char>(elements); std::memcpy(aron->data.data(), src, elements); } - std::vector<unsigned char> NDArray::getDataAsVector() const + std::vector<unsigned char> + NDArray::getDataAsVector() const { return aron->data; } - std::vector<int> NDArray::getShape() const + std::vector<int> + NDArray::getShape() const { return aron->shape; } - void NDArray::setShape(const std::vector<int>& d) + void + NDArray::setShape(const std::vector<int>& d) { aron->shape = d; } - void NDArray::addToShape(int i) + void + NDArray::addToShape(int i) { aron->shape.push_back(i); } - std::string NDArray::getType() const + std::string + NDArray::getType() const { return aron->type; } - void NDArray::setType(const std::string& t) + void + NDArray::setType(const std::string& t) { if (t.empty()) { @@ -149,76 +177,85 @@ namespace armarx::aron::data aron->type = t; } - data::dto::NDArrayPtr NDArray::toNDArrayDTO() const + data::dto::NDArrayPtr + NDArray::toNDArrayDTO() const { return aron; } // virtual implementations - std::string NDArray::getShortName() const + std::string + NDArray::getShortName() const { return "NDArray"; } - std::string NDArray::getFullName() const + std::string + NDArray::getFullName() const { - return "armarx::aron::data::NDArray<" + simox::alg::to_string(aron->shape, ", ") + ", " + aron->type + ">"; + return "armarx::aron::data::NDArray<" + simox::alg::to_string(aron->shape, ", ") + ", " + + aron->type + ">"; } - type::VariantPtr NDArray::recalculateType() const + type::VariantPtr + NDArray::recalculateType() const { ARMARX_TRACE; throw error::NotImplementedYetException(__PRETTY_FUNCTION__); } - bool NDArray::fullfillsType(const type::VariantPtr& type) const + bool + NDArray::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; type::Descriptor typeDesc = type->getDescriptor(); switch (typeDesc) { - case type::Descriptor::MATRIX: - { - auto casted = type::Matrix::DynamicCastAndCheck(type); - ARMARX_TRACE; - return (aron->shape.size() == 3 && aron->shape[0] == casted->getRows() && aron->shape[1] == casted->getCols()); - } - case type::Descriptor::QUATERNION: - { - auto casted = type::Quaternion::DynamicCastAndCheck(type); - ARMARX_TRACE; - return (aron->shape.size() == 3 && aron->shape[0] == 1 && aron->shape[1] == 4); - } - case type::Descriptor::POINTCLOUD: - { - auto casted = type::PointCloud::DynamicCastAndCheck(type); - ARMARX_TRACE; - return (aron->shape.size() == 3); - } - case type::Descriptor::IMAGE: - { - auto casted = type::Image::DynamicCastAndCheck(type); - ARMARX_TRACE; - return (aron->shape.size() == 3); - } - case type::Descriptor::NDARRAY: - { - auto casted = type::NDArray::DynamicCastAndCheck(type); - ARMARX_TRACE; - return (aron->shape.size() == (unsigned int) casted->getNumberDimensions()); - } - default: - ARMARX_TRACE; - return false; + case type::Descriptor::MATRIX: + { + auto casted = type::Matrix::DynamicCastAndCheck(type); + ARMARX_TRACE; + return (aron->shape.size() == 3 && aron->shape[0] == casted->getRows() && + aron->shape[1] == casted->getCols()); + } + case type::Descriptor::QUATERNION: + { + auto casted = type::Quaternion::DynamicCastAndCheck(type); + ARMARX_TRACE; + return (aron->shape.size() == 3 && aron->shape[0] == 1 && aron->shape[1] == 4); + } + case type::Descriptor::POINTCLOUD: + { + auto casted = type::PointCloud::DynamicCastAndCheck(type); + ARMARX_TRACE; + return (aron->shape.size() == 3); + } + case type::Descriptor::IMAGE: + { + auto casted = type::Image::DynamicCastAndCheck(type); + ARMARX_TRACE; + return (aron->shape.size() == 3); + } + case type::Descriptor::NDARRAY: + { + auto casted = type::NDArray::DynamicCastAndCheck(type); + ARMARX_TRACE; + return (aron->shape.size() == (unsigned int)casted->getNumberDimensions()); + } + default: + ARMARX_TRACE; + return false; } } - std::string NDArray::DimensionsToString(const std::vector<int>& dimensions) + std::string + NDArray::DimensionsToString(const std::vector<int>& dimensions) { std::stringstream ss; ss << "(" << simox::alg::join(simox::alg::multi_to_string(dimensions), ", ") << ")"; return ss.str(); } -} // namespace armarx::aron::datanavigator +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h b/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h index 068fd1a85cebc436ca6c1330c59c6d88ba9f183c..6d4203071c29b0d1d20123f85a4263d4c74db58b 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h @@ -26,8 +26,8 @@ // STD/STL #include <cstddef> #include <functional> -#include <memory> #include <map> +#include <memory> #include <numeric> #include <vector> @@ -40,20 +40,21 @@ // Types #include "../../../type/variant/ndarray/All.h" - namespace armarx::aron::data { class NDArray; using NDArrayPtr = std::shared_ptr<NDArray>; - class NDArray : - public detail::ComplexVariant<data::dto::NDArray, NDArray> + class NDArray : public detail::ComplexVariant<data::dto::NDArray, NDArray> { public: // constructors NDArray(const Path& path = Path()); NDArray(const data::dto::NDArrayPtr&, const Path& path = Path()); - NDArray(const std::vector<int>&, const std::string&, const std::vector<unsigned char>&, const Path& path = Path()); + NDArray(const std::vector<int>&, + const std::string&, + const std::vector<unsigned char>&, + const Path& path = Path()); // operators virtual bool operator==(const NDArray&) const override; @@ -84,11 +85,8 @@ namespace armarx::aron::data data::dto::NDArrayPtr toNDArrayDTO() const; // virtual implementations - NDArrayPtr clone() const override - { - NDArrayPtr ret(new NDArray(getShape(), getType(), getDataAsVector(), getPath())); - return ret; - } + using Base::clone; + NDArrayPtr clone(const Path& p) const override; virtual std::string getShortName() const override; virtual std::string getFullName() const override; @@ -96,13 +94,14 @@ namespace armarx::aron::data virtual type::VariantPtr recalculateType() const override; virtual bool fullfillsType(const type::VariantPtr&) const override; }; -} +} // namespace armarx::aron::data namespace armarx::aron { - template<typename... _Args> - aron::data::NDArrayPtr make_ndarray(_Args&&... args) + template <typename... _Args> + aron::data::NDArrayPtr + make_ndarray(_Args&&... args) { return std::make_shared<aron::data::NDArray>(args...); } -} +} // namespace armarx::aron diff --git a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp index 9724ae6279a2b2a2140d5964d7d101f6e9fbabc8..93400fe1761849e97c4e4c228eeae3b5e60e0047 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp @@ -36,12 +36,15 @@ namespace armarx::aron::data // constructors Dict::Dict(const Path& path) : - detail::ContainerVariant<data::dto::Dict, Dict>::ContainerVariant(data::Descriptor::DICT, path) + detail::ContainerVariant<data::dto::Dict, Dict>::ContainerVariant(data::Descriptor::DICT, + path) { } Dict::Dict(const data::dto::DictPtr& o, const Path& path) : - detail::ContainerVariant<data::dto::Dict, Dict>::ContainerVariant(o, data::Descriptor::DICT, path) + detail::ContainerVariant<data::dto::Dict, Dict>::ContainerVariant(o, + data::Descriptor::DICT, + path) { for (const auto& [key, dataPtr] : this->aron->elements) { @@ -49,8 +52,7 @@ namespace armarx::aron::data } } - Dict::Dict(const std::map<std::string, VariantPtr>& m, const Path& path) : - Dict(path) + Dict::Dict(const std::map<std::string, VariantPtr>& m, const Path& path) : Dict(path) { for (const auto& [key, dataPtr] : m) { @@ -59,7 +61,8 @@ namespace armarx::aron::data } // operators - bool Dict::operator==(const Dict& other) const + bool + Dict::operator==(const Dict& other) const { for (const auto& [key, nav] : childrenNavigators) { @@ -69,7 +72,7 @@ namespace armarx::aron::data } if (!nav) { - return !((bool) other.getElement(key)); + return !((bool)other.getElement(key)); } if (not(*nav == *other.getElement(key))) { @@ -78,7 +81,9 @@ namespace armarx::aron::data } return true; } - bool Dict::operator==(const DictPtr& other) const + + bool + Dict::operator==(const DictPtr& other) const { if (!other) { @@ -86,19 +91,35 @@ namespace armarx::aron::data } return *this == *other; } - VariantPtr Dict::operator[](const std::string& s) const + + VariantPtr + Dict::operator[](const std::string& s) const { return getElement(s); } - Dict& Dict::operator=(const Dict& other) + + Dict& + Dict::operator=(const Dict& other) { this->aron = other.aron; this->childrenNavigators = other.childrenNavigators; return *this; } + DictPtr + Dict::clone(const Path& p) const + { + DictPtr ret(new Dict(p)); + for (const auto& [key, val] : getElements()) + { + ret->addElement(key, val->cloneAsVariant()); + } + return ret; + } + // static methods - DictPtr Dict::FromAronDictDTO(const data::dto::DictPtr& aron) + DictPtr + Dict::FromAronDictDTO(const data::dto::DictPtr& aron) { if (!aron) { @@ -107,18 +128,21 @@ namespace armarx::aron::data return std::make_shared<Dict>(aron); } - data::dto::DictPtr Dict::ToAronDictDTO(const DictPtr& navigator) + data::dto::DictPtr + Dict::ToAronDictDTO(const DictPtr& navigator) { return navigator ? navigator->toAronDictDTO() : nullptr; } - data::dto::DictPtr Dict::toAronDictDTO() const + data::dto::DictPtr + Dict::toAronDictDTO() const { return aron; } // public member functions - std::vector<std::string> Dict::getAllKeys() const + std::vector<std::string> + Dict::getAllKeys() const { std::vector<std::string> ret; for (const auto& [key, _] : childrenNavigators) @@ -128,44 +152,74 @@ namespace armarx::aron::data return ret; } - std::string Dict::getAllKeysAsString() const + std::string + Dict::getAllKeysAsString() const { return simox::alg::to_string(getAllKeys(), ", "); } - void Dict::addElement(const std::string& key, const VariantPtr& data) + void + Dict::addElement(const std::string& key, const VariantPtr& data) { if (hasElement(key)) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "The key '"+key+"' already exists in a aron dict."); + throw error::AronException(__PRETTY_FUNCTION__, + "The key '" + key + "' already exists in a aron dict."); } setElement(key, data); } - bool Dict::hasElement(const std::string& key) const + void + Dict::addElementCopy(const std::string& key, const VariantPtr& data) + { + if (hasElement(key)) + { + ARMARX_TRACE; + throw error::AronException(__PRETTY_FUNCTION__, + "The key '" + key + "' already exists in a aron dict."); + } + setElementCopy(key, data); + } + + bool + Dict::hasElement(const std::string& key) const { return childrenNavigators.count(key) > 0; } - VariantPtr Dict::getElement(const std::string& key) const + VariantPtr + Dict::getElement(const std::string& key) const { auto it = childrenNavigators.find(key); if (it == childrenNavigators.end()) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Could not find key '" + key + "'. But I found the following keys: [" + simox::alg::join(this->getAllKeys(), ", ") + "]", getPath()); + throw error::AronException(__PRETTY_FUNCTION__, + "Could not find key '" + key + + "'. But I found the following keys: [" + + simox::alg::join(this->getAllKeys(), ", ") + "]", + getPath()); } return it->second; } - std::map<std::string, VariantPtr> Dict::getElements() const + std::map<std::string, VariantPtr> + Dict::getElements() const { return childrenNavigators; } - void Dict::setElement(const std::string& key, const VariantPtr& data) + void + Dict::setElement(const std::string& key, const VariantPtr& data) { + const auto& p = data->getPath(); + if (not p.hasDirectPrefix(this->getPath())) + { + ARMARX_WARNING << "An element added to a dict does not have a correct path set. This " + "may cause errors. Please use setElemetCopy() instead."; + } + this->childrenNavigators[key] = data; if (data) { @@ -177,44 +231,60 @@ namespace armarx::aron::data } } - void Dict::removeElement(const std::string& key) + void + Dict::setElementCopy(const std::string& key, const VariantPtr& data) + { + Path newPath = getPath().withElement(key); + auto copy = data->cloneAsVariant(newPath); + setElement(key, copy); + } + + void + Dict::removeElement(const std::string& key) { childrenNavigators.erase(key); aron->elements.erase(key); } - void Dict::clear() + void + Dict::clear() { childrenNavigators.clear(); aron->elements.clear(); } - VariantPtr Dict::at(const std::string& s) const + VariantPtr + Dict::at(const std::string& s) const { return getElement(s); } // virtual implementations - std::string Dict::getShortName() const + std::string + Dict::getShortName() const { return "Dict"; } - std::string Dict::getFullName() const + std::string + Dict::getFullName() const { return "armarx::aron::data::Dict"; } // TODO - type::VariantPtr Dict::recalculateType() const + type::VariantPtr + Dict::recalculateType() const { ARMARX_TRACE; throw error::NotImplementedYetException(__PRETTY_FUNCTION__); } - bool Dict::fullfillsType(const type::VariantPtr& type) const + bool + Dict::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; type::Descriptor typeDesc = type->getDescriptor(); @@ -259,7 +329,7 @@ namespace armarx::aron::data auto dictTypeNav = type::Dict::DynamicCastAndCheck(type); for (const auto& [key, nav] : childrenNavigators) { - (void) key; + (void)key; auto childTypeNav = dictTypeNav->getAcceptedType(); if (!nav) { @@ -287,7 +357,8 @@ namespace armarx::aron::data } } - std::vector<VariantPtr> Dict::getChildren() const + std::vector<VariantPtr> + Dict::getChildren() const { std::vector<VariantPtr> ret(childrenNavigators.size()); for (const auto& [key, nav] : childrenNavigators) @@ -297,23 +368,27 @@ namespace armarx::aron::data return ret; } - size_t Dict::childrenSize() const + size_t + Dict::childrenSize() const { return childrenNavigators.size(); } - VariantPtr Dict::navigateAbsolute(const Path& path) const + VariantPtr + Dict::navigateAbsolute(const Path& path) const { if (!path.hasElement()) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate without a valid path", path); + throw error::AronException( + __PRETTY_FUNCTION__, "Could not navigate without a valid path", path); } std::string el = path.getFirstElement(); if (!hasElement(el)) { ARMARX_TRACE; - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not find an element of a path.", el, path); + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "Could not find an element of a path.", el, path); } if (path.size() == 1) @@ -326,9 +401,12 @@ namespace armarx::aron::data if (!childrenNavigators.at(el)) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate into a NULL member. Seems like the member is optional and not set.", next); + throw error::AronException(__PRETTY_FUNCTION__, + "Could not navigate into a NULL member. Seems like the " + "member is optional and not set.", + next); } return childrenNavigators.at(el)->navigateAbsolute(next); } } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.h b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.h index 5006a0c97a5b830f7d0998024ce2113d38af59a5..b31f12957d1b6ca4dac0b303f0b3259be89733f0 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.h @@ -24,25 +24,24 @@ #pragma once // STD/STL -#include <memory> #include <map> +#include <memory> #include <utility> // Base class #include "../detail/ContainerVariant.h" // ArmarX +#include "../../../type/variant/any/AnyObject.h" #include "../../../type/variant/container/Dict.h" #include "../../../type/variant/container/Object.h" -#include "../../../type/variant/any/AnyObject.h" namespace armarx::aron::data { class Dict; typedef std::shared_ptr<Dict> DictPtr; - class Dict : - public detail::ContainerVariant<data::dto::Dict, Dict> + class Dict : public detail::ContainerVariant<data::dto::Dict, Dict> { public: // constructors @@ -65,8 +64,10 @@ namespace armarx::aron::data std::string getAllKeysAsString() const; void addElement(const std::string& key, const VariantPtr& = nullptr); + void addElementCopy(const std::string& key, const VariantPtr& = nullptr); bool hasElement(const std::string&) const; void setElement(const std::string&, const VariantPtr& = nullptr); + void setElementCopy(const std::string&, const VariantPtr& = nullptr); VariantPtr getElement(const std::string&) const; std::map<std::string, VariantPtr> getElements() const; @@ -74,16 +75,9 @@ namespace armarx::aron::data void removeElement(const std::string& key); void clear(); - // virtual implementations - DictPtr clone() const override - { - DictPtr ret(new Dict(getPath())); - for (const auto& [key, val] : getElements()) - { - ret->addElement(key, val->cloneAsVariant()); - } - return ret; - } + // virtual implementations + using Base::clone; + DictPtr clone(const Path& p) const override; std::string getShortName() const override; std::string getFullName() const override; @@ -99,13 +93,14 @@ namespace armarx::aron::data // members std::map<std::string, VariantPtr> childrenNavigators; }; -} +} // namespace armarx::aron::data namespace armarx::aron { - template<typename... _Args> - aron::data::DictPtr make_dict(_Args&&... args) + template <typename... _Args> + aron::data::DictPtr + make_dict(_Args&&... args) { return std::make_shared<aron::data::Dict>(args...); } -} +} // namespace armarx::aron diff --git a/source/RobotAPI/libraries/aron/core/data/variant/container/List.cpp b/source/RobotAPI/libraries/aron/core/data/variant/container/List.cpp index c53b51ee1b04c3e903b4ddd718b9793d75303412..83e23f76f43ca4a7ebf8b057c51142256b5ba618 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/container/List.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/container/List.cpp @@ -37,12 +37,15 @@ namespace armarx::aron::data { // constructors List::List(const Path& path) : - detail::ContainerVariant<data::dto::List, List>::ContainerVariant(data::Descriptor::LIST, path) + detail::ContainerVariant<data::dto::List, List>::ContainerVariant(data::Descriptor::LIST, + path) { } List::List(const data::dto::ListPtr& l, const Path& path) : - detail::ContainerVariant<data::dto::List, List>::ContainerVariant(l, data::Descriptor::LIST, path) + detail::ContainerVariant<data::dto::List, List>::ContainerVariant(l, + data::Descriptor::LIST, + path) { unsigned int i = 0; for (const auto& dataPtr : l->elements) @@ -51,8 +54,7 @@ namespace armarx::aron::data } } - List::List(const std::vector<VariantPtr>& n, const Path& path) : - List(path) + List::List(const std::vector<VariantPtr>& n, const Path& path) : List(path) { for (const auto& dataPtr : n) { @@ -61,7 +63,8 @@ namespace armarx::aron::data } // operators - bool List::operator==(const List& other) const + bool + List::operator==(const List& other) const { unsigned int i = 0; for (const auto& nav : childrenNavigators) @@ -85,7 +88,9 @@ namespace armarx::aron::data } return true; } - bool List::operator==(const ListPtr& other) const + + bool + List::operator==(const ListPtr& other) const { if (!other) { @@ -94,8 +99,20 @@ namespace armarx::aron::data return *this == *other; } + ListPtr + List::clone(const Path& p) const + { + ListPtr ret(new List(p)); + for (const auto& val : getElements()) + { + ret->addElement(val->cloneAsVariant()); + } + return ret; + } + // static methods - ListPtr List::FromAronListDTO(const data::dto::ListPtr& aron) + ListPtr + List::FromAronListDTO(const data::dto::ListPtr& aron) { if (!aron) { @@ -104,13 +121,15 @@ namespace armarx::aron::data return std::make_shared<List>(aron); } - data::dto::ListPtr List::ToAronListDTO(const ListPtr& navigator) + data::dto::ListPtr + List::ToAronListDTO(const ListPtr& navigator) { return navigator ? navigator->toAronListDTO() : nullptr; } // public member functions - DictPtr List::getAsDict() const + DictPtr + List::getAsDict() const { auto dict = std::make_shared<Dict>(); auto copy_this = FromAronDTO(toAronDTO(), getPath()); @@ -118,17 +137,22 @@ namespace armarx::aron::data return dict; } - void List::addElement(const VariantPtr& n) + void + List::addElement(const VariantPtr& n) { setElement(aron->elements.size(), n); } - void List::setElement(unsigned int i, const VariantPtr& n) + void + List::setElement(unsigned int i, const VariantPtr& n) { if (i > aron->elements.size()) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Cannot set a listelement at index " + std::to_string(i) + " because this list has size " + std::to_string(aron->elements.size())); + throw error::AronException(__PRETTY_FUNCTION__, + "Cannot set a listelement at index " + std::to_string(i) + + " because this list has size " + + std::to_string(aron->elements.size())); } if (i == aron->elements.size()) @@ -157,66 +181,81 @@ namespace armarx::aron::data } } - bool List::hasElement(unsigned int i) const + bool + List::hasElement(unsigned int i) const { return i < childrenNavigators.size(); } - VariantPtr List::getElement(unsigned int i) const + VariantPtr + List::getElement(unsigned int i) const { if (i >= childrenNavigators.size()) { ARMARX_TRACE; - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "The index is out of bounds (size = " + std::to_string(childrenNavigators.size()) + ")", std::to_string(i), getPath()); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "The index is out of bounds (size = " + + std::to_string(childrenNavigators.size()) + ")", + std::to_string(i), + getPath()); } return childrenNavigators[i]; } - std::vector<VariantPtr> List::getElements() const + std::vector<VariantPtr> + List::getElements() const { return childrenNavigators; } - void List::removeElement(unsigned int i) + void + List::removeElement(unsigned int i) { // Use with care since this function will not work in a loop with increasing indexes - i = std::min((unsigned int) childrenNavigators.size()-1, i); + i = std::min((unsigned int)childrenNavigators.size() - 1, i); childrenNavigators.erase(childrenNavigators.begin() + i); aron->elements.erase(aron->elements.begin() + i); } - void List::clear() + void + List::clear() { childrenNavigators.clear(); aron->elements.clear(); } - data::dto::ListPtr List::toAronListDTO() const + data::dto::ListPtr + List::toAronListDTO() const { return aron; } // virtual implementations - std::string List::getShortName() const + std::string + List::getShortName() const { return "List"; } - std::string List::getFullName() const + std::string + List::getFullName() const { return "armarx::aron::data::List"; } // TODO - type::VariantPtr List::recalculateType() const + type::VariantPtr + List::recalculateType() const { ARMARX_TRACE; throw error::NotImplementedYetException(__PRETTY_FUNCTION__); } - bool List::fullfillsType(const type::VariantPtr& type) const + bool + List::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; type::Descriptor typeDesc = type->getDescriptor(); switch (typeDesc) @@ -310,7 +349,8 @@ namespace armarx::aron::data return false; } ARMARX_TRACE; - return childrenNavigators[0]->fullfillsType(firstChildTypeNav) && childrenNavigators[1]->fullfillsType(secondChildTypeNav); + return childrenNavigators[0]->fullfillsType(firstChildTypeNav) && + childrenNavigators[1]->fullfillsType(secondChildTypeNav); } default: ARMARX_TRACE; @@ -318,27 +358,35 @@ namespace armarx::aron::data } } - std::vector<VariantPtr> List::getChildren() const + std::vector<VariantPtr> + List::getChildren() const { return childrenNavigators; } - size_t List::childrenSize() const + size_t + List::childrenSize() const { return childrenNavigators.size(); } - VariantPtr List::navigateAbsolute(const Path& path) const + VariantPtr + List::navigateAbsolute(const Path& path) const { if (!path.hasElement()) { - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate without a valid path. The path was empty."); + throw error::AronException( + __PRETTY_FUNCTION__, + "Could not navigate without a valid path. The path was empty."); } unsigned int i = std::stoi(path.getFirstElement()); if (!hasElement(i)) { ARMARX_TRACE; - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Could not find an element of a path.", std::to_string(i), std::to_string(childrenSize())); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Could not find an element of a path.", + std::to_string(i), + std::to_string(childrenSize())); } if (path.size() == 1) @@ -351,9 +399,12 @@ namespace armarx::aron::data if (!childrenNavigators.at(i)) { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate into a NULL member. Seems like the member is optional and not set.", next); + throw error::AronException(__PRETTY_FUNCTION__, + "Could not navigate into a NULL member. Seems like the " + "member is optional and not set.", + next); } return childrenNavigators.at(i)->navigateAbsolute(next); } } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/container/List.h b/source/RobotAPI/libraries/aron/core/data/variant/container/List.h index 142f42ee66940c6a5fa6d99a616d4845719234e2..4d7074ca6b4f6e43a1172837c07423d3eb0f281e 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/container/List.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/container/List.h @@ -30,18 +30,17 @@ #include "../detail/SpecializedVariant.h" // ArmarX -#include "Dict.h" #include "../../../type/variant/container/List.h" #include "../../../type/variant/container/Pair.h" #include "../../../type/variant/container/Tuple.h" +#include "Dict.h" namespace armarx::aron::data { class List; typedef std::shared_ptr<List> ListPtr; - class List : - public detail::ContainerVariant<data::dto::List, List> + class List : public detail::ContainerVariant<data::dto::List, List> { public: // constructors @@ -73,15 +72,7 @@ namespace armarx::aron::data void clear(); // virtual implementations - ListPtr clone() const override - { - ListPtr ret(new List(getPath())); - for (const auto& val : getElements()) - { - ret->addElement(val->cloneAsVariant()); - } - return ret; - } + ListPtr clone(const Path& p) const override; std::string getShortName() const override; std::string getFullName() const override; @@ -96,13 +87,14 @@ namespace armarx::aron::data private: std::vector<VariantPtr> childrenNavigators; }; -} +} // namespace armarx::aron::data namespace armarx::aron { - template<typename... _Args> - aron::data::ListPtr make_list(_Args&&... args) + template <typename... _Args> + aron::data::ListPtr + make_list(_Args&&... args) { return std::make_shared<aron::data::List>(args...); } -} +} // namespace armarx::aron diff --git a/source/RobotAPI/libraries/aron/core/data/variant/detail/ComplexVariant.h b/source/RobotAPI/libraries/aron/core/data/variant/detail/ComplexVariant.h index 868b7a8df691a47458d1f8a73b319034627cbfb7..afececc9372a6b5494ac2d686594b553b4752233 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/detail/ComplexVariant.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/detail/ComplexVariant.h @@ -33,29 +33,36 @@ namespace armarx::aron::data::detail { - template<typename AronDataT, typename DerivedT> - class ComplexVariant : - public SpecializedVariantBase<AronDataT, DerivedT> + template <typename AronDataT, typename DerivedT> + class ComplexVariant : public SpecializedVariantBase<AronDataT, DerivedT> { public: - using SpecializedVariantBase<AronDataT, DerivedT>::SpecializedVariantBase; + using Base = SpecializedVariantBase<AronDataT, DerivedT>; + using Base::SpecializedVariantBase; virtual ~ComplexVariant() = default; // virtual implementations - VariantPtr navigateAbsolute(const Path &path) const override + VariantPtr + navigateAbsolute(const Path& path) const override { - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate through a non container navigator. The input path was: " + path.toString(), Variant::getPath()); + throw error::AronException( + __PRETTY_FUNCTION__, + "Could not navigate through a non container navigator. The input path was: " + + path.toString(), + Variant::getPath()); } - std::vector<VariantPtr> getChildren() const override + std::vector<VariantPtr> + getChildren() const override { return {}; } - size_t childrenSize() const override + size_t + childrenSize() const override { return 0; } }; -} +} // namespace armarx::aron::data::detail diff --git a/source/RobotAPI/libraries/aron/core/data/variant/detail/ContainerVariant.h b/source/RobotAPI/libraries/aron/core/data/variant/detail/ContainerVariant.h index 69fff7c78e637d961eebad2253327be056f4b7a0..042ef1227918ce2930c1df755958633daf8c26fa 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/detail/ContainerVariant.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/detail/ContainerVariant.h @@ -33,13 +33,13 @@ namespace armarx::aron::data::detail { - template<typename AronDataT, typename DerivedT> - class ContainerVariant : - public SpecializedVariantBase<AronDataT, DerivedT> + template <typename AronDataT, typename DerivedT> + class ContainerVariant : public SpecializedVariantBase<AronDataT, DerivedT> { public: - using SpecializedVariantBase<AronDataT, DerivedT>::SpecializedVariantBase; + using Base = SpecializedVariantBase<AronDataT, DerivedT>; + using Base::SpecializedVariantBase; virtual ~ContainerVariant() = default; }; -} +} // namespace armarx::aron::data::detail diff --git a/source/RobotAPI/libraries/aron/core/data/variant/detail/PrimitiveVariant.h b/source/RobotAPI/libraries/aron/core/data/variant/detail/PrimitiveVariant.h index 3b36c6310386a27122ae7607e41a137fc6420833..69cabb5ba160f3abef84d331b971c4146d866c29 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/detail/PrimitiveVariant.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/detail/PrimitiveVariant.h @@ -36,19 +36,21 @@ namespace armarx::aron::data::detail { - template<typename AronDataT, typename ValueT, typename DerivedT> - class PrimitiveVariant : - public SpecializedVariantBase<AronDataT, DerivedT> + template <typename AronDataT, typename ValueT, typename DerivedT> + class PrimitiveVariant : public SpecializedVariantBase<AronDataT, DerivedT> { public: + using Base = SpecializedVariantBase<AronDataT, DerivedT>; using PointerType = std::shared_ptr<DerivedT>; using ValueType = ValueT; public: - using SpecializedVariantBase<AronDataT, DerivedT>::SpecializedVariantBase; + using Base::SpecializedVariantBase; - PrimitiveVariant(const ValueT& v, const data::Descriptor descriptor, const Path& path = Path()): - SpecializedVariantBase<AronDataT, DerivedT>(descriptor, path) + PrimitiveVariant(const ValueT& v, + const data::Descriptor descriptor, + const Path& path = Path()) : + Base(descriptor, path) { this->aron->value = v; } @@ -60,7 +62,8 @@ namespace armarx::aron::data::detail return this->aron->value; } - DerivedT& operator=(const ValueT& x) + DerivedT& + operator=(const ValueT& x) { this->aron->value = x; return *this; @@ -76,23 +79,33 @@ namespace armarx::aron::data::detail virtual void fromString(const std::string& setter) = 0; // virtual implementations - VariantPtr navigateAbsolute(const Path &path) const override + VariantPtr + navigateAbsolute(const Path& path) const override { - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate through a non container navigator. The input path was: " + path.toString(), Variant::getPath()); + throw error::AronException( + __PRETTY_FUNCTION__, + "Could not navigate through a non container navigator. The input path was: " + + path.toString(), + Variant::getPath()); } - PointerType clone() const override + using Base::clone; + + PointerType + clone(const Path& newPath) const override { - PointerType ret(new DerivedT(getValue(), this->getPath())); + PointerType ret(new DerivedT(getValue(), newPath)); return ret; } - std::vector<VariantPtr> getChildren() const override + std::vector<VariantPtr> + getChildren() const override { return {}; } - size_t childrenSize() const override + size_t + childrenSize() const override { return 0; } @@ -100,7 +113,8 @@ namespace armarx::aron::data::detail // static methods /* public member functions */ - DictPtr getAsDict() const + DictPtr + getAsDict() const { auto dict = std::make_shared<Dict>(); auto copy_this = FromAronDTO(this->toAronDTO(), this->getPath()); @@ -108,18 +122,22 @@ namespace armarx::aron::data::detail return dict; } - void setValue(const ValueT& x) + void + setValue(const ValueT& x) { this->aron->value = x; } - ValueT getValue() const + + ValueT + getValue() const { return this->aron->value; } - ValueT& getValue() + ValueT& + getValue() { return this->aron->value; } }; -} +} // namespace armarx::aron::data::detail diff --git a/source/RobotAPI/libraries/aron/core/data/variant/detail/SpecializedVariant.h b/source/RobotAPI/libraries/aron/core/data/variant/detail/SpecializedVariant.h index d7e6e4a55cd9e96fed989b8a1a4f60e6a1c5d8b2..1ce3a07fae4061b8fa99f3777c4b4ab321803fed 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/detail/SpecializedVariant.h +++ b/source/RobotAPI/libraries/aron/core/data/variant/detail/SpecializedVariant.h @@ -35,11 +35,11 @@ namespace armarx::aron::data::detail { - template<typename AronDataT, typename DerivedT> - class SpecializedVariantBase : - public data::Variant + template <typename AronDataT, typename DerivedT> + class SpecializedVariantBase : public data::Variant { public: + using Base = data::Variant; using PointerType = std::shared_ptr<DerivedT>; using AronDataType = AronDataT; @@ -47,15 +47,15 @@ namespace armarx::aron::data::detail SpecializedVariantBase() = delete; SpecializedVariantBase(const data::Descriptor descriptor, const Path& path = Path()) : - Variant(descriptor, path), - aron(new AronDataType()) + Variant(descriptor, path), aron(new AronDataType()) { aron->VERSION = aron::VERSION; } - SpecializedVariantBase(const typename AronDataType::PointerType& o, const data::Descriptor descriptor, const Path& path = Path()) : - Variant(descriptor, path), - aron(o) + SpecializedVariantBase(const typename AronDataType::PointerType& o, + const data::Descriptor descriptor, + const Path& path = Path()) : + Variant(descriptor, path), aron(o) { ARMARX_CHECK_NOT_NULL(aron); } @@ -68,7 +68,8 @@ namespace armarx::aron::data::detail return aron; } - bool operator==(const Variant& other) const override + bool + operator==(const Variant& other) const override { const auto& n = DerivedT::DynamicCast(other); return *this == n; @@ -78,43 +79,61 @@ namespace armarx::aron::data::detail virtual bool operator==(const PointerType& other) const = 0; // new interface methods - virtual PointerType clone() const = 0; + virtual PointerType + clone() const + { + return clone(getPath()); + } + + virtual PointerType clone(const Path& newPath) const = 0; // virtual implementations - VariantPtr cloneAsVariant() const override + VariantPtr + cloneAsVariant() const override { return clone(); } - data::dto::GenericDataPtr toAronDTO() const override + VariantPtr + cloneAsVariant(const Path& newPath) const override + { + return clone(newPath); + } + + data::dto::GenericDataPtr + toAronDTO() const override { return aron; } - VariantPtr navigateRelative(const Path& path) const override + VariantPtr + navigateRelative(const Path& path) const override { Path absoluteFromHere = path.getWithoutPrefix(getPath()); return navigateAbsolute(absoluteFromHere); } - // static methods - static PointerType DynamicCast(const VariantPtr& n) + static PointerType + DynamicCast(const VariantPtr& n) { return std::dynamic_pointer_cast<DerivedT>(n); } - static DerivedT& DynamicCast(Variant& n) + static DerivedT& + DynamicCast(Variant& n) { return dynamic_cast<DerivedT&>(n); } - static const DerivedT& DynamicCast(const Variant& n) + static const DerivedT& + DynamicCast(const Variant& n) { return dynamic_cast<const DerivedT&>(n); } - static PointerType DynamicCastAndCheck(const VariantPtr& n) + static PointerType + DynamicCastAndCheck(const VariantPtr& n) { if (!n) { @@ -122,13 +141,17 @@ namespace armarx::aron::data::detail } PointerType casted = DerivedT::DynamicCast(n); - ARMARX_CHECK_NOT_NULL(casted) << "The path was: " << n->getPath().toString() << ".\n" - << "It has the descriptor: '" << data::defaultconversion::string::Descriptor2String.at(n->getDescriptor()) << "'.\n" - << "And the typeid: " << typeid(n).name() << ". Tried to cast to " << typeid(PointerType).name(); + ARMARX_CHECK_NOT_NULL(casted) + << "The path was: " << n->getPath().toString() << ".\n" + << "It has the descriptor: '" + << data::defaultconversion::string::Descriptor2String.at(n->getDescriptor()) + << "'.\n" + << "And the typeid: " << typeid(n).name() << ". Tried to cast to " + << typeid(PointerType).name(); return casted; } protected: typename AronDataType::PointerType aron; }; -} +} // namespace armarx::aron::data::detail diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Bool.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Bool.cpp index 2f7fe6fc8e486c43c32875c1cf072e721146c402..ed29f88c343ba218155b7510c28e496882349fe2 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Bool.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Bool.cpp @@ -27,22 +27,31 @@ namespace armarx::aron::data { /* constructors */ Bool::Bool(const data::dto::AronBoolPtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(o, data::Descriptor::BOOL, path) + detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant( + o, + data::Descriptor::BOOL, + path) { } Bool::Bool(const Path& path) : - detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(data::Descriptor::BOOL, path) + detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant( + data::Descriptor::BOOL, + path) { } Bool::Bool(const bool d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant(d, data::Descriptor::BOOL, path) + detail::PrimitiveVariant<data::dto::AronBool, bool, Bool>::PrimitiveVariant( + d, + data::Descriptor::BOOL, + path) { } /* operators */ - bool Bool::operator==(const Bool& other) const + bool + Bool::operator==(const Bool& other) const { const auto& otherAron = other.toAronBoolDTO(); if (aron->value != otherAron->value) @@ -51,7 +60,9 @@ namespace armarx::aron::data } return true; } - bool Bool::operator==(const BoolPtr& other) const + + bool + Bool::operator==(const BoolPtr& other) const { if (!other) { @@ -60,9 +71,9 @@ namespace armarx::aron::data return *this == *other; } - /* static methods */ - BoolPtr Bool::FromAronBoolDTO(const data::dto::AronBoolPtr& aron) + BoolPtr + Bool::FromAronBoolDTO(const data::dto::AronBoolPtr& aron) { if (!aron) { @@ -71,19 +82,22 @@ namespace armarx::aron::data return std::make_shared<Bool>(aron); } - data::dto::AronBoolPtr Bool::ToAronBoolDTO(const BoolPtr& navigator) + data::dto::AronBoolPtr + Bool::ToAronBoolDTO(const BoolPtr& navigator) { return navigator ? navigator->toAronBoolDTO() : nullptr; } /* public member functions */ - data::dto::AronBoolPtr Bool::toAronBoolDTO() const + data::dto::AronBoolPtr + Bool::toAronBoolDTO() const { return aron; } /* virtual implementations */ - void Bool::fromString(const std::string& setter) + void + Bool::fromString(const std::string& setter) { if (setter == "true" || setter == "1" || setter == "yes") { @@ -96,27 +110,36 @@ namespace armarx::aron::data else { ARMARX_TRACE; - throw error::AronException(__PRETTY_FUNCTION__, "Could not set from string. Got: '" + setter + "'"); + throw error::AronException(__PRETTY_FUNCTION__, + "Could not set from string. Got: '" + setter + "'"); } } - std::string Bool::getShortName() const + std::string + Bool::getShortName() const { return "Bool"; } - std::string Bool::getFullName() const + + std::string + Bool::getFullName() const { return "armarx::aron::data::Bool"; } - bool Bool::fullfillsType(const type::VariantPtr& type) const + bool + Bool::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; return type->getDescriptor() == type::Descriptor::BOOL; } - type::VariantPtr Bool::recalculateType() const + type::VariantPtr + Bool::recalculateType() const { - return std::make_shared<type::Bool>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::Bool>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Double.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Double.cpp index 87ea9eeacbabc0356f13476714860756424f457d..66b23d4e11892841f17fbb520a61b80e54a498e2 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Double.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Double.cpp @@ -31,22 +31,31 @@ namespace armarx::aron::data { /* constructors */ Double::Double(const data::dto::AronDoublePtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant(o, data::Descriptor::DOUBLE, path) + detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant( + o, + data::Descriptor::DOUBLE, + path) { } Double::Double(const Path& path) : - detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant(data::Descriptor::DOUBLE, path) + detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant( + data::Descriptor::DOUBLE, + path) { } Double::Double(const double d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant(d, data::Descriptor::DOUBLE, path) + detail::PrimitiveVariant<data::dto::AronDouble, double, Double>::PrimitiveVariant( + d, + data::Descriptor::DOUBLE, + path) { } /* operators */ - bool Double::operator==(const Double& other) const + bool + Double::operator==(const Double& other) const { const auto& otherAron = other.toAronDoubleDTO(); if (this->aron->value != otherAron->value) @@ -55,7 +64,9 @@ namespace armarx::aron::data } return true; } - bool Double::operator==(const DoublePtr& other) const + + bool + Double::operator==(const DoublePtr& other) const { if (!other) { @@ -65,7 +76,8 @@ namespace armarx::aron::data } /* static methods */ - DoublePtr Double::FromAronDoubleDTO(const data::dto::AronDoublePtr& aron) + DoublePtr + Double::FromAronDoubleDTO(const data::dto::AronDoublePtr& aron) { if (!aron) { @@ -74,41 +86,51 @@ namespace armarx::aron::data return std::make_shared<Double>(aron); } - data::dto::AronDoublePtr Double::ToAronDoubleDTO(const DoublePtr& navigator) + data::dto::AronDoublePtr + Double::ToAronDoubleDTO(const DoublePtr& navigator) { return navigator ? navigator->toAronDoubleDTO() : nullptr; } - /* public member functions */ - data::dto::AronDoublePtr Double::toAronDoubleDTO() const + data::dto::AronDoublePtr + Double::toAronDoubleDTO() const { return aron; } /* virtual implementations */ - void Double::fromString(const std::string& setter) + void + Double::fromString(const std::string& setter) { setValue(std::stod(setter)); } - std::string Double::getShortName() const + std::string + Double::getShortName() const { return "Double"; } - std::string Double::getFullName() const + + std::string + Double::getFullName() const { return "armarx::aron::data::Double"; } - bool Double::fullfillsType(const type::VariantPtr& type) const + bool + Double::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; return type->getDescriptor() == type::Descriptor::DOUBLE; } - type::VariantPtr Double::recalculateType() const + type::VariantPtr + Double::recalculateType() const { - return std::make_shared<type::Double>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::Double>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Float.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Float.cpp index 8dd7721c4adf5e5e0ec86b04325ea6971b8413ad..26d08b4b50d88fae2045b9b1bcbcb6ea3fb237de 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Float.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Float.cpp @@ -27,22 +27,31 @@ namespace armarx::aron::data { /* constructors */ Float::Float(const data::dto::AronFloatPtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant(o, data::Descriptor::FLOAT, path) + detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant( + o, + data::Descriptor::FLOAT, + path) { } Float::Float(const Path& path) : - detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant(data::Descriptor::FLOAT, path) + detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant( + data::Descriptor::FLOAT, + path) { } Float::Float(const float d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant(d, data::Descriptor::FLOAT, path) + detail::PrimitiveVariant<data::dto::AronFloat, float, Float>::PrimitiveVariant( + d, + data::Descriptor::FLOAT, + path) { } /* operators */ - bool Float::operator==(const Float& other) const + bool + Float::operator==(const Float& other) const { const auto& otherAron = other.toAronFloatDTO(); if (this->aron->value != otherAron->value) @@ -51,7 +60,9 @@ namespace armarx::aron::data } return true; } - bool Float::operator==(const FloatPtr& other) const + + bool + Float::operator==(const FloatPtr& other) const { if (!other) { @@ -60,9 +71,9 @@ namespace armarx::aron::data return *this == *other; } - /* static methods */ - FloatPtr Float::FromAronFloatDTO(const data::dto::AronFloatPtr& aron) + FloatPtr + Float::FromAronFloatDTO(const data::dto::AronFloatPtr& aron) { if (!aron) { @@ -71,41 +82,51 @@ namespace armarx::aron::data return std::make_shared<Float>(aron); } - data::dto::AronFloatPtr Float::ToAronFloatDTO(const FloatPtr& navigator) + data::dto::AronFloatPtr + Float::ToAronFloatDTO(const FloatPtr& navigator) { return navigator ? navigator->toAronFloatDTO() : nullptr; } /* public member functions */ - data::dto::AronFloatPtr Float::toAronFloatDTO() const + data::dto::AronFloatPtr + Float::toAronFloatDTO() const { return aron; } - /* virtual implementations */ - void Float::fromString(const std::string& setter) + void + Float::fromString(const std::string& setter) { setValue(std::stof(setter)); } - std::string Float::getShortName() const + std::string + Float::getShortName() const { return "Float"; } - std::string Float::getFullName() const + + std::string + Float::getFullName() const { return "armarx::aron::data::Float"; } - bool Float::fullfillsType(const type::VariantPtr& type) const + bool + Float::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; return type->getDescriptor() == type::Descriptor::FLOAT; } - type::VariantPtr Float::recalculateType() const + type::VariantPtr + Float::recalculateType() const { - return std::make_shared<type::Float>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::Float>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Int.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Int.cpp index cc4d9dc2ec4285f3791e4f45752d578b6a304408..870cbcd22877a82237e143bc79bf1528e64d35de 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Int.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Int.cpp @@ -30,22 +30,31 @@ namespace armarx::aron::data { /* constructors */ Int::Int(const data::dto::AronIntPtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant(o, data::Descriptor::INT, path) + detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant( + o, + data::Descriptor::INT, + path) { } Int::Int(const Path& path) : - detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant(data::Descriptor::INT, path) + detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant( + data::Descriptor::INT, + path) { } Int::Int(const int d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant(d, data::Descriptor::INT, path) + detail::PrimitiveVariant<data::dto::AronInt, int, Int>::PrimitiveVariant( + d, + data::Descriptor::INT, + path) { } /* operators */ - bool Int::operator==(const Int& other) const + bool + Int::operator==(const Int& other) const { const auto& otherAron = other.toAronIntDTO(); if (this->aron->value != otherAron->value) @@ -54,7 +63,9 @@ namespace armarx::aron::data } return true; } - bool Int::operator==(const IntPtr& other) const + + bool + Int::operator==(const IntPtr& other) const { if (!other) { @@ -63,9 +74,9 @@ namespace armarx::aron::data return *this == *other; } - /* static methods */ - IntPtr Int::FromAronIntDTO(const data::dto::AronIntPtr& aron) + IntPtr + Int::FromAronIntDTO(const data::dto::AronIntPtr& aron) { if (!aron) { @@ -74,41 +85,52 @@ namespace armarx::aron::data return std::make_shared<Int>(aron); } - data::dto::AronIntPtr Int::ToAronIntDTO(const IntPtr& navigator) + data::dto::AronIntPtr + Int::ToAronIntDTO(const IntPtr& navigator) { return navigator ? navigator->toAronIntDTO() : nullptr; } /* public member functions */ - data::dto::AronIntPtr Int::toAronIntDTO() const + data::dto::AronIntPtr + Int::toAronIntDTO() const { return aron; } - /* virtual implementations */ - void Int::fromString(const std::string& setter) + void + Int::fromString(const std::string& setter) { setValue(std::stoi(setter)); } - std::string Int::getShortName() const + std::string + Int::getShortName() const { return "Int"; } - std::string Int::getFullName() const + + std::string + Int::getFullName() const { return "armarx::aron::data::Int"; } - bool Int::fullfillsType(const type::VariantPtr& type) const + bool + Int::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; - return type->getDescriptor() == type::Descriptor::INT || type->getDescriptor() == type::Descriptor::INT_ENUM; + if (!type) + return true; + return type->getDescriptor() == type::Descriptor::INT || + type->getDescriptor() == type::Descriptor::INT_ENUM; } - type::VariantPtr Int::recalculateType() const + type::VariantPtr + Int::recalculateType() const { - return std::make_shared<type::Int>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::Int>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Long.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Long.cpp index 6a271cdc821d275c8a9afec1b65f73436010ad2f..2f62027e1ca65333d48447c4490932ecc032b543 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/Long.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/Long.cpp @@ -31,22 +31,31 @@ namespace armarx::aron::data { /* constructors */ Long::Long(const data::dto::AronLongPtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant(o, data::Descriptor::LONG, path) + detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant( + o, + data::Descriptor::LONG, + path) { } Long::Long(const Path& path) : - detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant(data::Descriptor::LONG, path) + detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant( + data::Descriptor::LONG, + path) { } Long::Long(const long d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant(d, data::Descriptor::LONG, path) + detail::PrimitiveVariant<data::dto::AronLong, long, Long>::PrimitiveVariant( + d, + data::Descriptor::LONG, + path) { } /* operators */ - bool Long::operator==(const Long& other) const + bool + Long::operator==(const Long& other) const { const auto& otherAron = other.toAronLongDTO(); if (this->aron->value != otherAron->value) @@ -55,7 +64,9 @@ namespace armarx::aron::data } return true; } - bool Long::operator==(const LongPtr& other) const + + bool + Long::operator==(const LongPtr& other) const { if (!other) { @@ -64,9 +75,9 @@ namespace armarx::aron::data return *this == *other; } - /* static methods */ - LongPtr Long::FromAronLongDTO(const data::dto::AronLongPtr& aron) + LongPtr + Long::FromAronLongDTO(const data::dto::AronLongPtr& aron) { if (!aron) { @@ -75,41 +86,51 @@ namespace armarx::aron::data return std::make_shared<Long>(aron); } - data::dto::AronLongPtr Long::ToAronLongDTO(const LongPtr& navigator) + data::dto::AronLongPtr + Long::ToAronLongDTO(const LongPtr& navigator) { return navigator ? navigator->toAronLongDTO() : nullptr; } /* public member functions */ - data::dto::AronLongPtr Long::toAronLongDTO() const + data::dto::AronLongPtr + Long::toAronLongDTO() const { return aron; } - /* virtual implementations */ - void Long::fromString(const std::string& setter) + void + Long::fromString(const std::string& setter) { setValue(std::stol(setter)); } - std::string Long::getShortName() const + std::string + Long::getShortName() const { return "Long"; } - std::string Long::getFullName() const + + std::string + Long::getFullName() const { return "armarx::aron::data::Long"; } - bool Long::fullfillsType(const type::VariantPtr& type) const + bool + Long::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; return type->getDescriptor() == type::Descriptor::LONG; } - type::VariantPtr Long::recalculateType() const + type::VariantPtr + Long::recalculateType() const { - return std::make_shared<type::Long>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::Long>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/data/variant/primitive/String.cpp b/source/RobotAPI/libraries/aron/core/data/variant/primitive/String.cpp index 6415245f36a08faf2b02364ff4a298d33a4c9ac9..9f765ed209f40a84e6554eebb26e1671d1a04e8b 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/primitive/String.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/primitive/String.cpp @@ -27,22 +27,31 @@ namespace armarx::aron::data { /* constructors */ String::String(const data::dto::AronStringPtr& o, const Path& path) : - detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant(o, data::Descriptor::STRING, path) + detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant( + o, + data::Descriptor::STRING, + path) { } String::String(const Path& path) : - detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant(data::Descriptor::STRING, path) + detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant( + data::Descriptor::STRING, + path) { } String::String(const std::string& d, const Path& path) : - detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant(d, data::Descriptor::STRING, path) + detail::PrimitiveVariant<data::dto::AronString, std::string, String>::PrimitiveVariant( + d, + data::Descriptor::STRING, + path) { } /* operators */ - bool String::operator==(const String& other) const + bool + String::operator==(const String& other) const { const auto& otherAron = other.toAronStringDTO(); if (this->aron->value != otherAron->value) @@ -51,7 +60,9 @@ namespace armarx::aron::data } return true; } - bool String::operator==(const StringPtr& other) const + + bool + String::operator==(const StringPtr& other) const { if (!other) { @@ -60,9 +71,9 @@ namespace armarx::aron::data return *this == *other; } - /* static methods */ - StringPtr String::FromAronStringDTO(const data::dto::AronStringPtr& aron) + StringPtr + String::FromAronStringDTO(const data::dto::AronStringPtr& aron) { if (!aron) { @@ -71,41 +82,51 @@ namespace armarx::aron::data return std::make_shared<String>(aron); } - data::dto::AronStringPtr String::ToAronStringDTO(const StringPtr& navigator) + data::dto::AronStringPtr + String::ToAronStringDTO(const StringPtr& navigator) { return navigator ? navigator->toAronStringDTO() : nullptr; } /* public member functions */ - data::dto::AronStringPtr String::toAronStringDTO() const + data::dto::AronStringPtr + String::toAronStringDTO() const { return aron; } - /* virtual implementations */ - void String::fromString(const std::string& setter) + void + String::fromString(const std::string& setter) { setValue(setter); } - std::string String::getShortName() const + std::string + String::getShortName() const { return "String"; } - std::string String::getFullName() const + + std::string + String::getFullName() const { return "armarx::aron::data::String"; } - bool String::fullfillsType(const type::VariantPtr& type) const + bool + String::fullfillsType(const type::VariantPtr& type) const { - if (!type) return true; + if (!type) + return true; return type->getDescriptor() == type::Descriptor::STRING; } - type::VariantPtr String::recalculateType() const + type::VariantPtr + String::recalculateType() const { - return std::make_shared<type::String>(getPath()); + ARMARX_TRACE; + throw error::NotImplementedYetException(__PRETTY_FUNCTION__); + //return std::make_shared<type::String>(getPath()); } -} +} // namespace armarx::aron::data diff --git a/source/RobotAPI/libraries/aron/core/type/converter/Converter.h b/source/RobotAPI/libraries/aron/core/type/converter/Converter.h index e166ab4327c0dd9f8f800a6a0eadea3bf001408a..836dbd2fb7000f1eead75fa15ef807f896347ddf 100644 --- a/source/RobotAPI/libraries/aron/core/type/converter/Converter.h +++ b/source/RobotAPI/libraries/aron/core/type/converter/Converter.h @@ -23,9 +23,9 @@ #pragma once -#include "../visitor/Visitor.h" #include "../rw/Reader.h" #include "../rw/Writer.h" +#include "../visitor/Visitor.h" namespace armarx::aron::type { @@ -35,16 +35,20 @@ namespace armarx::aron::type struct Converter; template <class T> - concept isConverter = std::is_base_of<Converter<typename T::ReaderType, typename T::WriterType, typename T::This>, T>::value; + concept isConverter = + std::is_base_of<Converter<typename T::ReaderType, typename T::WriterType, typename T::This>, + T>::value; template <class ConverterImplementation> requires isConverter<ConverterImplementation> - typename ConverterImplementation::WriterReturnType readAndWrite(typename ConverterImplementation::ReaderInputType& o); + typename ConverterImplementation::WriterReturnType + readAndWrite(typename ConverterImplementation::ReaderInputType& o); /// Converter struct providing the needed methods. /// WriterImplementation is a writer class, TODO: add concepts template <class ReaderImplementation, class WriterImplementation, class DerivedT> requires isReader<ReaderImplementation> && isWriter<WriterImplementation> + struct Converter : virtual public Visitor<typename ReaderImplementation::InputType> { using WriterType = WriterImplementation; @@ -60,12 +64,14 @@ namespace armarx::aron::type virtual ~Converter() = default; - type::Descriptor getDescriptor(ReaderInputType& o) final + type::Descriptor + getDescriptor(ReaderInputType& o) final { return r.getDescriptor(o); } - void visitObject(ReaderInputType& o) final + void + visitObject(ReaderInputType& o) final { std::map<std::string, ReaderInputTypeNonConst> elementsOfInput; std::string name; @@ -81,10 +87,12 @@ namespace armarx::aron::type elementsReturn.insert({key, converted}); } - last_returned = w.writeObject(name, templates, templateInstantiations, elementsReturn, std::nullopt, maybe, p); + last_returned = w.writeObject( + name, templates, templateInstantiations, elementsReturn, std::nullopt, maybe, p); } - void visitDict(ReaderInputType& o) final + void + visitDict(ReaderInputType& o) final { ReaderInputTypeNonConst acceptedType; type::Maybe maybe; @@ -96,7 +104,8 @@ namespace armarx::aron::type last_returned = w.writeDict(converted, maybe, p); }; - void visitList(ReaderInputType& o) final + void + visitList(ReaderInputType& o) final { ReaderInputTypeNonConst acceptedType; type::Maybe maybe; @@ -108,7 +117,8 @@ namespace armarx::aron::type last_returned = w.writeList(converted, maybe, p); }; - void visitPair(ReaderInputType& o) final + void + visitPair(ReaderInputType& o) final { ReaderInputTypeNonConst acceptedType1; ReaderInputTypeNonConst acceptedType2; @@ -122,7 +132,8 @@ namespace armarx::aron::type last_returned = w.writePair(converted1, converted2, maybe, p); }; - void visitTuple(ReaderInputType& o) final + void + visitTuple(ReaderInputType& o) final { std::vector<ReaderInputTypeNonConst> acceptedTypes; std::vector<WriterReturnType> elementsReturn; @@ -139,7 +150,8 @@ namespace armarx::aron::type last_returned = w.writeTuple(elementsReturn, maybe, p); }; - void visitNDArray(ReaderInputType& o) final + void + visitNDArray(ReaderInputType& o) final { type::Maybe maybe; type::ndarray::ElementType type; @@ -149,7 +161,8 @@ namespace armarx::aron::type last_returned = w.writeNDArray(ndim, type, maybe, p); }; - void visitMatrix(ReaderInputType& o) final + void + visitMatrix(ReaderInputType& o) final { type::Maybe maybe; type::matrix::ElementType type; @@ -160,7 +173,8 @@ namespace armarx::aron::type last_returned = w.writeMatrix(rows, cols, type, maybe, p); }; - void visitQuaternion(ReaderInputType& o) final + void + visitQuaternion(ReaderInputType& o) final { type::Maybe maybe; type::quaternion::ElementType type; @@ -169,7 +183,8 @@ namespace armarx::aron::type last_returned = w.writeQuaternion(type, maybe, p); }; - void visitImage(ReaderInputType& o) final + void + visitImage(ReaderInputType& o) final { type::Maybe maybe; type::image::PixelType type; @@ -178,7 +193,8 @@ namespace armarx::aron::type last_returned = w.writeImage(type, maybe, p); }; - void visitPointCloud(ReaderInputType& o) final + void + visitPointCloud(ReaderInputType& o) final { type::Maybe maybe; type::pointcloud::VoxelType type; @@ -187,69 +203,85 @@ namespace armarx::aron::type last_returned = w.writePointCloud(type, maybe, p); }; - void visitIntEnum(ReaderInputType& o) final + void + visitIntEnum(ReaderInputType& o) final { type::Maybe maybe; std::string name; std::map<std::string, int> values; + std::string defaultValue; Path p; - r.readIntEnum(o, name, values, maybe, p); - last_returned = w.writeIntEnum(name, values, maybe, p); + r.readIntEnum(o, name, values, defaultValue, maybe, p); + last_returned = w.writeIntEnum(name, values, defaultValue, maybe, p); }; - void visitInt(ReaderInputType& o) final + void + visitInt(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readInt(o, maybe, p); - last_returned = w.writeInt(maybe, p); + int defaultValue; + r.readInt(o, defaultValue, maybe, p); + last_returned = w.writeInt(defaultValue, maybe, p); }; - void visitLong(ReaderInputType& o) final + void + visitLong(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readLong(o, maybe, p); - last_returned = w.writeLong(maybe, p); + long defaultValue; + r.readLong(o, defaultValue, maybe, p); + last_returned = w.writeLong(defaultValue, maybe, p); }; - void visitFloat(ReaderInputType& o) final + void + visitFloat(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readFloat(o, maybe, p); - last_returned = w.writeFloat(maybe, p); + float defaultValue; + r.readFloat(o, defaultValue, maybe, p); + last_returned = w.writeFloat(defaultValue, maybe, p); }; - void visitDouble(ReaderInputType& o) final + void + visitDouble(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readDouble(o, maybe, p); - last_returned = w.writeDouble(maybe, p); + double defaultValue; + r.readDouble(o, defaultValue, maybe, p); + last_returned = w.writeDouble(defaultValue, maybe, p); }; - void visitBool(ReaderInputType& o) final + void + visitBool(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readBool(o, maybe, p); - last_returned = w.writeBool(maybe, p); + bool defaultValue; + r.readBool(o, defaultValue, maybe, p); + last_returned = w.writeBool(defaultValue, maybe, p); }; - void visitString(ReaderInputType& o) final + void + visitString(ReaderInputType& o) final { type::Maybe maybe; Path p; - r.readString(o, maybe, p); - last_returned = w.writeString(maybe, p); + std::string defaultValue; + r.readString(o, defaultValue, maybe, p); + last_returned = w.writeString(defaultValue, maybe, p); }; - void visitUnknown(ReaderInputType& o) final + void + visitUnknown(ReaderInputType& o) final { if (!r.readNull(o)) { - throw error::AronException(__PRETTY_FUNCTION__, "A visitor got type but the enum is unknown."); + throw error::AronException(__PRETTY_FUNCTION__, + "A visitor got type but the enum is unknown."); } w.writeNull(); } @@ -259,10 +291,12 @@ namespace armarx::aron::type /// returns the returntype of T template <class ConverterImplementation> requires isConverter<ConverterImplementation> - typename ConverterImplementation::WriterReturnType readAndWrite(typename ConverterImplementation::ReaderInputType& o) + + typename ConverterImplementation::WriterReturnType + readAndWrite(typename ConverterImplementation::ReaderInputType& o) { ConverterImplementation v; type::visit(v, o); return v.last_returned; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/rw/Reader.h b/source/RobotAPI/libraries/aron/core/type/rw/Reader.h index 790a0d9fb7f9ed77f00ca40686582db063fd3fbe..a698c9c2e0f899a89948d2720ec189b8c6f1ee5b 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/Reader.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/Reader.h @@ -28,7 +28,6 @@ #include <RobotAPI/interface/aron.h> #include <RobotAPI/libraries/aron/core/Exception.h> - namespace armarx::aron::type { /** @@ -46,61 +45,112 @@ namespace armarx::aron::type virtual type::Descriptor getDescriptor(InputType& input) = 0; /// Extract information from an Object type - virtual void readObject(const InputType& input, std::string& name, std::vector<std::string>& templates, std::vector<std::string>& templateInstantiations, std::map<std::string, InputTypeNonConst>& memberTypes, type::Maybe& maybe, Path& p) = 0; + virtual void readObject(const InputType& input, + std::string& name, + std::vector<std::string>& templates, + std::vector<std::string>& templateInstantiations, + std::map<std::string, InputTypeNonConst>& memberTypes, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a list type - virtual void readList(const InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p) = 0; + virtual void readList(const InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a dict type - virtual void readDict(const InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p) = 0; + virtual void readDict(const InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a tuple type - virtual void readTuple(const InputType& input, std::vector<InputTypeNonConst>& acceptedTypes, type::Maybe& maybe, Path& p) = 0; + virtual void readTuple(const InputType& input, + std::vector<InputTypeNonConst>& acceptedTypes, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a pair type - virtual void readPair(const InputType& input, InputTypeNonConst& acceptedTypes1, InputTypeNonConst& acceptedTypes2, type::Maybe& maybe, Path& p) = 0; + virtual void readPair(const InputType& input, + InputTypeNonConst& acceptedTypes1, + InputTypeNonConst& acceptedTypes2, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a ndarray type - virtual void readNDArray(const InputType& input, int& ndim, type::ndarray::ElementType& type, type::Maybe& maybe, Path& p) = 0; + virtual void readNDArray(const InputType& input, + int& ndim, + type::ndarray::ElementType& type, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a matrix type - virtual void readMatrix(const InputType& input, int& rows, int& cols, type::matrix::ElementType& type, type::Maybe& maybe, Path& p) = 0; + virtual void readMatrix(const InputType& input, + int& rows, + int& cols, + type::matrix::ElementType& type, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a quaternion type - virtual void readQuaternion(const InputType& input, type::quaternion::ElementType& type, type::Maybe& maybe, Path& p) = 0; + virtual void readQuaternion(const InputType& input, + type::quaternion::ElementType& type, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from a pointcloud type - virtual void readPointCloud(const InputType& input, type::pointcloud::VoxelType& type, type::Maybe& maybe, Path& p) = 0; + virtual void readPointCloud(const InputType& input, + type::pointcloud::VoxelType& type, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from an image type - virtual void readImage(const InputType& input, type::image::PixelType& type, type::Maybe& maybe, Path& p) = 0; + virtual void readImage(const InputType& input, + type::image::PixelType& type, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from an int enum type - virtual void readIntEnum(const InputType& input, std::string& name, std::map<std::string, int>& acceptedValues, type::Maybe& maybe, Path& p) = 0; + virtual void readIntEnum(const InputType& input, + std::string& name, + std::map<std::string, int>& acceptedValues, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from an int type - virtual void readInt(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void + readInt(const InputType& input, int& defaultValue, type::Maybe& maybe, Path& p) = 0; /// Extract information from an long type - virtual void readLong(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void + readLong(const InputType& input, long& defaultValue, type::Maybe& maybe, Path& p) = 0; /// Extract information from an float type - virtual void readFloat(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void + readFloat(const InputType& input, float& defaultValue, type::Maybe& maybe, Path& p) = 0; /// Extract information from an double type - virtual void readDouble(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void + readDouble(const InputType& input, double& defaultValue, type::Maybe& maybe, Path& p) = 0; /// Extract information from an string type - virtual void readString(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void readString(const InputType& input, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) = 0; /// Extract information from an bool type - virtual void readBool(const InputType& input, type::Maybe& maybe, Path& p) = 0; + virtual void + readBool(const InputType& input, bool& defaultValue, type::Maybe& maybe, Path& p) = 0; /// Extract information from an time type virtual void readAnyObject(const InputType& input, type::Maybe& maybe, Path& p) = 0; /// Check if input is null - virtual bool readNull(InputType& input) // defaulted implementation + virtual bool + readNull(InputType& input) // defaulted implementation { InputType nil = {}; return input == nil; @@ -218,4 +268,4 @@ namespace armarx::aron::type template <class T> concept isReader = std::is_base_of<ReaderInterface<typename T::InputType>, T>::value; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/rw/Writer.h b/source/RobotAPI/libraries/aron/core/type/rw/Writer.h index 5cba5dd672c7a2ebcde343485e64bc781ce26a1f..7f923a993cf13afc970c22d72cd183265cd0cd2e 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/Writer.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/Writer.h @@ -22,14 +22,13 @@ // STD/STL #include <memory> -#include <string> #include <optional> +#include <string> // ArmarX #include <RobotAPI/interface/aron.h> #include <RobotAPI/libraries/aron/core/Exception.h> - namespace armarx::aron::type { /** @@ -47,67 +46,100 @@ namespace armarx::aron::type virtual type::Descriptor getDescriptor(ReturnTypeConst& input) = 0; /// Construct an object from the params - virtual ReturnType writeObject(const std::string& name, const std::vector<std::string>& templates, const std::vector<std::string>& templateInstantiations, const std::map<std::string, ReturnType>& memberTypes, const std::optional<ReturnType>& extends, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeObject(const std::string& name, + const std::vector<std::string>& templates, + const std::vector<std::string>& templateInstantiations, + const std::map<std::string, ReturnType>& memberTypes, + const std::optional<ReturnType>& extends, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a list from the params - virtual ReturnType writeList(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeList(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0; /// Construct a dict from the params - virtual ReturnType writeDict(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeDict(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p) = 0; /// Construct a pair from the params - virtual ReturnType writePair(const ReturnType& acceptedType1, const ReturnType& acceptedType2, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writePair(const ReturnType& acceptedType1, + const ReturnType& acceptedType2, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a tuple from the params - virtual ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a ndarray from the params - virtual ReturnType writeNDArray(const int ndim, const type::ndarray::ElementType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeNDArray(const int ndim, + const type::ndarray::ElementType, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a matrix from the params - virtual ReturnType writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeMatrix(const int rows, + const int cols, + const type::matrix::ElementType type, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a quaternion from the params - virtual ReturnType writeQuaternion(const type::quaternion::ElementType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeQuaternion(const type::quaternion::ElementType, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a image from the params - virtual ReturnType writeImage(const type::image::PixelType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeImage(const type::image::PixelType, const type::Maybe maybe, const Path& p) = 0; /// Construct a pointcloud from the params - virtual ReturnType writePointCloud(const type::pointcloud::VoxelType, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writePointCloud(const type::pointcloud::VoxelType, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a int enum from the params - virtual ReturnType writeIntEnum(const std::string& name, const std::map<std::string, int>& acceptedValues, const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeIntEnum(const std::string& name, + const std::map<std::string, int>& acceptedValues, + const std::string& defaultValue, + const type::Maybe maybe, + const Path& p) = 0; /// Construct a int from the params - virtual ReturnType writeInt(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeInt(int defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a long from the params - virtual ReturnType writeLong(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeLong(long defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a float from the params - virtual ReturnType writeFloat(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeFloat(float defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a double from the params - virtual ReturnType writeDouble(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeDouble(double defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a string from the params - virtual ReturnType writeString(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType + writeString(const std::string& defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a bool from the params - virtual ReturnType writeBool(const type::Maybe maybe, const Path& p) = 0; + virtual ReturnType writeBool(bool defaultValue, const type::Maybe maybe, const Path& p) = 0; /// Construct a time from the params virtual ReturnType writeAnyObject(const type::Maybe maybe, const Path& p) = 0; /// write a null - virtual ReturnType writeNull(const Path& p = Path()) // defaulted implementation + virtual ReturnType + writeNull(const Path& p = Path()) // defaulted implementation { - (void) p; + (void)p; return {}; } }; template <class T> concept isWriter = std::is_base_of<WriterInterface<typename T::ReturnType>, T>::value; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/rw/json/Data.cpp b/source/RobotAPI/libraries/aron/core/type/rw/json/Data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df60876fbdd629f5c43d7a3fd2efb3f2a28ba1f0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/type/rw/json/Data.cpp @@ -0,0 +1,21 @@ +/* +* 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/>. +* +* @author Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#include "Data.h" diff --git a/source/RobotAPI/libraries/aron/core/type/rw/json/Data.h b/source/RobotAPI/libraries/aron/core/type/rw/json/Data.h index a3dbadf76ff6c5d74e20f9b4ad66ae25b171d9aa..834b0b462f7f6de3e1bb6d1d4a1212773995f4ab 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/json/Data.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/json/Data.h @@ -34,45 +34,46 @@ namespace armarx::aron::type::rw::json { namespace constantes { - const std::string MAYBE_SLUG = "_ARON_MAYBE"; - const std::string TYPE_SLUG = "_ARON_TYPE"; - const std::string PATH_SLUG = "_ARON_PATH"; - const std::string VERSION_SLUG = "_ARON_VERSION"; + const constexpr auto MAYBE_SLUG = "_ARON_MAYBE"; + const constexpr auto TYPE_SLUG = "_ARON_TYPE"; + const constexpr auto PATH_SLUG = "_ARON_PATH"; + const constexpr auto VERSION_SLUG = "_ARON_VERSION"; - const std::string KEY_SLUG = "_ARON_KEY"; - const std::string VALUE_SLUG = "_ARON_VALUE"; - const std::string MEMBERS_SLUG = "_ARON_MEMBERS"; - const std::string ELEMENTS_SLUG = "_ARON_ELEMENTS"; + const constexpr auto KEY_SLUG = "_ARON_KEY"; + const constexpr auto VALUE_SLUG = "_ARON_VALUE"; + const constexpr auto MEMBERS_SLUG = "_ARON_MEMBERS"; + const constexpr auto ELEMENTS_SLUG = "_ARON_ELEMENTS"; - const std::string NAME_SLUG = "_ARON_NAME"; - const std::string EXTENDS_SLUG = "_ARON_EXTENDS"; - const std::string ACCEPTED_TYPE_SLUG = "_ARON_ACCEPTED_TYPE"; - const std::string DIMENSIONS_SLUG = "_ARON_DIMESIONS"; - const std::string DATA_SLUG = "_ARON_DATA"; - const std::string USED_TYPE_SLUG = "_ARON_USED_TYPE"; - const std::string TEMPLATES_SLUG = "_ARON_TEMPLATES"; - const std::string TEMPLATE_INSTANTIATIONS_SLUG = "_ARON_TEMPLATE_INSTANTIATION"; + const constexpr auto NAME_SLUG = "_ARON_NAME"; + const constexpr auto EXTENDS_SLUG = "_ARON_EXTENDS"; + const constexpr auto ACCEPTED_TYPE_SLUG = "_ARON_ACCEPTED_TYPE"; + const constexpr auto DIMENSIONS_SLUG = "_ARON_DIMESIONS"; + const constexpr auto DATA_SLUG = "_ARON_DATA"; + const constexpr auto USED_TYPE_SLUG = "_ARON_USED_TYPE"; + const constexpr auto TEMPLATES_SLUG = "_ARON_TEMPLATES"; + const constexpr auto TEMPLATE_INSTANTIATIONS_SLUG = "_ARON_TEMPLATE_INSTANTIATION"; + const constexpr auto DEFAULT_SLUG = "_ARON_DEFAULT"; - const std::string LIST_TYPENAME_SLUG = "_ARON_LIST"; - const std::string DICT_TYPENAME_SLUG = "_ARON_DICT"; - const std::string OBJECT_TYPENAME_SLUG = "_ARON_OBJECT"; - const std::string TUPLE_TYPENAME_SLUG = "_ARON_TUPLE"; - const std::string PAIR_TYPENAME_SLUG = "_ARON_PAIR"; - const std::string NDARRAY_TYPENAME_SLUG = "_ARON_NDARRAY"; - const std::string IMAGE_TYPENAME_SLUG = "_ARON_IMAGE"; - const std::string MATRIX_TYPENAME_SLUG = "_ARON_MATRIX"; - const std::string QUATERNION_TYPENAME_SLUG = "_ARON_QUATERNION"; - const std::string POINT_CLOUD_TYPENAME_SLUG = "_ARON_POINT_CLOUD"; - const std::string INT_ENUM_TYPENAME_SLUG = "_ARON_INT_ENUM"; - const std::string INT_TYPENAME_SLUG = "_ARON_INT"; - const std::string LONG_TYPENAME_SLUG = "_ARON_LONG"; - const std::string FLOAT_TYPENAME_SLUG = "_ARON_FLOAT"; - const std::string DOUBLE_TYPENAME_SLUG = "_ARON_DOUBLE"; - const std::string STRING_TYPENAME_SLUG = "_ARON_STRING"; - const std::string BOOL_TYPENAME_SLUG = "_ARON_BOOL"; - const std::string TIME_TYPENAME_SLUG = "_ARON_TIME"; - const std::string ANY_OBJECT_TYPENAME_SLUG = "_ARON_ANY_OBJECT"; - } + const constexpr auto LIST_TYPENAME_SLUG = "_ARON_LIST"; + const constexpr auto DICT_TYPENAME_SLUG = "_ARON_DICT"; + const constexpr auto OBJECT_TYPENAME_SLUG = "_ARON_OBJECT"; + const constexpr auto TUPLE_TYPENAME_SLUG = "_ARON_TUPLE"; + const constexpr auto PAIR_TYPENAME_SLUG = "_ARON_PAIR"; + const constexpr auto NDARRAY_TYPENAME_SLUG = "_ARON_NDARRAY"; + const constexpr auto IMAGE_TYPENAME_SLUG = "_ARON_IMAGE"; + const constexpr auto MATRIX_TYPENAME_SLUG = "_ARON_MATRIX"; + const constexpr auto QUATERNION_TYPENAME_SLUG = "_ARON_QUATERNION"; + const constexpr auto POINT_CLOUD_TYPENAME_SLUG = "_ARON_POINT_CLOUD"; + const constexpr auto INT_ENUM_TYPENAME_SLUG = "_ARON_INT_ENUM"; + const constexpr auto INT_TYPENAME_SLUG = "_ARON_INT"; + const constexpr auto LONG_TYPENAME_SLUG = "_ARON_LONG"; + const constexpr auto FLOAT_TYPENAME_SLUG = "_ARON_FLOAT"; + const constexpr auto DOUBLE_TYPENAME_SLUG = "_ARON_DOUBLE"; + const constexpr auto STRING_TYPENAME_SLUG = "_ARON_STRING"; + const constexpr auto BOOL_TYPENAME_SLUG = "_ARON_BOOL"; + const constexpr auto TIME_TYPENAME_SLUG = "_ARON_TIME"; + const constexpr auto ANY_OBJECT_TYPENAME_SLUG = "_ARON_ANY_OBJECT"; + } // namespace constantes namespace conversion { @@ -94,22 +95,18 @@ namespace armarx::aron::type::rw::json {type::Descriptor::DOUBLE, rw::json::constantes::DOUBLE_TYPENAME_SLUG}, {type::Descriptor::BOOL, rw::json::constantes::BOOL_TYPENAME_SLUG}, {type::Descriptor::STRING, rw::json::constantes::STRING_TYPENAME_SLUG}, - {type::Descriptor::ANY_OBJECT, rw::json::constantes::ANY_OBJECT_TYPENAME_SLUG} - }; + {type::Descriptor::ANY_OBJECT, rw::json::constantes::ANY_OBJECT_TYPENAME_SLUG}}; const auto String2Descriptor = aron::conversion::util::InvertMap(Descriptor2String); - const std::map<type::Maybe, std::string> Maybe2String = - { + const std::map<type::Maybe, std::string> Maybe2String = { {type::Maybe::NONE, "type::maybe::NONE"}, {type::Maybe::OPTIONAL, "type::maybe::OPTIONAL"}, {type::Maybe::RAW_PTR, "type::maybe::RAW_PTR"}, {type::Maybe::SHARED_PTR, "type::maybe::SHARED_PTR"}, - {type::Maybe::UNIQUE_PTR, "type::maybe::UNIQUE_PTR"} - }; + {type::Maybe::UNIQUE_PTR, "type::maybe::UNIQUE_PTR"}}; const auto String2Maybe = aron::conversion::util::InvertMap(Maybe2String); - const std::map<type::ndarray::ElementType, std::string> NDArrayType2String = - { + const std::map<type::ndarray::ElementType, std::string> NDArrayType2String = { {type::ndarray::ElementType::INT8, "type::ndarray::INT8"}, {type::ndarray::ElementType::INT16, "type::ndarray::INT16"}, {type::ndarray::ElementType::INT32, "type::ndarray::INT32"}, @@ -117,44 +114,35 @@ namespace armarx::aron::type::rw::json {type::ndarray::ElementType::UINT16, "type::ndarray::UINT16"}, {type::ndarray::ElementType::UINT32, "type::ndarray::UINT32"}, {type::ndarray::ElementType::FLOAT32, "type::ndarray::FLOAT32"}, - {type::ndarray::ElementType::FLOAT64, "type::ndarray::FLOAT64"} - }; + {type::ndarray::ElementType::FLOAT64, "type::ndarray::FLOAT64"}}; const auto String2NDArrayType = aron::conversion::util::InvertMap(NDArrayType2String); - const std::map<type::matrix::ElementType, std::string> MatrixType2String = - { + const std::map<type::matrix::ElementType, std::string> MatrixType2String = { {type::matrix::ElementType::INT16, "type::matrix::INT16"}, {type::matrix::ElementType::INT32, "type::matrix::INT32"}, {type::matrix::ElementType::INT64, "type::matrix::INT64"}, {type::matrix::ElementType::FLOAT32, "type::matrix::FLOAT32"}, - {type::matrix::ElementType::FLOAT64, "type::matrix::FLOAT64"} - }; + {type::matrix::ElementType::FLOAT64, "type::matrix::FLOAT64"}}; const auto String2MatrixType = aron::conversion::util::InvertMap(MatrixType2String); - const std::map<type::quaternion::ElementType, std::string> QuaternionType2String = - { + const std::map<type::quaternion::ElementType, std::string> QuaternionType2String = { {type::quaternion::ElementType::FLOAT32, "type::quaternion::FLOAT32"}, - {type::quaternion::ElementType::FLOAT64, "type::quaternion::FLOAT64"} - }; + {type::quaternion::ElementType::FLOAT64, "type::quaternion::FLOAT64"}}; const auto String2QuaternionType = aron::conversion::util::InvertMap(QuaternionType2String); - const std::map<type::image::PixelType, std::string> PixelType2String = - { + const std::map<type::image::PixelType, std::string> PixelType2String = { {type::image::PixelType::RGB24, "type::image::RGB24"}, - {type::image::PixelType::DEPTH32, "type::image::DEPTH32"} - }; + {type::image::PixelType::DEPTH32, "type::image::DEPTH32"}}; const auto String2PixelType = aron::conversion::util::InvertMap(PixelType2String); - const std::map<type::pointcloud::VoxelType, std::string> VoxelType2String = - { + const std::map<type::pointcloud::VoxelType, std::string> VoxelType2String = { {type::pointcloud::VoxelType::POINT_XYZ, "type::pointcloud::POINT_XYZ"}, {type::pointcloud::VoxelType::POINT_XYZI, "type::pointcloud::POINT_XYZI"}, {type::pointcloud::VoxelType::POINT_XYZL, "type::pointcloud::POINT_XYZL"}, {type::pointcloud::VoxelType::POINT_XYZRGB, "type::pointcloud::POINT_XYZRGB"}, {type::pointcloud::VoxelType::POINT_XYZRGBA, "type::pointcloud::POINT_XYZRGBA"}, {type::pointcloud::VoxelType::POINT_XYZRGBL, "type::pointcloud::POINT_XYZRGBL"}, - {type::pointcloud::VoxelType::POINT_XYZHSV, "type::pointcloud::POINT_XYZHSV"} - }; + {type::pointcloud::VoxelType::POINT_XYZHSV, "type::pointcloud::POINT_XYZHSV"}}; const auto String2VoxelType = aron::conversion::util::InvertMap(VoxelType2String); - } -} + } // namespace conversion +} // namespace armarx::aron::type::rw::json diff --git a/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp index 028b6681ce8ee3f57db6a33861eb0c28d4228811..0839ada57b6718869561db5c20795ca35519aba9 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp +++ b/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.cpp @@ -27,33 +27,48 @@ // ArmarX #include <RobotAPI/libraries/aron/core/Exception.h> -#include "../../json/Data.h" #include <RobotAPI/libraries/aron/core/type/visitor/nlohmannJSON/NlohmannJSONVisitor.h> +#include "../../json/Data.h" + namespace armarx::aron::type::reader { namespace { /// Throw an exception if the type is other than expected - void getAronMetaInformationForType(const nlohmann::json& input, const std::string& expectedType, Path& p) + void + getAronMetaInformationForType(const nlohmann::json& input, + const std::string& expectedType, + Path& p) { if (input[rw::json::constantes::TYPE_SLUG] != expectedType) { - throw error::ValueNotValidException(__PRETTY_FUNCTION__, "Wrong type in json encountered.", input[rw::json::constantes::TYPE_SLUG], expectedType); + throw error::ValueNotValidException(__PRETTY_FUNCTION__, + "Wrong type in json encountered.", + input[rw::json::constantes::TYPE_SLUG], + expectedType); } // get Path std::vector<std::string> pathElements = input[rw::json::constantes::PATH_SLUG]; p = Path(pathElements); } - } + } // namespace - type::Descriptor NlohmannJSONReader::getDescriptor(InputType& input) + type::Descriptor + NlohmannJSONReader::getDescriptor(InputType& input) { return ConstNlohmannJSONVisitor::GetDescriptor(input); } - void NlohmannJSONReader::readObject(const nlohmann::json& input, std::string& name, std::vector<std::string>& templates, std::vector<std::string>& templateInstantiations, std::map<std::string, nlohmann::json>& memberTypes, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readObject(const nlohmann::json& input, + std::string& name, + std::vector<std::string>& templates, + std::vector<std::string>& templateInstantiations, + std::map<std::string, nlohmann::json>& memberTypes, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::OBJECT_TYPENAME_SLUG, p); @@ -64,14 +79,21 @@ namespace armarx::aron::type::reader } if (input.count(rw::json::constantes::TEMPLATE_INSTANTIATIONS_SLUG)) { - templateInstantiations = input[rw::json::constantes::TEMPLATE_INSTANTIATIONS_SLUG].get<std::vector<std::string>>(); + templateInstantiations = input[rw::json::constantes::TEMPLATE_INSTANTIATIONS_SLUG] + .get<std::vector<std::string>>(); } maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); - memberTypes = input[rw::json::constantes::MEMBERS_SLUG].get<std::map<std::string, nlohmann::json>>(); + memberTypes = + input[rw::json::constantes::MEMBERS_SLUG].get<std::map<std::string, nlohmann::json>>(); } - void NlohmannJSONReader::readList(const nlohmann::json& input, nlohmann::json& acceptedType, type::Maybe& maybe, Path& p) + + void + NlohmannJSONReader::readList(const nlohmann::json& input, + nlohmann::json& acceptedType, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::LIST_TYPENAME_SLUG, p); @@ -79,7 +101,11 @@ namespace armarx::aron::type::reader acceptedType = input[rw::json::constantes::ACCEPTED_TYPE_SLUG]; } - void NlohmannJSONReader::readDict(const nlohmann::json& input, nlohmann::json& acceptedType, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readDict(const nlohmann::json& input, + nlohmann::json& acceptedType, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::DICT_TYPENAME_SLUG, p); @@ -87,25 +113,41 @@ namespace armarx::aron::type::reader acceptedType = input[rw::json::constantes::ACCEPTED_TYPE_SLUG]; } - void NlohmannJSONReader::readTuple(const nlohmann::json& input, std::vector<nlohmann::json>& acceptedTypes, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readTuple(const nlohmann::json& input, + std::vector<nlohmann::json>& acceptedTypes, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::TUPLE_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); - acceptedTypes = input[rw::json::constantes::ACCEPTED_TYPE_SLUG].get<std::vector<nlohmann::json>>(); + acceptedTypes = + input[rw::json::constantes::ACCEPTED_TYPE_SLUG].get<std::vector<nlohmann::json>>(); } - void NlohmannJSONReader::readPair(const nlohmann::json& input, nlohmann::json& acceptedType1, nlohmann::json& acceptedType2, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readPair(const nlohmann::json& input, + nlohmann::json& acceptedType1, + nlohmann::json& acceptedType2, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::PAIR_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); - auto list = input[rw::json::constantes::ACCEPTED_TYPE_SLUG].get<std::vector<nlohmann::json>>(); + auto list = + input[rw::json::constantes::ACCEPTED_TYPE_SLUG].get<std::vector<nlohmann::json>>(); acceptedType1 = list[0]; acceptedType2 = list[1]; } - void NlohmannJSONReader::readNDArray(const nlohmann::json& input, int& ndim, type::ndarray::ElementType& type, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readNDArray(const nlohmann::json& input, + int& ndim, + type::ndarray::ElementType& type, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::NDARRAY_TYPENAME_SLUG, p); @@ -116,7 +158,13 @@ namespace armarx::aron::type::reader type = armarx::aron::type::rw::json::conversion::String2NDArrayType.at(t); } - void NlohmannJSONReader::readMatrix(const nlohmann::json& input, int& rows, int& cols, type::matrix::ElementType& type, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readMatrix(const nlohmann::json& input, + int& rows, + int& cols, + type::matrix::ElementType& type, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::MATRIX_TYPENAME_SLUG, p); @@ -129,7 +177,11 @@ namespace armarx::aron::type::reader type = armarx::aron::type::rw::json::conversion::String2MatrixType.at(t); } - void NlohmannJSONReader::readQuaternion(const nlohmann::json& input, type::quaternion::ElementType& type, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readQuaternion(const nlohmann::json& input, + type::quaternion::ElementType& type, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::QUATERNION_TYPENAME_SLUG, p); @@ -139,7 +191,11 @@ namespace armarx::aron::type::reader type = armarx::aron::type::rw::json::conversion::String2QuaternionType.at(t); } - void NlohmannJSONReader::readPointCloud(const nlohmann::json& input, type::pointcloud::VoxelType& type, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readPointCloud(const nlohmann::json& input, + type::pointcloud::VoxelType& type, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::POINT_CLOUD_TYPENAME_SLUG, p); @@ -149,7 +205,11 @@ namespace armarx::aron::type::reader type = armarx::aron::type::rw::json::conversion::String2VoxelType.at(t); } - void NlohmannJSONReader::readImage(const nlohmann::json& input, type::image::PixelType& type, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readImage(const nlohmann::json& input, + type::image::PixelType& type, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::IMAGE_TYPENAME_SLUG, p); @@ -159,62 +219,94 @@ namespace armarx::aron::type::reader type = armarx::aron::type::rw::json::conversion::String2PixelType.at(t); } - void NlohmannJSONReader::readIntEnum(const nlohmann::json& input, std::string& name, std::map<std::string, int>& acceptedValues, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readIntEnum(const nlohmann::json& input, + std::string& name, + std::map<std::string, int>& acceptedValues, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::INT_ENUM_TYPENAME_SLUG, p); name = input[rw::json::constantes::NAME_SLUG]; maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); - acceptedValues = input[rw::json::constantes::ELEMENTS_SLUG].get<std::map<std::string, int>>(); + acceptedValues = + input[rw::json::constantes::ELEMENTS_SLUG].get<std::map<std::string, int>>(); } - void NlohmannJSONReader::readInt(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readInt(const nlohmann::json& input, + int& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::INT_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readLong(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readLong(const nlohmann::json& input, + long& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::LONG_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readFloat(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readFloat(const nlohmann::json& input, + float& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::FLOAT_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readDouble(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readDouble(const nlohmann::json& input, + double& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::DOUBLE_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readString(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readString(const nlohmann::json& input, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::STRING_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readBool(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readBool(const nlohmann::json& input, + bool& defaultValue, + type::Maybe& maybe, + Path& p) { getAronMetaInformationForType(input, rw::json::constantes::BOOL_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } - void NlohmannJSONReader::readAnyObject(const nlohmann::json& input, type::Maybe& maybe, Path& p) + void + NlohmannJSONReader::readAnyObject(const nlohmann::json& input, type::Maybe& maybe, Path& p) { getAronMetaInformationForType(input, rw::json::constantes::ANY_OBJECT_TYPENAME_SLUG, p); maybe = rw::json::conversion::String2Maybe.at(input[rw::json::constantes::MAYBE_SLUG]); } -} +} // namespace armarx::aron::type::reader diff --git a/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.h b/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.h index 3775977b41ff3bc07c6c7763ed87dc34123fb1aa..da87293f58ac41b3731a4062d7706803a88cb2cb 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/reader/nlohmannJSON/NlohmannJSONReader.h @@ -32,8 +32,7 @@ namespace armarx::aron::type::reader { - class NlohmannJSONReader : - public ReaderInterface<const nlohmann::json> + class NlohmannJSONReader : public ReaderInterface<const nlohmann::json> { public: // constructors @@ -41,27 +40,87 @@ namespace armarx::aron::type::reader type::Descriptor getDescriptor(InputType& input) final; - void readObject(InputType& input, std::string& name, std::vector<std::string>& templates, std::vector<std::string>& templateInstantiations, std::map<std::string, InputTypeNonConst>& memberTypes, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readList(InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readDict(InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readTuple(InputType& input, std::vector<InputTypeNonConst>& acceptedTypes, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readPair(InputType& input, InputTypeNonConst& acceptedType1, InputTypeNonConst& acceptedType2, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readObject(InputType& input, + std::string& name, + std::vector<std::string>& templates, + std::vector<std::string>& templateInstantiations, + std::map<std::string, InputTypeNonConst>& memberTypes, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readList(InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readDict(InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readTuple(InputType& input, + std::vector<InputTypeNonConst>& acceptedTypes, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readPair(InputType& input, + InputTypeNonConst& acceptedType1, + InputTypeNonConst& acceptedType2, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readNDArray(InputType& input, int& ndim, type::ndarray::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readMatrix(InputType& input, int& rows, int& cols, type::matrix::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readQuaternion(InputType& input, type::quaternion::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readPointCloud(InputType& input, type::pointcloud::VoxelType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readImage(InputType& input, type::image::PixelType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readNDArray(InputType& input, + int& ndim, + type::ndarray::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readMatrix(InputType& input, + int& rows, + int& cols, + type::matrix::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readQuaternion(InputType& input, + type::quaternion::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readPointCloud(InputType& input, + type::pointcloud::VoxelType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readImage(InputType& input, + type::image::PixelType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readIntEnum(InputType& input, std::string& name, std::map<std::string, int>& acceptedValues, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readIntEnum(InputType& input, + std::string& name, + std::map<std::string, int>& acceptedValues, + std::string& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readInt(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readLong(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readFloat(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readDouble(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readString(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readBool(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readInt(InputType& input, + int& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readLong(InputType& input, + long& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readFloat(InputType& input, + float& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readDouble(InputType& input, + double& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readString(InputType& input, + std::string& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readBool(InputType& input, + bool& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; void readAnyObject(InputType& input, type::Maybe& maybe, Path& p) override; }; -} +} // namespace armarx::aron::type::reader diff --git a/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.cpp b/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.cpp index 452f240a5373678a3523dbe418d670e065e62423..f165e71205f7a19786be90ec5037a41c91ec95e6 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.cpp +++ b/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.cpp @@ -33,12 +33,20 @@ namespace armarx::aron::type::reader { - type::Descriptor VariantReader::getDescriptor(InputType& input) + type::Descriptor + VariantReader::getDescriptor(InputType& input) { return ConstVariantVisitor::GetDescriptor(input); } - void VariantReader::readObject(const aron::type::VariantPtr& input, std::string& name, std::vector<std::string>& templates, std::vector<std::string>& templateInstantiations, std::map<std::string, aron::type::VariantPtr>& memberTypes, type::Maybe& maybe, Path& p) + void + VariantReader::readObject(const aron::type::VariantPtr& input, + std::string& name, + std::vector<std::string>& templates, + std::vector<std::string>& templateInstantiations, + std::map<std::string, aron::type::VariantPtr>& memberTypes, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Object::DynamicCastAndCheck(input); @@ -50,7 +58,12 @@ namespace armarx::aron::type::reader memberTypes = o->getMemberTypes(); p = o->getPath(); } - void VariantReader::readList(const aron::type::VariantPtr& input, aron::type::VariantPtr& acceptedType, type::Maybe& maybe, Path& p) + + void + VariantReader::readList(const aron::type::VariantPtr& input, + aron::type::VariantPtr& acceptedType, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::List::DynamicCastAndCheck(input); @@ -60,7 +73,11 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readDict(const aron::type::VariantPtr& input, aron::type::VariantPtr& acceptedType, type::Maybe& maybe, Path& p) + void + VariantReader::readDict(const aron::type::VariantPtr& input, + aron::type::VariantPtr& acceptedType, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Dict::DynamicCastAndCheck(input); @@ -70,7 +87,11 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readTuple(const aron::type::VariantPtr& input, std::vector<aron::type::VariantPtr>& acceptedTypes, type::Maybe& maybe, Path& p) + void + VariantReader::readTuple(const aron::type::VariantPtr& input, + std::vector<aron::type::VariantPtr>& acceptedTypes, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Tuple::DynamicCastAndCheck(input); @@ -80,7 +101,12 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readPair(const aron::type::VariantPtr& input, aron::type::VariantPtr& acceptedType1, aron::type::VariantPtr& acceptedType2, type::Maybe& maybe, Path& p) + void + VariantReader::readPair(const aron::type::VariantPtr& input, + aron::type::VariantPtr& acceptedType1, + aron::type::VariantPtr& acceptedType2, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Pair::DynamicCastAndCheck(input); @@ -91,7 +117,12 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readNDArray(const aron::type::VariantPtr& input, int& ndim, type::ndarray::ElementType& type, type::Maybe& maybe, Path& p) + void + VariantReader::readNDArray(const aron::type::VariantPtr& input, + int& ndim, + type::ndarray::ElementType& type, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::NDArray::DynamicCastAndCheck(input); @@ -102,7 +133,13 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readMatrix(const aron::type::VariantPtr& input, int& rows, int& cols, type::matrix::ElementType& type, type::Maybe& maybe, Path& p) + void + VariantReader::readMatrix(const aron::type::VariantPtr& input, + int& rows, + int& cols, + type::matrix::ElementType& type, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Matrix::DynamicCastAndCheck(input); @@ -114,7 +151,11 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readQuaternion(const aron::type::VariantPtr& input, type::quaternion::ElementType& type, type::Maybe& maybe, Path& p) + void + VariantReader::readQuaternion(const aron::type::VariantPtr& input, + type::quaternion::ElementType& type, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Quaternion::DynamicCastAndCheck(input); @@ -124,7 +165,11 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readPointCloud(const aron::type::VariantPtr& input, type::pointcloud::VoxelType& type, type::Maybe& maybe, Path& p) + void + VariantReader::readPointCloud(const aron::type::VariantPtr& input, + type::pointcloud::VoxelType& type, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::PointCloud::DynamicCastAndCheck(input); @@ -134,7 +179,11 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readImage(const aron::type::VariantPtr& input, type::image::PixelType& type, type::Maybe& maybe, Path& p) + void + VariantReader::readImage(const aron::type::VariantPtr& input, + type::image::PixelType& type, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Image::DynamicCastAndCheck(input); @@ -144,7 +193,13 @@ namespace armarx::aron::type::reader p = o->getPath(); } - void VariantReader::readIntEnum(const aron::type::VariantPtr& input, std::string& name, std::map<std::string, int>& acceptedValues, type::Maybe& maybe, Path& p) + void + VariantReader::readIntEnum(const aron::type::VariantPtr& input, + std::string& name, + std::map<std::string, int>& acceptedValues, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::IntEnum::DynamicCastAndCheck(input); @@ -152,64 +207,96 @@ namespace armarx::aron::type::reader name = o->getEnumName(); acceptedValues = o->getAcceptedValueMap(); maybe = o->getMaybe(); + defaultValue = o->getDefaultValueName(); p = o->getPath(); } - void VariantReader::readInt(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readInt(const aron::type::VariantPtr& input, + int& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Int::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readLong(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readLong(const aron::type::VariantPtr& input, + long& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Long::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readFloat(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readFloat(const aron::type::VariantPtr& input, + float& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Float::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readDouble(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readDouble(const aron::type::VariantPtr& input, + double& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Double::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readString(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readString(const aron::type::VariantPtr& input, + std::string& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::String::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readBool(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readBool(const aron::type::VariantPtr& input, + bool& defaultValue, + type::Maybe& maybe, + Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::Bool::DynamicCastAndCheck(input); maybe = o->getMaybe(); + defaultValue = o->getDefaultValue(); p = o->getPath(); } - void VariantReader::readAnyObject(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) + void + VariantReader::readAnyObject(const aron::type::VariantPtr& input, type::Maybe& maybe, Path& p) { ARMARX_CHECK_NOT_NULL(input); auto o = type::AnyObject::DynamicCastAndCheck(input); @@ -217,4 +304,4 @@ namespace armarx::aron::type::reader maybe = o->getMaybe(); p = o->getPath(); } -} +} // namespace armarx::aron::type::reader diff --git a/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.h b/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.h index 5b9d592c08b4e4b43d80b3f960d90e92288b01f6..76eecdba969d5b60de4c929d86c739f48f549558 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/reader/variant/VariantReader.h @@ -30,11 +30,9 @@ // ArmarX #include <RobotAPI/libraries/aron/core/type/variant/Variant.h> - namespace armarx::aron::type::reader { - class VariantReader : - public ReaderInterface<const aron::type::VariantPtr> + class VariantReader : public ReaderInterface<const aron::type::VariantPtr> { public: // constructors @@ -42,27 +40,89 @@ namespace armarx::aron::type::reader type::Descriptor getDescriptor(InputType& input) final; - void readObject(InputType& input, std::string& name, std::vector<std::string>& templates, std::vector<std::string>& templateInstantiations, std::map<std::string, InputTypeNonConst>& memberTypes, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readList(InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readDict(InputType& input, InputTypeNonConst& acceptedType, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readTuple(InputType& input, std::vector<InputTypeNonConst>& acceptedTypes, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readPair(InputType& input, InputTypeNonConst& acceptedType1, InputTypeNonConst& acceptedType2, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readObject(InputType& input, + std::string& name, + std::vector<std::string>& templates, + std::vector<std::string>& templateInstantiations, + std::map<std::string, InputTypeNonConst>& memberTypes, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readList(InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readDict(InputType& input, + InputTypeNonConst& acceptedType, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readTuple(InputType& input, + std::vector<InputTypeNonConst>& acceptedTypes, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readPair(InputType& input, + InputTypeNonConst& acceptedType1, + InputTypeNonConst& acceptedType2, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readNDArray(InputType& input, int& ndim, type::ndarray::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readMatrix(InputType& input, int& rows, int& cols, type::matrix::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readQuaternion(InputType& input, type::quaternion::ElementType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readPointCloud(InputType& input, type::pointcloud::VoxelType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readImage(InputType& input, type::image::PixelType& type, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readNDArray(InputType& input, + int& ndim, + type::ndarray::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readMatrix(InputType& input, + int& rows, + int& cols, + type::matrix::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readQuaternion(InputType& input, + type::quaternion::ElementType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readPointCloud(InputType& input, + type::pointcloud::VoxelType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readImage(InputType& input, + type::image::PixelType& type, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readIntEnum(InputType& input, std::string& name, std::map<std::string, int>& acceptedValues, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readIntEnum(InputType& input, + std::string& name, + std::map<std::string, int>& acceptedValues, + std::string& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readInt(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readLong(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readFloat(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readDouble(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readString(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; - void readBool(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readInt(InputType& input, + int& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readLong(InputType& input, + long& defaultvalue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readFloat(InputType& input, + float& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readDouble(InputType& input, + double& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readString(InputType& input, + std::string& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; + void readBool(InputType& input, + bool& defaultValue, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; - void readAnyObject(InputType& input, type::Maybe& maybe, Path& p = *std::unique_ptr<Path>(new Path())) override; + void readAnyObject(InputType& input, + type::Maybe& maybe, + Path& p = *std::unique_ptr<Path>(new Path())) override; }; -} +} // namespace armarx::aron::type::reader diff --git a/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.cpp b/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.cpp index 159c604b10c0e0bb4d761cc855538240e879abbe..5a8488c98e627894bb73adc1c2937e73fe32577e 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.cpp +++ b/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.cpp @@ -25,29 +25,41 @@ #include "NlohmannJSONWriter.h" // Constantes -#include "../../json/Data.h" #include <RobotAPI/libraries/aron/core/type/visitor/nlohmannJSON/NlohmannJSONVisitor.h> +#include "../../json/Data.h" namespace armarx::aron::type::writer { namespace { /// Set important members for json object (aron meta information) - void setupAronMetaInformationForType(nlohmann::json& json, const std::string& type, const type::Maybe& maybe, const Path& p) + void + setupAronMetaInformationForType(nlohmann::json& json, + const std::string& type, + const type::Maybe& maybe, + const Path& p) { json[rw::json::constantes::TYPE_SLUG] = type; json[rw::json::constantes::PATH_SLUG] = p.getPath(); json[rw::json::constantes::MAYBE_SLUG] = rw::json::conversion::Maybe2String.at(maybe); } - } + } // namespace - type::Descriptor NlohmannJSONWriter::getDescriptor(ReturnTypeConst& input) + type::Descriptor + NlohmannJSONWriter::getDescriptor(ReturnTypeConst& input) { return ConstNlohmannJSONVisitor::GetDescriptor(input); } - nlohmann::json NlohmannJSONWriter::writeObject(const std::string& name, const std::vector<std::string>& templates, const std::vector<std::string>& templateInstantiations, const std::map<std::string, nlohmann::json>& memberTypes, const std::optional<nlohmann::json>& extends, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeObject(const std::string& name, + const std::vector<std::string>& templates, + const std::vector<std::string>& templateInstantiations, + const std::map<std::string, nlohmann::json>& memberTypes, + const std::optional<nlohmann::json>& extends, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::OBJECT_TYPENAME_SLUG, maybe, p); @@ -73,7 +85,10 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeList(const nlohmann::json& acceptedType, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeList(const nlohmann::json& acceptedType, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::LIST_TYPENAME_SLUG, maybe, p); @@ -81,7 +96,10 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeDict(const nlohmann::json& acceptedType, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeDict(const nlohmann::json& acceptedType, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::DICT_TYPENAME_SLUG, maybe, p); @@ -89,7 +107,11 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writePair(const nlohmann::json& acceptedType1, const nlohmann::json& acceptedType2, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writePair(const nlohmann::json& acceptedType1, + const nlohmann::json& acceptedType2, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::PAIR_TYPENAME_SLUG, maybe, p); @@ -97,7 +119,10 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeTuple(const std::vector<nlohmann::json>& acceptedTypes, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeTuple(const std::vector<nlohmann::json>& acceptedTypes, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::TUPLE_TYPENAME_SLUG, maybe, p); @@ -105,7 +130,11 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeNDArray(const int ndim, const type::ndarray::ElementType type, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeNDArray(const int ndim, + const type::ndarray::ElementType type, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::NDARRAY_TYPENAME_SLUG, maybe, p); @@ -114,7 +143,12 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeMatrix(const int rows, + const int cols, + const type::matrix::ElementType type, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::MATRIX_TYPENAME_SLUG, maybe, p); @@ -123,15 +157,23 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeQuaternion(const type::quaternion::ElementType type, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeQuaternion(const type::quaternion::ElementType type, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; - setupAronMetaInformationForType(o, rw::json::constantes::QUATERNION_TYPENAME_SLUG, maybe, p); - o[rw::json::constantes::USED_TYPE_SLUG] = rw::json::conversion::QuaternionType2String.at(type); + setupAronMetaInformationForType( + o, rw::json::constantes::QUATERNION_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::USED_TYPE_SLUG] = + rw::json::conversion::QuaternionType2String.at(type); return o; } - nlohmann::json NlohmannJSONWriter::writeImage(const type::image::PixelType type, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeImage(const type::image::PixelType type, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::IMAGE_TYPENAME_SLUG, maybe, p); @@ -139,19 +181,29 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writePointCloud(const type::pointcloud::VoxelType type, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writePointCloud(const type::pointcloud::VoxelType type, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; - setupAronMetaInformationForType(o, rw::json::constantes::POINT_CLOUD_TYPENAME_SLUG, maybe, p); + setupAronMetaInformationForType( + o, rw::json::constantes::POINT_CLOUD_TYPENAME_SLUG, maybe, p); o[rw::json::constantes::USED_TYPE_SLUG] = rw::json::conversion::VoxelType2String.at(type); return o; } - nlohmann::json NlohmannJSONWriter::writeIntEnum(const std::string& name, const std::map<std::string, int>& acceptedValues, const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeIntEnum(const std::string& name, + const std::map<std::string, int>& acceptedValues, + const std::string& defaultValue, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::INT_ENUM_TYPENAME_SLUG, maybe, p); o[rw::json::constantes::NAME_SLUG] = name; + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; o[rw::json::constantes::ELEMENTS_SLUG] = nlohmann::json(nlohmann::json::value_t::object); for (const auto& [key, value] : acceptedValues) @@ -161,52 +213,68 @@ namespace armarx::aron::type::writer return o; } - nlohmann::json NlohmannJSONWriter::writeInt(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeInt(int defaultValue, const type::Maybe maybe, const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::INT_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeLong(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeLong(long defaultValue, const type::Maybe maybe, const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::LONG_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeFloat(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeFloat(float defaultValue, const type::Maybe maybe, const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::FLOAT_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeDouble(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeDouble(double defaultValue, const type::Maybe maybe, const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::DOUBLE_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeString(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeString(const std::string& defaultValue, + const type::Maybe maybe, + const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::STRING_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeBool(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeBool(bool defaultValue, const type::Maybe maybe, const Path& p) { nlohmann::json o; setupAronMetaInformationForType(o, rw::json::constantes::BOOL_TYPENAME_SLUG, maybe, p); + o[rw::json::constantes::DEFAULT_SLUG] = defaultValue; return o; } - nlohmann::json NlohmannJSONWriter::writeAnyObject(const type::Maybe maybe, const Path& p) + nlohmann::json + NlohmannJSONWriter::writeAnyObject(const type::Maybe maybe, const Path& p) { nlohmann::json o; - setupAronMetaInformationForType(o, rw::json::constantes::ANY_OBJECT_TYPENAME_SLUG, maybe, p); + setupAronMetaInformationForType( + o, rw::json::constantes::ANY_OBJECT_TYPENAME_SLUG, maybe, p); return o; } -} +} // namespace armarx::aron::type::writer diff --git a/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.h b/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.h index 25e89bdf09322528c30aac0d94a41d6483497c25..652dd4903c8ed2926981a0c0d82ff3b975d50e88 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/writer/nlohmannJSON/NlohmannJSONWriter.h @@ -22,8 +22,8 @@ // STD / STL #include <memory> -#include <stack> #include <sstream> +#include <stack> // Simox #include <SimoxUtility/json.h> @@ -33,35 +33,73 @@ namespace armarx::aron::type::writer { - class NlohmannJSONWriter : - public WriterInterface<nlohmann::json> + class NlohmannJSONWriter : public WriterInterface<nlohmann::json> { public: NlohmannJSONWriter() = default; type::Descriptor getDescriptor(ReturnTypeConst& input) final; - ReturnType writeObject(const std::string& name, const std::vector<std::string>& templates, const std::vector<std::string>& templateInstantiations, const std::map<std::string, ReturnType>& memberTypes, const std::optional<ReturnType>& extends, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeList(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeDict(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writePair(const ReturnType& acceptedType1, const ReturnType& acceptedType2, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeObject(const std::string& name, + const std::vector<std::string>& templates, + const std::vector<std::string>& templateInstantiations, + const std::map<std::string, ReturnType>& memberTypes, + const std::optional<ReturnType>& extends, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeList(const ReturnType& acceptedType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeDict(const ReturnType& acceptedType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writePair(const ReturnType& acceptedType1, + const ReturnType& acceptedType2, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeNDArray(const int ndim, const type::ndarray::ElementType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeQuaternion(const type::quaternion::ElementType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeImage(const type::image::PixelType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writePointCloud(const type::pointcloud::VoxelType, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeNDArray(const int ndim, + const type::ndarray::ElementType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeMatrix(const int rows, + const int cols, + const type::matrix::ElementType type, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeQuaternion(const type::quaternion::ElementType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeImage(const type::image::PixelType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writePointCloud(const type::pointcloud::VoxelType, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeIntEnum(const std::string& name, const std::map<std::string, int>& acceptedValues, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeIntEnum(const std::string& name, + const std::map<std::string, int>& acceptedValues, + const std::string& defaultValue, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeInt(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeLong(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeFloat(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeDouble(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeString(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeBool(const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeInt(int defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeLong(long defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeFloat(float defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeDouble(double defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeString(const std::string& defaultValue, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType + writeBool(bool defaultValue, const type::Maybe maybe, const Path& p = Path()) override; ReturnType writeAnyObject(const type::Maybe maybe, const Path& p = Path()) override; }; -} +} // namespace armarx::aron::type::writer diff --git a/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.cpp b/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.cpp index 87af0839552de8e5a66a3e48bb2a95763f6636cb..bee4d57f8719d6b548a6a148f20b91d66fc05f04 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.cpp +++ b/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.cpp @@ -20,23 +20,32 @@ #include "VariantWriter.h" -#include <RobotAPI/libraries/aron/core/type/variant/All.h> - #include <memory> #include <numeric> + +#include <RobotAPI/libraries/aron/core/type/variant/All.h> #include <RobotAPI/libraries/aron/core/type/visitor/variant/VariantVisitor.h> namespace armarx::aron::type::writer { - type::Descriptor VariantWriter::getDescriptor(ReturnTypeConst& input) + type::Descriptor + VariantWriter::getDescriptor(ReturnTypeConst& input) { return ConstVariantVisitor::GetDescriptor(input); } - aron::type::VariantPtr VariantWriter::writeObject(const std::string& name, const std::vector<std::string>& templates, const std::vector<std::string>& templateInstantiations, const std::map<std::string, aron::type::VariantPtr>& memberTypes, const std::optional<aron::type::VariantPtr>& extends, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeObject(const std::string& name, + const std::vector<std::string>& templates, + const std::vector<std::string>& templateInstantiations, + const std::map<std::string, aron::type::VariantPtr>& memberTypes, + const std::optional<aron::type::VariantPtr>& extends, + const type::Maybe maybe, + const Path& p) { - auto o = std::make_shared<type::Object>(name, templates, templateInstantiations, memberTypes, p); + auto o = + std::make_shared<type::Object>(name, templates, templateInstantiations, memberTypes, p); o->setMaybe(maybe); if (extends.has_value()) { @@ -46,41 +55,63 @@ namespace armarx::aron::type::writer return o; } - aron::type::VariantPtr VariantWriter::writeList(const aron::type::VariantPtr& acceptedType, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeList(const aron::type::VariantPtr& acceptedType, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::List>(acceptedType, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeDict(const aron::type::VariantPtr& acceptedType, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeDict(const aron::type::VariantPtr& acceptedType, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Dict>(acceptedType, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writePair(const aron::type::VariantPtr& acceptedType1, const aron::type::VariantPtr& acceptedType2, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writePair(const aron::type::VariantPtr& acceptedType1, + const aron::type::VariantPtr& acceptedType2, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Pair>(acceptedType1, acceptedType2, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeTuple(const std::vector<aron::type::VariantPtr>& acceptedTypes, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeTuple(const std::vector<aron::type::VariantPtr>& acceptedTypes, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Tuple>(acceptedTypes, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeNDArray(const int ndim, const type::ndarray::ElementType, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeNDArray(const int ndim, + const type::ndarray::ElementType, + const type::Maybe maybe, + const Path& p) { - auto o = std::make_shared<type::NDArray>(p); - return o; + auto o = std::make_shared<type::NDArray>(p); + return o; } - aron::type::VariantPtr VariantWriter::writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeMatrix(const int rows, + const int cols, + const type::matrix::ElementType type, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Matrix>(p); o->setMaybe(maybe); @@ -90,7 +121,10 @@ namespace armarx::aron::type::writer return o; } - aron::type::VariantPtr VariantWriter::writeQuaternion(const type::quaternion::ElementType type, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeQuaternion(const type::quaternion::ElementType type, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Quaternion>(p); o->setMaybe(maybe); @@ -98,7 +132,10 @@ namespace armarx::aron::type::writer return o; } - aron::type::VariantPtr VariantWriter::writeImage(const type::image::PixelType type, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeImage(const type::image::PixelType type, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::Image>(p); o->setMaybe(maybe); @@ -106,7 +143,10 @@ namespace armarx::aron::type::writer return o; } - aron::type::VariantPtr VariantWriter::writePointCloud(const type::pointcloud::VoxelType type, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writePointCloud(const type::pointcloud::VoxelType type, + const type::Maybe maybe, + const Path& p) { auto o = std::make_shared<type::PointCloud>(p); o->setMaybe(maybe); @@ -114,59 +154,73 @@ namespace armarx::aron::type::writer return o; } - aron::type::VariantPtr VariantWriter::writeIntEnum(const std::string& name, const std::map<std::string, int>& acceptedValues, const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeIntEnum(const std::string& name, + const std::map<std::string, int>& acceptedValues, + const std::string& defaultValue, + const type::Maybe maybe, + const Path& p) { - auto o = std::make_shared<type::IntEnum>(name, acceptedValues, p); + auto o = std::make_shared<type::IntEnum>(name, acceptedValues, defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeInt(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeInt(int defaultValue, const type::Maybe maybe, const Path& p) { - auto o = std::make_shared<type::Int>(p); + auto o = std::make_shared<type::Int>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeLong(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeLong(long defaultValue, const type::Maybe maybe, const Path& p) { - auto o = std::make_shared<type::Long>(p); + auto o = std::make_shared<type::Long>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeFloat(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeFloat(float defaultValue, const type::Maybe maybe, const Path& p) { - auto o = std::make_shared<type::Float>(p); + auto o = std::make_shared<type::Float>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeDouble(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeDouble(double defaultValue, const type::Maybe maybe, const Path& p) { - auto o = std::make_shared<type::Double>(p); + auto o = std::make_shared<type::Double>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeString(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeString(const std::string& defaultValue, + const type::Maybe maybe, + const Path& p) { - auto o = std::make_shared<type::String>(p); + auto o = std::make_shared<type::String>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeBool(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeBool(bool defaultValue, const type::Maybe maybe, const Path& p) { - auto o = std::make_shared<type::Bool>(p); + auto o = std::make_shared<type::Bool>(defaultValue, p); o->setMaybe(maybe); return o; } - aron::type::VariantPtr VariantWriter::writeAnyObject(const type::Maybe maybe, const Path& p) + aron::type::VariantPtr + VariantWriter::writeAnyObject(const type::Maybe maybe, const Path& p) { auto o = std::make_shared<type::AnyObject>(p); o->setMaybe(maybe); return o; } -} +} // namespace armarx::aron::type::writer diff --git a/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h b/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h index 92fea0d713c496a4b09915dc392252a5c8c9275a..e3c44fe493ce797511f8dbd26445c757e10cca7f 100644 --- a/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h +++ b/source/RobotAPI/libraries/aron/core/type/rw/writer/variant/VariantWriter.h @@ -20,44 +20,81 @@ #pragma once -#include <RobotAPI/libraries/aron/core/type/rw/Writer.h> -#include <RobotAPI/libraries/aron/core/type/variant/Variant.h> - #include <memory> #include <stack> +#include <RobotAPI/libraries/aron/core/type/rw/Writer.h> +#include <RobotAPI/libraries/aron/core/type/variant/Variant.h> namespace armarx::aron::type::writer { - class VariantWriter : - public type::WriterInterface<aron::type::VariantPtr> + class VariantWriter : public type::WriterInterface<aron::type::VariantPtr> { public: VariantWriter() = default; type::Descriptor getDescriptor(ReturnTypeConst& input) final; - ReturnType writeObject(const std::string& name, const std::vector<std::string>& templates, const std::vector<std::string>& templateInstantiations, const std::map<std::string, ReturnType>& memberTypes, const std::optional<ReturnType>& extends, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeList(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeDict(const ReturnType& acceptedType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writePair(const ReturnType& acceptedType1, const ReturnType& acceptedType2, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeObject(const std::string& name, + const std::vector<std::string>& templates, + const std::vector<std::string>& templateInstantiations, + const std::map<std::string, ReturnType>& memberTypes, + const std::optional<ReturnType>& extends, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeList(const ReturnType& acceptedType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeDict(const ReturnType& acceptedType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writePair(const ReturnType& acceptedType1, + const ReturnType& acceptedType2, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeTuple(const std::vector<ReturnType>& acceptedTypes, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeNDArray(const int ndim, const type::ndarray::ElementType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeMatrix(const int rows, const int cols, const type::matrix::ElementType type, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeQuaternion(const type::quaternion::ElementType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeImage(const type::image::PixelType, const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writePointCloud(const type::pointcloud::VoxelType, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeNDArray(const int ndim, + const type::ndarray::ElementType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeMatrix(const int rows, + const int cols, + const type::matrix::ElementType type, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeQuaternion(const type::quaternion::ElementType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writeImage(const type::image::PixelType, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType writePointCloud(const type::pointcloud::VoxelType, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeIntEnum(const std::string& name, const std::map<std::string, int>& acceptedValues, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeIntEnum(const std::string& name, + const std::map<std::string, int>& acceptedValues, + const std::string& defaultValue, + const type::Maybe maybe, + const Path& p = Path()) override; - ReturnType writeInt(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeLong(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeFloat(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeDouble(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeString(const type::Maybe maybe, const Path& p = Path()) override; - ReturnType writeBool(const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeInt(int defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeLong(long defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeFloat(float defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType + writeDouble(double defaultValue, const type::Maybe maybe, const Path& p = Path()) override; + ReturnType writeString(const std::string& defaultValue, + const type::Maybe maybe, + const Path& p = Path()) override; + ReturnType + writeBool(bool defaultValue, const type::Maybe maybe, const Path& p = Path()) override; ReturnType writeAnyObject(const type::Maybe maybe, const Path& p = Path()) override; }; -} +} // namespace armarx::aron::type::writer diff --git a/source/RobotAPI/libraries/aron/core/type/variant/Variant.h b/source/RobotAPI/libraries/aron/core/type/variant/Variant.h index ab996582c630a9083bafb45bc7ec19755e59bb67..6a1e2afa366ff9ae61bef7871d1ddaff9f1b070e 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/Variant.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/Variant.h @@ -24,19 +24,19 @@ #pragma once // STD/STL -#include <memory> -#include <vector> #include <map> +#include <memory> #include <string> +#include <vector> // Simox // #include <SimoxUtility/algorithm/string.h> // ArmarX -#include <RobotAPI/libraries/aron/core/Path.h> -#include <RobotAPI/libraries/aron/core/Exception.h> #include <RobotAPI/interface/aron.h> #include <RobotAPI/libraries/aron/core/Descriptor.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Path.h> namespace armarx::aron::type { @@ -64,15 +64,17 @@ namespace armarx::aron::type public: // constructors Variant(const type::Descriptor& descriptor, const Path& path = Path()) : - descriptor(descriptor), - path(path) + descriptor(descriptor), path(path) { } + virtual ~Variant() = default; // operators virtual bool operator==(const Variant& other) const = 0; - bool operator==(const VariantPtr& other) const + + bool + operator==(const VariantPtr& other) const { if (!other) { @@ -87,17 +89,20 @@ namespace armarx::aron::type static VariantPtr FromAronDTO(const type::dto::GenericType&, const Path& = Path()); // public methods - type::Descriptor getDescriptor() const + type::Descriptor + getDescriptor() const { return descriptor; } - Path getPath() const + Path + getPath() const { return path; } - std::string pathToString() const + std::string + pathToString() const { return path.toString(); } @@ -139,4 +144,4 @@ namespace armarx::aron::type template <class T> concept isVariant = std::is_base_of<Variant, T>::value; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/detail/EnumVariant.h b/source/RobotAPI/libraries/aron/core/type/variant/detail/EnumVariant.h index a9b390b8db6383d63fbc594f23841351861def4f..89a4c9c5ae785ede159bcc38f81459692f3e0db3 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/detail/EnumVariant.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/detail/EnumVariant.h @@ -35,29 +35,160 @@ namespace armarx::aron::type::detail { - template<typename AronTypeT, typename DerivedT> - class EnumVariant : - public SpecializedVariantBase<AronTypeT, DerivedT> + template <typename AronTypeT, typename DerivedT, typename ValueT> + class EnumVariant : public SpecializedVariantBase<AronTypeT, DerivedT> { public: - using SpecializedVariantBase<AronTypeT, DerivedT>::SpecializedVariantBase; + using ValueType = ValueT; + using Base = SpecializedVariantBase<AronTypeT, DerivedT>; + + using Base::SpecializedVariantBase; + + EnumVariant(const type::Descriptor& descriptor, + const std::string& name, + const std::map<std::string, ValueType>& valueMap, + const std::string& def, + const Path& path = {}) : + Base(descriptor, path) + { + this->aron->enumName = name; + this->aron->acceptedValues = valueMap; + setDefaultValueName(def); + } virtual ~EnumVariant() = default; /* virtual implementations */ - VariantPtr navigateAbsolute(const Path &path) const override + VariantPtr + navigateAbsolute(const Path& path) const override { - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate through a non container navigator. The input path was: " + path.toString(), Variant::getPath()); + throw error::AronException( + __PRETTY_FUNCTION__, + "Could not navigate through a non container navigator. The input path was: " + + path.toString(), + Variant::getPath()); } - std::vector<VariantPtr> getChildren() const override + std::vector<VariantPtr> + getChildren() const override { return {}; } - size_t childrenSize() const override + size_t + childrenSize() const override { return 0; } + + std::map<std::string, int> + getAcceptedValueMap() const + { + return this->aron->acceptedValues; + } + + std::vector<std::string> + getAcceptedValueNames() const + { + std::vector<std::string> names; + for (const auto& [k, _] : this->aron->acceptedValues) + { + names.push_back(k); + } + return names; + } + + std::vector<ValueType> + getAcceptedValues() const + { + std::vector<ValueType> vals; + for (const auto& [_, i] : this->aron->acceptedValues) + { + vals.push_back(i); + } + return vals; + } + + std::string + getValueName(ValueType i) const + { + for (const auto& [k, v] : this->aron->acceptedValues) + { + if (v == i) + { + return k; + } + } + throw error::AronException(__PRETTY_FUNCTION__, + "Enum could not be resolved. Input was: " + + std::to_string(i), + this->getPath()); + } + + int + getValue(const std::string& s) const + { + return this->aron->acceptedValues[s]; + } + + std::string + getEnumName() const + { + return this->aron->enumName; + } + + void + setEnumName(const std::string& s) + { + this->aron->enumName = s; + } + + void + addAcceptedValue(const std::string& s, ValueType i) + { + this->aron->acceptedValues[s] = i; + } + + std::string + getDefaultValueName() const + { + return this->aron->defaultValue; + } + + ValueType + getDefaultValue() const + { + // ARMARX_CHECK(std::find(this->aron->acceptedValues.begin(), + // this->aron->acceptedValues.end(), + // this->aron->defaultValue) != this->aron->acceptedValues.end()) + // << "An aron enum type has an invalid default value set. Got: " + // << this->aron->defaultValue; + return this->aron->acceptedValues[this->aron->defaultValue]; + } + + void + setDefaultValue(const ValueType& v) + { + for (const auto& [key, value] : this->aron->acceptedValues) + { + if (value == v) + { + this->aron->defaultValue = key; + } + } + throw error::ValueNotValidException( + __PRETTY_FUNCTION__, "Got invalid input for enum value", std::to_string(v)); + } + + void + setDefaultValueName(const std::string& v) + { + // ARMARX_CHECK(std::find(this->aron->acceptedValues.begin(), + // this->aron->acceptedValues.end(), + // this->aron->defaultValue) != this->aron->acceptedValues.end()) + // << "Trying to set an invalid default value for aron enum type. Got: " + // << this->aron->defaultValue; + this->aron->defaultValue = v; + } }; -} +} // namespace armarx::aron::type::detail diff --git a/source/RobotAPI/libraries/aron/core/type/variant/detail/PrimitiveVariant.h b/source/RobotAPI/libraries/aron/core/type/variant/detail/PrimitiveVariant.h index c7c6eb0b9c00e9ab1cd40800d5917929b8e9e5c3..d17de89fcf21a53299999448626ed8e3488287c9 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/detail/PrimitiveVariant.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/detail/PrimitiveVariant.h @@ -35,29 +35,59 @@ namespace armarx::aron::type::detail { - template<typename AronTypeT, typename DerivedT> - class PrimitiveVariant : - public SpecializedVariantBase<AronTypeT, DerivedT> + template <typename AronTypeT, typename DerivedT, typename ValueT> + class PrimitiveVariant : public SpecializedVariantBase<AronTypeT, DerivedT> { public: - using SpecializedVariantBase<AronTypeT, DerivedT>::SpecializedVariantBase; + using Base = SpecializedVariantBase<AronTypeT, DerivedT>; + + using ValueType = ValueT; + + using Base::SpecializedVariantBase; + + PrimitiveVariant(ValueType def, const type::Descriptor& descriptor, const Path& path) : + Base(descriptor, path) + { + setDefaultValue(def); + } virtual ~PrimitiveVariant() = default; /* virtual implementations */ - VariantPtr navigateAbsolute(const Path &path) const override + VariantPtr + navigateAbsolute(const Path& path) const override { - throw error::AronException(__PRETTY_FUNCTION__, "Could not navigate through a non container navigator. The input path was: " + path.toString(), Variant::getPath()); + throw error::AronException( + __PRETTY_FUNCTION__, + "Could not navigate through a non container navigator. The input path was: " + + path.toString(), + Variant::getPath()); } - std::vector<VariantPtr> getChildren() const override + std::vector<VariantPtr> + getChildren() const override { return {}; } - size_t childrenSize() const override + size_t + childrenSize() const override { return 0; } + + ValueType + getDefaultValue() const + { + return this->aron->defaultValue; + } + + void + setDefaultValue(const ValueType& v) + { + this->aron->defaultValue = v; + } + + protected: }; -} +} // namespace armarx::aron::type::detail diff --git a/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.cpp b/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.cpp index 5ccace22723cbd9eb530064614339827cfcdd3ae..90e8a26e9a36bb52138811dde2f07c95c00b163f 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.cpp @@ -27,89 +27,35 @@ namespace armarx::aron::type { // constructors - IntEnum::IntEnum(const std::string& name, const std::map<std::string, int>& valueMap, const Path& path) : - detail::EnumVariant<type::dto::IntEnum, IntEnum>(type::Descriptor::INT_ENUM, path) + IntEnum::IntEnum(const std::string& name, + const std::map<std::string, ValueType>& valueMap, + const std::string& def, + const Path& path) : + Base(type::Descriptor::INT_ENUM, name, valueMap, def, path) { - aron->enumName = name; - aron->acceptedValues = valueMap; } IntEnum::IntEnum(const type::dto::IntEnum& o, const Path& path) : - detail::EnumVariant<type::dto::IntEnum, IntEnum>(o, type::Descriptor::INT_ENUM, path) + Base(o, type::Descriptor::INT_ENUM, path) { } - std::map<std::string, int> IntEnum::getAcceptedValueMap() const - { - return this->aron->acceptedValues; - } - - std::vector<std::string> IntEnum::getAcceptedValueNames() const - { - std::vector<std::string> names; - for (const auto& [k, _] : aron->acceptedValues) - { - names.push_back(k); - } - return names; - } - - std::vector<int> IntEnum::getAcceptedValues() const - { - std::vector<int> vals; - for (const auto& [_, i] : aron->acceptedValues) - { - vals.push_back(i); - } - return vals; - } - - std::string IntEnum::getValueName(int i) const - { - for (const auto& [k, v] : this->aron->acceptedValues) - { - if (v == i) - { - return k; - } - } - throw error::AronException(__PRETTY_FUNCTION__, "Enum could not be resolved. Input was: " + std::to_string(i), getPath()); - } - - int IntEnum::getValue(const std::string& s) const - { - return this->aron->acceptedValues[s]; - } - - std::string IntEnum::getEnumName() const - { - return this->aron->enumName; - } - - void IntEnum::setEnumName(const std::string& s) - { - this->aron->enumName = s; - } - - void IntEnum::addAcceptedValue(const std::string& s, int i) - { - this->aron->acceptedValues[s] = i; - } - - type::dto::IntEnumPtr IntEnum::toIntEnumDTO() const + type::dto::IntEnumPtr + IntEnum::toIntEnumDTO() const { return this->aron; } // virtual implementations - std::string IntEnum::getShortName() const + std::string + IntEnum::getShortName() const { return "IntEnum"; } - std::string IntEnum::getFullName() const + std::string + IntEnum::getFullName() const { return "armarx::aron::type::IntEnum"; } -} - +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h b/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h index cf652d23cfb225d1ba4efde9c7d48af7c0e34966..62a236068d694e3ecf3848fc24d57fa2af6a6ac9 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/enum/IntEnum.h @@ -24,8 +24,8 @@ #pragma once // STD/STL -#include <string> #include <map> +#include <string> // Base class #include "../detail/EnumVariant.h" @@ -39,25 +39,18 @@ namespace armarx::aron::type * @brief The IntEnum class. It represents the int enum type * An int enum contains a map from strings to int values */ - class IntEnum : - public detail::EnumVariant<type::dto::IntEnum, IntEnum> + class IntEnum : public detail::EnumVariant<type::dto::IntEnum, IntEnum, int> { public: - // constructors - IntEnum(const std::string& name, const std::map<std::string, int>& valueMap, const Path& path = Path()); - IntEnum(const type::dto::IntEnum&, const Path& path = Path()); + using Base = detail::EnumVariant<type::dto::IntEnum, IntEnum, int>; - // public member functions - std::map<std::string, int> getAcceptedValueMap() const; - std::vector<std::string> getAcceptedValueNames() const; - std::vector<int> getAcceptedValues() const; - - std::string getValueName(int) const; - int getValue(const std::string&) const; - std::string getEnumName() const; + // constructors + IntEnum(const std::string& name, + const std::map<std::string, ValueType>& valueMap, + const std::string& def, + const Path& path = Path()); - void setEnumName(const std::string&); - void addAcceptedValue(const std::string&, int); + IntEnum(const type::dto::IntEnum&, const Path& path = Path()); type::dto::IntEnumPtr toIntEnumDTO() const; @@ -65,4 +58,4 @@ namespace armarx::aron::type std::string getShortName() const override; std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.cpp index fc5cdb5cb403e4de3605b82ad9f7a755c925c5d2..538f1c4a715fbd406647c5e5539bb3ca0255b1ca 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "Bool.h" @@ -32,29 +32,31 @@ namespace armarx::aron::type { /* constructors */ - Bool::Bool(const Path& path) : - detail::PrimitiveVariant<type::dto::AronBool, Bool>(type::Descriptor::BOOL, path) + Bool::Bool(ValueType def, const Path& path) : Base(def, type::Descriptor::BOOL, path) { } - Bool::Bool(const type::dto::AronBool&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronBool, Bool>(o, type::Descriptor::BOOL, path) + Bool::Bool(const type::dto::AronBool& o, const Path& path) : + Base(o, type::Descriptor::BOOL, path) { } - type::dto::AronBoolPtr Bool::toBoolDTO() const + type::dto::AronBoolPtr + Bool::toBoolDTO() const { return this->aron; } /* virtual implementations */ - std::string Bool::getShortName() const + std::string + Bool::getShortName() const { return "Bool"; } - std::string Bool::getFullName() const + std::string + Bool::getFullName() const { return "armarx::aron::type::Bool"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.h index eac4aeaea068387ba065a98376a64212a2fc2307..51454cf0dfb041d5b09e17a109ddece0391cee19 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Bool.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The Bool class. It represents the bool type */ - class Bool : - public detail::PrimitiveVariant<type::dto::AronBool, Bool> + class Bool : public detail::PrimitiveVariant<type::dto::AronBool, Bool, bool> { public: + using Base = detail::PrimitiveVariant<type::dto::AronBool, Bool, bool>; + /* constructors */ - Bool(const Path& = Path()); + Bool(ValueType def = false, const Path& = Path()); Bool(const type::dto::AronBool&, const Path& = Path()); type::dto::AronBoolPtr toBoolDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.cpp index e4fd415fe7c54b34d6e60314810a336856e845c0..630ddde856fa783a45bad64948ef3bf6b3656fb6 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "Double.h" @@ -32,29 +32,31 @@ namespace armarx::aron::type { /* constructors */ - Double::Double(const Path& path) : - detail::PrimitiveVariant<type::dto::AronDouble, Double>(type::Descriptor::DOUBLE, path) + Double::Double(ValueType def, const Path& path) : Base(def, type::Descriptor::DOUBLE, path) { } - Double::Double(const type::dto::AronDouble&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronDouble, Double>(o, type::Descriptor::DOUBLE, path) + Double::Double(const type::dto::AronDouble& o, const Path& path) : + Base(o, type::Descriptor::DOUBLE, path) { } - type::dto::AronDoublePtr Double::toDoubleDTO() const + type::dto::AronDoublePtr + Double::toDoubleDTO() const { return this->aron; } /* virtual implementations */ - std::string Double::getShortName() const + std::string + Double::getShortName() const { return "Double"; } - std::string Double::getFullName() const + std::string + Double::getFullName() const { return "armarx::aron::type::Double"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.h index 17aa98ad764ac8081cfcd2e23aad38f388749d18..9472d269c0850bb6f479f1ab63edc43d8acd27f4 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Double.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The Double class. It represents the double type */ - class Double : - public detail::PrimitiveVariant<type::dto::AronDouble, Double> + class Double : public detail::PrimitiveVariant<type::dto::AronDouble, Double, double> { public: + using Base = detail::PrimitiveVariant<type::dto::AronDouble, Double, double>; + /* constructors */ - Double(const Path& = Path()); + Double(ValueType def = 0.0, const Path& = Path()); Double(const type::dto::AronDouble&, const Path& = Path()); type::dto::AronDoublePtr toDoubleDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.cpp index 45bbad7dec390c876ff1033c650e187f29a4788e..9ecdb88a3670d66cd5cd8d8df7174d2457a038e2 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "Float.h" @@ -32,29 +32,31 @@ namespace armarx::aron::type { /* constructors */ - Float::Float(const Path& path) : - detail::PrimitiveVariant<type::dto::AronFloat, Float>(type::Descriptor::FLOAT, path) + Float::Float(ValueType def, const Path& path) : Base(def, type::Descriptor::FLOAT, path) { } - Float::Float(const type::dto::AronFloat&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronFloat, Float>(o, type::Descriptor::FLOAT, path) + Float::Float(const type::dto::AronFloat& o, const Path& path) : + Base(o, type::Descriptor::FLOAT, path) { } - type::dto::AronFloatPtr Float::toFloatDTO() const + type::dto::AronFloatPtr + Float::toFloatDTO() const { return this->aron; } /* virtual implementations */ - std::string Float::getShortName() const + std::string + Float::getShortName() const { return "Float"; } - std::string Float::getFullName() const + std::string + Float::getFullName() const { return "armarx::aron::type::Float"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.h index 2dedfb1739b6f000baddc8bb13306781a3d34a99..627e2a1e859da6c08ed48b65b0322f0de940fd63 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Float.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The Float class. It represents the float type */ - class Float : - public detail::PrimitiveVariant<type::dto::AronFloat, Float> + class Float : public detail::PrimitiveVariant<type::dto::AronFloat, Float, float> { public: + using Base = detail::PrimitiveVariant<type::dto::AronFloat, Float, float>; + /* constructors */ - Float(const Path& = Path()); + Float(ValueType def = 0.0f, const Path& = Path()); Float(const type::dto::AronFloat&, const Path& = Path()); type::dto::AronFloatPtr toFloatDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.cpp index 6abe9850c96afcdf34785f0226cd22f11e067be8..288e770d353336160a466a347800125f3c9bf754 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "Int.h" @@ -32,29 +32,30 @@ namespace armarx::aron::type { /* constructors */ - Int::Int(const Path& path) : - detail::PrimitiveVariant<type::dto::AronInt, Int>(type::Descriptor::INT, path) + Int::Int(ValueType def, const Path& path) : Base(def, type::Descriptor::INT, path) { } - Int::Int(const type::dto::AronInt&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronInt, Int>(o, type::Descriptor::INT, path) + Int::Int(const type::dto::AronInt& o, const Path& path) : Base(o, type::Descriptor::INT, path) { } - type::dto::AronIntPtr Int::toIntDTO() const + type::dto::AronIntPtr + Int::toIntDTO() const { return this->aron; } /* virtual implementations */ - std::string Int::getShortName() const + std::string + Int::getShortName() const { return "Int"; } - std::string Int::getFullName() const + std::string + Int::getFullName() const { return "armarx::aron::type::Int"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.h index 240cd4a50df8687f8cdba2ff15c040d21ec27fbe..899e753ac7b1a5e126c395b2117ae69c6b3c9a83 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Int.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The Int class. It represents the int type */ - class Int : - public detail::PrimitiveVariant<type::dto::AronInt, Int> + class Int : public detail::PrimitiveVariant<type::dto::AronInt, Int, int> { public: + using Base = detail::PrimitiveVariant<type::dto::AronInt, Int, int>; + /* constructors */ - Int(const Path& = Path()); + Int(ValueType def = 0, const Path& = Path()); Int(const type::dto::AronInt&, const Path& = Path()); type::dto::AronIntPtr toIntDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.cpp index f7898bcf2247ddbffea6fedba1c51699571030ba..f7769d4c6f46212b042e75117e873eafac560bfe 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "Long.h" @@ -32,29 +32,31 @@ namespace armarx::aron::type { /* constructors */ - Long::Long(const Path& path) : - detail::PrimitiveVariant<type::dto::AronLong, Long>(type::Descriptor::LONG, path) + Long::Long(ValueType def, const Path& path) : Base(def, type::Descriptor::LONG, path) { } - Long::Long(const type::dto::AronLong&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronLong, Long>(o, type::Descriptor::LONG, path) + Long::Long(const type::dto::AronLong& o, const Path& path) : + Base(o, type::Descriptor::LONG, path) { } - type::dto::AronLongPtr Long::toLongDTO() const + type::dto::AronLongPtr + Long::toLongDTO() const { return this->aron; } /* virtual implementations */ - std::string Long::getShortName() const + std::string + Long::getShortName() const { return "Long"; } - std::string Long::getFullName() const + std::string + Long::getFullName() const { return "armarx::aron::type::Long"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.h index 710df1a421e5ff684ac85b70839ff7cff513378e..6c7e94780f08582bc611c04f32de1a385d382917 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/Long.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The Long class. It represents the long type */ - class Long : - public detail::PrimitiveVariant<type::dto::AronLong, Long> + class Long : public detail::PrimitiveVariant<type::dto::AronLong, Long, long> { public: + using Base = detail::PrimitiveVariant<type::dto::AronLong, Long, long>; + /* constructors */ - Long(const Path& = Path()); + Long(ValueType def = 0L, const Path& = Path()); Long(const type::dto::AronLong&, const Path& = Path()); type::dto::AronLongPtr toLongDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.cpp b/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.cpp index 0ede75062e53745057b0c181db65681656365d7d..314401f8d1ac8a2c6c41bdaf09358cb74d1d6701 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.cpp +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.cpp @@ -23,8 +23,8 @@ // STD/STL -#include <string> #include <map> +#include <string> // Header #include "String.h" @@ -32,30 +32,33 @@ namespace armarx::aron::type { /* constructors */ - String::String(const Path& path) : - detail::PrimitiveVariant<type::dto::AronString, String>(type::Descriptor::STRING, path) + String::String(const ValueType& def, const Path& path) : + Base(def, type::Descriptor::STRING, path) { } - String::String(const type::dto::AronString&o, const Path& path) : - detail::PrimitiveVariant<type::dto::AronString, String>(o, type::Descriptor::STRING, path) + String::String(const type::dto::AronString& o, const Path& path) : + Base(o, type::Descriptor::STRING, path) { } /* public member functions */ - type::dto::AronStringPtr String::toStringDTO() const + type::dto::AronStringPtr + String::toStringDTO() const { return aron; } /* virtual implementations */ - std::string String::getShortName() const + std::string + String::getShortName() const { return "String"; } - std::string String::getFullName() const + std::string + String::getFullName() const { return "armarx::aron::type::String"; } -} +} // namespace armarx::aron::type diff --git a/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.h b/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.h index 54dedab7b228d2262097d0cbe59675c4f721eb39..4adeca624da708e15dcdf4dc4f47d111ca4b381c 100644 --- a/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.h +++ b/source/RobotAPI/libraries/aron/core/type/variant/primitive/String.h @@ -34,12 +34,13 @@ namespace armarx::aron::type /** * @brief The String class. It represents the string type */ - class String : - public detail::PrimitiveVariant<type::dto::AronString, String> + class String : public detail::PrimitiveVariant<type::dto::AronString, String, std::string> { public: + using Base = detail::PrimitiveVariant<type::dto::AronString, String, std::string>; + /* constructors */ - String(const Path& = Path()); + String(const ValueType& def = "", const Path& = Path()); String(const type::dto::AronString&, const Path& = Path()); type::dto::AronStringPtr toStringDTO() const; @@ -48,4 +49,4 @@ namespace armarx::aron::type virtual std::string getShortName() const override; virtual std::string getFullName() const override; }; -} +} // namespace armarx::aron::type