diff --git a/source/RobotAPI/applications/AronCodeGenerator/main.cpp b/source/RobotAPI/applications/AronCodeGenerator/main.cpp index 046053dfb6d34a4979807b7eaf4dd43b7db01367..3de3dc06515dcc47c36657e51edb56baddb76823 100644 --- a/source/RobotAPI/applications/AronCodeGenerator/main.cpp +++ b/source/RobotAPI/applications/AronCodeGenerator/main.cpp @@ -39,8 +39,8 @@ #include <ArmarXCore/libraries/cppgen/CppMethod.h> #include <ArmarXCore/libraries/cppgen/CppClass.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.h> +#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h> +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.h> using namespace armarx; using namespace aron; @@ -131,32 +131,33 @@ int main(int argc, char* argv[]) std::cout << "Parsing the XML file..." << std::endl; } - codegeneration::typereader::AronTypeXMLReader reader; + xmltypereader::Reader reader; reader.parseFile(input_file); if (verbose) { std::cout << "Parsing the XML file... done!" << std::endl; - std::cout << "--> Found " << reader.getGenerateTypes().size() << " types." << std::endl; + std::cout << "--> Found " << reader.getGenerateObjects().size() << " types." << std::endl; std::cout << "--> They are: " << std::endl; - for (const auto& generateType : reader.getGenerateTypes()) + for (const auto& generateType : reader.getGenerateObjects()) { std::cout << "----> " << generateType->typeName << "( with " << generateType->nestedObjects.size() << " inner definitions)" << std::endl; } } - codegeneration::classwriter::AronTypeClassCppWriter writer("AronTestSegment", reader.getCodeIncludes()); + cppcodegenerator::Writer writer("AronTestSegment", reader.getCodeIncludes()); if (verbose) { std::cout << "Running the type class generator..." << std::endl; } - writer.generateTypeClasses(reader.getGenerateTypes()); + writer.generateTypeIntEnums(reader.getGenerateIntEnums()); + writer.generateTypeObjects(reader.getGenerateObjects()); if (verbose) { std::cout << "Running the type class generator... done!" << std::endl; - std::cout << "--> Found " << writer.getTypeClasses().size() << " type classes." << std::endl; + std::cout << "--> Found " << writer.getTypeClasses().size() << " type objects." << std::endl; std::cout << "--> They are: " << std::endl; for (const auto& c : writer.getTypeClasses()) { @@ -248,7 +249,7 @@ int main(int argc, char* argv[]) if (verbose) { - std::cout << "Finished generating <" + output_file.string() + ">" << std::endl; + std::cout << "Finished generating <" + output_file.string() + ">. The new file ist called <" << output_file.string() << ">" << std::endl; } } catch (const cxxopts::OptionException& e) diff --git a/source/RobotAPI/components/RobotState/RobotStateComponent.cpp b/source/RobotAPI/components/RobotState/RobotStateComponent.cpp index 3d51ac4aa003553fa4ea9a5994951904001c29c2..94b1deab94ab62fa3707552fea3ef92560ecba67 100644 --- a/source/RobotAPI/components/RobotState/RobotStateComponent.cpp +++ b/source/RobotAPI/components/RobotState/RobotStateComponent.cpp @@ -692,5 +692,24 @@ namespace armarx } + // legacy + void RobotStateComponent::reportPlatformPose(const PlatformPose& currentPose, const Current&) + { + const float z = 0; + const Eigen::Vector3f position(currentPose.x, currentPose.y, z); + const Eigen::Matrix3f orientation = + Eigen::AngleAxisf(currentPose.rotationAroundZ, Eigen::Vector3f::UnitZ()).toRotationMatrix(); + const Eigen::Matrix4f globalPose = math::Helpers::Pose(position, orientation); + + IceUtil::Time time = IceUtil::Time::microSeconds(currentPose.timestampInMicroSeconds); + insertPose(time, globalPose); + + if (_sharedRobotServant) + { + _sharedRobotServant->setTimestamp(time); + } + } + + } diff --git a/source/RobotAPI/components/RobotState/RobotStateComponent.h b/source/RobotAPI/components/RobotState/RobotStateComponent.h index 881e97ddc17fc75f45a64e2048c620c17beee40f..685567a476bd7ecfd8d97981fa2cc205d53c43bd 100644 --- a/source/RobotAPI/components/RobotState/RobotStateComponent.h +++ b/source/RobotAPI/components/RobotState/RobotStateComponent.h @@ -128,6 +128,20 @@ namespace armarx void setRobotStateObserver(RobotStateObserverPtr observer); + + // PlatformUnitListener interface + // TODO: Remove this interface and use GlobalRobotPoseLocalizationListener only. + /// Stores the platform pose in the pose history. + void reportPlatformPose(const PlatformPose& currentPose, const Ice::Current& = Ice::emptyCurrent) override; + /// Does nothing. + void reportNewTargetPose(Ice::Float newPlatformPositionX, Ice::Float newPlatformPositionY, Ice::Float newPlatformRotation, const Ice::Current& = Ice::emptyCurrent) override {} + /// Does nothing. + void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current& = Ice::emptyCurrent) override {} + /// Does nothing. + void reportPlatformOdometryPose(Ice::Float x, Ice::Float y, Ice::Float angle, const Ice::Current& = Ice::emptyCurrent) override {} + + + protected: // Component interface. diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp b/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp deleted file mode 100644 index 859bbd4a23a6dd324ae884bd1aa0cf4cb6dcb804..0000000000000000000000000000000000000000 --- a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This file is part of ArmarX. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @package RobotAPI::ArmarXObjects::ArMemDebugMemory - * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) - * @date 2020 - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include "ArMemDebugMemory.h" - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> - -#include <SimoxUtility/algorithm/string.h> - -#include <RobotAPI/libraries/armem/core/error.h> -#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> - -namespace armarx -{ - ArMemDebugMemoryPropertyDefinitions::ArMemDebugMemoryPropertyDefinitions(std::string prefix) : - armarx::ComponentPropertyDefinitions(prefix) - { - } - - ArMemDebugMemory::ArMemDebugMemory() - { - } - - armarx::PropertyDefinitionsPtr ArMemDebugMemory::createPropertyDefinitions() - { - armarx::PropertyDefinitionsPtr defs = new ArMemDebugMemoryPropertyDefinitions(getConfigIdentifier()); - - defs->topic(debugObserver); - return defs; - } - - - std::string ArMemDebugMemory::getDefaultName() const - { - return "ArMemDebugMemory"; - } - - - void ArMemDebugMemory::onInitComponent() - { - memory.name() = memoryName; - } - - - void ArMemDebugMemory::onConnectComponent() - { - RemoteGui__createTab(); - RemoteGui_startRunningTask(); - } - - - void ArMemDebugMemory::onDisconnectComponent() - { - } - - - void ArMemDebugMemory::onExitComponent() - { - } - - - - // WRITING - armem::data::AddSegmentsResult ArMemDebugMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) - { - armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, addCoreSegmentOnUsage); - tab.rebuild = true; - return result; - } - - - armem::data::CommitResult ArMemDebugMemory::commit(const armem::data::Commit& commit, const Ice::Current&) - { - armem::data::CommitResult result = ComponentPluginUser::commit(commit); - tab.rebuild = true; - return result; - } - - - // READING - - // Inherited from Plugin - - - - // REMOTE GUI - - void ArMemDebugMemory::RemoteGui__createTab() - { - using namespace armarx::RemoteGui::Client; - - armem::server::MemoryRemoteGui mrg; - { - std::scoped_lock lock(memoryMutex); - tab.memoryGroup = mrg.makeGroupBox(memory); - } - - VBoxLayout root = {tab.memoryGroup, VSpacer()}; - RemoteGui_createTab(getName(), root, &tab); - } - - - void ArMemDebugMemory::RemoteGui_update() - { - if (tab.rebuild.exchange(false)) - { - RemoteGui__createTab(); - } - } - -} diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml b/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml deleted file mode 100644 index 0cd92acebcb91a793a58a7ce09896ac8c2f91214..0000000000000000000000000000000000000000 --- a/source/RobotAPI/components/armem/ArMemDebugMemory/xmls/ExampleData.xml +++ /dev/null @@ -1,86 +0,0 @@ -<!--Some fancy comment --> -<?xml version="1.0" encoding="UTF-8" ?> -<AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - <Include include="<Image/ByteImage.h>" /> - </CodeIncludes> - <GenerateTypes> - <GenerateType name='armarx::armem::aron::example::ExampleData'> - <ObjectChild key='the_int'> - <Int /> - </ObjectChild> - <ObjectChild key='the_long'> - <Long /> - </ObjectChild> - <ObjectChild key='the_float'> - <Float /> - </ObjectChild> - <ObjectChild key='the_double'> - <Double /> - </ObjectChild> - <ObjectChild key='the_string'> - <String /> - </ObjectChild> - <ObjectChild key='the_bool'> - <Bool /> - </ObjectChild> - - - <ObjectChild key='the_eigen_position'> - <EigenMatrix rows="3" cols="1" type="float" /> - </ObjectChild> - <ObjectChild key='the_eigen_pose'> - <EigenMatrix rows="4" cols="4" type="float" /> - </ObjectChild> - <ObjectChild key='the_ivt_image'> - <IVTCByteImage type="GrayScale" /> - </ObjectChild> - - - <ObjectChild key='the_float_list'> - <List> - <Float /> - </List> - </ObjectChild> - <ObjectChild key='the_int_list'> - <List> - <Int /> - </List> - </ObjectChild> - <ObjectChild key='the_string_list'> - <List> - <String /> - </List> - </ObjectChild> - - <ObjectChild key='the_object_list'> - <List> - <Object name='ListClass'> - <ObjectChild key='element_int'> - <Int /> - </ObjectChild> - <ObjectChild key='element_float'> - <Float /> - </ObjectChild> - <ObjectChild key='element_string'> - <String /> - </ObjectChild> - </Object> - </List> - </ObjectChild> - - <ObjectChild key='the_float_dict'> - <Dict> - <Float /> - </Dict> - </ObjectChild> - <ObjectChild key='the_int_dict'> - <Dict> - <Int /> - </Dict> - </ObjectChild> - - </GenerateType> - </GenerateTypes> -</AronTypeDefinition> diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/test/CMakeLists.txt b/source/RobotAPI/components/armem/ArMemExampleMemory/test/CMakeLists.txt deleted file mode 100644 index 8c8e23c047ea826570eaaa45c497838112124af8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -# Libs required for the tests -SET(LIBS ${LIBS} ArmarXCore ArMemExampleMemory) - -armarx_add_test(ArMemExampleMemoryTest ArMemExampleMemoryTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/CMakeLists.txt b/source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/CMakeLists.txt deleted file mode 100644 index aeab2d50f304cf5fe4081deb1c7b7cab6be175f4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ - -# Libs required for the tests -SET(LIBS ${LIBS} ArmarXCore ArMemMemoryNameSystem) - -armarx_add_test(ArMemMemoryNameSystemTest ArMemMemoryNameSystemTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/CMakeLists.txt b/source/RobotAPI/components/armem/CMakeLists.txt index 6d4b4b0bf0e91cff4278a646479140f9afd27b59..b80992aeaf1f03968a7b229d600def905796d1f7 100644 --- a/source/RobotAPI/components/armem/CMakeLists.txt +++ b/source/RobotAPI/components/armem/CMakeLists.txt @@ -1,4 +1,14 @@ -add_subdirectory(ArMemExampleMemory) -add_subdirectory(ArMemDebugMemory) -add_subdirectory(ArMemExampleClient) -add_subdirectory(ArMemMemoryNameSystem) +# memory servers +add_subdirectory(server/ExampleMemory) +add_subdirectory(server/GeneralPurposeMemory) +add_subdirectory(server/RobotSensorMemory) +add_subdirectory(server/SkillsMemory) + +# memory server addons + + +# clients +add_subdirectory(client) + +# The memory name system +add_subdirectory(MemoryNameSystem) diff --git a/source/RobotAPI/components/armem/MemoryNameSystem/CMakeLists.txt b/source/RobotAPI/components/armem/MemoryNameSystem/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..75a50c54304d11e5452f1e4d1f8287a65fd0e9f6 --- /dev/null +++ b/source/RobotAPI/components/armem/MemoryNameSystem/CMakeLists.txt @@ -0,0 +1,22 @@ +armarx_component_set_name("MemoryNameSystem") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem + # RobotAPIComponentPlugins # for ArViz and other plugins +) + +set(SOURCES + MemoryNameSystem.cpp +) +set(HEADERS + MemoryNameSystem.h +) + + +armarx_add_component("${SOURCES}" "${HEADERS}") + +#generate the application +armarx_generate_and_add_component_executable() diff --git a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.cpp b/source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.cpp similarity index 67% rename from source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.cpp rename to source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.cpp index 22c9235a354a2f3eabc89d99d9e26212cd6ed5b4..47131a79a44f25dabc1e3364fcc7d3d044b3e506 100644 --- a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.cpp +++ b/source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.cpp @@ -13,14 +13,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemMemoryNameSystem + * @package RobotAPI::ArmarXObjects::MemoryNameSystem * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#include "ArMemMemoryNameSystem.h" +#include "MemoryNameSystem.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> @@ -31,49 +31,49 @@ namespace armarx { - ArMemMemoryNameSystemPropertyDefinitions::ArMemMemoryNameSystemPropertyDefinitions(std::string prefix) : + MemoryNameSystemPropertyDefinitions::MemoryNameSystemPropertyDefinitions(std::string prefix) : armarx::ComponentPropertyDefinitions(prefix) { } - armarx::PropertyDefinitionsPtr ArMemMemoryNameSystem::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr MemoryNameSystem::createPropertyDefinitions() { - armarx::PropertyDefinitionsPtr defs = new ArMemMemoryNameSystemPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr defs = new MemoryNameSystemPropertyDefinitions(getConfigIdentifier()); return defs; } - std::string ArMemMemoryNameSystem::getDefaultName() const + std::string MemoryNameSystem::getDefaultName() const { - return "ArMemMemoryNameSystem"; + return "MemoryNameSystem"; } - void ArMemMemoryNameSystem::onInitComponent() + void MemoryNameSystem::onInitComponent() { } - void ArMemMemoryNameSystem::onConnectComponent() + void MemoryNameSystem::onConnectComponent() { RemoteGui__createTab(); RemoteGui_startRunningTask(); } - void ArMemMemoryNameSystem::onDisconnectComponent() + void MemoryNameSystem::onDisconnectComponent() { } - void ArMemMemoryNameSystem::onExitComponent() + void MemoryNameSystem::onExitComponent() { } - armem::data::RegisterMemoryResult ArMemMemoryNameSystem::registerMemory( + armem::data::RegisterMemoryResult MemoryNameSystem::registerMemory( const armem::data::RegisterMemoryInput& input, const Ice::Current& c) { armem::data::RegisterMemoryResult result = Plugin::registerMemory(input, c); @@ -82,7 +82,7 @@ namespace armarx } - armem::data::RemoveMemoryResult ArMemMemoryNameSystem::removeMemory( + armem::data::RemoveMemoryResult MemoryNameSystem::removeMemory( const armem::data::RemoveMemoryInput& input, const Ice::Current& c) { armem::data::RemoveMemoryResult result = Plugin::removeMemory(input, c); @@ -94,7 +94,7 @@ namespace armarx // REMOTE GUI - void ArMemMemoryNameSystem::RemoteGui__createTab() + void MemoryNameSystem::RemoteGui__createTab() { using namespace armarx::RemoteGui::Client; @@ -106,7 +106,7 @@ namespace armarx } - void ArMemMemoryNameSystem::RemoteGui_update() + void MemoryNameSystem::RemoteGui_update() { if (tab.rebuild.exchange(false)) { diff --git a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.h b/source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.h similarity index 82% rename from source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.h rename to source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.h index 5147135bce50689bfeccde89464039cf0db10440..795aecc66f96423aa29b28660694e09ea50a1426 100644 --- a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/ArMemMemoryNameSystem.h +++ b/source/RobotAPI/components/armem/MemoryNameSystem/MemoryNameSystem.h @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemMemoryNameSystem + * @package RobotAPI::ArmarXObjects::MemoryNameSystem * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt @@ -37,30 +37,30 @@ namespace armarx { /** - * @class ArMemMemoryNameSystemPropertyDefinitions - * @brief Property definitions of `ArMemMemoryNameSystem`. + * @class MemoryNameSystemPropertyDefinitions + * @brief Property definitions of `MemoryNameSystem`. */ - class ArMemMemoryNameSystemPropertyDefinitions : + class MemoryNameSystemPropertyDefinitions : public armarx::ComponentPropertyDefinitions { public: - ArMemMemoryNameSystemPropertyDefinitions(std::string prefix); + MemoryNameSystemPropertyDefinitions(std::string prefix); }; /** - * @defgroup Component-ArMemMemoryNameSystem ArMemMemoryNameSystem + * @defgroup Component-MemoryNameSystem MemoryNameSystem * @ingroup RobotAPI-Components - * A description of the component ArMemMemoryNameSystem. + * A description of the component MemoryNameSystem. * - * @class ArMemMemoryNameSystem - * @ingroup Component-ArMemMemoryNameSystem - * @brief Brief description of class ArMemMemoryNameSystem. + * @class MemoryNameSystem + * @ingroup Component-MemoryNameSystem + * @brief Brief description of class MemoryNameSystem. * - * Detailed description of class ArMemMemoryNameSystem. + * Detailed description of class MemoryNameSystem. */ - class ArMemMemoryNameSystem : + class MemoryNameSystem : virtual public armarx::Component , virtual public armem::mns::ComponentPluginUser , virtual public LightweightRemoteGuiComponentPluginUser diff --git a/source/RobotAPI/components/armem/MemoryNameSystem/test/CMakeLists.txt b/source/RobotAPI/components/armem/MemoryNameSystem/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b495ddff0ba086967c34c28e0d2da770ae4f8998 --- /dev/null +++ b/source/RobotAPI/components/armem/MemoryNameSystem/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore MemoryNameSystem) + +armarx_add_test(MemoryNameSystemTest MemoryNameSystemTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/ArMemMemoryNameSystemTest.cpp b/source/RobotAPI/components/armem/MemoryNameSystem/test/MemoryNameSystemTest.cpp similarity index 81% rename from source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/ArMemMemoryNameSystemTest.cpp rename to source/RobotAPI/components/armem/MemoryNameSystem/test/MemoryNameSystemTest.cpp index 7c2f6aea7d307d2ced486c746f57aeb21824fc89..3eecee385f44a1a05596c617a938f00048fcc1fd 100644 --- a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/test/ArMemMemoryNameSystemTest.cpp +++ b/source/RobotAPI/components/armem/MemoryNameSystem/test/MemoryNameSystemTest.cpp @@ -13,25 +13,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemMemoryNameSystem + * @package RobotAPI::ArmarXObjects::MemoryNameSystem * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ArMemMemoryNameSystem +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::MemoryNameSystem #define ARMARX_BOOST_TEST #include <RobotAPI/Test.h> -#include "../ArMemMemoryNameSystem.h" +#include "../MemoryNameSystem.h" #include <iostream> BOOST_AUTO_TEST_CASE(testExample) { - armarx::ArMemMemoryNameSystem instance; + armarx::MemoryNameSystem instance; BOOST_CHECK_EQUAL(true, true); } diff --git a/source/RobotAPI/components/armem/client/CMakeLists.txt b/source/RobotAPI/components/armem/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a8e816bf283467a0a0efbadf9fff40d555ec153b --- /dev/null +++ b/source/RobotAPI/components/armem/client/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ExampleClient) diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/CMakeLists.txt b/source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt similarity index 84% rename from source/RobotAPI/components/armem/ArMemExampleClient/CMakeLists.txt rename to source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt index 01eb7b07b3fc2a9c2d48345b84a1784663958ca7..a6c8b9c637db73dc5cae91c430346542b834dec4 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/CMakeLists.txt +++ b/source/RobotAPI/components/armem/client/ExampleClient/CMakeLists.txt @@ -1,4 +1,4 @@ -armarx_component_set_name("ArMemExampleClient") +armarx_component_set_name("ExampleClient") find_package(IVT QUIET) armarx_build_if(IVT_FOUND "IVT not available") @@ -11,11 +11,11 @@ set(COMPONENT_LIBS ) set(SOURCES - ArMemExampleClient.cpp + ExampleClient.cpp ) set(HEADERS - ArMemExampleClient.h + ExampleClient.h ) armarx_add_component("${SOURCES}" "${HEADERS}") diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp b/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp similarity index 86% rename from source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp rename to source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp index d2f6c51d85292b249c83649fd11b10446bc8312f..b69d0aa5380712e216996be6f69b0a8b0c28b39d 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.cpp +++ b/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.cpp @@ -13,14 +13,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemExampleClient + * @package RobotAPI::ArmarXObjects::ExampleClient * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#include "ArMemExampleClient.h" +#include "ExampleClient.h" #include <SimoxUtility/color/cmaps.h> @@ -32,19 +32,19 @@ #include <RobotAPI/libraries/armem/client/query/query_fns.h> #include <RobotAPI/libraries/armem/core/ice_conversions.h> -#include <RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.aron.generated.h> +#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> namespace armarx { - ArMemExampleClientPropertyDefinitions::ArMemExampleClientPropertyDefinitions(std::string prefix) : + ExampleClientPropertyDefinitions::ExampleClientPropertyDefinitions(std::string prefix) : armarx::ComponentPropertyDefinitions(prefix) { } - armarx::PropertyDefinitionsPtr ArMemExampleClient::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr ExampleClient::createPropertyDefinitions() { - armarx::PropertyDefinitionsPtr defs = new ArMemExampleClientPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr defs = new ExampleClientPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); @@ -53,18 +53,18 @@ namespace armarx return defs; } - std::string ArMemExampleClient::getDefaultName() const + std::string ExampleClient::getDefaultName() const { - return "ArMemExampleClient"; + return "ExampleClient"; } - void ArMemExampleClient::onInitComponent() + void ExampleClient::onInitComponent() { } - void ArMemExampleClient::onConnectComponent() + void ExampleClient::onConnectComponent() { createRemoteGuiTab(); RemoteGui_startRunningTask(); @@ -90,26 +90,26 @@ namespace armarx ARMARX_INFO << "Entity " << entityID << " was updated by " << snapshotIDs.size() << " snapshots."; }); // Using a member function: - memoryReader.subscribe(entityID, this, &ArMemExampleClient::example_entityUpdated); + memoryReader.subscribe(entityID, this, &ExampleClient::example_entityUpdated); - task = new RunningTask<ArMemExampleClient>(this, &ArMemExampleClient::run); + task = new RunningTask<ExampleClient>(this, &ExampleClient::run); task->start(); } - void ArMemExampleClient::onDisconnectComponent() + void ExampleClient::onDisconnectComponent() { task->stop(); } - void ArMemExampleClient::onExitComponent() + void ExampleClient::onExitComponent() { } - void ArMemExampleClient::run() + void ExampleClient::run() { ARMARX_IMPORTANT << "Running example."; @@ -142,7 +142,7 @@ namespace armarx } - armem::MemoryID ArMemExampleClient::addProviderSegment() + armem::MemoryID ExampleClient::addProviderSegment() { armem::data::AddSegmentInput input; input.coreSegmentName = "ExampleModality"; @@ -155,7 +155,7 @@ namespace armarx return armem::MemoryID(result.segmentID); } - armem::MemoryID ArMemExampleClient::commitSingleSnapshot(const armem::MemoryID& entityID) + armem::MemoryID ExampleClient::commitSingleSnapshot(const armem::MemoryID& entityID) { // Prepare the update with some empty instances. armem::EntityUpdate update; @@ -163,8 +163,8 @@ namespace armarx update.timeCreated = armem::Time::now(); update.instancesData = { - std::make_shared<aron::datanavigator::AronDictDataNavigator>(), - std::make_shared<aron::datanavigator::AronDictDataNavigator>() + std::make_shared<aron::datanavigator::DictNavigator>(), + std::make_shared<aron::datanavigator::DictNavigator>() }; ARMARX_IMPORTANT << "Committing " << update; @@ -178,7 +178,7 @@ namespace armarx return updateResult.snapshotID; } - void ArMemExampleClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num) + void ExampleClient::commitMultipleSnapshots(const armem::MemoryID& entityID, int num) { // Commit a number of updates with different timestamps and number of instances. armem::Commit commit; @@ -189,7 +189,7 @@ namespace armarx update.timeCreated = armem::Time::now() + armem::Time::seconds(i); for (int j = 0; j < i; ++j) { - update.instancesData.push_back(std::make_shared<aron::datanavigator::AronDictDataNavigator>()); + update.instancesData.push_back(std::make_shared<aron::datanavigator::DictNavigator>()); } } ARMARX_IMPORTANT << "Committing " << commit; @@ -202,7 +202,7 @@ namespace armarx } - void ArMemExampleClient::queryLatestSnapshot(const armem::MemoryID& entityID) + void ExampleClient::queryLatestSnapshot(const armem::MemoryID& entityID) { ARMARX_IMPORTANT << "Querying latest snapshot: " @@ -262,7 +262,7 @@ namespace armarx } } - void ArMemExampleClient::queryExactSnapshot(const armem::MemoryID& snapshotID) + void ExampleClient::queryExactSnapshot(const armem::MemoryID& snapshotID) { ARMARX_IMPORTANT << "Querying exact smapshot: " @@ -297,7 +297,7 @@ namespace armarx } - void ArMemExampleClient::commitExampleData() + void ExampleClient::commitExampleData() { ARMARX_IMPORTANT << "Adding segment " << "ExampleData" << "/" << getName(); @@ -376,7 +376,7 @@ namespace armarx } } - void ArMemExampleClient::queryExampleData() + void ExampleClient::queryExampleData() { // Query all entities from provider. armem::client::query::Builder qb; @@ -400,7 +400,7 @@ namespace armarx - void ArMemExampleClient::example_entityUpdated(const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs) + void ExampleClient::example_entityUpdated(const armem::MemoryID& subscriptionID, const std::vector<armem::MemoryID>& snapshotIDs) { std::stringstream ss; ss << "example_entity got updated: " << subscriptionID << "\n"; @@ -414,7 +414,7 @@ namespace armarx } - void ArMemExampleClient::createRemoteGuiTab() + void ExampleClient::createRemoteGuiTab() { using namespace armarx::RemoteGui::Client; @@ -427,7 +427,7 @@ namespace armarx RemoteGui_createTab(getName(), root, &tab); } - void ArMemExampleClient::RemoteGui_update() + void ExampleClient::RemoteGui_update() { if (tab.rebuild.exchange(false)) { diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h b/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h similarity index 82% rename from source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h rename to source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h index 263e5f5d51c9c9fca6fdd10312c7435a285ada3e..3ee6d82e44f6efa8feb62b504d3d966ac23387fb 100644 --- a/source/RobotAPI/components/armem/ArMemExampleClient/ArMemExampleClient.h +++ b/source/RobotAPI/components/armem/client/ExampleClient/ExampleClient.h @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemExampleClient + * @package RobotAPI::ArmarXObjects::ExampleClient * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt @@ -40,29 +40,29 @@ namespace armarx { /** - * @class ArMemExampleClientPropertyDefinitions - * @brief Property definitions of `ArMemExampleClient`. + * @class ExampleClientPropertyDefinitions + * @brief Property definitions of `ExampleClient`. */ - class ArMemExampleClientPropertyDefinitions : + class ExampleClientPropertyDefinitions : public armarx::ComponentPropertyDefinitions { public: - ArMemExampleClientPropertyDefinitions(std::string prefix); + ExampleClientPropertyDefinitions(std::string prefix); }; /** - * @defgroup Component-ArMemExampleClient ArMemExampleClient + * @defgroup Component-ExampleClient ExampleClient * @ingroup RobotAPI-Components - * A description of the component ArMemExampleClient. + * A description of the component ExampleClient. * - * @class ArMemExampleClient - * @ingroup Component-ArMemExampleClient - * @brief Brief description of class ArMemExampleClient. + * @class ExampleClient + * @ingroup Component-ExampleClient + * @brief Brief description of class ExampleClient. * - * Detailed description of class ArMemExampleClient. + * Detailed description of class ExampleClient. */ - class ArMemExampleClient : + class ExampleClient : virtual public armarx::Component, virtual public armarx::armem::client::ComponentPluginUser, virtual public LightweightRemoteGuiComponentPluginUser @@ -114,7 +114,7 @@ namespace armarx private: - armarx::RunningTask<ArMemExampleClient>::pointer_type task; + armarx::RunningTask<ExampleClient>::pointer_type task; armarx::DebugObserverInterfacePrx debugObserver; diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/test/ArMemExampleClientTest.cpp b/source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp similarity index 100% rename from source/RobotAPI/components/armem/ArMemExampleClient/test/ArMemExampleClientTest.cpp rename to source/RobotAPI/components/armem/client/ExampleClient/test/ArMemExampleClientTest.cpp diff --git a/source/RobotAPI/components/armem/ArMemExampleClient/test/CMakeLists.txt b/source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt similarity index 100% rename from source/RobotAPI/components/armem/ArMemExampleClient/test/CMakeLists.txt rename to source/RobotAPI/components/armem/client/ExampleClient/test/CMakeLists.txt diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/ExampleMemory/CMakeLists.txt similarity index 88% rename from source/RobotAPI/components/armem/ArMemExampleMemory/CMakeLists.txt rename to source/RobotAPI/components/armem/server/ExampleMemory/CMakeLists.txt index c02d06dd2fc8aae51f745685e8fcb29a2b3fc696..99070a2c52f970a6ac9f64992a5a9a113de7f227 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/CMakeLists.txt +++ b/source/RobotAPI/components/armem/server/ExampleMemory/CMakeLists.txt @@ -1,4 +1,4 @@ -armarx_component_set_name("ArMemExampleMemory") +armarx_component_set_name("ExampleMemory") find_package(IVT QUIET) armarx_build_if(IVT_FOUND "IVT not available") @@ -14,10 +14,10 @@ set(COMPONENT_LIBS ) set(SOURCES - ArMemExampleMemory.cpp + ExampleMemory.cpp ) set(HEADERS - ArMemExampleMemory.h + ExampleMemory.h ) diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp similarity index 73% rename from source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp rename to source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp index 8ef1905c1773892912986b24c13c4dc1a9647357..19b547583a3678d9b244e8fa4b13b48730229033 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.cpp +++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.cpp @@ -13,14 +13,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemExampleMemory + * @package RobotAPI::ArmarXObjects::ExampleMemory * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#include "ArMemExampleMemory.h" +#include "ExampleMemory.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> @@ -29,19 +29,14 @@ #include <RobotAPI/libraries/armem/core/error.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> -#include <RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.aron.generated.h> +#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> namespace armarx { - ArMemExampleMemoryPropertyDefinitions::ArMemExampleMemoryPropertyDefinitions(std::string prefix) : - armarx::ComponentPropertyDefinitions(prefix) + armarx::PropertyDefinitionsPtr ExampleMemory::createPropertyDefinitions() { - } - - armarx::PropertyDefinitionsPtr ArMemExampleMemory::createPropertyDefinitions() - { - armarx::PropertyDefinitionsPtr defs = new ArMemExampleMemoryPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); defs->topic(debugObserver); @@ -58,12 +53,12 @@ namespace armarx } - std::string ArMemExampleMemory::getDefaultName() const + std::string ExampleMemory::getDefaultName() const { - return "ArMemExampleMemory"; + return "ExampleMemory"; } - void ArMemExampleMemory::onInitComponent() + void ExampleMemory::onInitComponent() { memory.name() = p.memoryName; @@ -77,17 +72,17 @@ namespace armarx memory.addCoreSegments(p.core.defaultCoreSegments); } - void ArMemExampleMemory::onConnectComponent() + void ExampleMemory::onConnectComponent() { RemoteGui__createTab(); RemoteGui_startRunningTask(); } - void ArMemExampleMemory::onDisconnectComponent() + void ExampleMemory::onDisconnectComponent() { } - void ArMemExampleMemory::onExitComponent() + void ExampleMemory::onExitComponent() { } @@ -95,7 +90,7 @@ namespace armarx // WRITING - armem::data::AddSegmentsResult ArMemExampleMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) + armem::data::AddSegmentsResult ExampleMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) { // This function is overloaded to trigger the remote gui rebuild. armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, p.core.addOnUsage); @@ -104,7 +99,7 @@ namespace armarx } - armem::data::CommitResult ArMemExampleMemory::commit(const armem::data::Commit& commit, const Ice::Current&) + armem::data::CommitResult ExampleMemory::commit(const armem::data::Commit& commit, const Ice::Current&) { // This function is overloaded to trigger the remote gui rebuild. armem::data::CommitResult result = ComponentPluginUser::commit(commit); @@ -121,7 +116,7 @@ namespace armarx // REMOTE GUI - void ArMemExampleMemory::RemoteGui__createTab() + void ExampleMemory::RemoteGui__createTab() { using namespace armarx::RemoteGui::Client; @@ -135,7 +130,7 @@ namespace armarx } - void ArMemExampleMemory::RemoteGui_update() + void ExampleMemory::RemoteGui_update() { if (tab.rebuild.exchange(false)) { diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h similarity index 80% rename from source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h rename to source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h index aedb1732f88bbb926393877ea6fb12600a252f83..37d20608bea3c0c14cda73332693768899d6ce90 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/ArMemExampleMemory.h +++ b/source/RobotAPI/components/armem/server/ExampleMemory/ExampleMemory.h @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemExampleMemory + * @package RobotAPI::ArmarXObjects::ExampleMemory * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt @@ -35,30 +35,17 @@ namespace armarx { /** - * @class ArMemExampleMemoryPropertyDefinitions - * @brief Property definitions of `ArMemExampleMemory`. - */ - class ArMemExampleMemoryPropertyDefinitions : - public armarx::ComponentPropertyDefinitions - { - public: - ArMemExampleMemoryPropertyDefinitions(std::string prefix); - }; - - - - /** - * @defgroup Component-ArMemExampleMemory ArMemExampleMemory + * @defgroup Component-ExampleMemory ExampleMemory * @ingroup RobotAPI-Components - * A description of the component ArMemExampleMemory. + * A description of the component ExampleMemory. * - * @class ArMemExampleMemory - * @ingroup Component-ArMemExampleMemory - * @brief Brief description of class ArMemExampleMemory. + * @class ExampleMemory + * @ingroup Component-ExampleMemory + * @brief Brief description of class ExampleMemory. * - * Detailed description of class ArMemExampleMemory. + * Detailed description of class ExampleMemory. */ - class ArMemExampleMemory : + class ExampleMemory : virtual public armarx::Component , virtual public armem::server::ComponentPluginUser , virtual public LightweightRemoteGuiComponentPluginUser diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.xml b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml similarity index 96% rename from source/RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.xml rename to source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml index 25a8fe286bcff547cecb6a9ffb255b8d6821977b..7acb4e6d45870a95e90848fbb36479e5b7dee193 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.xml +++ b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml @@ -6,7 +6,7 @@ <Include include="<Image/ByteImage.h>" /> </CodeIncludes> <GenerateTypes> - <GenerateType name='armarx::armem::example::ExampleData'> + <Object name='armarx::armem::example::ExampleData'> <ObjectChild key='the_int'> <Int /> </ObjectChild> @@ -26,7 +26,6 @@ <Bool /> </ObjectChild> - <ObjectChild key='the_eigen_position'> <EigenMatrix rows="3" cols="1" type="float" /> </ObjectChild> @@ -37,7 +36,6 @@ <IVTCByteImage type="GrayScale" /> </ObjectChild> - <ObjectChild key='the_float_list'> <List> <Float /> @@ -81,6 +79,6 @@ </Dict> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/test/CMakeLists.txt b/source/RobotAPI/components/armem/server/ExampleMemory/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b2d0b8524117c1c46d2cdc5097ce017c753b2653 --- /dev/null +++ b/source/RobotAPI/components/armem/server/ExampleMemory/test/CMakeLists.txt @@ -0,0 +1,5 @@ + +# Libs required for the tests +SET(LIBS ${LIBS} ArmarXCore ExampleMemory) + +armarx_add_test(ExampleMemoryTest ExampleMemoryTest.cpp "${LIBS}") diff --git a/source/RobotAPI/components/armem/ArMemExampleMemory/test/ArMemExampleMemoryTest.cpp b/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp similarity index 76% rename from source/RobotAPI/components/armem/ArMemExampleMemory/test/ArMemExampleMemoryTest.cpp rename to source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp index 9f391d139acba82d1b4da11101f2599191e5a3e2..6cc16927355f90c56f99ea9552bb356581a492bc 100644 --- a/source/RobotAPI/components/armem/ArMemExampleMemory/test/ArMemExampleMemoryTest.cpp +++ b/source/RobotAPI/components/armem/server/ExampleMemory/test/ExampleMemoryTest.cpp @@ -13,21 +13,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemExampleMemory + * @package RobotAPI::ArmarXObjects::ExampleMemory * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt * GNU General Public License */ -#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ArMemExampleMemory +#define BOOST_TEST_MODULE RobotAPI::ArmarXObjects::ExampleMemory #define ARMARX_BOOST_TEST #include <RobotAPI/Test.h> -#include "../ArMemExampleMemory.h" +#include "../ExampleMemory.h" -#include <RobotAPI/components/armem/ArMemExampleMemory/aron/ExampleData.aron.generated.h> +#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> #include <RobotAPI/libraries/armem/core.h> #include <iostream> @@ -47,9 +47,9 @@ BOOST_AUTO_TEST_CASE(test_ExampleData) BOOST_AUTO_TEST_CASE(test_ExampleData_type) { - armarx::aron::typenavigator::AronObjectTypeNavigatorPtr type = ExampleData::toInitialAronType(); + armarx::aron::typenavigator::ObjectNavigatorPtr type = ExampleData::toInitialAronType(); - BOOST_CHECK_EQUAL(type->getAcceptedTypes().size(), 15); + BOOST_CHECK_EQUAL(type->childrenSize(), 15); armem::Memory memory; armem::CoreSegment& core = memory.addCoreSegment("ExampleData", type); diff --git a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/CMakeLists.txt b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/CMakeLists.txt similarity index 71% rename from source/RobotAPI/components/armem/ArMemMemoryNameSystem/CMakeLists.txt rename to source/RobotAPI/components/armem/server/GeneralPurposeMemory/CMakeLists.txt index 5551a07dcf06737d017f6b7e104bdee9cbef4b1f..f0521043e0891a4b42b3fd75e612b607b3e421aa 100644 --- a/source/RobotAPI/components/armem/ArMemMemoryNameSystem/CMakeLists.txt +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/CMakeLists.txt @@ -1,4 +1,4 @@ -armarx_component_set_name("ArMemMemoryNameSystem") +armarx_component_set_name("GeneralPurposeMemory") set(COMPONENT_LIBS @@ -6,21 +6,22 @@ set(COMPONENT_LIBS ArmarXGuiComponentPlugins RobotAPICore RobotAPIInterfaces armem # RobotAPIComponentPlugins # for ArViz and other plugins + + ${IVT_LIBRARIES} ) set(SOURCES - ArMemMemoryNameSystem.cpp + GeneralPurposeMemory.cpp ) set(HEADERS - ArMemMemoryNameSystem.h + GeneralPurposeMemory.h ) armarx_add_component("${SOURCES}" "${HEADERS}") - -# add unit tests -# add_subdirectory(test) - #generate the application armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cc9356831b2da36ee8facfb55c777722fa47350 --- /dev/null +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.cpp @@ -0,0 +1,86 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::GeneralPurposeMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "GeneralPurposeMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + +namespace armarx +{ + GeneralPurposeMemory::GeneralPurposeMemory() + { + } + + armarx::PropertyDefinitionsPtr GeneralPurposeMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + return defs; + } + + + std::string GeneralPurposeMemory::getDefaultName() const + { + return "GeneralPurposeMemory"; + } + + + void GeneralPurposeMemory::onInitComponent() + { + memory.name() = memoryName; + } + + + void GeneralPurposeMemory::onConnectComponent() + { + } + + + void GeneralPurposeMemory::onDisconnectComponent() + { + } + + + void GeneralPurposeMemory::onExitComponent() + { + } + + + + // WRITING + armem::data::AddSegmentsResult GeneralPurposeMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) + { + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, addCoreSegmentOnUsage); + return result; + } + + + armem::data::CommitResult GeneralPurposeMemory::commit(const armem::data::Commit& commit, const Ice::Current&) + { + armem::data::CommitResult result = ComponentPluginUser::commit(commit); + return result; + } +} diff --git a/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h new file mode 100644 index 0000000000000000000000000000000000000000..c91e38d07df966ec61c06653bc7d828358275797 --- /dev/null +++ b/source/RobotAPI/components/armem/server/GeneralPurposeMemory/GeneralPurposeMemory.h @@ -0,0 +1,84 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::GeneralPurposeMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <ArmarXCore/core/Component.h> + +#include <ArmarXCore/interface/observers/ObserverInterface.h> +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h> + +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + + +namespace armarx +{ + /** + * @defgroup Component-GeneralPurposeMemory GeneralPurposeMemory + * @ingroup RobotAPI-Components + * A description of the component GeneralPurposeMemory. + * + * @class GeneralPurposeMemory + * @ingroup Component-GeneralPurposeMemory + * @brief Brief description of class GeneralPurposeMemory. + * + * Detailed description of class GeneralPurposeMemory. + */ + class GeneralPurposeMemory : + virtual public armarx::Component, + virtual public armem::server::ComponentPluginUser + { + public: + GeneralPurposeMemory(); + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + public: + armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; + armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; + + protected: + /// @see armarx::ManagedIceObject::onInitComponent() + void onInitComponent() override; + + /// @see armarx::ManagedIceObject::onConnectComponent() + void onConnectComponent() override; + + /// @see armarx::ManagedIceObject::onDisconnectComponent() + void onDisconnectComponent() override; + + /// @see armarx::ManagedIceObject::onExitComponent() + void onExitComponent() override; + + /// @see PropertyUser::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + + private: + std::string memoryName = "GeneralPurposeMemory"; + bool addCoreSegmentOnUsage = true; + + }; +} diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/ObjectMemory/CMakeLists.txt similarity index 55% rename from source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt rename to source/RobotAPI/components/armem/server/ObjectMemory/CMakeLists.txt index 017e1709df01b4becba5b6aef90fa3dc031399a0..28ade93141eef153f7ed6dd8972cc0adda2b9f3b 100644 --- a/source/RobotAPI/components/armem/ArMemDebugMemory/CMakeLists.txt +++ b/source/RobotAPI/components/armem/server/ObjectMemory/CMakeLists.txt @@ -1,7 +1,4 @@ -armarx_component_set_name("ArMemDebugMemory") - -find_package(IVT QUIET) -armarx_build_if(IVT_FOUND "IVT not available") +armarx_component_set_name("ObjectMemory") set(COMPONENT_LIBS @@ -14,21 +11,13 @@ set(COMPONENT_LIBS ) set(SOURCES - ArMemDebugMemory.cpp + ObjectMemory.cpp ) set(HEADERS - ArMemDebugMemory.h + ObjectMemory.h ) - armarx_add_component("${SOURCES}" "${HEADERS}") -if (IVT_FOUND) - target_include_directories(${ARMARX_COMPONENT_NAME} PUBLIC ${IVT_INCLUDE_DIRS}) -endif() - - -# add unit tests -# add_subdirectory(test) #generate the application armarx_generate_and_add_component_executable() diff --git a/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93977f9d9a04181f9b22c24d0c6639571d591412 --- /dev/null +++ b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::ObjectMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "ObjectMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + +namespace armarx +{ + ObjectMemory::ObjectMemory() + { + } + + armarx::PropertyDefinitionsPtr ObjectMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + return defs; + } + + + std::string ObjectMemory::getDefaultName() const + { + return "ObjectMemory"; + } + + + void ObjectMemory::onInitComponent() + { + memory.name() = memoryName; + } + + + void ObjectMemory::onConnectComponent() + { + } + + + void ObjectMemory::onDisconnectComponent() + { + } + + + void ObjectMemory::onExitComponent() + { + } + + + + // WRITING + armem::data::AddSegmentsResult ObjectMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) + { + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, addCoreSegmentOnUsage); + return result; + } + + + armem::data::CommitResult ObjectMemory::commit(const armem::data::Commit& commit, const Ice::Current&) + { + armem::data::CommitResult result = ComponentPluginUser::commit(commit); + return result; + } + + + // READING + // Inherited from Plugin + + +} diff --git a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.h similarity index 65% rename from source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h rename to source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.h index 568f22c1674e319cdfc0d4eca37618ee314a9835..ca194dfbf6c2f0c3b527a2170aa1308f883780ae 100644 --- a/source/RobotAPI/components/armem/ArMemDebugMemory/ArMemDebugMemory.h +++ b/source/RobotAPI/components/armem/server/ObjectMemory/ObjectMemory.h @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * @package RobotAPI::ArmarXObjects::ArMemDebugMemory + * @package RobotAPI::ArmarXObjects::ObjectMemory * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) * @date 2020 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt @@ -35,36 +35,23 @@ namespace armarx { /** - * @class ArMemDebugMemoryPropertyDefinitions - * @brief Property definitions of `ArMemDebugMemory`. - */ - class ArMemDebugMemoryPropertyDefinitions : - public armarx::ComponentPropertyDefinitions - { - public: - ArMemDebugMemoryPropertyDefinitions(std::string prefix); - }; - - - /** - * @defgroup Component-ArMemDebugMemory ArMemDebugMemory + * @defgroup Component-ObjectMemory ObjectMemory * @ingroup RobotAPI-Components - * A description of the component ArMemDebugMemory. + * A description of the component ObjectMemory. * - * @class ArMemDebugMemory - * @ingroup Component-ArMemDebugMemory - * @brief Brief description of class ArMemDebugMemory. + * @class ObjectMemory + * @ingroup Component-ObjectMemory + * @brief Brief description of class ObjectMemory. * - * Detailed description of class ArMemDebugMemory. + * Detailed description of class ObjectMemory. */ - class ArMemDebugMemory : + class ObjectMemory : virtual public armarx::Component , virtual public armem::server::ComponentPluginUser - , virtual public LightweightRemoteGuiComponentPluginUser // , virtual public armarx::ArVizComponentPluginUser { public: - ArMemDebugMemory(); + ObjectMemory(); /// @see armarx::ManagedIceObject::getDefaultName() std::string getDefaultName() const override; @@ -74,11 +61,6 @@ namespace armarx armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; - // LightweightRemoteGuiComponentPluginUser interface - public: - void RemoteGui__createTab(); - void RemoteGui_update() override; - protected: /// @see armarx::ManagedIceObject::onInitComponent() @@ -98,18 +80,7 @@ namespace armarx private: - /// Debug observer. Used to visualize e.g. time series. - armarx::DebugObserverInterfacePrx debugObserver; - - std::string memoryName = "DebugMemory"; + std::string memoryName = "ObjectMemory"; bool addCoreSegmentOnUsage = true; - - struct RemoteGuiTab : RemoteGui::Client::Tab - { - std::atomic_bool rebuild = false; - RemoteGui::Client::GroupBox memoryGroup; - }; - RemoteGuiTab tab; - }; } diff --git a/source/RobotAPI/components/armem/server/RobotSensorMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/RobotSensorMemory/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..14939bd0373bc2df2d38d22e7d81133a35c75914 --- /dev/null +++ b/source/RobotAPI/components/armem/server/RobotSensorMemory/CMakeLists.txt @@ -0,0 +1,24 @@ +armarx_component_set_name("RobotSensorMemory") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces RobotAPIComponentPlugins armem + # RobotAPIComponentPlugins # for ArViz and other plugins +) + +set(SOURCES + RobotSensorMemory.cpp +) +set(HEADERS + RobotSensorMemory.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +#generate the application +armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd1987ee72282d4fdf1c99e6229c9b1fdf1b7637 --- /dev/null +++ b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.cpp @@ -0,0 +1,519 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::RobotSensorMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD +#include <algorithm> + +// Header +#include "RobotSensorMemory.h" + +// Simox +#include <SimoxUtility/algorithm/string.h> + +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + +namespace armarx +{ + RobotSensorMemory::RobotSensorMemory() + { + } + + armarx::PropertyDefinitionsPtr RobotSensorMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + defs->optional(robotUnitSensorPrefix, "SensorValuePrefix", "Prefix of all sensor values"); + defs->optional(robotUnitMemoryBatchSize, "RobotUnitMemoryBatchSize", "The size of the entity snapshot to send to the memory. Min is 1"); + defs->optional(robotUnitPollFrequency, "RobotUnitUpdateFrequency", "The frequency in Hz to store values. All other values get discarded. Min is 1, max is " + std::to_string(ROBOT_UNIT_MAXIMUM_FREQUENCY)); + + defs->optional(robotStateComponentMemoryBatchSize, "RobotStateComponentMemoryBatchSize", "The size of the entity snapshot to send to the memory. Min is 1"); + defs->optional(robotStateComponentPollFrequency, "RobotStateComponentUpdateFrequency", "The frequency in Hz to store values. All other values get discarded. Min is 1, max is " + std::to_string(ROBOT_STATE_COMPONENT_MAXIMUM_FREQUENCY)); + + return defs; + } + + + std::string RobotSensorMemory::getDefaultName() const + { + return "RobotSensorMemory"; + } + + + void RobotSensorMemory::onInitComponent() + { + robotUnitMemoryBatchSize = std::max((unsigned int) 1, robotUnitMemoryBatchSize); + robotUnitPollFrequency = std::clamp(robotUnitPollFrequency, 1, ROBOT_UNIT_MAXIMUM_FREQUENCY); + + robotStateComponentMemoryBatchSize = std::max((unsigned int) 1, robotStateComponentMemoryBatchSize); + robotStateComponentPollFrequency = std::clamp(robotStateComponentPollFrequency, 1, ROBOT_STATE_COMPONENT_MAXIMUM_FREQUENCY); + + memory.name() = memoryName; + } + + + void RobotSensorMemory::onConnectComponent() + { + setupRobotUnitSegment(); + setupRobotStateComponentSegment(); + + cfg.loggingNames.emplace_back(robotUnitSensorPrefix); + handler = make_shared<RobotUnitDataStreamingReceiver>(this, getRobotUnit(), cfg); + keys = handler->getDataDescription(); + + robotUnitConversionTask = new PeriodicTask<RobotSensorMemory>(this, &RobotSensorMemory::convertRobotUnitStreamingDataToAron, (1000 / robotUnitPollFrequency)); + robotUnitStoringTask = new PeriodicTask<RobotSensorMemory>(this, &RobotSensorMemory::storeConvertedRobotUnitDataInMemory, (1000 / robotUnitPollFrequency)); + + robotStateComponentConversionTask = new PeriodicTask<RobotSensorMemory>(this, &RobotSensorMemory::convertRobotStateComponentDataToAron, (1000 / robotStateComponentPollFrequency)); + robotStateComponentStoringTask = new PeriodicTask<RobotSensorMemory>(this, &RobotSensorMemory::storeConvertedRobotStateComponentDataInMemory, (1000 / robotStateComponentPollFrequency)); + + startRobotUnitStream(); + startRobotStateComponentPoll(); + } + + + void RobotSensorMemory::onDisconnectComponent() + { + stopRobotUnitStream(); + startRobotStateComponentPoll(); + } + + + void RobotSensorMemory::onExitComponent() + { + stopRobotUnitStream(); + stopRobotStateComponentPoll(); + } + + /*************************************************************/ + // RobotUnit Streaming functions + /*************************************************************/ + void RobotSensorMemory::setupRobotUnitSegment() + { + ARMARX_INFO << "Adding core segment " << robotUnitCoreSegmentName; + memory.addCoreSegments({robotUnitCoreSegmentName}); + + ARMARX_INFO << "Adding provider segment " << robotUnitCoreSegmentName << "/" << robotUnitProviderSegmentName; + armem::data::AddSegmentInput input; + input.coreSegmentName = robotUnitCoreSegmentName; + input.providerSegmentName = robotUnitProviderSegmentName; + + auto encoderEntryType = std::make_shared<aron::typenavigator::ObjectNavigator>("RobotUnitEncoderEntry"); + auto encoderNameType = std::make_shared<aron::typenavigator::StringNavigator>(); + auto encoderIterationIDType = std::make_shared<aron::typenavigator::LongNavigator>(); + encoderEntryType->addMemberType("EncoderGroupName", encoderNameType); + encoderEntryType->addMemberType("IterationId", encoderIterationIDType); + //auto encoderValueType = std::make_shared<aron::typenavigator::AnyType>(); + //encoderEntryType->addMemberType("value", encoderValueType); + + auto result = addSegments({input})[0]; + + if (!result.success) + { + ARMARX_ERROR << "Could not add segment " << robotUnitCoreSegmentName << "/" << robotUnitProviderSegmentName << ". The error message is: " << result.errorMessage; + } + + robotUnitProviderID.memoryName = memoryName; + robotUnitProviderID.coreSegmentName = robotUnitCoreSegmentName; + robotUnitProviderID.providerSegmentName = robotUnitProviderSegmentName; + } + + void RobotSensorMemory::convertRobotUnitStreamingDataToAron() + { + auto& data = handler->getDataBuffer(); + if (data.size() == 0) + { + return; + } + auto& currentTimestep = data.back(); + + ARMARX_DEBUG << "RobotUnitData: Generating new aron map for current timestep"; + auto start = std::chrono::high_resolution_clock::now(); + + RobotUnitData convertedAndGroupedData; + for (const auto& [name, dataEntry] : keys.entries) + { + size_t dot_pos = name.find(".", name.find(".") + 1); // find second occurence of "." + if (dot_pos == std::string::npos) + { + ARMARX_WARNING << "Could not find a groupname for the sensor with name " << name << ". All sensors must be called sens.X.Y where X is the name of the group and Y is the actual sensor. Ignoring this sensor."; + continue; + } + + std::string groupName = name.substr(0, dot_pos); + RobotUnitData::RobotUnitDataGroup e; + if (auto it = convertedAndGroupedData.groups.find(groupName); it == convertedAndGroupedData.groups.end()) + { + // generate new dict for the group + auto dict = std::make_shared<aron::datanavigator::DictNavigator>(); + auto encGroupName = std::make_shared<aron::datanavigator::StringNavigator>(groupName); + dict->addElement("EncoderGroupName", encGroupName); + + auto iterId = std::make_shared<aron::datanavigator::LongNavigator>(currentTimestep.iterationId); + dict->addElement("IterationId", iterId); + + e.timestamp = currentTimestep.timestampUSec; + e.name = groupName; + e.data = dict; + } + else + { + // reuse existing entry + e = it->second; + } + + switch (dataEntry.type) + { + case RobotUnitDataStreaming::NodeTypeFloat: + { + float value = RobotUnitDataStreamingReceiver::GetAs<Ice::Float>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::FloatNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeBool: + { + bool value = RobotUnitDataStreamingReceiver::GetAs<bool>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::BoolNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeByte: + { + int value = RobotUnitDataStreamingReceiver::GetAs<Ice::Byte>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::IntNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeShort: + { + int value = RobotUnitDataStreamingReceiver::GetAs<Ice::Short>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::IntNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeInt: + { + int value = RobotUnitDataStreamingReceiver::GetAs<Ice::Int>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::IntNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeLong: + { + long value = RobotUnitDataStreamingReceiver::GetAs<Ice::Long>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::LongNavigator>(value); + e.data->addElement(name, aron); + break; + } + case RobotUnitDataStreaming::NodeTypeDouble: + { + double value = RobotUnitDataStreamingReceiver::GetAs<Ice::Double>(currentTimestep, dataEntry); + auto aron = std::make_shared<aron::datanavigator::DoubleNavigator>(value); + e.data->addElement(name, aron); + break; + } + default: + throw LocalException("The enum type should not exist! Perhaps someone changed the RobotUnitDataStreaming::NodeType enum definition?"); + } + + convertedAndGroupedData.groups.insert({groupName, e}); + } + { + std::lock_guard g{robotUnitDataMutex}; + robotUnitDataQueue.push(convertedAndGroupedData); + } + + auto stop = std::chrono::high_resolution_clock::now(); + ARMARX_DEBUG << "RobotUnitData: The total time needed to convert the data to aron is: " << std::chrono::duration_cast<std::chrono::microseconds>(stop - start); + } + + void RobotSensorMemory::storeConvertedRobotUnitDataInMemory() + { + unsigned int size = 0; + { + std::lock_guard g{robotUnitDataMutex}; + size = robotUnitDataQueue.size(); // the size can only grow + } + if (size >= robotUnitMemoryBatchSize) + { + ARMARX_DEBUG << "RobotUnitData: Sending batch of " << robotUnitMemoryBatchSize << " timesteps to memory... The size of the queue is: " << size; + auto start = std::chrono::high_resolution_clock::now(); + + // send batch to memory + armem::data::Commit c; + for (unsigned int i = 0; i < robotUnitMemoryBatchSize; ++i) + { + std::lock_guard g{robotUnitDataMutex}; + const auto& convertedAndGroupedData = robotUnitDataQueue.front(); + for (const auto& [encName, encTimestep] : convertedAndGroupedData.groups) + { + ARMARX_CHECK_EQUAL(encName, encTimestep.name); + + auto entityID = robotUnitProviderID; + entityID.entityName = encName; + + const auto& timeUSec = encTimestep.timestamp; + const auto& aron = encTimestep.data; + + armem::data::EntityUpdate& update = c.updates.emplace_back(); + update.entityID = entityID; + update.timeCreatedMicroSeconds = timeUSec; + update.instancesData = {aron->toAronDictPtr()}; + } + robotUnitDataQueue.pop(); + } + + auto results = commit(c); + auto stop = std::chrono::high_resolution_clock::now(); + ARMARX_DEBUG << "RobotUnitData: The total runtime of sending a batch to the memory is: " << std::chrono::duration_cast<std::chrono::microseconds>(stop - start); + + for (const auto& result : results.results) + { + if (!result.success) + { + ARMARX_WARNING << "Could not add data to memory. Error message: " << result.errorMessage; + } + } + } + } + + void RobotSensorMemory::stopRobotUnitStream() + { + std::lock_guard g{startStopMutex}; + robotUnitConversionTask->stop(); + robotUnitStoringTask->stop(); + } + + void RobotSensorMemory::startRobotUnitStream() + { + std::lock_guard g{startStopMutex}; + if (robotUnitConversionTask->isRunning() || robotUnitStoringTask->isRunning()) + { + if (robotUnitConversionTask->isRunning() && robotUnitStoringTask->isRunning()) + { + return; + } + ARMARX_WARNING << "Found inconsistency in running tasks. Restarting all!"; + stopRobotUnitStream(); + } + + std::stringstream ss; + ss << "Getting sensor values for:" << std::endl; + for (const auto& [name, dataEntry] : keys.entries) + { + std::string type = ""; + switch (dataEntry.type) + { + case RobotUnitDataStreaming::NodeTypeBool: + { + type = "Bool"; + break; + } + case RobotUnitDataStreaming::NodeTypeByte: + { + type = "Byte"; + break; + } + case RobotUnitDataStreaming::NodeTypeShort: + { + type = "Short"; + break; + } + case RobotUnitDataStreaming::NodeTypeInt: + { + type = "Int"; + break; + } + case RobotUnitDataStreaming::NodeTypeLong: + { + type = "Long"; + break; + } + case RobotUnitDataStreaming::NodeTypeFloat: + { + type = "Float"; + break; + } + case RobotUnitDataStreaming::NodeTypeDouble: + { + type = "Double"; + break; + } + } + ss << "\t" << name << " (type: '" << type << "')" << std::endl; + } + ARMARX_INFO << ss.str(); + + robotUnitConversionTask->start(); + robotUnitStoringTask->start(); + } + + + /*************************************************************/ + // RobotStateComponent Polling functions + /*************************************************************/ + void RobotSensorMemory::setupRobotStateComponentSegment() + { + ARMARX_INFO << "Adding core segment " << robotStateComponentCoreSegmentName; + memory.addCoreSegments({robotStateComponentCoreSegmentName}); + + ARMARX_INFO << "Adding provider segment " << robotStateComponentCoreSegmentName << "/" << robotStateComponentProviderSegmentName; + armem::data::AddSegmentInput input; + input.coreSegmentName = robotStateComponentCoreSegmentName; + input.providerSegmentName = robotStateComponentProviderSegmentName; + + // Todo add type + + auto result = addSegments({input})[0]; + + if (!result.success) + { + ARMARX_ERROR << "Could not add segment " << robotStateComponentCoreSegmentName << "/" << robotStateComponentProviderSegmentName << ". The error message is: " << result.errorMessage; + } + + robotStateComponentProviderID.memoryName = memoryName; + robotStateComponentProviderID.coreSegmentName = robotStateComponentCoreSegmentName; + robotStateComponentProviderID.providerSegmentName = robotStateComponentProviderSegmentName; + } + + void RobotSensorMemory::convertRobotStateComponentDataToAron() + { + ARMARX_DEBUG << "RobotStateComponentData: Generating new aron map for current timestep"; + auto start = std::chrono::high_resolution_clock::now(); + + auto synchronizedRobot = getRobotStateComponent()->getSynchronizedRobot(); + auto framedPose = synchronizedRobot->getRootNode()->getGlobalPose(); + + RobotStateComponentData convertedData; + convertedData.timestamp = synchronizedRobot->getTimestamp()->timestamp; + + auto dict = std::make_shared<aron::datanavigator::DictNavigator>(); + + auto x = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->position->x); + dict->addElement("x", x); + + auto y = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->position->y); + dict->addElement("y", y); + + auto z = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->position->z); + dict->addElement("z", z); + + auto qw = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->orientation->qw); + dict->addElement("qw", qw); + + auto qx = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->orientation->qx); + dict->addElement("qx", qx); + + auto qy = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->orientation->qy); + dict->addElement("qy", qy); + + auto qz = std::make_shared<aron::datanavigator::IntNavigator>(framedPose->orientation->qz); + dict->addElement("z", qz); + + convertedData.data = dict; + + { + std::lock_guard g{robotStateComponentDataMutex}; + robotStateComponentDataQueue.push(convertedData); + } + + auto stop = std::chrono::high_resolution_clock::now(); + ARMARX_DEBUG << "RobotStateComponentData: The total time needed to convert the data to aron is: " << std::chrono::duration_cast<std::chrono::microseconds>(stop - start); + } + + void RobotSensorMemory::storeConvertedRobotStateComponentDataInMemory() + { + unsigned int size = 0; + { + std::lock_guard g{robotStateComponentDataMutex}; + size = robotStateComponentDataQueue.size(); // the size can only grow + } + if (size >= robotStateComponentMemoryBatchSize) + { + ARMARX_DEBUG << "RobotStateComponentData: Sending batch of " << robotStateComponentMemoryBatchSize << " timesteps to memory... The size of the queue is: " << size; + auto start = std::chrono::high_resolution_clock::now(); + + // send batch to memory + armem::data::Commit c; + for (unsigned int i = 0; i < robotStateComponentMemoryBatchSize; ++i) + { + std::lock_guard g{robotStateComponentDataMutex}; + const auto& convertedData = robotStateComponentDataQueue.front(); + + auto entityID = robotStateComponentProviderID; + entityID.entityName = "GlobalPositionRootFrame"; + + const auto& timeUSec = convertedData.timestamp; + const auto& aron = convertedData.data; + + armem::data::EntityUpdate& update = c.updates.emplace_back(); + update.entityID = entityID; + update.timeCreatedMicroSeconds = timeUSec; + update.instancesData = {aron->toAronDictPtr()}; + robotStateComponentDataQueue.pop(); + } + + auto results = commit(c); + auto stop = std::chrono::high_resolution_clock::now(); + ARMARX_DEBUG << "RobotStateComponentData: The total runtime of sending a batch to the memory is: " << std::chrono::duration_cast<std::chrono::microseconds>(stop - start); + + for (const auto& result : results.results) + { + if (!result.success) + { + ARMARX_WARNING << "Could not add data to memory. Error message: " << result.errorMessage; + } + } + } + } + + void RobotSensorMemory::stopRobotStateComponentPoll() + { + std::lock_guard g{startStopMutex}; + robotStateComponentConversionTask->stop(); + robotStateComponentStoringTask->stop(); + } + + void RobotSensorMemory::startRobotStateComponentPoll() + { + std::lock_guard g{startStopMutex}; + if (robotStateComponentConversionTask->isRunning() || robotStateComponentStoringTask->isRunning()) + { + if (robotStateComponentConversionTask->isRunning() && robotStateComponentStoringTask->isRunning()) + { + return; + } + ARMARX_WARNING << "Found inconsistency in running tasks. Restarting all!"; + stopRobotStateComponentPoll(); + } + + ARMARX_INFO << "Start polling of robotStateComponent"; + + robotStateComponentConversionTask->start(); + robotStateComponentStoringTask->start(); + } +} diff --git a/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.h b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.h new file mode 100644 index 0000000000000000000000000000000000000000..3ac03aebafa0b3480c7457ee9b028f9515904170 --- /dev/null +++ b/source/RobotAPI/components/armem/server/RobotSensorMemory/RobotSensorMemory.h @@ -0,0 +1,173 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::RobotSensorMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD +#include <atomic> +#include <thread> +#include <queue> + +// Simox +#include <SimoxUtility/meta/enum/adapt_enum.h> + +// BaseClass +#include <ArmarXCore/core/Component.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/RobotUnitComponentPlugin.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/RobotStateComponentPlugin.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/PlatformUnitComponentPlugin.h> +#include <RobotAPI/libraries/RobotUnitDataStreamingReceiver/RobotUnitDataStreamingReceiver.h> +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + +// ArmarX +#include <ArmarXCore/core/services/tasks/PeriodicTask.h> + + +namespace armarx +{ + /** + * @defgroup Component-RobotSensorMemory RobotSensorMemory + * @ingroup RobotAPI-Components + * A description of the component RobotSensorMemory. + * + * @class RobotSensorMemory + * @ingroup Component-RobotSensorMemory + * @brief Brief description of class RobotSensorMemory. + * + * Detailed description of class RobotSensorMemory. + */ + class RobotSensorMemory : + virtual public armarx::Component, + virtual public armem::server::ComponentPluginUser, + virtual public RobotUnitComponentPluginUser, + virtual public RobotStateComponentPluginUser + + { + public: + RobotSensorMemory(); + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + protected: + /// @see armarx::ManagedIceObject::onInitComponent() + void onInitComponent() override; + + /// @see armarx::ManagedIceObject::onConnectComponent() + void onConnectComponent() override; + + /// @see armarx::ManagedIceObject::onDisconnectComponent() + void onDisconnectComponent() override; + + /// @see armarx::ManagedIceObject::onExitComponent() + void onExitComponent() override; + + /// @see PropertyUser::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + private: + // RobotUnit Streaming + void setupRobotUnitSegment(); + + void convertRobotUnitStreamingDataToAron(); + void storeConvertedRobotUnitDataInMemory(); + + void startRobotUnitStream(); + void stopRobotUnitStream(); + + // RobotStateComponent Poll + void setupRobotStateComponentSegment(); + + void convertRobotStateComponentDataToAron(); + void storeConvertedRobotStateComponentDataInMemory(); + + void startRobotStateComponentPoll(); + void stopRobotStateComponentPoll(); + + private: + std::string memoryName = "RobotSensorMemory"; + bool addCoreSegmentOnUsage = false; + + mutable std::recursive_mutex startStopMutex; + + // Memory IDs + std::string robotUnitCoreSegmentName = "Proprioception"; + std::string robotUnitProviderSegmentName = "RobotUnit"; // get robot name? + armem::data::MemoryID robotUnitProviderID; + + std::string robotStateComponentCoreSegmentName = "Localization"; + std::string robotStateComponentProviderSegmentName = "RobotStateComponent"; // get robot name? + armem::data::MemoryID robotStateComponentProviderID; + + // RobotUnit stuff + RobotUnitDataStreaming::DataStreamingDescription keys; + std::vector<RobotUnitDataStreaming::DataEntry> keysList; + RobotUnitDataStreaming::Config cfg; + RobotUnitDataStreamingReceiverPtr handler; + + struct RobotUnitData + { + struct RobotUnitDataGroup + { + long timestamp; + std::string name; + aron::datanavigator::DictNavigatorPtr data; + }; + + std::map<std::string, RobotUnitDataGroup> groups; + }; + + // params + static const int ROBOT_UNIT_MAXIMUM_FREQUENCY = 100; + int robotUnitPollFrequency = 50; + std::string robotUnitSensorPrefix = "sens.*"; + unsigned int robotUnitMemoryBatchSize = 50; + + // queue + std::queue<RobotUnitData> robotUnitDataQueue; + mutable std::mutex robotUnitDataMutex; + + // running tasks + armarx::PeriodicTask<RobotSensorMemory>::pointer_type robotUnitConversionTask; + armarx::PeriodicTask<RobotSensorMemory>::pointer_type robotUnitStoringTask; + + // RobotStateComponent stuff + struct RobotStateComponentData + { + long timestamp; + aron::datanavigator::DictNavigatorPtr data; + }; + + // params + static const int ROBOT_STATE_COMPONENT_MAXIMUM_FREQUENCY = 100; + int robotStateComponentPollFrequency = 50; + unsigned int robotStateComponentMemoryBatchSize = 50; + + // queue + std::queue<RobotStateComponentData> robotStateComponentDataQueue; + mutable std::mutex robotStateComponentDataMutex; + + // running tasks + armarx::PeriodicTask<RobotSensorMemory>::pointer_type robotStateComponentConversionTask; + armarx::PeriodicTask<RobotSensorMemory>::pointer_type robotStateComponentStoringTask; + }; +} diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/CMakeLists.txt b/source/RobotAPI/components/armem/server/SkillsMemory/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c00bd89e9c47178acbe3ea49ac4b3d3bc3cc5436 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SkillsMemory/CMakeLists.txt @@ -0,0 +1,26 @@ +armarx_component_set_name("SkillsMemory") + + +set(COMPONENT_LIBS + ArmarXCore ArmarXCoreInterfaces # for DebugObserverInterface + ArmarXGuiComponentPlugins + RobotAPICore RobotAPIInterfaces armem + # RobotAPIComponentPlugins # for ArViz and other plugins + + ${IVT_LIBRARIES} +) + +set(SOURCES + SkillsMemory.cpp +) +set(HEADERS + SkillsMemory.h +) + +armarx_add_component("${SOURCES}" "${HEADERS}") + +#generate the application +armarx_generate_and_add_component_executable() + + + diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14dd8887985350929b4a729a4387a5ba448c68f9 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.cpp @@ -0,0 +1,91 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::SkillsMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "SkillsMemory.h" + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <SimoxUtility/algorithm/string.h> + +#include <RobotAPI/libraries/armem/core/error.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> + +namespace armarx +{ + SkillsMemory::SkillsMemory() + { + } + + armarx::PropertyDefinitionsPtr SkillsMemory::createPropertyDefinitions() + { + armarx::PropertyDefinitionsPtr defs = new ComponentPropertyDefinitions(getConfigIdentifier()); + return defs; + } + + + std::string SkillsMemory::getDefaultName() const + { + return "SkillsMemory"; + } + + + void SkillsMemory::onInitComponent() + { + memory.name() = memoryName; + } + + + void SkillsMemory::onConnectComponent() + { + } + + + void SkillsMemory::onDisconnectComponent() + { + } + + + void SkillsMemory::onExitComponent() + { + } + + + + // WRITING + armem::data::AddSegmentsResult SkillsMemory::addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) + { + armem::data::AddSegmentsResult result = ComponentPluginUser::addSegments(input, addCoreSegmentOnUsage); + return result; + } + + + armem::data::CommitResult SkillsMemory::commit(const armem::data::Commit& commit, const Ice::Current&) + { + armem::data::CommitResult result = ComponentPluginUser::commit(commit); + return result; + } + + + // READING + // Inherited from Plugin + +} diff --git a/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h new file mode 100644 index 0000000000000000000000000000000000000000..6201ffb07640bf4c75473d0a0e29876f4fdbf265 --- /dev/null +++ b/source/RobotAPI/components/armem/server/SkillsMemory/SkillsMemory.h @@ -0,0 +1,86 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects::SkillsMemory + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2020 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +#include <ArmarXCore/core/Component.h> + +#include <ArmarXCore/interface/observers/ObserverInterface.h> +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> +#include <RobotAPI/libraries/RobotAPIComponentPlugins/ArVizComponentPlugin.h> + +#include <RobotAPI/libraries/armem/server/ComponentPlugin.h> + + +namespace armarx +{ + /** + * @defgroup Component-SkillsMemory SkillsMemory + * @ingroup RobotAPI-Components + * A description of the component SkillsMemory. + * + * @class SkillsMemory + * @ingroup Component-SkillsMemory + * @brief Brief description of class SkillsMemory. + * + * Detailed description of class SkillsMemory. + */ + class SkillsMemory : + virtual public armarx::Component, + virtual public armem::server::ComponentPluginUser + // , virtual public armarx::ArVizComponentPluginUser + { + public: + SkillsMemory(); + + /// @see armarx::ManagedIceObject::getDefaultName() + std::string getDefaultName() const override; + + // WritingInterface interface + public: + armem::data::AddSegmentsResult addSegments(const armem::data::AddSegmentsInput& input, const Ice::Current&) override; + armem::data::CommitResult commit(const armem::data::Commit& commit, const Ice::Current&) override; + + + protected: + /// @see armarx::ManagedIceObject::onInitComponent() + void onInitComponent() override; + + /// @see armarx::ManagedIceObject::onConnectComponent() + void onConnectComponent() override; + + /// @see armarx::ManagedIceObject::onDisconnectComponent() + void onDisconnectComponent() override; + + /// @see armarx::ManagedIceObject::onExitComponent() + void onExitComponent() override; + + /// @see PropertyUser::createPropertyDefinitions() + armarx::PropertyDefinitionsPtr createPropertyDefinitions() override; + + + private: + std::string memoryName = "SkillsMemory"; + bool addCoreSegmentOnUsage = true; + }; +} diff --git a/source/RobotAPI/components/units/ObstacleAvoidingPlatformUnit/ObstacleAvoidingPlatformUnit.cpp b/source/RobotAPI/components/units/ObstacleAvoidingPlatformUnit/ObstacleAvoidingPlatformUnit.cpp index 59625f6aa98261c2f24c220a440a0225967a5974..14f1348ce043e1fb9158d9d2eca4268b15c17d1c 100644 --- a/source/RobotAPI/components/units/ObstacleAvoidingPlatformUnit/ObstacleAvoidingPlatformUnit.cpp +++ b/source/RobotAPI/components/units/ObstacleAvoidingPlatformUnit/ObstacleAvoidingPlatformUnit.cpp @@ -855,7 +855,6 @@ armarx::PropertyDefinitionsPtr armarx::ObstacleAvoidingPlatformUnit::createPropertyDefinitions() { PropertyDefinitionsPtr def = PlatformUnit::createPropertyDefinitions(); - def->setPrefix(getConfigIdentifier()); def->component(m_platform, "Platform"); def->component(m_obstacle_avoidance, "PlatformObstacleAvoidance"); diff --git a/source/RobotAPI/components/units/PlatformUnit.cpp b/source/RobotAPI/components/units/PlatformUnit.cpp index 5f026957d977c4894264f06634d1b8ce036a1bde..6f5c6b07454e2ad831d48ba327b33c7cd768ddde 100644 --- a/source/RobotAPI/components/units/PlatformUnit.cpp +++ b/source/RobotAPI/components/units/PlatformUnit.cpp @@ -34,13 +34,12 @@ namespace armarx { PropertyDefinitionsPtr PlatformUnit::createPropertyDefinitions() { - armarx::PropertyDefinitionsPtr def = new ComponentPropertyDefinitions(getConfigIdentifier()); + armarx::PropertyDefinitionsPtr def = new PlatformUnitPropertyDefinitions(getConfigIdentifier()); + def->topic(odometryPrx); def->topic(globalPosePrx); - // legacy - // defineOptionalProperty<std::string>("PlatformName", "Platform", "Name of the platform (will publish values on PlatformName + 'State')"); - def->topic(listenerPrx, "PlatformState"); + def->component(robotStateComponent); return def; } @@ -48,12 +47,19 @@ namespace armarx void PlatformUnit::onInitComponent() { + std::string platformName = getProperty<std::string>("PlatformName").getValue(); + + listenerChannelName = platformName + "State"; + offeringTopic(listenerChannelName); + this->onInitPlatformUnit(); } void PlatformUnit::onConnectComponent() { + listenerPrx = getTopic<PlatformUnitListenerPrx>(listenerChannelName); + this->onStartPlatformUnit(); } diff --git a/source/RobotAPI/components/units/PlatformUnit.h b/source/RobotAPI/components/units/PlatformUnit.h index 23f5f14fc2b0b842ffc08ba622b2717414528ae3..097de6689522498722a1ec499b83cbeb12c5fa25 100644 --- a/source/RobotAPI/components/units/PlatformUnit.h +++ b/source/RobotAPI/components/units/PlatformUnit.h @@ -29,6 +29,7 @@ #include <ArmarXCore/core/application/properties/Properties.h> #include <ArmarXCore/core/system/ImportExportComponent.h> +#include <RobotAPI/interface/core/RobotState.h> #include <RobotAPI/interface/units/PlatformUnitInterface.h> #include <vector> @@ -36,6 +37,21 @@ namespace armarx { + /** + * \class PlatformUnitPropertyDefinitions + * \brief Defines all necessary properties for armarx::PlatformUnit + */ + class PlatformUnitPropertyDefinitions: + public ComponentPropertyDefinitions + { + public: + PlatformUnitPropertyDefinitions(std::string prefix): + ComponentPropertyDefinitions(prefix) + { + defineOptionalProperty<std::string>("PlatformName", "Platform", "Name of the platform (will publish values on PlatformName + 'State')"); + } + }; + /** * \defgroup Component-PlatformUnit PlatformUnit @@ -100,6 +116,8 @@ namespace armarx PropertyDefinitionsPtr createPropertyDefinitions() override; protected: + + std::string listenerChannelName; /** * PlatformUnitListener proxy for publishing state updates */ @@ -108,6 +126,9 @@ namespace armarx GlobalRobotPoseLocalizationListenerPrx globalPosePrx; OdometryListenerPrx odometryPrx; + RobotStateComponentInterfacePrx robotStateComponent; + + }; PlatformPose toPlatformPose(const TransformStamped& transformStamped); diff --git a/source/RobotAPI/components/units/PlatformUnitSimulation.cpp b/source/RobotAPI/components/units/PlatformUnitSimulation.cpp index f9beaced057488d00bc05de630b206c138953eff..0f4d58b0fbc2be757117a70aac3a213bea3f8da9 100644 --- a/source/RobotAPI/components/units/PlatformUnitSimulation.cpp +++ b/source/RobotAPI/components/units/PlatformUnitSimulation.cpp @@ -43,7 +43,6 @@ namespace armarx PropertyDefinitionsPtr PlatformUnitSimulation::createPropertyDefinitions() { auto def = PlatformUnit::createPropertyDefinitions(); - def->setPrefix(getConfigIdentifier()); def->defineOptionalProperty<int>("IntervalMs", 10, "The time in milliseconds between two calls to the simulation method."); def->defineOptionalProperty<float>("InitialRotation", 0, "Initial rotation of the platform."); diff --git a/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.cpp b/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.cpp index 809be741c620d0a5de372cb0276c19788aa2dc2d..49e49a65f436d35425e2babce87e0940f0857ce4 100755 --- a/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.cpp +++ b/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.cpp @@ -32,18 +32,6 @@ namespace armarx { - - PropertyDefinitionsPtr armarx::PlatformSubUnit::createPropertyDefinitions() - { - auto def = PlatformUnit::createPropertyDefinitions(); - def->setPrefix(getConfigIdentifier()); - - def->component(robotStateComponent); - - return def; - } - - void armarx::PlatformSubUnit::update(const armarx::SensorAndControl& sc, const JointAndNJointControllers&) { if (!getProxy()) @@ -218,4 +206,28 @@ namespace armarx globalPosCtrl->setGlobalPos(toPlatformPose(currentPose)); } + + + // legacy stuff + + + void armarx::PlatformSubUnit::reportPlatformPose(PlatformPose const& currentPose, const Ice::Current& c) + { + globalPosCtrl->setGlobalPos(currentPose); + } + + void armarx::PlatformSubUnit::reportNewTargetPose(Ice::Float newPlatformPositionX, Ice::Float newPlatformPositionY, Ice::Float newPlatformRotation, const Ice::Current& c) + { + + } + + void armarx::PlatformSubUnit::reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current& c) + { + + } + + void armarx::PlatformSubUnit::reportPlatformOdometryPose(Ice::Float, Ice::Float, Ice::Float, const Ice::Current&) + { + } + } \ No newline at end of file diff --git a/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.h b/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.h index df975ed0e999c8e19ed588dbb426ab7695643c89..21ab6338ee505a526222b52b3dfea085404a91af 100755 --- a/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.h +++ b/source/RobotAPI/components/units/RobotUnit/Units/PlatformSubUnit.h @@ -61,12 +61,17 @@ namespace armarx void reportGlobalRobotPose(const TransformStamped& currentPose, const Ice::Current& = Ice::emptyCurrent) override; - PropertyDefinitionsPtr createPropertyDefinitions() override; + + void reportPlatformPose(PlatformPose const& currentPose, const Ice::Current& c = ::Ice::Current()) override ; + void reportNewTargetPose(Ice::Float newPlatformPositionX, Ice::Float newPlatformPositionY, Ice::Float newPlatformRotation, const Ice::Current& c = ::Ice::Current()) override; + void reportPlatformVelocity(Ice::Float currentPlatformVelocityX, Ice::Float currentPlatformVelocityY, Ice::Float currentPlatformVelocityRotation, const Ice::Current& c = ::Ice::Current()) override; + void reportPlatformOdometryPose(::Ice::Float, ::Ice::Float, ::Ice::Float, const ::Ice::Current& = ::Ice::Current()) override; // PlatformUnit interface void onInitPlatformUnit() override { + usingTopic("PlatformState"); } void onStartPlatformUnit() override { @@ -97,8 +102,6 @@ namespace armarx // TODO(fabian.reister): likely remove or adapt Eigen::Matrix4f positionCorrection = Eigen::Matrix4f::Identity(); - protected: - RobotStateComponentInterfacePrx robotStateComponent; private: diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui index 0eb55660336c5ec4d72f869ff0faa3cadb8ff2ca..a972b97b164a83ef25695aaf618e790f250ac09a 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidget.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>776</width> - <height>590</height> + <width>926</width> + <height>616</height> </rect> </property> <property name="windowTitle"> @@ -15,34 +15,7 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPushButton" name="updateButton"> - <property name="text"> - <string>Update</string> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="updateAutoCheckBox"> - <property name="text"> - <string>Auto Update</string> - </property> - </widget> - </item> - <item> - <widget class="QDoubleSpinBox" name="updateFrequencySpinBox"> - <property name="suffix"> - <string> Hz</string> - </property> - <property name="maximum"> - <double>60.000000000000000</double> - </property> - <property name="value"> - <double>2.000000000000000</double> - </property> - </widget> - </item> + <layout class="QHBoxLayout" name="updateWidgetLayout"> <item> <spacer name="horizontalSpacer"> <property name="orientation"> @@ -78,387 +51,13 @@ <property name="bottomMargin"> <number>0</number> </property> - <item> - <widget class="QTreeWidget" name="_memoryTreeWidget"> - <column> - <property name="text"> - <string notr="true">ID</string> - </property> - </column> - <column> - <property name="text"> - <string>Size</string> - </property> - </column> - <column> - <property name="text"> - <string>Type</string> - </property> - </column> - <column> - <property name="text"> - <string>Level</string> - </property> - </column> - <column> - <property name="text"> - <string>Memory ID</string> - </property> - </column> - <item> - <property name="text"> - <string>MyMemory</string> - </property> - <property name="text"> - <string>1</string> - </property> - <property name="text"> - <string/> - </property> - <property name="text"> - <string/> - </property> - <item> - <property name="text"> - <string>MyModality</string> - </property> - <property name="text"> - <string>1</string> - </property> - <property name="text"> - <string>Modality</string> - </property> - <item> - <property name="text"> - <string>MyProvider</string> - </property> - <property name="text"> - <string>2</string> - </property> - <property name="text"> - <string>ModalitySpecial</string> - </property> - <item> - <property name="text"> - <string>entity_one</string> - </property> - <property name="text"> - <string>10</string> - </property> - <property name="text"> - <string/> - </property> - </item> - <item> - <property name="text"> - <string>entity_two</string> - </property> - <property name="text"> - <string>20</string> - </property> - </item> - </item> - </item> - </item> - <item> - <property name="text"> - <string>This widget is replaced in code</string> - </property> - </item> - </widget> - </item> - <item> - <widget class="QGroupBox" name="queryGroupBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="title"> - <string>Queries</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <widget class="QCheckBox" name="checkBox"> - <property name="text"> - <string>Get Data</string> - </property> - </widget> - </item> - <item> - <widget class="QTabWidget" name="_queryTabWidget"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="currentIndex"> - <number>3</number> - </property> - <widget class="QWidget" name="queryTabWidgetPage1"> - <attribute name="title"> - <string/> - </attribute> - </widget> - <widget class="QWidget" name="queryTabWidgetPage2"> - <attribute name="title"> - <string/> - </attribute> - </widget> - <widget class="QWidget" name="queryTabWidgetPage3"> - <attribute name="title"> - <string/> - </attribute> - </widget> - <widget class="QWidget" name="queryTabWidgetPage4"> - <attribute name="title"> - <string/> - </attribute> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QComboBox" name="comboBox"/> - </item> - </layout> - </item> - <item> - <widget class="QWidget" name="entityQueryFormAll" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QFormLayout" name="formLayout_5"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="entityQueryFormSingle" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QGridLayout" name="gridLayout"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item row="1" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Timestamp:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDateTimeEdit" name="dateTimeEdit"> - <property name="date"> - <date> - <year>2020</year> - <month>12</month> - <day>31</day> - </date> - </property> - <property name="displayFormat"> - <string>yyyy-MM-dd HH:mm:ss.ms</string> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QCheckBox" name="checkBox_2"> - <property name="text"> - <string>Latest</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="entityQueryFormTimeRange" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QGridLayout" name="gridLayout_2"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item row="2" column="0"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>To:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDateTimeEdit" name="dateTimeEdit_3"/> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>From:</string> - </property> - </widget> - </item> - <item row="0" column="2"> - <widget class="QCheckBox" name="checkBox_3"> - <property name="text"> - <string>First</string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QCheckBox" name="checkBox_4"> - <property name="text"> - <string>Latest</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QDateTimeEdit" name="dateTimeEdit_2"/> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QWidget" name="entityQueryFormIndexRange" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <layout class="QGridLayout" name="gridLayout_3"> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item row="2" column="1"> - <widget class="QSpinBox" name="spinBox_3"> - <property name="minimum"> - <number>-1000</number> - </property> - <property name="maximum"> - <number>1000</number> - </property> - <property name="value"> - <number>-1</number> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Last:</string> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>First:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="spinBox"> - <property name="minimum"> - <number>-1000</number> - </property> - <property name="maximum"> - <number>1000</number> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QCheckBox" name="checkBox_5"> - <property name="text"> - <string>Begin</string> - </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QCheckBox" name="checkBox_6"> - <property name="text"> - <string>End</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - </item> </layout> </widget> </item> <item> <widget class="QGroupBox" name="instanceGroupBox"> <property name="title"> - <string>Entity Instance (click on an instance on the left)</string> + <string>Entity View (click on an instance on the left)</string> </property> <layout class="QVBoxLayout" name="verticalLayout_5"> <property name="leftMargin"> @@ -473,67 +72,6 @@ <property name="bottomMargin"> <number>0</number> </property> - <item> - <widget class="QTreeWidget" name="_instanceTree"> - <column> - <property name="text"> - <string notr="true">Key</string> - </property> - </column> - <column> - <property name="text"> - <string>Type</string> - </property> - </column> - <column> - <property name="text"> - <string>Value</string> - </property> - </column> - <item> - <property name="text"> - <string>id</string> - </property> - </item> - <item> - <property name="text"> - <string>data</string> - </property> - </item> - <item> - <property name="text"> - <string>metadata</string> - </property> - </item> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QCheckBox" name="instanceUseTypeInfoCheckBox"> - <property name="text"> - <string>Use Type Info</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </item> </layout> </widget> </item> @@ -553,7 +91,7 @@ </font> </property> <property name="text"> - <string>TextLabel</string> + <string>StatusLabel</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp index 2636ee8ade97c82c97a40a93d4741bddfa466569..efe81d7170e97515f8bf39e692a16bcd68f1a6fe 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.cpp @@ -22,69 +22,17 @@ #include "ArMemMemoryViewerWidgetController.h" -#include <string> - -#include <QSplitter> -#include <QTimer> - -#include <ArmarXCore/observers/variant/Variant.h> -#include <ArmarXCore/core/time/TimeUtil.h> - -#include <RobotAPI/libraries/armem/core/ice_conversions.h> #include <RobotAPI/libraries/armem_gui/gui_utils.h> +#include <string> + namespace armarx { - template <class WidgetT> - void replaceWidget(WidgetT*& old, QWidget* neu, QLayout* parentLayout) - { - QLayoutItem* oldItem = parentLayout->replaceWidget(old, neu); - if (oldItem) - { - delete oldItem; - delete old; - old = nullptr; - } - } - - static QSplitter* useSplitter(QLayout* layout) - { - ARMARX_CHECK(layout); - - QSplitter* splitter; - if (dynamic_cast<QHBoxLayout*>(layout)) - { - splitter = new QSplitter(Qt::Orientation::Horizontal); - } - else if (dynamic_cast<QVBoxLayout*>(layout)) - { - splitter = new QSplitter(Qt::Orientation::Vertical); - } - else - { - splitter = new QSplitter(); - } - - while (layout->count() > 0) - { - int index = 0; - if (layout->itemAt(index)->widget()) - { - QLayoutItem* item = layout->takeAt(index); - splitter->addWidget(item->widget()); - } - } - layout->addWidget(splitter); - - return splitter; - } - - QString ArMemMemoryViewerWidgetController::GetWidgetName() { - return "MemoryX.ArMemMemoryViewer"; + return "ArMem.MemoryViewer"; } @@ -92,53 +40,22 @@ namespace armarx { widget.setupUi(getWidget()); - // Setup widgets - widget.statusLabel->clear(); - - - // Update timer - updateTimer = new QTimer(this); - updateTimer->setInterval(static_cast<int>(std::round(1000 / widget.updateFrequencySpinBox->value()))); - widget.updateFrequencySpinBox->setEnabled(widget.updateAutoCheckBox->isChecked()); - - - memoryTree = new armem::gui::MemoryTreeWidget(); - replaceWidget(widget._memoryTreeWidget, memoryTree, widget.memoryGroupBox->layout()); - ARMARX_CHECK_NULL(widget._memoryTreeWidget); - - queryTabs = new armem::gui::QueryWidget(); - widget._queryTabWidget = nullptr; - - armarx::gui::clearLayout(widget.queryGroupBox->layout()); - widget.queryGroupBox->layout()->addWidget(queryTabs); - - - instanceView = new armem::gui::InstanceView(); - instanceView->setStatusLabel(widget.statusLabel); - replaceWidget(widget._instanceTree, instanceView, widget.instanceGroupBox->layout()); - ARMARX_CHECK_NULL(widget._instanceTree); - - - useSplitter(widget.treesLayout); - useSplitter(widget.memoryGroupBox->layout()); + viewer = std::make_unique<MemoryViewer>( + widget.updateWidgetLayout, + widget.memoryGroupBox, + widget.treesLayout, - // Connect signals - connect(this, &This::connected, this, &This::updateMemory); - connect(widget.updateButton, &QPushButton::pressed, this, &This::updateMemory); - connect(updateTimer, &QTimer::timeout, this, &This::updateMemory); + widget.instanceGroupBox, + widget.treesLayout, - connect(widget.updateAutoCheckBox, &QCheckBox::toggled, widget.updateFrequencySpinBox, &QDoubleSpinBox::setEnabled); - connect(widget.updateAutoCheckBox, &QCheckBox::toggled, this, &This::toggleTimer); - connect(widget.updateFrequencySpinBox, &QDoubleSpinBox::editingFinished, this, &This::updateTimerFrequency); + widget.statusLabel + ); + viewer->setLogTag(getName()); - connect(this, &This::memoryDataChanged, this, &This::updateMemoryTree); - connect(memoryTree, &armem::gui::MemoryTreeWidget::selectedItemChanged, this, &This::updateInstanceTree); + armarx::gui::useSplitter(widget.treesLayout); - connect(widget.instanceUseTypeInfoCheckBox, &QCheckBox::toggled, instanceView, &armem::gui::InstanceView::setUseTypeInfo); - - connect(memoryTree, &armem::gui::MemoryTreeWidget::updated, this, &This::memoryTreeUpdated); - connect(instanceView, &armem::gui::InstanceView::updated, this, &This::instanceTreeUpdated); + armarx::gui::connectLifecycle(&lifecycleServer, viewer.get()); } ArMemMemoryViewerWidgetController::~ArMemMemoryViewerWidgetController() @@ -148,175 +65,27 @@ namespace armarx void ArMemMemoryViewerWidgetController::onInitComponent() { - if (memoryName.size() > 0) - { - usingProxy(memoryName); - } - if (debugObserverName.size() > 0) - { - usingProxy(debugObserverName); - } - - emit initialized(); + emit lifecycleServer.initialized(this); } void ArMemMemoryViewerWidgetController::onConnectComponent() { - if (!memoryName.empty()) - { - getProxy(memory, memoryName); - memoryReader = armem::client::Reader(memory); - } - // DebugObserver is optional (check for null on every call) - if (!debugObserverName.empty()) - { - getProxy(debugObserver, debugObserverName, false, "", false); - } - - toggleTimer(widget.updateAutoCheckBox->isChecked()); - - emit connected(); + emit lifecycleServer.connected(this); } - void ArMemMemoryViewerWidgetController::onDisconnectComponent() { - if (updateTimer) - { - updateTimer->stop(); - } - } - - void ArMemMemoryViewerWidgetController::updateTimerFrequency() - { - updateTimer->setInterval(static_cast<int>(std::round(1000 / widget.updateFrequencySpinBox->value()))); - } - - void ArMemMemoryViewerWidgetController::toggleTimer(bool start) - { - if (start) - { - updateTimer->start(); - } - else - { - updateTimer->stop(); - } - } - - - void ArMemMemoryViewerWidgetController::updateMemoryTree() - { - if (!memoryData) - { - return; - } - TIMING_START(GuiUpdate); - memoryTree->update(*memoryData); - TIMING_END_STREAM(GuiUpdate, ARMARX_VERBOSE); - - if (debugObserver) - { - debugObserver->setDebugDatafield(debugObserverChannelName, "GUI Update [ms]", new Variant(GuiUpdate.toMilliSecondsDouble())); - } - } - - - void ArMemMemoryViewerWidgetController::updateMemory() - { - if (!memoryReader) - { - return; - } - - TIMING_START(MemoryQuery); - { - armem::client::QueryInput input = queryTabs->queryInput(); - armem::client::QueryResult result = memoryReader.query(input); - if (result) - { - this->memoryData = std::move(result.memory); - } - else - { - widget.statusLabel->setText(QString::fromStdString(result.errorMessage)); - } - } - TIMING_END_STREAM(MemoryQuery, ARMARX_VERBOSE); - - if (debugObserver) - { - debugObserver->setDebugDatafield(debugObserverChannelName, "Memory Query [ms]", new Variant(MemoryQuery.toMilliSecondsDouble())); - } - - if (this->memoryData) - { - emit memoryDataChanged(); - } - else - { - widget.statusLabel->setText("No query result."); - } + emit lifecycleServer.disconnected(this); } - void ArMemMemoryViewerWidgetController::updateInstanceTree(const armem::MemoryID& selectedID) - { - if (memoryData) - { - if (!selectedID.hasEntityName()) - { - return; - } - armem::MemoryID id = selectedID; - const armem::EntitySnapshot* snapshot = nullptr; - if (!id.hasTimestamp()) - { - const armem::Entity& entity = memoryData->getEntity(id); - if (entity.empty()) - { - return; - } - snapshot = &entity.getLatestSnapshot(); - id.timestamp = snapshot->time(); - } - if (!id.hasInstanceIndex()) - { - if (!snapshot) - { - try - { - snapshot = &memoryData->getEntitySnapshot(id); - } - catch (const armem::error::ArMemError& e) - { - widget.statusLabel->setText(e.what()); - } - } - if (snapshot && snapshot->size() > 0) - { - id.instanceIndex = 0; - } - } - if (id.hasInstanceIndex()) - { - instanceView->update(id, *memoryData); - } - } - } - - - const static std::string CONFIG_KEY_MEMORY = "MemoryName"; - const static std::string CONFIG_KEY_DEBUG_OBSERVER = "DebugObserverName"; void ArMemMemoryViewerWidgetController::loadSettings(QSettings* settings) { - memoryName = settings->value(QString::fromStdString(CONFIG_KEY_MEMORY), "Memory").toString().toStdString(); - debugObserverName = settings->value(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER), "DebugObserver").toString().toStdString(); + viewer->loadSettings(settings); } void ArMemMemoryViewerWidgetController::saveSettings(QSettings* settings) { - settings->setValue(QString::fromStdString(CONFIG_KEY_MEMORY), QString::fromStdString(memoryName)); - settings->setValue(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER), QString::fromStdString(debugObserverName)); + viewer->saveSettings(settings); } QPointer<QDialog> ArMemMemoryViewerWidgetController::getConfigDialog(QWidget* parent) @@ -324,8 +93,7 @@ namespace armarx if (!configDialog) { configDialog = new SimpleConfigDialog(parent); - configDialog->addProxyFinder<armem::server::MemoryInterfacePrx>({CONFIG_KEY_MEMORY, "Memory", "*Memory"}); - configDialog->addProxyFinder<armarx::DebugObserverInterfacePrx>({CONFIG_KEY_DEBUG_OBSERVER, "Debug Observer", "DebugObserver"}); + viewer->writeConfigDialog(configDialog.data()); } return qobject_cast<QDialog*>(configDialog); } @@ -334,8 +102,7 @@ namespace armarx { if (configDialog) { - memoryName = configDialog->getProxyName(CONFIG_KEY_MEMORY); - debugObserverName = configDialog->getProxyName(CONFIG_KEY_DEBUG_OBSERVER); + viewer->readConfigDialog(configDialog.data()); } } } diff --git a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h index 8bf1ae02224c6ac8b55ec1ba2fb97ec3870371ea..ccb06e18a3cfafb185c257e9f6e33da8d07dd508 100644 --- a/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h +++ b/source/RobotAPI/gui-plugins/ArMemMemoryViewer/ArMemMemoryViewerWidgetController.h @@ -21,22 +21,18 @@ */ #pragma once -#include <RobotAPI/gui-plugins/ArMemMemoryViewer/ui_ArMemMemoryViewerWidget.h> +#include <memory> -#include <ArmarXCore/interface/observers/ObserverInterface.h> #include <ArmarXCore/core/system/ImportExportComponent.h> #include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h> #include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXComponentWidgetController.h> #include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> -#include <ArmarXCore/core/system/ImportExportComponent.h> +#include <RobotAPI/libraries/armem_gui/lifecycle.h> +#include <RobotAPI/libraries/armem_gui/MemoryViewer.h> -#include <RobotAPI/interface/armem/server/MemoryInterface.h> -#include <RobotAPI/libraries/armem/client/Reader.h> -#include <RobotAPI/libraries/armem_gui/instance/InstanceView.h> -#include <RobotAPI/libraries/armem_gui/MemoryTreeWidget.h> -#include <RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h> +#include <RobotAPI/gui-plugins/ArMemMemoryViewer/ui_ArMemMemoryViewerWidget.h> namespace armarx @@ -66,88 +62,53 @@ namespace armarx * Detailed description */ class ARMARXCOMPONENT_IMPORT_EXPORT - ArMemMemoryViewerWidgetController: + ArMemMemoryViewerWidgetController : public armarx::ArmarXComponentWidgetControllerTemplate < ArMemMemoryViewerWidgetController > { Q_OBJECT using This = ArMemMemoryViewerWidgetController; + using MemoryViewer = armarx::armem::gui::MemoryViewer; public: - /// Returns the Widget name displayed in the ArmarXGui to create an instance of this class. + static QString GetWidgetName(); - /// Controller Constructor explicit ArMemMemoryViewerWidgetController(); - /// Controller destructor virtual ~ArMemMemoryViewerWidgetController() override; + void loadSettings(QSettings* settings) override; void saveSettings(QSettings* settings) override; QPointer<QDialog> getConfigDialog(QWidget* parent) override; void configured() override; + void onInitComponent() override; void onConnectComponent() override; void onDisconnectComponent() override; public slots: - /* QT slot declarations */ - - void updateTimerFrequency(); - void toggleTimer(bool start); - void updateMemory(); - void updateInstanceTree(const armem::MemoryID& selectedID); - signals: - /* QT signal declarations */ - - void initialized(); - void connected(); - - void memoryTreeUpdated(); - void instanceTreeUpdated(); private slots: - void updateMemoryTree(); - signals: - void memoryDataChanged(); - - private: /// Widget Form Ui::ArMemMemoryViewerWidget widget; + armarx::gui::LifecycleServer lifecycleServer; QPointer<SimpleConfigDialog> configDialog; - std::string memoryName; - armem::server::MemoryInterfacePrx memory; - armem::client::Reader memoryReader; - - std::optional<armem::Memory> memoryData; - - armem::gui::MemoryTreeWidget* memoryTree; - armem::gui::QueryWidget* queryTabs; - armem::gui::InstanceView* instanceView; - - - std::string debugObserverName; - std::string debugObserverChannelName = "ArMemMemoryViewer"; - DebugObserverInterfacePrx debugObserver; - - QTimer* updateTimer; - - // Queries. - armem::query::data::EntityQueryPtr entityQuery; + std::unique_ptr<MemoryViewer> viewer; }; } diff --git a/source/RobotAPI/interface/CMakeLists.txt b/source/RobotAPI/interface/CMakeLists.txt index 88db84d51e8fb8cce6e551e8a818936928e1c854..d8f47110e34bf45513b29455969abe4e1d84ba33 100644 --- a/source/RobotAPI/interface/CMakeLists.txt +++ b/source/RobotAPI/interface/CMakeLists.txt @@ -106,6 +106,7 @@ set(SLICE_FILES armem.ice + armem/io.ice armem/commit.ice armem/memory.ice armem/query.ice @@ -114,7 +115,9 @@ set(SLICE_FILES armem/client/MemoryListenerInterface.ice armem/server.ice + armem/server/LongTermMemoryInterface.ice armem/server/MemoryInterface.ice + armem/server/MemoryPredictorInterface.ice armem/server/ReadingMemoryInterface.ice armem/server/WritingMemoryInterface.ice diff --git a/source/RobotAPI/interface/armem/io.ice b/source/RobotAPI/interface/armem/io.ice new file mode 100644 index 0000000000000000000000000000000000000000..cccea43c0b749441c30bc1834f3c86ce690b7195 --- /dev/null +++ b/source/RobotAPI/interface/armem/io.ice @@ -0,0 +1,53 @@ +#pragma once + +#include <ArmarXCore/interface/core/PackagePath.ice> +#include <RobotAPI/interface/armem/memory.ice> + +module armarx +{ + module armem + { + module data + { + struct LoadInput + { + armarx::data::PackagePath path; + armem::data::MemoryID entityID; + }; + + struct LoadResult + { + bool success = false; + long timeStartedMicroSeconds; + long timeFinishedMicroSeconds; + + long numLoadedCoreSegments; + long numLoadedProviderSegments; + long numLoadedEntities; + long numLoadedEntitySnapshots; + + string errorMessage; + }; + + struct StoreInput + { + armarx::data::PackagePath path; + armem::data::MemoryID entityID; + }; + + struct StoreResult + { + bool success = false; + long timeStartedMicroSeconds; + long timeFinishedMicroSeconds; + + long numStoredCoreSegments; + long numStoredLoadedProviderSegments; + long numStoredLoadedEntities; + long numStoredLoadedEntitySnapshots; + + string errorMessage; + }; + }; + }; +}; diff --git a/source/RobotAPI/interface/armem/server/LongTermMemoryInterface.ice b/source/RobotAPI/interface/armem/server/LongTermMemoryInterface.ice new file mode 100644 index 0000000000000000000000000000000000000000..ba64d626c1c156c3820a508625d1c3a3b36ec847 --- /dev/null +++ b/source/RobotAPI/interface/armem/server/LongTermMemoryInterface.ice @@ -0,0 +1,19 @@ +#pragma once + +#include <RobotAPI/interface/armem/io.ice> + + +module armarx +{ + module armem + { + module server + { + interface LongTermMemoryInterface + { + data::LoadResult load(data::LoadInput input); + data::StoreResult store(data::StoreInput input); + }; + }; + }; +}; diff --git a/source/RobotAPI/interface/armem/server/MemoryInterface.ice b/source/RobotAPI/interface/armem/server/MemoryInterface.ice index 2764998e2bf3d1226d8d34abb76772806b6bfd25..93213eed1d85269c83cfcd2547908e2be61f2d2a 100644 --- a/source/RobotAPI/interface/armem/server/MemoryInterface.ice +++ b/source/RobotAPI/interface/armem/server/MemoryInterface.ice @@ -3,6 +3,7 @@ #include <RobotAPI/interface/armem/server/ReadingMemoryInterface.ice> #include <RobotAPI/interface/armem/server/WritingMemoryInterface.ice> +#include <RobotAPI/interface/armem/server/LongTermMemoryInterface.ice> module armarx { diff --git a/source/RobotAPI/interface/armem/server/MemoryPredictorInterface.ice b/source/RobotAPI/interface/armem/server/MemoryPredictorInterface.ice new file mode 100644 index 0000000000000000000000000000000000000000..42920804f6d80d9e79151600864dc50e3b0c7aa3 --- /dev/null +++ b/source/RobotAPI/interface/armem/server/MemoryPredictorInterface.ice @@ -0,0 +1,16 @@ +#pragma once + +#include <RobotAPI/interface/armem/server/ReadingMemoryInterface.ice> +#include <RobotAPI/interface/armem/server/WritingMemoryInterface.ice> + +module armarx { + module armem { + module server { + interface MemoryPredictorInterface + { + // TODO + void predict(); + } + }; + }; +}; diff --git a/source/RobotAPI/interface/aron/Aron.ice b/source/RobotAPI/interface/aron/Aron.ice index cddbcc1558554cdb3ad19e81e981d0480e48b668..50e821e1b4d794906f353d30623f904d21266098 100644 --- a/source/RobotAPI/interface/aron/Aron.ice +++ b/source/RobotAPI/interface/aron/Aron.ice @@ -1,51 +1,28 @@ #pragma once -// AronMacros +// AronMacros (copied from Config.h) /************************************ * TYPES **************************** ***********************************/ - -#define HANDLE_CONTAINER_TYPES \ - RUN_ARON_MACRO(Object, object, OBJECT) \ - RUN_ARON_MACRO(List, list, LIST) \ - RUN_ARON_MACRO(Dict, dict, DICT) \ - RUN_ARON_MACRO(Tuple, tuple, TUPLE) \ - -#define HANDLE_COMPLEX_TYPES \ - RUN_ARON_MACRO(EigenMatrix, eigenmatrix, EIGEN_MATRIX) \ - RUN_ARON_MACRO(IVTCByteImage, ivtcbyteimage, IVT_CBYTE_IMAGE) \ - RUN_ARON_MACRO(OpenCVMat, opencvmat, OPENCV_MAT) \ - RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD) - #define HANDLE_PRIMITIVE_TYPES \ RUN_ARON_MACRO(Int, int, INT) \ RUN_ARON_MACRO(Long, long, LONG) \ RUN_ARON_MACRO(Float, float, FLOAT) \ RUN_ARON_MACRO(Double, double, DOUBLE) \ RUN_ARON_MACRO(String, string, STRING) \ - RUN_ARON_MACRO(Bool, bool, BOOL) - -#define HANDLE_ALL_ARON_TYPES \ - HANDLE_CONTAINER_TYPES \ - HANDLE_COMPLEX_TYPES \ - HANDLE_PRIMITIVE_TYPES + RUN_ARON_MACRO(Bool, bool, BOOL) \ + RUN_ARON_MACRO(Time, time, TIME) /************************************ * DATA ***************************** ***********************************/ - -#define HANDLE_CONTAINER_DATA \ - RUN_ARON_MACRO(List, list, LIST) \ - RUN_ARON_MACRO(Dict, dict, DICT) - -#define HANDLE_COMPLEX_DATA \ - RUN_ARON_MACRO(NDArray, ndarray, NDARRAY) - -#define HANDLE_ALL_ARON_DATA \ - HANDLE_CONTAINER_DATA \ - HANDLE_COMPLEX_DATA \ - HANDLE_PRIMITIVE_TYPES - +#define HANDLE_PRIMITIVE_DATA \ + RUN_ARON_MACRO(Int, int, INT) \ + RUN_ARON_MACRO(Long, long, LONG) \ + RUN_ARON_MACRO(Float, float, FLOAT) \ + RUN_ARON_MACRO(Double, double, DOUBLE) \ + RUN_ARON_MACRO(String, string, STRING) \ + RUN_ARON_MACRO(Bool, bool, BOOL) module armarx { @@ -56,11 +33,9 @@ module armarx * General Definitions *** ************************/ sequence<byte> AronByteSequence; -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - sequence<lowerType> Aron##upperType##Sequence; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO + sequence<int> AronIntSequence; + sequence<string> AronStringSequence; + dictionary<string, int> AronIntDict; /************************* @@ -72,32 +47,29 @@ module armarx sequence<AronType> AronTypeList; dictionary<string, AronType> AronTypeDict; - // Container Types (serialize to object/list) - class AronContainerType extends AronType {}; - - // Please note that either elementTypes xor acceptedType is set!!! - class AronDictSerializerType extends AronContainerType { AronTypeDict elementTypes; AronType acceptedType;}; - class AronListSerializerType extends AronContainerType { AronTypeList elementTypes; AronType acceptedType;}; - - class AronListType extends AronListSerializerType { }; - class AronTupleType extends AronListSerializerType { }; - - class AronObjectType extends AronDictSerializerType { AronObjectType parent; string objectName; }; - class AronDictType extends AronDictSerializerType { }; + // Container types + class AronList extends AronType { AronType acceptedType; }; + class AronTuple extends AronType { AronTypeList elementTypes; }; + class AronPair extends AronType { AronType acceptedType1; AronType acceptedType2; }; + class AronObject extends AronType { AronObject parent; string objectName; AronTypeDict elementTypes;}; + class AronDict extends AronType { AronType acceptedType; }; // Complex Types (serialize to ndarray) - class AronComplexType extends AronType {}; - class AronNDArraySerializerType extends AronComplexType { AronIntSequence dimensions; string typeName; }; - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##Type extends AronNDArraySerializerType { }; - - HANDLE_COMPLEX_TYPES - #undef RUN_ARON_MACRO + class AronEigenMatrix extends AronType { AronIntSequence dimensions; string typeName; }; + class AronEigenQuaternion extends AronType { string typeName; } + class AronIVTCByteImage extends AronType { int width; int height; string typeName; } + class AronOpenCVMat extends AronType { AronIntSequence dimensions; string typeName; } + class AronPCLPointCloud extends AronType { int width; int height; string typeName; } + class AronPosition extends AronType { } + class AronOrientation extends AronType { } + class AronPose extends AronType { } + + // Enum types + class AronIntEnum extends AronType { string enumName; AronIntDict acceptedValues; } // Primitive Types - class AronPrimitiveType extends AronType {}; #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##Type extends AronPrimitiveType { }; + class Aron##upperType extends AronType { }; HANDLE_PRIMITIVE_TYPES #undef RUN_ARON_MACRO @@ -114,34 +86,27 @@ module armarx dictionary<string, AronData> AronDataDict; // Container Data - class AronContainer extends AronData {}; - class AronList extends AronContainer { AronDataList elements; }; - class AronDict extends AronContainer { AronDataDict elements; }; + class AronList extends AronData { AronDataList elements; }; + class AronDict extends AronData { AronDataDict elements; }; - // Complex Data. The NDArray contains the same information as an AronType, but there is no other way to do it - class AronComplex extends AronData {}; - class AronNDArray extends AronComplex { AronIntSequence dimensions; string type; AronByteSequence data; }; + // 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") 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 AronNDArray extends AronData { AronIntSequence dimensions; string type; AronByteSequence data; }; - // Basic Data - class AronPrimitive extends AronData {}; + // Primitive Data #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType extends AronPrimitive { lowerType value; }; + class Aron##upperType extends AronData { lowerType value; }; - HANDLE_PRIMITIVE_TYPES + HANDLE_PRIMITIVE_DATA #undef RUN_ARON_MACRO - + // useful for memory ice_conversions sequence<AronDict> AronDictSeq; }; }; }; -#undef HANDLE_ALL_ARON_TYPES +#undef HANDLE_PRIMITIVE_DATA #undef HANDLE_PRIMITIVE_TYPES -#undef HANDLE_COMPLEX_TYPES -#undef HANDLE_CONTAINER_TYPES - -#undef HANDLE_ALL_ARON_DATA -#undef HANDLE_COMPLEX_DATA -#undef HANDLE_CONTAINER_DATA diff --git a/source/RobotAPI/interface/core/RobotState.ice b/source/RobotAPI/interface/core/RobotState.ice index 467b5c9552928a82c899642f2958b5c863d91993..a80b9b22c09d331e30f726dfb751c45543319fc5 100644 --- a/source/RobotAPI/interface/core/RobotState.ice +++ b/source/RobotAPI/interface/core/RobotState.ice @@ -188,6 +188,7 @@ module armarx */ interface RobotStateComponentInterface extends KinematicUnitListener, + PlatformUnitListener, GlobalRobotPoseLocalizationListener, SimulatorResetEvent { diff --git a/source/RobotAPI/interface/units/PlatformUnitInterface.ice b/source/RobotAPI/interface/units/PlatformUnitInterface.ice index 2d93b642a7658524d9b092cc569781c83797f71d..148e807f9514e1ea69db397c337a7030235f5702 100644 --- a/source/RobotAPI/interface/units/PlatformUnitInterface.ice +++ b/source/RobotAPI/interface/units/PlatformUnitInterface.ice @@ -117,7 +117,7 @@ module armarx void reportPlatformOdometryPose(float x, float y, float angle); }; - interface PlatformSubUnitInterface extends PlatformUnitInterface, GlobalRobotPoseLocalizationListener + interface PlatformSubUnitInterface extends PlatformUnitInterface, GlobalRobotPoseLocalizationListener, PlatformUnitListener { }; diff --git a/source/RobotAPI/libraries/ArmarXObjects/CMakeLists.txt b/source/RobotAPI/libraries/ArmarXObjects/CMakeLists.txt index d4fc9c35b6c57da50aa9ef6c8b05c9b5210797b3..57878bbbdea5f9724bc16002ffaf570aa7659298 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/CMakeLists.txt +++ b/source/RobotAPI/libraries/ArmarXObjects/CMakeLists.txt @@ -15,6 +15,7 @@ set(LIB_FILES json_conversions.cpp ice_conversions.cpp + aron_conversions.cpp ) set(LIB_HEADERS ArmarXObjects.h @@ -26,9 +27,19 @@ set(LIB_HEADERS json_conversions.h ice_conversions.h + aron_conversions.h ) armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +armarx_enable_aron_file_generation_for_target( + TARGET_NAME + "${LIB_NAME}" + ARON_FILES + aron/ObjectPose.xml +) + + # add unit tests add_subdirectory(test) diff --git a/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml b/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml new file mode 100644 index 0000000000000000000000000000000000000000..441ec9b60ac7cd6cee5be2be62cf3e391b117862 --- /dev/null +++ b/source/RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.xml @@ -0,0 +1,109 @@ +<!--This class contains the data structure for ObjectPose --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + <GenerateTypes> + + <IntEnum name="armarx::objpose::aron::ObjectTypes"> + <EnumValue key="ANY_OBJECT" value="0" /> + <EnumValue key="KNOWN_OBJECT" value="1" /> + <EnumValue key="UNKNOWN_OBJECT" value="2" /> + </IntEnum> + + <Object name="armarx::objpose::aron::ObjectID"> + <ObjectChild key='dataset'> + <string /> + </ObjectChild> + <ObjectChild key='className'> + <string /> + </ObjectChild> + <ObjectChild key='instanceName'> + <string /> + </ObjectChild> + </Object> + + <Object name="armarx::objpose::aron::ObjectAttachmentInfo"> + <ObjectChild key='frameName'> + <string /> + </ObjectChild> + <ObjectChild key='agentName'> + <string /> + </ObjectChild> + <ObjectChild key='poseInFrame'> + <Pose /> + </ObjectChild> + </Object> + + <Object name="armarx::objpose::aron::OrientedBoundingBox"> + <ObjectChild key='centerPose'> + <Pose /> + </ObjectChild> + <ObjectChild key='extends'> + <Position /> + </ObjectChild> + </Object> + + <Object name='armarx::objpose::aron::ObjectPose'> + + <ObjectChild key='providerName'> + <string /> + </ObjectChild> + + <ObjectChild key='objectType'> + <armarx::objpose::aron::ObjectTypes /> + </ObjectChild> + + <ObjectChild key='objectID'> + <armarx::objpose::aron::ObjectID /> + </ObjectChild> + + <ObjectChild key='objectPoseRobot'> + <Pose /> + </ObjectChild> + + <ObjectChild key='objectPoseGlobal'> + <Pose /> + </ObjectChild> + + <ObjectChild key='objectPoseOriginal'> + <Pose /> + </ObjectChild> + + <ObjectChild key='objectPoseOriginalFrame'> + <string /> + </ObjectChild> + + <ObjectChild key='robotConfig'> + <Dict> + <Float /> + </Dict> + </ObjectChild> + + <ObjectChild key='robotPose'> + <Pose /> + </ObjectChild> + + <ObjectChild key='attachment'> + <armarx::objpose::aron::ObjectAttachmentInfo /> + </ObjectChild> + + <ObjectChild key='confidence'> + <float /> + </ObjectChild> + + <ObjectChild key='timestamp'> + <Time /> + </ObjectChild> + + <ObjectChild key='localOOBB'> + <armarx::objpose::aron::OrientedBoundingBox /> + </ObjectChild> + + </Object> + + + </GenerateTypes> +</AronTypeDefinition> + diff --git a/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.cpp b/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ac7717c5e632d33873f6e4ff43fa97f9362c6a3 --- /dev/null +++ b/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.cpp @@ -0,0 +1,183 @@ +#include "aron_conversions.h" + +// STL +#include <stdexcept> +#include <string> + +// Ice +#include <IceUtil/Time.h> + +// Simox +#include <SimoxUtility/shapes/OrientedBox.h> + +// RobotAPI +// TODO: ice dependency! header should be removed. +#include <RobotAPI/interface/objectpose/object_pose_types.h> + +#include <RobotAPI/libraries/ArmarXObjects/ObjectPose.h> +#include <RobotAPI/libraries/ArmarXObjects/aron/ObjectPose.aron.generated.h> + + +namespace armarx::objpose +{ + + ObjectID fromAron(const aron::ObjectID& id) + { + return ObjectID(id.dataset, id.className, id.instanceName); + } + + ObjectTypeEnum fromAron(const aron::ObjectTypes& objectType) + { + using AronObjectType = aron::ObjectTypes::__ImplEnum; + + ObjectTypeEnum e{}; + + switch (objectType.value) + { + case AronObjectType::ANY_OBJECT: + e = ObjectTypeEnum::AnyObject; + break; + case AronObjectType::KNOWN_OBJECT: + e = ObjectTypeEnum::KnownObject; + break; + case AronObjectType::UNKNOWN_OBJECT: + e = ObjectTypeEnum::UnknownObject; + break; + } + + return e; + } + + simox::OrientedBoxf fromAron(const aron::OrientedBoundingBox& obb) + { + return simox::OrientedBoxf(obb.centerPose, obb.extends); + } + + ObjectAttachmentInfo fromAron(const aron::ObjectAttachmentInfo& info) + { + return + { + .frameName = info.frameName, + .agentName = info.agentName, + .poseInFrame = info.poseInFrame + }; + } + + + void fromAron(const aron::ObjectPose& aronObjectPose, ObjectPose& objectPose) + { + objectPose.providerName = aronObjectPose.providerName; + + objectPose.objectType = fromAron(aronObjectPose.objectType); + + objectPose.objectID = fromAron(aronObjectPose.objectID); + + objectPose.objectPoseRobot = aronObjectPose.objectPoseRobot; + objectPose.objectPoseGlobal = aronObjectPose.objectPoseGlobal; + objectPose.objectPoseOriginal = aronObjectPose.objectPoseOriginal; + objectPose.objectPoseOriginalFrame = aronObjectPose.objectPoseOriginalFrame; + + objectPose.robotConfig = aronObjectPose.robotConfig; + objectPose.robotPose = aronObjectPose.robotPose; + + objectPose.attachment = fromAron(aronObjectPose.attachment); + + objectPose.confidence = aronObjectPose.confidence; + + objectPose.timestamp = IceUtil::Time::microSeconds(aronObjectPose.timestamp); + + objectPose.localOOBB = fromAron(aronObjectPose.localOOBB); + + } + + + aron::ObjectID toAron(const ObjectID& id) + { + aron::ObjectID aronId; + + aronId.className = id.className(); + aronId.dataset = id.dataset(); + aronId.instanceName = id.instanceName(); + + return aronId; + } + + aron::ObjectTypes toAron(const ObjectTypeEnum& objectType) + { + aron::ObjectTypes ot{}; + + switch (objectType) + { + case ObjectTypeEnum::AnyObject: + ot = aron::ObjectTypes::ANY_OBJECT; + break; + case ObjectTypeEnum::KnownObject: + ot = aron::ObjectTypes::KNOWN_OBJECT; + break; + case ObjectTypeEnum::UnknownObject: + ot = aron::ObjectTypes::UNKNOWN_OBJECT; + break; + } + + return ot; + } + + aron::ObjectAttachmentInfo toAron(const ObjectAttachmentInfo& info) + { + aron::ObjectAttachmentInfo aronInfo; + + aronInfo.agentName = info.agentName; + aronInfo.frameName = info.frameName; + aronInfo.poseInFrame = info.poseInFrame; + + return aronInfo; + } + + aron::OrientedBoundingBox toAron(const simox::OrientedBoxf& box) + { + aron::OrientedBoundingBox aronBox; + aronBox.centerPose = box.transformation(); + aronBox.extends = box.dimensions(); + return aronBox; + } + + template <typename T> + auto toAron(const std::optional<T>& p) + { + if (p) + { + return toAron(p.value()); + } + + // TODO(fabian.reister): handle optional properly + // current fallback: default c'tor + return decltype(toAron(p.value()))(); + } + + + void toAron(const ObjectPose& objectPose, aron::ObjectPose& aronObjectPose) + { + aronObjectPose.providerName = objectPose.providerName; + + aronObjectPose.objectType = toAron(objectPose.objectType); + + aronObjectPose.objectID = toAron(objectPose.objectID); + + aronObjectPose.objectPoseRobot = objectPose.objectPoseRobot; + aronObjectPose.objectPoseGlobal = objectPose.objectPoseGlobal; + aronObjectPose.objectPoseOriginal = objectPose.objectPoseOriginal; + aronObjectPose.objectPoseOriginalFrame = objectPose.objectPoseOriginalFrame; + + aronObjectPose.robotConfig = objectPose.robotConfig; + aronObjectPose.robotPose = objectPose.robotPose; + + aronObjectPose.attachment = toAron(objectPose.attachment); + + aronObjectPose.confidence = objectPose.confidence; + + aronObjectPose.timestamp = objectPose.timestamp.toMicroSeconds(); + + aronObjectPose.localOOBB = toAron(objectPose.localOOBB); + } + +} // namespace armarx::objpose diff --git a/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.h b/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.h new file mode 100644 index 0000000000000000000000000000000000000000..04abe6667678e88f6a9fe3239a5695585dd100b4 --- /dev/null +++ b/source/RobotAPI/libraries/ArmarXObjects/aron_conversions.h @@ -0,0 +1,15 @@ +#pragma once + + +namespace armarx::objpose +{ + struct ObjectPose; + + namespace aron { + struct ObjectPose; + } + + void fromAron(const aron::ObjectPose& aronObjectPose, ObjectPose& objectPose); + void toAron(const ObjectPose& objectPose, aron::ObjectPose& aronObjectPose); + +} // namespace armarx::objpose \ No newline at end of file diff --git a/source/RobotAPI/libraries/CMakeLists.txt b/source/RobotAPI/libraries/CMakeLists.txt index b876e68f7c6ecbf390f608e428721cde7ea30195..369ad1d5504d233fdfac46ccfae3ab90d0b512a5 100644 --- a/source/RobotAPI/libraries/CMakeLists.txt +++ b/source/RobotAPI/libraries/CMakeLists.txt @@ -19,6 +19,7 @@ add_subdirectory(natik) add_subdirectory(armem) add_subdirectory(armem_gui) +add_subdirectory(armem_robot_localization) add_subdirectory(aron) add_subdirectory(NJointControllerGuiPluginUtility) diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 5e85729b15a7afbf8855a6eca1059062635df405..0dca18cdbbbb8d1c4302c26666d7755a3d671673 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -145,8 +145,11 @@ armarx_enable_aron_file_generation_for_target( ${LIB_NAME} ARON_FILES ${ARON_FILES} + #ENABLE_DEBUG_INFO ) +add_library(RobotAPI::libraries::armem ALIAS "${LIB_NAME}") + # add unit tests add_subdirectory(test) diff --git a/source/RobotAPI/libraries/armem/client/Reader.cpp b/source/RobotAPI/libraries/armem/client/Reader.cpp index 48df371763673c30cc9cc4bd3415540306a55316..8c336da2fcee343364e479734203a63cfef55625 100644 --- a/source/RobotAPI/libraries/armem/client/Reader.cpp +++ b/source/RobotAPI/libraries/armem/client/Reader.cpp @@ -15,13 +15,13 @@ namespace armarx::armem::client QueryResult - Reader::query(const QueryInput& input) + Reader::query(const QueryInput& input) const { return QueryResult::fromIce(query(input.toIce())); } armem::query::data::Result - Reader::query(const armem::query::data::Input& input) + Reader::query(const armem::query::data::Input& input) const { auto makeErrorMsg = [](auto e) { @@ -50,12 +50,12 @@ namespace armarx::armem::client return result; } - QueryResult Reader::query(armem::query::data::MemoryQueryPtr query, DataMode dataMode) + QueryResult Reader::query(armem::query::data::MemoryQueryPtr query, DataMode dataMode) const { return this->query(armem::query::data::MemoryQuerySeq{query}, dataMode); } - QueryResult Reader::query(const armem::query::data::MemoryQuerySeq& queries, DataMode dataMode) + QueryResult Reader::query(const armem::query::data::MemoryQuerySeq& queries, DataMode dataMode) const { QueryInput input; input.memoryQueries = queries; diff --git a/source/RobotAPI/libraries/armem/client/Reader.h b/source/RobotAPI/libraries/armem/client/Reader.h index 76795ad5edf87bbd14f893f82811292915718382..26237f31b832057908823152057bc5d1f360df97 100644 --- a/source/RobotAPI/libraries/armem/client/Reader.h +++ b/source/RobotAPI/libraries/armem/client/Reader.h @@ -39,11 +39,11 @@ namespace armarx::armem::client void setReadingMemory(server::ReadingMemoryInterfacePrx memory); - QueryResult query(const QueryInput& input); - armem::query::data::Result query(const armem::query::data::Input& input); + QueryResult query(const QueryInput& input) const; + armem::query::data::Result query(const armem::query::data::Input& input) const; - QueryResult query(armem::query::data::MemoryQueryPtr query, DataMode dataMode = DataMode::WithData); - QueryResult query(const armem::query::data::MemoryQuerySeq& queries, DataMode dataMode = DataMode::WithData); + QueryResult query(armem::query::data::MemoryQueryPtr query, DataMode dataMode = DataMode::WithData) const; + QueryResult query(const armem::query::data::MemoryQuerySeq& queries, DataMode dataMode = DataMode::WithData) const; QueryResult getAll(DataMode dataMode = DataMode::WithData); diff --git a/source/RobotAPI/libraries/armem/client/ReaderComponentPlugin.h b/source/RobotAPI/libraries/armem/client/ReaderComponentPlugin.h index c4b6eae7a875baf2ae0814ffc89c233aacf4fee6..44f276ac95cc79d867287be68ebdb1b734056849 100644 --- a/source/RobotAPI/libraries/armem/client/ReaderComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/client/ReaderComponentPlugin.h @@ -8,7 +8,7 @@ #include <ArmarXCore/core/Component.h> // RobotAPI -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> #include <RobotAPI/interface/armem/server/ReadingMemoryInterface.h> #include <RobotAPI/interface/armem/client/MemoryListenerInterface.h> diff --git a/source/RobotAPI/libraries/armem/client/Writer.cpp b/source/RobotAPI/libraries/armem/client/Writer.cpp index 8b1362104b29968c7894db559e9d0e4a7fc5b818..93dbb39ae33d6e614fb0f4e95de58e0522a99b20 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.cpp +++ b/source/RobotAPI/libraries/armem/client/Writer.cpp @@ -113,7 +113,7 @@ namespace armarx::armem::client EntityUpdateResult Writer::commit( const MemoryID& entityID, - const std::vector<aron::datanavigator::AronDictDataNavigatorPtr>& instancesData, + const std::vector<aron::datanavigator::DictNavigatorPtr>& instancesData, Time timeCreated) { EntityUpdate update; diff --git a/source/RobotAPI/libraries/armem/client/Writer.h b/source/RobotAPI/libraries/armem/client/Writer.h index 98e18f01399521bfe54078868598528e5feb9f1b..f4c0754a10c129062f482d581d3d81f5bc0977ce 100644 --- a/source/RobotAPI/libraries/armem/client/Writer.h +++ b/source/RobotAPI/libraries/armem/client/Writer.h @@ -47,7 +47,7 @@ namespace armarx::armem::client /// Commit a single entity update. EntityUpdateResult commit( const MemoryID& entityID, - const std::vector<aron::datanavigator::AronDictDataNavigatorPtr>& instancesData, + const std::vector<aron::datanavigator::DictNavigatorPtr>& instancesData, Time timeCreated); void setWritingMemory(server::WritingMemoryInterfacePrx memory); diff --git a/source/RobotAPI/libraries/armem/client/WriterComponentPlugin.h b/source/RobotAPI/libraries/armem/client/WriterComponentPlugin.h index 9e1608c10cfb0173d9dc80aa1c87b3dbe1b38a18..6df32feea8e85f4b2edf2eb43c3ba131a3238f78 100644 --- a/source/RobotAPI/libraries/armem/client/WriterComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/client/WriterComponentPlugin.h @@ -5,7 +5,7 @@ #include <ArmarXCore/core/Component.h> // RobotAPI -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> #include <RobotAPI/interface/armem/server/WritingMemoryInterface.h> #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> diff --git a/source/RobotAPI/libraries/armem/core/Commit.h b/source/RobotAPI/libraries/armem/core/Commit.h index 7d246f8ae0e3a05aff05c6d842a9947b12fec937..6a25f7a7c0e362dbf25ba9ee4a895724bea50a05 100644 --- a/source/RobotAPI/libraries/armem/core/Commit.h +++ b/source/RobotAPI/libraries/armem/core/Commit.h @@ -2,7 +2,7 @@ #include <vector> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> #include "../core/MemoryID.h" #include "../core/Time.h" @@ -20,7 +20,7 @@ namespace armarx::armem MemoryID entityID; /// The entity data. - std::vector<aron::datanavigator::AronDictDataNavigatorPtr> instancesData; + std::vector<aron::datanavigator::DictNavigatorPtr> instancesData; /** * @brief Time when this entity update was created (e.g. time of image recording). diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/CoreSegment.cpp index 34f73cbdf4f7845a8fc2ad0ab14bc7d9ffcb8775..61098ee9a268d6bd06748c02878cc70e013e72af 100644 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/CoreSegment.cpp @@ -12,17 +12,17 @@ namespace armarx::armem { } - CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + CoreSegment::CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : CoreSegment(name, MemoryID(), aronType) { } - CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + CoreSegment::CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : CoreSegment(parentID.getMemoryID().withCoreSegmentName(name), aronType) { } - CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + CoreSegment::CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType) : Base(id, aronType) { } @@ -108,9 +108,9 @@ namespace armarx::armem } - ProviderSegment& CoreSegment::addProviderSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr providerSegmentType) + ProviderSegment& CoreSegment::addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType) { - aron::typenavigator::AronObjectTypeNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType(); + aron::typenavigator::ObjectNavigatorPtr type = providerSegmentType ? providerSegmentType : this->aronType(); return addProviderSegment(ProviderSegment(name, type)); } diff --git a/source/RobotAPI/libraries/armem/core/CoreSegment.h b/source/RobotAPI/libraries/armem/core/CoreSegment.h index aed697fb00d5aaf4c3d1f8446be5b289fae97cb8..f492c0f1a735bd8c7343bfb503bc66f3add11908 100644 --- a/source/RobotAPI/libraries/armem/core/CoreSegment.h +++ b/source/RobotAPI/libraries/armem/core/CoreSegment.h @@ -23,9 +23,9 @@ namespace armarx::armem public: CoreSegment(); - CoreSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); - CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); - CoreSegment(const MemoryID& id, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); + CoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const std::string& name, const MemoryID& parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + CoreSegment(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); CoreSegment(const CoreSegment& other); CoreSegment& operator=(const CoreSegment& other); @@ -55,7 +55,7 @@ namespace armarx::armem * @param providerSegmentType The provider type. If nullptr, the core segment type is used. * @return The added provider segment. */ - ProviderSegment& addProviderSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr providerSegmentType = nullptr); + ProviderSegment& addProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr providerSegmentType = nullptr); /// Copy and insert a provider segment. ProviderSegment& addProviderSegment(const ProviderSegment& providerSegment); /// Move and insert a provider segment. diff --git a/source/RobotAPI/libraries/armem/core/EntityInstance.h b/source/RobotAPI/libraries/armem/core/EntityInstance.h index 7b3235bec867296d72784e446f0d2f0ef41bf00a..25311339e6429d62b4f7de77476804a553574a7f 100644 --- a/source/RobotAPI/libraries/armem/core/EntityInstance.h +++ b/source/RobotAPI/libraries/armem/core/EntityInstance.h @@ -1,7 +1,7 @@ #pragma once #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> #include "../core/Time.h" @@ -66,11 +66,11 @@ namespace armarx::armem return _metadata; } - inline armarx::aron::datanavigator::AronDictDataNavigatorPtr data() const + inline armarx::aron::datanavigator::DictNavigatorPtr data() const { return _data; } - void setData(const aron::datanavigator::AronDictDataNavigatorPtr& data) + void setData(const aron::datanavigator::DictNavigatorPtr& data) { this->_data = data; } @@ -101,7 +101,7 @@ namespace armarx::armem EntityInstanceMetadata _metadata; /// The data. May be nullptr. - armarx::aron::datanavigator::AronDictDataNavigatorPtr _data; + armarx::aron::datanavigator::DictNavigatorPtr _data; }; diff --git a/source/RobotAPI/libraries/armem/core/Memory.cpp b/source/RobotAPI/libraries/armem/core/Memory.cpp index c78e22733a9dc05f2748061b4fd8680b9b1f7172..3d218f0b098670cbc6e704e9e500ffecd752c2ac 100644 --- a/source/RobotAPI/libraries/armem/core/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/Memory.cpp @@ -83,7 +83,7 @@ namespace armarx::armem } - CoreSegment& Memory::addCoreSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr coreSegmentType) + CoreSegment& Memory::addCoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr coreSegmentType) { return addCoreSegment(CoreSegment(name, coreSegmentType)); } diff --git a/source/RobotAPI/libraries/armem/core/Memory.h b/source/RobotAPI/libraries/armem/core/Memory.h index 1f38f7eab44be7f08020c1e78c41a3460b9ebe76..2059d0c0dcdc13e683e20fd9c4646bb499b6d1ce 100644 --- a/source/RobotAPI/libraries/armem/core/Memory.h +++ b/source/RobotAPI/libraries/armem/core/Memory.h @@ -47,7 +47,7 @@ namespace armarx::armem * @param coreSegmentType The core segment type (optional). * @return The added core segment. */ - CoreSegment& addCoreSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr coreSegmentType = nullptr); + CoreSegment& addCoreSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr coreSegmentType = nullptr); /// Copy and insert a core segment. CoreSegment& addCoreSegment(const CoreSegment& coreSegment); /// Move and insert a core segment. diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp index fb0ca8cc82a3cfcbf3f89251c87b2d79a7f4e357..879932739ff86a8a9b091d561053f0f76ca08be0 100644 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/ProviderSegment.cpp @@ -12,17 +12,17 @@ namespace armarx::armem { } - ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + ProviderSegment::ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType) : ProviderSegment(name, MemoryID(), aronType) { } - ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + ProviderSegment::ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType) : ProviderSegment(parentID.withProviderSegmentName(name), aronType) { } - ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) : + ProviderSegment::ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType) : Base(id, aronType) { } diff --git a/source/RobotAPI/libraries/armem/core/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/ProviderSegment.h index 384ee1b416c2dac48ae1dcccdc9fa3e984ff6700..cbb2080de0af157cb45f9d938edcde62315f7483 100644 --- a/source/RobotAPI/libraries/armem/core/ProviderSegment.h +++ b/source/RobotAPI/libraries/armem/core/ProviderSegment.h @@ -25,9 +25,9 @@ namespace armarx::armem public: ProviderSegment(); - ProviderSegment(const std::string& name, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); - ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); - ProviderSegment(const MemoryID id, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); + ProviderSegment(const std::string& name, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const std::string& name, const MemoryID parentID, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); + ProviderSegment(const MemoryID id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); ProviderSegment(const ProviderSegment& other); ProviderSegment& operator=(const ProviderSegment& other); diff --git a/source/RobotAPI/libraries/armem/core/aron/MemoryID.xml b/source/RobotAPI/libraries/armem/core/aron/MemoryID.xml index d7ba24e0525a8f9087ac1d9200e910fa03bd1ee5..11d0fee395edca2c597dc1ea9de53dfbd7f9eae9 100644 --- a/source/RobotAPI/libraries/armem/core/aron/MemoryID.xml +++ b/source/RobotAPI/libraries/armem/core/aron/MemoryID.xml @@ -1,8 +1,7 @@ -<!--Some fancy comment --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::armem::aron::MemoryID'> + <Object name='armarx::armem::aron::MemoryID'> <ObjectChild key='memoryName'> <string /> </ObjectChild> @@ -21,6 +20,6 @@ <ObjectChild key='instanceIndex'> <int /> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h b/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h index 5a74fd0e742bc33ae3f1d75ea92ea3489d4806f3..f932b72297b89eb9248bd05751ef9a3b0085324f 100644 --- a/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h +++ b/source/RobotAPI/libraries/armem/core/detail/TypedEntityContainer.h @@ -2,7 +2,7 @@ #include "EntityContainer.h" -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> namespace armarx::armem::detail { @@ -18,9 +18,9 @@ namespace armarx::armem::detail public: - TypedEntityContainer(aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr) : _aronType(aronType) + TypedEntityContainer(aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : _aronType(aronType) {} - TypedEntityContainer(const MemoryID& id, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr) : + TypedEntityContainer(const MemoryID& id, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr) : EntityContainer<ValueT, Derived>(id), _aronType(aronType) {} @@ -32,11 +32,11 @@ namespace armarx::armem::detail { return _aronType != nullptr; } - aron::typenavigator::AronObjectTypeNavigatorPtr& aronType() + aron::typenavigator::ObjectNavigatorPtr& aronType() { return _aronType; } - aron::typenavigator::AronObjectTypeNavigatorPtr aronType() const + aron::typenavigator::ObjectNavigatorPtr aronType() const { return _aronType; } @@ -55,7 +55,7 @@ namespace armarx::armem::detail private: /// The expected Aron type. May be nullptr, in which case no type information is available. - aron::typenavigator::AronObjectTypeNavigatorPtr _aronType; + aron::typenavigator::ObjectNavigatorPtr _aronType; }; diff --git a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp index 74d2262cf01c4b43aacf740444f4912c50e03972..684028ae6c96d8e905de06d1bf957669d6db3d47 100644 --- a/source/RobotAPI/libraries/armem/core/ice_conversions.cpp +++ b/source/RobotAPI/libraries/armem/core/ice_conversions.cpp @@ -86,7 +86,7 @@ namespace armarx update.instancesData.clear(); update.instancesData.reserve(ice.instancesData.size()); std::transform(ice.instancesData.begin(), ice.instancesData.end(), std::back_inserter(update.instancesData), - aron::datanavigator::AronDictDataNavigator::FromAronDictPtr); + aron::datanavigator::DictNavigator::FromAronDictPtr); update.timeCreated = Time::microSeconds(ice.timeCreatedMicroSeconds); @@ -101,7 +101,7 @@ namespace armarx ice.instancesData.clear(); ice.instancesData.reserve(update.instancesData.size()); std::transform(update.instancesData.begin(), update.instancesData.end(), std::back_inserter(ice.instancesData), - aron::datanavigator::AronDictDataNavigator::ToAronDictPtr); + aron::datanavigator::DictNavigator::ToAronDictPtr); ice.timeCreatedMicroSeconds = update.timeCreated.toMicroSeconds(); @@ -187,7 +187,7 @@ namespace armarx if (ice.data) { - data.setData(aron::datanavigator::AronDictDataNavigator::FromAronDictPtr(ice.data)); + data.setData(aron::datanavigator::DictNavigator::FromAronDictPtr(ice.data)); } fromIce(ice.metadata, data.metadata()); } @@ -236,8 +236,8 @@ namespace armarx if (ice.aronType) { - providerSegment.aronType() = aron::typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck( - aron::typenavigator::AronTypeNavigator::FromAronType(ice.aronType) + providerSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( + aron::typenavigator::Navigator::FromAronType(ice.aronType) ); } fromIce(ice.entities, providerSegment.entities); @@ -259,8 +259,8 @@ namespace armarx if (ice.aronType) { - coreSegment.aronType() = aron::typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck( - aron::typenavigator::AronTypeNavigator::FromAronType(ice.aronType) + coreSegment.aronType() = aron::typenavigator::ObjectNavigator::DynamicCastAndCheck( + aron::typenavigator::Navigator::FromAronType(ice.aronType) ); } fromIce(ice.providerSegments, coreSegment.providerSegments); diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp index 4f4937a5d6d5309db588383d16424148ae949f5c..08584369d6f745f7c0203497a531cd2e133319c2 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp @@ -26,14 +26,14 @@ // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> #include <RobotAPI/libraries/armem/core/error.h> @@ -121,13 +121,13 @@ namespace armarx::armem::io return ret; } - EntityInstance DiskReader::readSingleInstanceFromDisk(const MemoryID& id, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const + EntityInstance DiskReader::readSingleInstanceFromDisk(const MemoryID& id, const aron::typenavigator::NavigatorPtr& expectedStructure) const { std::filesystem::path p = rootPath / (id.str() + getEntityInstanceSuffix()); return readSingleInstanceFromDisk(p, expectedStructure); } - EntityInstance DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const + EntityInstance DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::NavigatorPtr& expectedStructure) const { if (!std::filesystem::is_regular_file(p)) { @@ -137,17 +137,17 @@ namespace armarx::armem::io std::ifstream ifs(p); std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - aron::datanavigator::AronDictDataNavigatorPtr dictdata = getStringAsDataNavigator(file_content, expectedStructure); + aron::datanavigator::DictNavigatorPtr dictdata = getStringAsDataNavigator(file_content, expectedStructure); return unwrapData(dictdata); } - aron::typenavigator::AronObjectTypeNavigatorPtr DiskReader::readSingleTypeInformationFromDisk(const MemoryID& id) const + aron::typenavigator::ObjectNavigatorPtr DiskReader::readSingleTypeInformationFromDisk(const MemoryID& id) const { std::filesystem::path p = rootPath / id.str() / (id.getLeafItem() + getTypeSuffix()); return readSingleTypeInformationFromDisk(p); } - aron::typenavigator::AronObjectTypeNavigatorPtr DiskReader::readSingleTypeInformationFromDisk(const std::filesystem::path& p) const + aron::typenavigator::ObjectNavigatorPtr DiskReader::readSingleTypeInformationFromDisk(const std::filesystem::path& p) const { if (!std::filesystem::is_regular_file(p)) { @@ -157,38 +157,38 @@ namespace armarx::armem::io std::ifstream ifs(p); std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - aron::typenavigator::AronObjectTypeNavigatorPtr objecttype = getStringAsTypeNavigator(file_content); + aron::typenavigator::ObjectNavigatorPtr objecttype = getStringAsTypeNavigator(file_content); return objecttype; } - EntityInstance DiskReader::unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr& dataWrapped) const + EntityInstance DiskReader::unwrapData(const aron::datanavigator::DictNavigatorPtr& dataWrapped) const { EntityInstance e; EntityInstanceMetadata& metadata = e.metadata(); - aron::datanavigator::AronDictDataNavigatorPtr data = aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_DATA_FIELD)); + aron::datanavigator::DictNavigatorPtr data = aron::datanavigator::DictNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_DATA_FIELD)); e.setData(data); // not used right now - //aron::datanavigator::AronLongDataNavigatorPtr timeWrapped = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD)); + //aron::datanavigator::LongNavigatorPtr timeWrapped = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD)); - aron::datanavigator::AronLongDataNavigatorPtr timeCreated = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_CREATED_FIELD)); + aron::datanavigator::LongNavigatorPtr timeCreated = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_CREATED_FIELD)); metadata.timeCreated = Time::microSeconds(timeCreated->toAronLongPtr()->value); - aron::datanavigator::AronLongDataNavigatorPtr timeSent = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_SENT_FIELD)); + aron::datanavigator::LongNavigatorPtr timeSent = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_SENT_FIELD)); metadata.timeSent = Time::microSeconds(timeSent->toAronLongPtr()->value); - aron::datanavigator::AronLongDataNavigatorPtr timeArrived = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD)); + aron::datanavigator::LongNavigatorPtr timeArrived = aron::datanavigator::LongNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD)); metadata.timeArrived = Time::microSeconds(timeArrived->toAronLongPtr()->value); - aron::datanavigator::AronDoubleDataNavigatorPtr confidence = aron::datanavigator::AronDoubleDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_CONFIDENCE_FIELD)); + aron::datanavigator::DoubleNavigatorPtr confidence = aron::datanavigator::DoubleNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_CONFIDENCE_FIELD)); metadata.confidence = static_cast<float>(confidence->toAronDoublePtr()->value); return e; } - aron::typenavigator::AronObjectTypeNavigatorPtr DiskReader::unwrapType(const aron::typenavigator::AronObjectTypeNavigatorPtr& t) const + aron::typenavigator::ObjectNavigatorPtr DiskReader::unwrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const { - return aron::typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(t->getAcceptedType(DISK_READER_WRITER_DATA_FIELD)); + return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(t->getMemberType(DISK_READER_WRITER_DATA_FIELD)); } } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h index 415dde225b7c686d27987d2e83ef1d1282de191a..2ae252521b823e270533d2305a4af272b76bf944 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h @@ -25,9 +25,9 @@ #include <memory> #include <string> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> #include <RobotAPI/libraries/armem/core/EntityInstance.h> @@ -49,17 +49,17 @@ namespace armarx::armem::io FileSystemLookupMemory readMemoryStructureFromDisk(); FileSystemLookupMemory readMemoryStructureFromDisk(const std::string&); - EntityInstance readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; - EntityInstance readSingleInstanceFromDisk(const MemoryID&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; + EntityInstance readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::NavigatorPtr& expectedStructure = nullptr) const; + EntityInstance readSingleInstanceFromDisk(const MemoryID&, const aron::typenavigator::NavigatorPtr& expectedStructure = nullptr) const; - aron::typenavigator::AronObjectTypeNavigatorPtr readSingleTypeInformationFromDisk(const std::filesystem::path&) const; - aron::typenavigator::AronObjectTypeNavigatorPtr readSingleTypeInformationFromDisk(const MemoryID&) const; + aron::typenavigator::ObjectNavigatorPtr readSingleTypeInformationFromDisk(const std::filesystem::path&) const; + aron::typenavigator::ObjectNavigatorPtr readSingleTypeInformationFromDisk(const MemoryID&) const; protected: - EntityInstance unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr&) const; - aron::typenavigator::AronObjectTypeNavigatorPtr unwrapType(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const; + EntityInstance unwrapData(const aron::datanavigator::DictNavigatorPtr&) const; + aron::typenavigator::ObjectNavigatorPtr unwrapType(const aron::typenavigator::ObjectNavigatorPtr&) const; - virtual aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::AronTypeNavigatorPtr&) const = 0; - virtual aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; + virtual aron::datanavigator::DictNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::NavigatorPtr&) const = 0; + virtual aron::typenavigator::ObjectNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; }; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp index 41e230cd614abbf8647697904dd1b4b736a6dc03..3742996cda7cf4f03a15615a5ba7a296dfeba591 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp @@ -1,10 +1,11 @@ #include "NlohmannJSONDiskReader.h" -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> namespace armarx::armem::io @@ -22,19 +23,19 @@ namespace armarx::armem::io { } - aron::datanavigator::AronDictDataNavigatorPtr NlohmannJSONDiskReader::getStringAsDataNavigator(const std::string& s, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const + aron::datanavigator::DictNavigatorPtr NlohmannJSONDiskReader::getStringAsDataNavigator(const std::string& s, const aron::typenavigator::NavigatorPtr& expectedStructure) const { - aron::io::AronDataNlohmannJSONReader dataReader(s); - aron::io::AronDataNavigatorWriter navWriter; - aron::io::AronDataConverter::ConvertFromReader(dataReader, navWriter, expectedStructure); - return aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(navWriter.getResult()); + aron::dataIO::reader::NlohmannJSONReader dataReader(s); + aron::dataIO::writer::NavigatorWriter navWriter; + aron::dataIO::Converter::ConvertFromReader(dataReader, navWriter, expectedStructure); + return aron::datanavigator::DictNavigator::DynamicCastAndCheck(navWriter.getResult()); } - aron::typenavigator::AronObjectTypeNavigatorPtr NlohmannJSONDiskReader::getStringAsTypeNavigator(const std::string& s) const + aron::typenavigator::ObjectNavigatorPtr NlohmannJSONDiskReader::getStringAsTypeNavigator(const std::string& s) const { - aron::io::AronTypeNlohmannJSONReader typeReader(s); - aron::io::AronTypeNavigatorWriter navWriter; - aron::io::AronTypeConverter::ConvertFromReader(typeReader, navWriter); - return aron::typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(navWriter.getResult()); + aron::typeIO::reader::NlohmannJSONReader typeReader(s); + aron::typeIO::writer::NavigatorWriter navWriter; + aron::typeIO::Converter::ConvertFromReader(typeReader, navWriter); + return aron::typenavigator::ObjectNavigator::DynamicCastAndCheck(navWriter.getResult()); } } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h index 16e9ff7a1463a227644493d7c1b6e898ccc3db42..6358d751b07fe395de0345bf06aa4af374b85289 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h @@ -41,9 +41,9 @@ namespace armarx::armem::io protected: - aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator( - const std::string&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const override; - aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const override; + aron::datanavigator::DictNavigatorPtr getStringAsDataNavigator( + const std::string&, const aron::typenavigator::NavigatorPtr& expectedStructure = nullptr) const override; + aron::typenavigator::ObjectNavigatorPtr getStringAsTypeNavigator(const std::string& s) const override; std::string getEntityInstanceSuffix() const override { diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp index 27c3ab13b303552f29e4de9d11266c9ac9accfab..9168f8adf64313f17a21700a50d93113db60954c 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp @@ -26,13 +26,13 @@ // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> // BaseClass @@ -214,47 +214,47 @@ namespace armarx::armem::io return ret; } - aron::datanavigator::AronDictDataNavigatorPtr DiskWriter::wrapData(const EntityInstance& e) const + aron::datanavigator::DictNavigatorPtr DiskWriter::wrapData(const EntityInstance& e) const { - aron::datanavigator::AronDictDataNavigatorPtr dataWrapped(new aron::datanavigator::AronDictDataNavigator()); + aron::datanavigator::DictNavigatorPtr dataWrapped(new aron::datanavigator::DictNavigator()); dataWrapped->addElement(DISK_READER_WRITER_DATA_FIELD, e.data()); - aron::datanavigator::AronLongDataNavigatorPtr timeWrapped(new aron::datanavigator::AronLongDataNavigator()); + aron::datanavigator::LongNavigatorPtr timeWrapped(new aron::datanavigator::LongNavigator()); timeWrapped->setValue(Time::now().toMicroSeconds()); dataWrapped->addElement(DISK_READER_WRITER_TIME_STORED_FIELD, timeWrapped); const EntityInstanceMetadata& metadata = e.metadata(); - aron::datanavigator::AronLongDataNavigatorPtr timeCreated(new aron::datanavigator::AronLongDataNavigator()); + aron::datanavigator::LongNavigatorPtr timeCreated(new aron::datanavigator::LongNavigator()); timeCreated->setValue(metadata.timeCreated.toMicroSeconds()); dataWrapped->addElement(DISK_READER_WRITER_TIME_CREATED_FIELD, timeCreated); - aron::datanavigator::AronLongDataNavigatorPtr timeSent(new aron::datanavigator::AronLongDataNavigator()); + aron::datanavigator::LongNavigatorPtr timeSent(new aron::datanavigator::LongNavigator()); timeSent->setValue(metadata.timeSent.toMicroSeconds()); dataWrapped->addElement(DISK_READER_WRITER_TIME_SENT_FIELD, timeSent); - aron::datanavigator::AronLongDataNavigatorPtr timeArrived(new aron::datanavigator::AronLongDataNavigator()); + aron::datanavigator::LongNavigatorPtr timeArrived(new aron::datanavigator::LongNavigator()); timeArrived->setValue(metadata.timeArrived.toMicroSeconds()); dataWrapped->addElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD, timeArrived); - aron::datanavigator::AronDoubleDataNavigatorPtr confidence(new aron::datanavigator::AronDoubleDataNavigator()); + aron::datanavigator::DoubleNavigatorPtr confidence(new aron::datanavigator::DoubleNavigator()); confidence->setValue(metadata.confidence); dataWrapped->addElement(DISK_READER_WRITER_CONFIDENCE_FIELD, confidence); return dataWrapped; } - aron::typenavigator::AronObjectTypeNavigatorPtr DiskWriter::wrapType(const aron::typenavigator::AronObjectTypeNavigatorPtr& t) const + aron::typenavigator::ObjectNavigatorPtr DiskWriter::wrapType(const aron::typenavigator::ObjectNavigatorPtr& t) const { - aron::typenavigator::AronObjectTypeNavigatorPtr typeWrapped(new aron::typenavigator::AronObjectTypeNavigator()); - typeWrapped->setObjectName(t->getObjectName() + "__ltm_export"); - typeWrapped->addAcceptedType(DISK_READER_WRITER_DATA_FIELD, t); - - typeWrapped->addAcceptedType(DISK_READER_WRITER_TIME_STORED_FIELD, aron::typenavigator::AronLongTypeNavigatorPtr(new aron::typenavigator::AronLongTypeNavigator())); - typeWrapped->addAcceptedType(DISK_READER_WRITER_TIME_CREATED_FIELD, aron::typenavigator::AronLongTypeNavigatorPtr(new aron::typenavigator::AronLongTypeNavigator())); - typeWrapped->addAcceptedType(DISK_READER_WRITER_TIME_SENT_FIELD, aron::typenavigator::AronLongTypeNavigatorPtr(new aron::typenavigator::AronLongTypeNavigator())); - typeWrapped->addAcceptedType(DISK_READER_WRITER_TIME_ARRIVED_FIELD, aron::typenavigator::AronLongTypeNavigatorPtr(new aron::typenavigator::AronLongTypeNavigator())); - typeWrapped->addAcceptedType(DISK_READER_WRITER_CONFIDENCE_FIELD, aron::typenavigator::AronDoubleTypeNavigatorPtr(new aron::typenavigator::AronDoubleTypeNavigator())); + aron::typenavigator::ObjectNavigatorPtr typeWrapped(new aron::typenavigator::ObjectNavigator()); + typeWrapped->setObjectName(t->getName() + "__ltm_export"); + typeWrapped->addMemberType(DISK_READER_WRITER_DATA_FIELD, t); + + typeWrapped->addMemberType(DISK_READER_WRITER_TIME_STORED_FIELD, aron::typenavigator::LongNavigatorPtr(new aron::typenavigator::LongNavigator())); + typeWrapped->addMemberType(DISK_READER_WRITER_TIME_CREATED_FIELD, aron::typenavigator::LongNavigatorPtr(new aron::typenavigator::LongNavigator())); + typeWrapped->addMemberType(DISK_READER_WRITER_TIME_SENT_FIELD, aron::typenavigator::LongNavigatorPtr(new aron::typenavigator::LongNavigator())); + typeWrapped->addMemberType(DISK_READER_WRITER_TIME_ARRIVED_FIELD, aron::typenavigator::LongNavigatorPtr(new aron::typenavigator::LongNavigator())); + typeWrapped->addMemberType(DISK_READER_WRITER_CONFIDENCE_FIELD, aron::typenavigator::DoubleNavigatorPtr(new aron::typenavigator::DoubleNavigator())); return typeWrapped; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h index 6e7a2567c6f69b2c5f64ecbd4e28664c18648699..c8b4e4541e341e23bab18f45cb956620178771c8 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h @@ -26,9 +26,9 @@ #include <filesystem> // ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> // BaseClass @@ -59,11 +59,11 @@ namespace armarx::armem::io DiskWriterReturnInformation writeOnDisk(const MemoryID&, const EntitySnapshot&); protected: - aron::datanavigator::AronDictDataNavigatorPtr wrapData(const EntityInstance& e) const; - aron::typenavigator::AronObjectTypeNavigatorPtr wrapType(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const; + aron::datanavigator::DictNavigatorPtr wrapData(const EntityInstance& e) const; + aron::typenavigator::ObjectNavigatorPtr wrapType(const aron::typenavigator::ObjectNavigatorPtr&) const; - virtual std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const = 0; - virtual std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const = 0; + virtual std::string getDataAsString(const aron::datanavigator::DictNavigatorPtr&) const = 0; + virtual std::string getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr&) const = 0; bool directoryPathExists(const std::filesystem::path& p) const; bool ensureDirectoryPathExists(const std::filesystem::path& p) const; diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp index 29268e81831eb2f460aaddad0e4d45bb77fb37d5..a52253d8cdfe867195e3f595832746a7e312f0fc 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp @@ -1,9 +1,9 @@ #include "NlohmannJSONDiskWriter.h" -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> namespace armarx::armem::io @@ -20,17 +20,17 @@ namespace armarx::armem::io { } - std::string NlohmannJSONDiskWriter::getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr& aronDataNav) const + std::string NlohmannJSONDiskWriter::getDataAsString(const aron::datanavigator::DictNavigatorPtr& aronDataNav) const { - aron::io::AronDataNlohmannJSONWriter dataWriter; - aron::io::AronDataWriterVisitor::SetupWriterFromAronDataPtr(dataWriter, aronDataNav->getResult()); + aron::dataIO::writer::NlohmannJSONWriter dataWriter; + aron::dataIO::Visitor::SetupWriterFromAronDataPtr(dataWriter, aronDataNav->getResult()); return dataWriter.getResult().dump(2); } - std::string NlohmannJSONDiskWriter::getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr& aronTypeNav) const + std::string NlohmannJSONDiskWriter::getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr& aronTypeNav) const { - aron::io::AronTypeNlohmannJSONWriter typeWriter; - aron::io::AronTypeWriterVisitor::SetupWriterFromAronTypePtr(typeWriter, aronTypeNav->getResult()); + aron::typeIO::writer::NlohmannJSONWriter typeWriter; + aron::typeIO::Visitor::SetupWriterFromAronTypePtr(typeWriter, aronTypeNav->getResult()); return typeWriter.getResult().dump(2); } } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h index 5d4c798cc46fefcbf065120c9af679f45371a03d..67d35f01aa874f3c203d4ffffd5bd5691b237bb0 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h @@ -41,8 +41,8 @@ namespace armarx::armem::io protected: - std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const override; - std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const override; + std::string getDataAsString(const aron::datanavigator::DictNavigatorPtr&) const override; + std::string getTypeAsString(const aron::typenavigator::ObjectNavigatorPtr&) const override; std::string getEntityInstanceSuffix() const override { diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp index c63702f0e6b01deb45ed82debd55050787866202..d39acab1af52a9ed4ec40b01d887a9168960df80 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp @@ -1,6 +1,6 @@ #include "MemoryFileSystemStorage.h" -#include <RobotAPI/libraries/aron/aroncore/AronDebug.h> +#include <RobotAPI/libraries/aron/core/Debug.h> #include <RobotAPI/libraries/armem/core/error.h> @@ -169,18 +169,18 @@ namespace armarx::armem::io EntityInstance ret(_id.instanceIndex); if (internalMemory.hasEntityInstance(_id)) { - aron::typenavigator::AronObjectTypeNavigatorPtr typeInformation = readClosestTypeInformation(_id); + aron::typenavigator::ObjectNavigatorPtr typeInformation = readClosestTypeInformation(_id); const DiskEntityInstance& path = internalMemory.getDiskEntityInstance(_id); return reader->readSingleInstanceFromDisk(path, typeInformation); } return ret; } - aron::typenavigator::AronObjectTypeNavigatorPtr FileSystemMemoryManager::readClosestTypeInformation(const MemoryID& _id) const + aron::typenavigator::ObjectNavigatorPtr FileSystemMemoryManager::readClosestTypeInformation(const MemoryID& _id) const { if (_id.hasInstanceIndex()) { - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(_id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(_id); if (t != nullptr) { return t; @@ -189,7 +189,7 @@ namespace armarx::armem::io if (_id.hasTimestamp()) { MemoryID id = _id.getEntitySnapshotID(); - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); if (t != nullptr) { return t; @@ -198,7 +198,7 @@ namespace armarx::armem::io if (_id.hasEntityName()) { MemoryID id = _id.getEntityID(); - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); if (t != nullptr) { return t; @@ -207,7 +207,7 @@ namespace armarx::armem::io if (_id.hasProviderSegmentName()) { MemoryID id = _id.getProviderSegmentID(); - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); if (t != nullptr) { return t; @@ -216,7 +216,7 @@ namespace armarx::armem::io if (_id.hasCoreSegmentName()) { MemoryID id = _id.getCoreSegmentID(); - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); if (t != nullptr) { return t; @@ -225,7 +225,7 @@ namespace armarx::armem::io if (_id.hasMemoryName()) { MemoryID id = _id.getMemoryID(); - aron::typenavigator::AronObjectTypeNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); + aron::typenavigator::ObjectNavigatorPtr t = reader->readSingleTypeInformationFromDisk(id); if (t != nullptr) { return t; diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h index 80c9c2c703f22690a61deacfe9658b0b24d33ee1..9f44bb7a037aeed8dcf32acda6c5b8374514c45c 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h @@ -47,7 +47,7 @@ namespace armarx::armem::io void writeOnDisk(const MemoryID& coreSegmentID, const CoreSegment& coreSegment); void writeOnDisk(const MemoryID& providerSegmentID, const ProviderSegment& providerSegment); void writeOnDisk(const MemoryID& entityID, const Entity& entity); - // void writeOnDisk(const MemoryID&, const Entity&, aron::typenavigator::AronObjectTypeNavigatorPtr = nullptr); + // void writeOnDisk(const MemoryID&, const Entity&, aron::typenavigator::ObjectNavigatorPtr = nullptr); void writeOnDisk(const MemoryID& entitySnapshotID, const EntitySnapshot& entitySnapshot); void update(); @@ -61,10 +61,10 @@ namespace armarx::armem::io EntitySnapshot readEntitySnapshotFromDisk(const MemoryID& entitySnapshotID) const; EntityInstance readEntityInstanceFromDisk(const MemoryID& entityInstanceID) const; - aron::typenavigator::AronObjectTypeNavigatorPtr readClosestTypeInformation(const MemoryID&) const; + aron::typenavigator::ObjectNavigatorPtr readClosestTypeInformation(const MemoryID&) const; - //std::pair<Entity, aron::typenavigator::AronObjectTypeNavigatorPtr> readTypedEntityFromDisk(); - //std::pair<EntitySnapshot, aron::typenavigator::AronObjectTypeNavigatorPtr> readTypedEntitySnapshotFromDisk(); + //std::pair<Entity, aron::typenavigator::ObjectNavigatorPtr> readTypedEntityFromDisk(); + //std::pair<EntitySnapshot, aron::typenavigator::ObjectNavigatorPtr> readTypedEntitySnapshotFromDisk(); std::string toString(); diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp index 0d35fd3346f7a3f8ec4fc89c9551e1edb16ec827..de811a33125e672a0a57e266ef5ca9b59971b083 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.cpp @@ -17,7 +17,7 @@ namespace armarx::armem::server::plugins void ComponentPlugin::postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties) { ClientPlugin::postCreatePropertyDefinitions(properties); - properties->topic(memoryListener, "MemoryUpdates"); + properties->topic(memoryListener, this->parent<ComponentPluginUser>().memoryListenerDefaultName); } diff --git a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h index 4ad1d462251a488316d0e4153a26bc5b246d58bb..ca0958b3c93203ef519c2c5311b71c1b0f54cd98 100644 --- a/source/RobotAPI/libraries/armem/server/ComponentPlugin.h +++ b/source/RobotAPI/libraries/armem/server/ComponentPlugin.h @@ -86,6 +86,9 @@ namespace armarx::armem::server Memory memory; std::mutex memoryMutex; + /// property defauls + std::string memoryListenerDefaultName = "MemoryUpdates"; + /// Helps connecting `memory` to ice. Used to handle Ice callbacks. MemoryToIceAdapter iceMemory { &memory }; diff --git a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp index 3c5e7b6ecb4172b075d6cca7b4a59b0d543c3283..b2ada310d271e5c9161d2f3f74e12ca16ee66ae6 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryRemoteGui.cpp @@ -2,8 +2,8 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h> #include <SimoxUtility/meta/type_name.h> diff --git a/source/RobotAPI/libraries/armem/server/RemoteGuiAronDataVisitor.h b/source/RobotAPI/libraries/armem/server/RemoteGuiAronDataVisitor.h index ee2c40570db1cca8a4e371e3d4bfd5f7347cf18f..6149cbbc85faddd4ed8b51e33a73c3ae5f712875 100644 --- a/source/RobotAPI/libraries/armem/server/RemoteGuiAronDataVisitor.h +++ b/source/RobotAPI/libraries/armem/server/RemoteGuiAronDataVisitor.h @@ -5,7 +5,7 @@ #include <ArmarXGui/libraries/RemoteGui/Client/Widgets.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h> +#include <RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h> namespace armarx::armem::server diff --git a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp index f4ed16fd550f0412488a91d2e9008c80c95dbe8f..dea566c5ee235868f23334f381095e1949f4f044 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp @@ -28,17 +28,16 @@ #include "../core/Memory.h" #include "../core/error.h" -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> #include <RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h> -#include <RobotAPI/libraries/aron/aroncore/AronRandomizer.h> +#include <RobotAPI/libraries/aron/core/Randomizer.h> -#include <RobotAPI/libraries/aron/aroncore/AronDebug.h> +#include <RobotAPI/libraries/aron/core/Debug.h> #include <filesystem> #include <iostream> - namespace armem = armarx::armem; namespace aron = armarx::aron; namespace fs = std::filesystem; @@ -71,12 +70,12 @@ namespace ArMemLTMTest static armem::Memory setupMemoryWithType( const std::string& memoryName, - const aron::typenavigator::AronObjectTypeNavigatorPtr& t1, - const aron::typenavigator::AronObjectTypeNavigatorPtr& t2, + const aron::typenavigator::ObjectNavigatorPtr& t1, + const aron::typenavigator::ObjectNavigatorPtr& t2, unsigned int numSnapshots, unsigned int numInstances) { - aron::AronRandomizer r; + aron::Randomizer r; armem::Memory memory(memoryName); BOOST_CHECK_EQUAL(memory.name(), memoryName); @@ -92,16 +91,16 @@ namespace ArMemLTMTest coreSegment.aronType() = t1; providerSegment.aronType() = t2; - aron::typenavigator::AronObjectTypeNavigatorPtr t = t2 != nullptr ? t2 : t1; + aron::typenavigator::ObjectNavigatorPtr t = t2 != nullptr ? t2 : t1; for (unsigned int i = 0; i < numSnapshots; ++i) { armem::EntityUpdate update; - std::vector<aron::datanavigator::AronDictDataNavigatorPtr> q; + std::vector<aron::datanavigator::DictNavigatorPtr> q; for (unsigned int j = 0; j < numInstances; ++j) { - aron::datanavigator::AronDictDataNavigatorPtr m = aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(r.generateAronDataFromType(t)); + aron::datanavigator::DictNavigatorPtr m = aron::datanavigator::DictNavigator::DynamicCastAndCheck(r.generateAronDataFromType(t)); r.initializeRandomly(m, t); q.push_back(m); } @@ -117,14 +116,14 @@ namespace ArMemLTMTest } template <class TypeNavigatorT> - aron::typenavigator::AronObjectTypeNavigatorPtr makeType(const std::string& memberPrefix, int numMembers = 4) + aron::typenavigator::ObjectNavigatorPtr makeType(const std::string& memberPrefix, int numMembers = 4) { - aron::typenavigator::AronObjectTypeNavigatorPtr t = std::make_shared<aron::typenavigator::AronObjectTypeNavigator>(aron::AronPath()); + aron::typenavigator::ObjectNavigatorPtr t = std::make_shared<aron::typenavigator::ObjectNavigator>(aron::Path()); t->setObjectName("TestObjectType1"); for (int i = 0; i < numMembers; ++i) { - t->addAcceptedType(memberPrefix + std::to_string(i + 1), std::make_shared<TypeNavigatorT>()); + t->addMemberType(memberPrefix + std::to_string(i + 1), std::make_shared<TypeNavigatorT>()); } return t; @@ -132,15 +131,14 @@ namespace ArMemLTMTest }; } - BOOST_FIXTURE_TEST_SUITE(ArMemLTMTest, Fixture) - +/* BOOST_AUTO_TEST_CASE(test_memory_export__easy_int_setup) { std::string memoryName = "TestMemory_IntSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronIntTypeNavigator>("theInt"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronIntTypeNavigator>("theInt"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -169,7 +167,7 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_long_setup) { std::string memoryName = "TestMemory_LongSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronLongTypeNavigator>("theLong"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronLongTypeNavigator>("theLong"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -198,7 +196,7 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_float_setup) { std::string memoryName = "TestMemory_FloatSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronFloatTypeNavigator>("theFloat"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronFloatTypeNavigator>("theFloat"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -227,7 +225,7 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_double_setup) { std::string memoryName = "TestMemory_DoubleSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronDoubleTypeNavigator>("theDouble"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronDoubleTypeNavigator>("theDouble"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -256,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_string_setup) { std::string memoryName = "TestMemory_StringSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronStringTypeNavigator>("theString"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronStringTypeNavigator>("theString"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -285,7 +283,7 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_bool_setup) { std::string memoryName = "TestMemory_BoolSetup"; - aron::typenavigator::AronObjectTypeNavigatorPtr t = makeType<aron::typenavigator::AronBoolTypeNavigator>("theBool"); + aron::typenavigator::ObjectNavigatorPtr t = makeType<aron::typenavigator::AronBoolTypeNavigator>("theBool"); armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); // export memory @@ -310,6 +308,51 @@ BOOST_AUTO_TEST_CASE(test_memory_export__easy_bool_setup) BOOST_CHECK_EQUAL(memory.equalsDeep(memory2), true); } +BOOST_AUTO_TEST_CASE(test_memory_export__easy_rainer_setup) +{ + std::string memoryName = "TestMemory_RainerSetup"; + + aron::typenavigator::ObjectNavigatorPtr t(new aron::typenavigator::ObjectNavigator(aron::Path())); + t->setObjectName("TestRainerType1"); + + aron::typenavigator::DictNavigatorPtr tm1(new aron::typenavigator::DictNavigator(aron::Path())); + aron::typenavigator::AronFloatTypeNavigatorPtr tm1m1(new aron::typenavigator::AronFloatTypeNavigator(aron::Path())); + tm1->setAcceptedType(tm1m1); + aron::typenavigator::AronStringTypeNavigatorPtr tm2(new aron::typenavigator::AronStringTypeNavigator(aron::Path())); + aron::typenavigator::DictNavigatorPtr tm3(new aron::typenavigator::DictNavigator(aron::Path())); + aron::typenavigator::AronStringTypeNavigatorPtr tm3m1(new aron::typenavigator::AronStringTypeNavigator(aron::Path())); + tm3->setAcceptedType(tm3m1); + aron::typenavigator::AronStringTypeNavigatorPtr tm4(new aron::typenavigator::AronStringTypeNavigator(aron::Path())); + t->addAcceptedType("float_params", tm1); + t->addAcceptedType("name", tm2); + //t->addAcceptedType("string_params", tm3); + t->addAcceptedType("type", tm4); + + armem::Memory memory = setupMemoryWithType(memoryName, t, nullptr, 15, 1); + + // export memory + std::string storagePath = "/tmp/MemoryExport"; // important! without tailing / + std::filesystem::remove_all(storagePath); + armem::io::FileSystemMemoryManager mfs(storagePath, true); + mfs.writeOnDisk(memory); + + std::string mfs_str = mfs.toString(); + + armem::io::FileSystemMemoryManager mfs2(storagePath); + mfs2.update(); + + std::string mfs2_str = mfs2.toString(); + + //std::cout << "MFS1: " << std::endl; + //std::cout << mfs_str << std::endl; + //std::cout << "MFS2: " << std::endl; + //std::cout << mfs2_str << std::endl; + BOOST_CHECK_EQUAL(mfs_str == mfs2_str, true); + + armem::Memory memory2 = mfs.readMemoryFromDisk(memoryName); + BOOST_CHECK_EQUAL(memory.equalsDeep(memory2), true); +}*/ + BOOST_AUTO_TEST_SUITE_END() diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index 6983c42dceef954ad5857c8a26626332666bf86b..b7ba95c633d7d561024b848c1afa862e0bc51caa 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -31,8 +31,7 @@ #include <iostream> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> - +#include <RobotAPI/libraries/aron/core/navigator/data/container/Dict.h> namespace armem = armarx::armem; namespace aron = armarx::aron; @@ -114,8 +113,8 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) update.entityID = armem::MemoryID::fromString("Memory/ImageRGB/SomeRGBImageProvider/image"); update.instancesData = { - std::make_shared<aron::datanavigator::AronDictDataNavigator>(), - std::make_shared<aron::datanavigator::AronDictDataNavigator>() + std::make_shared<aron::datanavigator::DictNavigator>(), + std::make_shared<aron::datanavigator::DictNavigator>() }; update.timeCreated = armem::Time::milliSeconds(1000); BOOST_CHECK_NO_THROW(providerSegment.update(update)); @@ -135,7 +134,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) // Another update (on memory). - update.instancesData = { std::make_shared<aron::datanavigator::AronDictDataNavigator>() }; + update.instancesData = { std::make_shared<aron::datanavigator::DictNavigator>() }; update.timeCreated = armem::Time::milliSeconds(2000); memory.update(update); BOOST_CHECK_EQUAL(entity.history.size(), 2); @@ -144,7 +143,7 @@ BOOST_AUTO_TEST_CASE(test_segment_setup) // A third update (on entity). - update.instancesData = { std::make_shared<aron::datanavigator::AronDictDataNavigator>() }; + update.instancesData = { std::make_shared<aron::datanavigator::DictNavigator>() }; update.timeCreated = armem::Time::milliSeconds(3000); entity.update(update); BOOST_CHECK_EQUAL(entity.history.size(), 3); diff --git a/source/RobotAPI/libraries/armem_gui/CMakeLists.txt b/source/RobotAPI/libraries/armem_gui/CMakeLists.txt index 8e3658ccde3d14f367275413008dc87d58eb6d8e..4b49856774ca0fd7236ad259b2b2346094c0501b 100644 --- a/source/RobotAPI/libraries/armem_gui/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem_gui/CMakeLists.txt @@ -5,35 +5,52 @@ armarx_set_target("Library: ${LIB_NAME}") set(LIBRARIES + # ArmarXCore ArmarXCoreInterfaces ArmarXCore + # ArmarXGui + SimpleConfigDialog + # RobotAPI armem ) set(SOURCES + MemoryViewer.cpp - MemoryTreeWidget.cpp + PeriodicUpdateWidget.cpp gui_utils.cpp + lifecycle.cpp + instance/GroupBox.cpp instance/ImageView.cpp - instance/InstanceTreeDataVisitorBase.cpp - instance/InstanceTreeDataVisitor.cpp - instance/InstanceTreeTypedDataVisitor.cpp instance/InstanceView.cpp + instance/TreeDataVisitorBase.cpp + instance/TreeDataVisitor.cpp + instance/TreeTypedDataVisitor.cpp + + memory/GroupBox.cpp + memory/TreeWidget.cpp query_widgets/QueryWidget.cpp query_widgets/SnapshotForm.cpp query_widgets/SnapshotSelectorWidget.cpp ) set(HEADERS - MemoryTreeWidget.h + MemoryViewer.h + + PeriodicUpdateWidget.h TreeWidgetBuilder.h gui_utils.h + lifecycle.h + instance/GroupBox.h instance/ImageView.h - instance/InstanceTreeDataVisitorBase.h - instance/InstanceTreeDataVisitor.h - instance/InstanceTreeTypedDataVisitor.h instance/InstanceView.h + instance/TreeDataVisitorBase.h + instance/TreeDataVisitor.h + instance/TreeTypedDataVisitor.h + + memory/GroupBox.h + memory/TreeWidget.h query_widgets/QueryWidget.h query_widgets/SnapshotForm.h diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2cff7aa28476ba530a8b72febb11d563e5101b0b --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp @@ -0,0 +1,242 @@ +#include "MemoryViewer.h" + +#include <RobotAPI/libraries/armem/core/ice_conversions.h> +#include <RobotAPI/libraries/armem_gui/gui_utils.h> + +#include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> + +#include <ArmarXCore/core/ManagedIceObject.h> +#include <ArmarXCore/core/time/TimeUtil.h> +#include <ArmarXCore/observers/variant/Variant.h> + +#include <QBoxLayout> +#include <QDialog> +#include <QCheckBox> +#include <QGroupBox> +#include <QLabel> +#include <QLayout> +#include <QSettings> + + +namespace armarx::armem::gui +{ + + MemoryViewer::MemoryViewer( + QBoxLayout* updateWidgetLayout, + QGroupBox* _memoryGroupBox, QLayout* memoryGroupBoxParentLayout, + QGroupBox* _instanceGroupBox, QLayout* instanceGroupBoxParentLayout, + QLabel* statusLabel) + { + Logging::setTag("MemoryViewer"); + + this->statusLabel = statusLabel; + this->statusLabel->clear(); + + // Update timer + this->updateWidgetLayout = updateWidgetLayout; + updateWidget = new armem::gui::PeriodicUpdateWidget(2.0, 60); + updateWidgetLayout->insertWidget(0, updateWidget); + + memoryGroup = new armem::gui::MemoryGroupBox(); + armarx::gui::replaceWidget(_memoryGroupBox, memoryGroup, memoryGroupBoxParentLayout); + ARMARX_CHECK_NULL(_memoryGroupBox); + + this->instanceGroup = new armem::gui::InstanceGroupBox(); + armarx::gui::replaceWidget(_instanceGroupBox, instanceGroup, instanceGroupBoxParentLayout); + this->instanceGroup->setStatusLabel(statusLabel); + ARMARX_CHECK_NULL(_instanceGroupBox); + + + connect(this, &This::connected, this, &This::updateMemory); + connect(updateWidget, &armem::gui::PeriodicUpdateWidget::update, this, &This::updateMemory); + + connect(this, &This::memoryDataChanged, this, &This::updateMemoryTree); + connect(memoryGroup->tree(), &armem::gui::MemoryTreeWidget::selectedItemChanged, this, &This::updateInstanceTree); + + connect(memoryGroup->tree(), &armem::gui::MemoryTreeWidget::updated, this, &This::memoryTreeUpdated); + connect(instanceGroup, &armem::gui::InstanceGroupBox::viewUpdated, this, &This::instanceTreeUpdated); + } + + void MemoryViewer::setLogTag(const std::string& tag) + { + Logging::setTag(tag); + } + + void MemoryViewer::onInit(ManagedIceObject& component) + { + if (memoryName.size() > 0) + { + component.usingProxy(memoryName); + } + if (debugObserverName.size() > 0) + { + component.usingProxy(debugObserverName); + } + + emit initialized(); + } + + void MemoryViewer::onConnect(ManagedIceObject& component) + { + if (!memoryName.empty()) + { + component.getProxy(memory, memoryName); + memoryReader = armem::client::Reader(memory); + } + // DebugObserver is optional (check for null on every call) + if (!debugObserverName.empty()) + { + component.getProxy(debugObserver, debugObserverName, false, "", false); + } + updateWidget->startTimerIfEnabled(); + + emit connected(); + } + + void MemoryViewer::onDisconnect(ManagedIceObject&) + { + updateWidget->stopTimer(); + + emit disconnected(); + } + + + void MemoryViewer::updateMemory() + { + if (!memoryReader) + { + return; + } + + TIMING_START(MemoryQuery); + { + armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); + armem::client::QueryResult result = memoryReader.query(input); + if (result) + { + this->memoryData = std::move(result.memory); + } + else + { + if (statusLabel) + { + statusLabel->setText(QString::fromStdString(result.errorMessage)); + } + } + } + TIMING_END_STREAM(MemoryQuery, ARMARX_VERBOSE); + + if (debugObserver) + { + debugObserver->setDebugDatafield(Logging::tag.tagName, "Memory Query [ms]", new Variant(MemoryQuery.toMilliSecondsDouble())); + } + + if (this->memoryData) + { + emit memoryDataChanged(); + } + else + { + if (statusLabel) + { + statusLabel->setText("No query result."); + } + } + } + + void MemoryViewer::updateInstanceTree(const armem::MemoryID& selectedID) + { + if (memoryData) + { + if (!selectedID.hasEntityName()) + { + return; + } + armem::MemoryID id = selectedID; + const armem::EntitySnapshot* snapshot = nullptr; + if (!id.hasTimestamp()) + { + const armem::Entity& entity = memoryData->getEntity(id); + if (entity.empty()) + { + return; + } + snapshot = &entity.getLatestSnapshot(); + id.timestamp = snapshot->time(); + } + if (!id.hasInstanceIndex()) + { + if (!snapshot) + { + try + { + snapshot = &memoryData->getEntitySnapshot(id); + } + catch (const armem::error::ArMemError& e) + { + if (statusLabel) + { + statusLabel->setText(e.what()); + } + } + } + if (snapshot && snapshot->size() > 0) + { + id.instanceIndex = 0; + } + } + if (id.hasInstanceIndex()) + { + instanceGroup->view->update(id, *memoryData); + } + } + } + + void MemoryViewer::updateMemoryTree() + { + if (!memoryData) + { + return; + } + TIMING_START(GuiUpdate); + memoryGroup->tree()->update(*memoryData); + TIMING_END_STREAM(GuiUpdate, ARMARX_VERBOSE); + + if (debugObserver) + { + debugObserver->setDebugDatafield(Logging::tag.tagName, "GUI Update [ms]", new Variant(GuiUpdate.toMilliSecondsDouble())); + } + } + + + const static std::string CONFIG_KEY_MEMORY = "MemoryViewer.MemoryName"; + const static std::string CONFIG_KEY_DEBUG_OBSERVER = "MemoryViewer.DebugObserverName"; + + void MemoryViewer::loadSettings(QSettings* settings) + { + memoryName = settings->value(QString::fromStdString(CONFIG_KEY_MEMORY), "Memory").toString().toStdString(); + debugObserverName = settings->value(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER), "DebugObserver").toString().toStdString(); + } + void MemoryViewer::saveSettings(QSettings* settings) + { + settings->setValue(QString::fromStdString(CONFIG_KEY_MEMORY), QString::fromStdString(memoryName)); + settings->setValue(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER), QString::fromStdString(debugObserverName)); + } + + void MemoryViewer::writeConfigDialog(SimpleConfigDialog* dialog) + { + dialog->addProxyFinder<armem::server::MemoryInterfacePrx>({CONFIG_KEY_MEMORY, "Memory", "*Memory"}); + dialog->addProxyFinder<armarx::DebugObserverInterfacePrx>({CONFIG_KEY_DEBUG_OBSERVER, "Debug Observer", "DebugObserver"}); + } + void MemoryViewer::readConfigDialog(SimpleConfigDialog* dialog) + { + memoryName = dialog->getProxyName(CONFIG_KEY_MEMORY); + debugObserverName = dialog->getProxyName(CONFIG_KEY_DEBUG_OBSERVER); + } + +} + + + + + diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h new file mode 100644 index 0000000000000000000000000000000000000000..df66ad86fa603443119744d0ee152f5f126e805a --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h @@ -0,0 +1,125 @@ +#pragma once + +#include <string> + +#include <QObject> + +#include <ArmarXCore/interface/observers/ObserverInterface.h> +#include <ArmarXCore/core/logging/Logging.h> + +#include <RobotAPI/interface/armem/server/MemoryInterface.h> +#include <RobotAPI/libraries/armem/client/Reader.h> +#include <RobotAPI/libraries/armem_gui/lifecycle.h> +#include <RobotAPI/libraries/armem_gui/instance/GroupBox.h> +#include <RobotAPI/libraries/armem_gui/memory/GroupBox.h> +#include <RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.h> + + + +class QBoxLayout; +class QDialog; +class QGroupBox; +class QLabel; +class QLayout; +class QSettings; + + +namespace armarx +{ + class ManagedIceObject; + class SimpleConfigDialog; +} + +namespace armarx::armem::gui +{ + + class MemoryViewer : + public QObject, + public armarx::Logging, + public armarx::gui::LifecycleClient + { + Q_OBJECT + using This = MemoryViewer; + + + public: + + MemoryViewer( + QBoxLayout* updateWidgetLayout, + QGroupBox* _memoryGroupBox, QLayout* memoryGroupBoxParentLayout, + QGroupBox* _instanceGroupBox, QLayout* instanceGroupBoxParentLayout, + QLabel* statusLabel + ); + + void setLogTag(const std::string& tag); + + + void loadSettings(QSettings* settings); + void saveSettings(QSettings* settings); + + void writeConfigDialog(SimpleConfigDialog* dialog); + void readConfigDialog(SimpleConfigDialog* dialog); + + + public slots: + + void updateMemory(); + void updateInstanceTree(const armem::MemoryID& selectedID); + + + signals: + + void initialized(); + void connected(); + void disconnected(); + + void memoryTreeUpdated(); + void instanceTreeUpdated(); + + + private slots: + + void updateMemoryTree(); + + signals: + + void memoryDataChanged(); + + + private: + + void onInit(ManagedIceObject& component); + void onConnect(ManagedIceObject& component); + void onDisconnect(ManagedIceObject& component); + + + public: + + std::string memoryName; + armem::server::MemoryInterfacePrx memory; + armem::client::Reader memoryReader; + + std::optional<armem::Memory> memoryData; + + + QLayout* updateWidgetLayout; + armem::gui::PeriodicUpdateWidget* updateWidget; + + armem::gui::MemoryGroupBox* memoryGroup; + + armem::gui::InstanceGroupBox* instanceGroup; + + QLabel* statusLabel = nullptr; + + + std::string debugObserverName; + DebugObserverInterfacePrx debugObserver; + + // Queries. + armem::query::data::EntityQueryPtr entityQuery; + + }; + +} + + diff --git a/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.cpp b/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a62659cd78d4448bb72913ae432fc22f8f2b6eae --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.cpp @@ -0,0 +1,112 @@ +#include "PeriodicUpdateWidget.h" + +#include <QCheckBox> +#include <QDoubleSpinBox> +#include <QPushButton> +#include <QTimer> +#include <QHBoxLayout> + +#include <cmath> + + +namespace armarx::armem::gui +{ + + PeriodicUpdateWidget::PeriodicUpdateWidget(double frequency, double maxFrequency) + { + setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Fixed); + + QLayout* layout = new QHBoxLayout(); + this->setLayout(layout); + + const int margin = 0; + layout->setContentsMargins(margin, margin, margin, margin); + + _updateButton = new QPushButton("Update", this); + _autoCheckBox = new QCheckBox("Auto Update", this); + _frequencySpinBox = new QDoubleSpinBox(this); + _frequencySpinBox->setValue(frequency); + _frequencySpinBox->setMinimum(0); + _frequencySpinBox->setMaximum(maxFrequency); + _frequencySpinBox->setSingleStep(1.0); + _frequencySpinBox->setSuffix(" Hz"); + + + layout->addWidget(_updateButton); + layout->addWidget(_autoCheckBox); + layout->addWidget(_frequencySpinBox); + + _timer = new QTimer(this); + _updateTimerFrequency(); + _frequencySpinBox->setEnabled(_autoCheckBox->isChecked()); + + + // Private connections. + connect(_autoCheckBox, &QCheckBox::toggled, this, &This::_toggleAutoUpdates); + connect(_frequencySpinBox, &QDoubleSpinBox::editingFinished, this, &This::_updateTimerFrequency); + + // Public connections. + connect(_updateButton, &QPushButton::pressed, this, &This::update); + connect(_timer, &QTimer::timeout, this, &This::update); + } + + QPushButton* PeriodicUpdateWidget::updateButton() + { + return _updateButton; + } + + void PeriodicUpdateWidget::startTimerIfEnabled() + { + if (_autoCheckBox->isChecked()) + { + _timer->start(); + } + else + { + _timer->stop(); + } + } + + void PeriodicUpdateWidget::stopTimer() + { + if (_timer) + { + _timer->stop(); + } + } + + void PeriodicUpdateWidget::_updateTimerFrequency() + { + _timer->setInterval(static_cast<int>(std::round(1000 / _frequencySpinBox->value()))); + } + + void PeriodicUpdateWidget::_toggleAutoUpdates(bool enabled) + { + _frequencySpinBox->setEnabled(enabled); + if (enabled) + { + _timer->start(); + } + else + { + _timer->stop(); + } + } + + QCheckBox* PeriodicUpdateWidget::autoCheckBox() + { + return _autoCheckBox; + } + + QDoubleSpinBox* PeriodicUpdateWidget::frequencySpinBox() + { + return _frequencySpinBox; + } + + QTimer* PeriodicUpdateWidget::timer() + { + return _timer; + } + +} + diff --git a/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.h b/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..41b725220d283ddcae534d68c9932f89c89169e4 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/PeriodicUpdateWidget.h @@ -0,0 +1,64 @@ +#pragma once + +#include <QWidget> + + +class QCheckBox; +class QDoubleSpinBox; +class QPushButton; +class QTimer; + +namespace armarx::armem::gui +{ + + class PeriodicUpdateWidget : public QWidget + { + Q_OBJECT + using This = PeriodicUpdateWidget; + + public: + + PeriodicUpdateWidget(double frequency = 2.0, double maxFrequency = 60); + + + QTimer* timer(); + + QCheckBox* autoCheckBox(); + QDoubleSpinBox* frequencySpinBox(); + QPushButton* updateButton(); + + bool autoEnabled() const; + double updateFrequency() const; + + void startTimerIfEnabled(); + void stopTimer(); + + + public slots: + + signals: + + void update(); + + + private slots: + + void _updateTimerFrequency(); + void _toggleAutoUpdates(bool enabled); + + + signals: + + + + private: + + QPushButton* _updateButton; + QCheckBox* _autoCheckBox; + QDoubleSpinBox* _frequencySpinBox; + + QTimer* _timer; + + }; + +} diff --git a/source/RobotAPI/libraries/armem_gui/gui_utils.cpp b/source/RobotAPI/libraries/armem_gui/gui_utils.cpp index 1bbfe2dc065129bdc65d35dd09b27856b2a70742..29be82baa3cd7501350353fb7b567e2fac456d35 100644 --- a/source/RobotAPI/libraries/armem_gui/gui_utils.cpp +++ b/source/RobotAPI/libraries/armem_gui/gui_utils.cpp @@ -2,39 +2,87 @@ #include <QLayout> #include <QLayoutItem> +#include <QSplitter> #include <QWidget> #include <QTreeWidgetItem> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> -namespace armarx + +void armarx::gui::clearLayout(QLayout* layout) { + // Source: https://stackoverflow.com/a/4857631 - void gui::clearLayout(QLayout* layout) - { - // Source: https://stackoverflow.com/a/4857631 + ARMARX_CHECK(layout); - QLayoutItem* item; - while ((item = layout->takeAt(0))) + QLayoutItem* item; + while ((item = layout->takeAt(0))) + { + if (item->layout()) { - if (item->layout()) - { - clearLayout(item->layout()); - delete item->layout(); - } - if (item->widget()) - { - delete item->widget(); - } - delete item; + clearLayout(item->layout()); + delete item->layout(); } + if (item->widget()) + { + delete item->widget(); + } + delete item; + } +} + +void armarx::gui::clearItem(QTreeWidgetItem* item) +{ + while (item->childCount() > 0) + { + delete item->takeChild(0); } +} - void gui::clearItem(QTreeWidgetItem* item) + +QSplitter* armarx::gui::useSplitter(QLayout* layout) +{ + ARMARX_CHECK(layout); + + // Check all items + for (int i = 0; i < layout->count(); ++i) { - while (item->childCount() > 0) + ARMARX_CHECK_NOT_NULL(layout->itemAt(i)->widget()) + << "QSplitter only supports widgets, but layout item #" << i << " is not a widget."; + } + + QSplitter* splitter; + if (dynamic_cast<QHBoxLayout*>(layout)) + { + splitter = new QSplitter(Qt::Orientation::Horizontal); + } + else if (dynamic_cast<QVBoxLayout*>(layout)) + { + splitter = new QSplitter(Qt::Orientation::Vertical); + } + else + { + splitter = new QSplitter(); + } + + while (layout->count() > 0) + { + const int index = 0; + if (layout->itemAt(index)) { - delete item->takeChild(0); + QLayoutItem* item = layout->takeAt(index); + + ARMARX_CHECK(item->widget()); + splitter->addWidget(item->widget()); + + delete item; } } -} + ARMARX_CHECK_EQUAL(layout->count(), 0); + + layout->addWidget(splitter); + ARMARX_CHECK_EQUAL(layout->count(), 1); + ARMARX_CHECK_EQUAL(layout->itemAt(0)->widget(), splitter); + return splitter; +} diff --git a/source/RobotAPI/libraries/armem_gui/gui_utils.h b/source/RobotAPI/libraries/armem_gui/gui_utils.h index 23824173121dda4dce002e4185a94601fa739beb..7979a2f2e8af127023c6c9dee3da719b23546310 100644 --- a/source/RobotAPI/libraries/armem_gui/gui_utils.h +++ b/source/RobotAPI/libraries/armem_gui/gui_utils.h @@ -1,7 +1,11 @@ #pragma once +#include <QLayout> +#include <QLayoutItem> +#include <QWidget> class QLayout; +class QSplitter; class QTreeWidgetItem; @@ -25,4 +29,31 @@ namespace armarx::gui */ void clearItem(QTreeWidgetItem* item); + + + template <class WidgetT> + void replaceWidget(WidgetT*& old, QWidget* neu, QLayout* parentLayout) + { + QLayoutItem* oldItem = parentLayout->replaceWidget(old, neu); + if (oldItem) + { + delete oldItem; + delete old; + old = nullptr; + } + } + + /** + * @brief Let items in `layout` be children of a splitter. + * + * Items in `layout` are moved to a new `QSplitter`, which will + * be the only child of `layout`. + * If `layout` is a Q{H,V}BoxLayout, the respective orientation + * will be adopted. + * + * @param The parent layout. + * @return The splitter item. + */ + QSplitter* useSplitter(QLayout* layout); + } diff --git a/source/RobotAPI/libraries/armem_gui/instance/GroupBox.cpp b/source/RobotAPI/libraries/armem_gui/instance/GroupBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b33c381970dfe3f3eb0ce0b0b7be9e9599f75f7f --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/instance/GroupBox.cpp @@ -0,0 +1,41 @@ +#include "GroupBox.h" + +#include <QCheckBox> +#include <QHBoxLayout> +#include <QVBoxLayout> + + +namespace armarx::armem::gui::instance +{ + + GroupBox::GroupBox() + { + QVBoxLayout* layout = new QVBoxLayout(); + this->setLayout(layout); + + view = new armem::gui::InstanceView(); + + useTypeInfoCheckBox = new QCheckBox("Use Type Info", this); + useTypeInfoCheckBox->setChecked(true); + + QHBoxLayout* checkBoxLayout = new QHBoxLayout(); + checkBoxLayout->addWidget(useTypeInfoCheckBox); + + layout->addLayout(checkBoxLayout); + layout->addWidget(view); + + this->setTitle("Instance View (select an entity instance on the left)"); + const int margin = 3; + this->layout()->setContentsMargins(margin, margin, margin, margin); + + + connect(view, &InstanceView::updated, this, &This::viewUpdated); + connect(useTypeInfoCheckBox, &QCheckBox::toggled, view, &InstanceView::setUseTypeInfo); + } + + void GroupBox::setStatusLabel(QLabel* statusLabel) + { + view->setStatusLabel(statusLabel); + } + +} diff --git a/source/RobotAPI/libraries/armem_gui/instance/GroupBox.h b/source/RobotAPI/libraries/armem_gui/instance/GroupBox.h new file mode 100644 index 0000000000000000000000000000000000000000..af3c4d4405cadf82bbef1fe007e802a2f9d9ab9a --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/instance/GroupBox.h @@ -0,0 +1,51 @@ +#pragma once + +#include <QGroupBox> + +#include "InstanceView.h" + + +class QCheckBox; +class QLabel; + + +namespace armarx::armem::gui::instance +{ + + class GroupBox : public QGroupBox + { + Q_OBJECT + using This = GroupBox; + + public: + + GroupBox(); + + void setStatusLabel(QLabel* statusLabel); + + + public slots: + + signals: + + void viewUpdated(); + + + private slots: + + signals: + + + public: + + InstanceView* view; + QCheckBox* useTypeInfoCheckBox; + + }; + +} + +namespace armarx::armem::gui +{ + using InstanceGroupBox = instance::GroupBox; +} diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp index 9f9b735acd747704bad699c833d6ac64ce6898b9..83d528d4bee1946760a56e74688d1eca348a31ca 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.cpp @@ -15,12 +15,12 @@ #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> #include <RobotAPI/libraries/armem_gui/gui_utils.h> -#include <RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.h> -#include <RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h> +#include <RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.h> +#include <RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.h> #include <RobotAPI/libraries/armem_gui/instance/ImageView.h> @@ -91,7 +91,7 @@ namespace armarx::armem::gui::instance void InstanceView::update(const MemoryID& id, const Memory& memory) { - aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr; + aron::typenavigator::ObjectNavigatorPtr aronType = nullptr; const armem::EntityInstance* instance = nullptr; try { @@ -113,7 +113,7 @@ namespace armarx::armem::gui::instance } - void InstanceView::update(const EntityInstance& instance, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) + void InstanceView::update(const EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType) { currentInstance = instance; currentAronType = aronType; @@ -145,7 +145,7 @@ namespace armarx::armem::gui::instance } } - void InstanceView::updateData(const aron::datanavigator::AronDictDataNavigatorPtr& data, aron::typenavigator::AronObjectTypeNavigatorPtr aronType) + void InstanceView::updateData(const aron::datanavigator::DictNavigatorPtr& data, aron::typenavigator::ObjectNavigatorPtr aronType) { armarx::gui::clearItem(treeItemData); if (!data) @@ -155,13 +155,13 @@ namespace armarx::armem::gui::instance } else if (useTypeInfo && aronType) { - InstanceTreeTypedDataVisitor visitor(treeItemData); + TreeTypedDataVisitor visitor(treeItemData); visitor.setColumns(int(Columns::KEY), int(Columns::VALUE), int(Columns::TYPE)); visitor.applyTo(*aronType, *data); } else { - InstanceTreeDataVisitor visitor(treeItemData); + TreeDataVisitor visitor(treeItemData); visitor.setColumns(int(Columns::KEY), int(Columns::VALUE), int(Columns::TYPE)); visitor.applyTo(*data); } @@ -205,13 +205,13 @@ namespace armarx::armem::gui::instance QMenu menu(this); - aron::AronTypeDescriptor type = static_cast<aron::AronTypeDescriptor>(item->data(int(Columns::TYPE), Qt::UserRole).toInt()); + aron::type::Descriptor type = static_cast<aron::type::Descriptor>(item->data(int(Columns::TYPE), Qt::UserRole).toInt()); switch (type) { - case aron::AronTypeDescriptor::eAronIVTCByteImageType: + case aron::type::Descriptor::eIVTCByteImage: { QStringList qpath = item->data(int(Columns::KEY), Qt::UserRole).toStringList(); - aron::AronPath path = InstanceTreeTypedDataVisitor::deserializeAronPath(qpath); + aron::Path path = TreeTypedDataVisitor::deserializePath(qpath); QAction* viewAction = new QAction("Show image"); menu.addAction(viewAction); @@ -228,7 +228,7 @@ namespace armarx::armem::gui::instance menu.exec(tree->mapToGlobal(pos)); } - void InstanceView::showImageView(const aron::AronPath& elementPath) + void InstanceView::showImageView(const aron::Path& elementPath) { if (!currentInstance) { @@ -249,9 +249,9 @@ namespace armarx::armem::gui::instance imageView = std::nullopt; } - void InstanceView::updateImageView(const aron::datanavigator::AronDictDataNavigatorPtr& data) + void InstanceView::updateImageView(const aron::datanavigator::DictNavigatorPtr& data) { - using aron::datanavigator::AronNDArrayDataNavigator; + using aron::datanavigator::NDArrayNavigator; if (!imageView) { @@ -263,14 +263,14 @@ namespace armarx::armem::gui::instance return; } - aron::datanavigator::AronDataNavigatorPtr element; + aron::datanavigator::NavigatorPtr element; try { element = data->navigateAbsolute(imageView->elementPath); } // This can happen when the underlying entity structure changes (a new entity has been selected). // In this case, we disable the image view. - catch (const aron::exception::AronException&) + catch (const aron::error::AronException&) { // showErrorMessage(e.what()); removeImageView(); @@ -283,10 +283,10 @@ namespace armarx::armem::gui::instance return; } - AronNDArrayDataNavigator::PointerType imageData = AronNDArrayDataNavigator::DynamicCast(element); + NDArrayNavigator::PointerType imageData = NDArrayNavigator::DynamicCast(element); if (!imageData) { - showErrorMessage("Expected AronNDArrayDataNavigator, but got: " + simox::meta::get_type_name(element)); + showErrorMessage("Expected NDArrayNavigator, but got: " + simox::meta::get_type_name(element)); return; } @@ -294,7 +294,7 @@ namespace armarx::armem::gui::instance if (shape.size() != 3) { showErrorMessage("Expected array shape with 3 dimensions, but got: " - + AronNDArrayDataNavigator::DimensionsToString(shape)); + + NDArrayNavigator::DimensionsToString(shape)); return; } @@ -309,7 +309,7 @@ namespace armarx::armem::gui::instance break; default: showErrorMessage("Expected 1 or 3 elements in last dimension, but got shape: " - + AronNDArrayDataNavigator::DimensionsToString(shape)); + + NDArrayNavigator::DimensionsToString(shape)); return; } diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h index 4717e5adebf3f0bb9a403abb783f87ea7597e661..00027a3e0cc4c826e24c62262bf4404f645e1bdf 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceView.h @@ -4,7 +4,7 @@ #include <QWidget> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> #include <RobotAPI/libraries/armem/core/Memory.h> @@ -35,7 +35,7 @@ namespace armarx::armem::gui::instance void setUseTypeInfo(bool enable); void update(const MemoryID& id, const Memory& memory); - void update(const EntityInstance& instance, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); + void update(const EntityInstance& instance, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); void update(); @@ -48,16 +48,16 @@ namespace armarx::armem::gui::instance private slots: void prepareTreeContextMenu(const QPoint& pos); - void showImageView(const aron::AronPath& elementPath); + void showImageView(const aron::Path& elementPath); void removeImageView(); private: void updateInstanceID(const MemoryID& id); - void updateData(const aron::datanavigator::AronDictDataNavigatorPtr& data, aron::typenavigator::AronObjectTypeNavigatorPtr aronType = nullptr); + void updateData(const aron::datanavigator::DictNavigatorPtr& data, aron::typenavigator::ObjectNavigatorPtr aronType = nullptr); void updateMetaData(const EntityInstanceMetadata& metadata); - void updateImageView(const aron::datanavigator::AronDictDataNavigatorPtr& data); + void updateImageView(const aron::datanavigator::DictNavigatorPtr& data); void showErrorMessage(const std::string& message); @@ -72,7 +72,7 @@ namespace armarx::armem::gui::instance }; std::optional<EntityInstance> currentInstance; - aron::typenavigator::AronObjectTypeNavigatorPtr currentAronType = nullptr; + aron::typenavigator::ObjectNavigatorPtr currentAronType = nullptr; bool useTypeInfo = true; QSplitter* splitter; @@ -90,7 +90,7 @@ namespace armarx::armem::gui::instance QGroupBox* group; instance::ImageView* view; - aron::AronPath elementPath; + aron::Path elementPath; }; std::optional<ImageView> imageView; diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.cpp b/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b0c0cec792666b1bee40d72ceb00951bb4a3bf4 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.cpp @@ -0,0 +1,41 @@ +#include "InstanceViewList.h" + +#include <QAction> +#include <QGroupBox> +#include <QHBoxLayout> +#include <QHeaderView> +#include <QImage> +#include <QLabel> +#include <QLayout> +#include <QMenu> +#include <QSplitter> +#include <QVBoxLayout> + +#include <SimoxUtility/algorithm/string.h> + +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/armem_gui/gui_utils.h> + + +namespace armarx::armem::gui::instance +{ + + InstanceViewList::InstanceViewList() + { + } + + void InstanceViewList::setStatusLabel(QLabel* statusLabel) + { + this->statusLabel = statusLabel; + } + + void InstanceViewList::setUseTypeInfo(bool enable) + { + this->useTypeInfo = enable; + update(); + } + + +} diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.h b/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.h new file mode 100644 index 0000000000000000000000000000000000000000..640712dffb91bbd019bc8cdb58469b5309487575 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/instance/InstanceViewList.h @@ -0,0 +1,69 @@ +#pragma once + +#include <optional> + +#include <QWidget> + +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> + +#include <RobotAPI/libraries/armem/core/Memory.h> + + +class QGroupBox; +class QLabel; +class QSplitter; +class QTreeWidget; +class QTreeWidgetItem; + + +namespace armarx::armem::gui::instance +{ + namespace instance + { + class ImageView; + } + + + class InstanceViewList : public QWidget + { + Q_OBJECT + using This = InstanceViewList; + + + public: + + InstanceViewList(); + + void setStatusLabel(QLabel* statusLabel); + void setUseTypeInfo(bool enable); + + + + signals: + + void updated(); + + + private slots: + + + private: + + + + private: + + + QSplitter* splitter; + + QLabel* statusLabel = nullptr; + bool useTypeInfo = true; + + }; + +} + +namespace armarx::armem::gui +{ + using InstanceViewList = instance::InstanceViewList; +} diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.cpp b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.cpp similarity index 73% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.cpp rename to source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.cpp index d92450283599807b2b4d35531bccc113c0906f54..0d1721ef244c8e4a44eba5003a19302c190518d7 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.cpp @@ -1,4 +1,4 @@ -#include "InstanceTreeDataVisitor.h" +#include "TreeDataVisitor.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.h b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.h similarity index 87% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.h rename to source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.h index 2ceb790caf10591bb0260a52f83445f4458fa84f..b751084bf8af57f2d7f6598e2ae2e835c0948b6c 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.h +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitor.h @@ -6,21 +6,21 @@ #include <QTreeWidget> #include <QLabel> -#include <RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h> +#include <RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h> -#include "InstanceTreeDataVisitorBase.h" +#include "TreeDataVisitorBase.h" namespace armarx::armem::gui { - class InstanceTreeDataVisitor : + class TreeDataVisitor : public aron::visitor::DataVisitor, - public InstanceTreeDataVisitorBase + public TreeDataVisitorBase { public: - using InstanceTreeDataVisitorBase::InstanceTreeDataVisitorBase; + using TreeDataVisitorBase::TreeDataVisitorBase; bool visitEnter(const std::string& key, DictDataNavigator& n) override diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.cpp b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.cpp similarity index 57% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.cpp rename to source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.cpp index cda47aae0cd398e78070c8eef0a0ef2e2d84fbb7..39ba3d5e35de1247790dfb7c0e8837096b3b1b77 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.cpp @@ -1,4 +1,4 @@ -#include "InstanceTreeDataVisitorBase.h" +#include "TreeDataVisitorBase.h" #include <ArmarXCore/core/exceptions/local/ExpressionException.h> @@ -6,26 +6,26 @@ namespace armarx::armem::gui { - InstanceTreeDataVisitorBase::InstanceTreeDataVisitorBase() + TreeDataVisitorBase::TreeDataVisitorBase() { } - InstanceTreeDataVisitorBase::InstanceTreeDataVisitorBase(QTreeWidgetItem* root) + TreeDataVisitorBase::TreeDataVisitorBase(QTreeWidgetItem* root) { rootItems.push(root); } - InstanceTreeDataVisitorBase::~InstanceTreeDataVisitorBase() + TreeDataVisitorBase::~TreeDataVisitorBase() {} - void InstanceTreeDataVisitorBase::setColumns(int key, int value, int type) + void TreeDataVisitorBase::setColumns(int key, int value, int type) { this->columnKey = key; this->columnType = type; this->columnValue = value; } - bool InstanceTreeDataVisitorBase::_visitEnter(const std::string& key, const std::string& type, size_t numChildren) + bool TreeDataVisitorBase::_visitEnter(const std::string& key, const std::string& type, size_t numChildren) { QTreeWidgetItem* item = nullptr; if (rootItems.size() > 0) @@ -45,7 +45,7 @@ namespace armarx::armem::gui return true; } - bool InstanceTreeDataVisitorBase::_visitExit() + bool TreeDataVisitorBase::_visitExit() { ARMARX_CHECK_POSITIVE(items.size()); QTreeWidgetItem* item = items.top(); @@ -62,7 +62,7 @@ namespace armarx::armem::gui return true; } - void InstanceTreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::BoolDataNavigator& n, std::stringstream& ss) + void TreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::BoolDataNavigator& n, std::stringstream& ss) { if (n.getValue()) { @@ -74,14 +74,14 @@ namespace armarx::armem::gui } } - void InstanceTreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::StringDataNavigator& n, std::stringstream& ss) + void TreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::StringDataNavigator& n, std::stringstream& ss) { ss << "'" << n.getValue() << "'"; } - void InstanceTreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::NDArrayDataNavigator& n, std::stringstream& ss) + void TreeDataVisitorBase::streamValueText(aron::visitor::DataVisitor::NDArrayDataNavigator& n, std::stringstream& ss) { - ss << "shape " << aron::datanavigator::AronNDArrayDataNavigator::DimensionsToString(n.getDimensions()); + ss << "shape " << aron::datanavigator::NDArrayNavigator::DimensionsToString(n.getDimensions()); } } diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.h b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.h similarity index 87% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.h rename to source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.h index a0b9a913b9e47ea07ee5cb393cbfef64eeb803bc..35dcca57a868e050c561045af0a948276f43af60 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitorBase.h +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeDataVisitorBase.h @@ -6,19 +6,19 @@ #include <QTreeWidget> #include <QLabel> -#include <RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h> +#include <RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h> namespace armarx::armem::gui { - class InstanceTreeDataVisitorBase + class TreeDataVisitorBase { public: - InstanceTreeDataVisitorBase(); - InstanceTreeDataVisitorBase(QTreeWidgetItem* root); - virtual ~InstanceTreeDataVisitorBase(); + TreeDataVisitorBase(); + TreeDataVisitorBase(QTreeWidgetItem* root); + virtual ~TreeDataVisitorBase(); void setColumns(int key, int value, int type); diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.cpp b/source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.cpp similarity index 68% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.cpp rename to source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.cpp index 6e9c63c47be8be806befc7a31b75376afe23df4c..fa51ab6fe0018927ebb03da63828a7aea598035a 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.cpp +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.cpp @@ -1,4 +1,4 @@ -#include "InstanceTreeTypedDataVisitor.h" +#include "TreeTypedDataVisitor.h" #include <SimoxUtility/algorithm/string.h> @@ -8,7 +8,7 @@ namespace armarx::armem::gui { - std::string InstanceTreeTypedDataVisitor::sanitizeTypeName(const std::string& typeName) const + std::string TreeTypedDataVisitor::sanitizeTypeName(const std::string& typeName) const { std::string n = typeName; n = simox::alg::replace_all(n, "Aron", ""); @@ -16,7 +16,7 @@ namespace armarx::armem::gui return n; } - QStringList InstanceTreeTypedDataVisitor::serializeAronPath(const aron::AronPath& path) + QStringList TreeTypedDataVisitor::serializePath(const aron::Path& path) { QStringList qpath; qpath.append(QString::fromStdString(path.getRootIdentifier())); @@ -28,7 +28,7 @@ namespace armarx::armem::gui return qpath; } - aron::AronPath InstanceTreeTypedDataVisitor::deserializeAronPath(const QStringList& qpath) + aron::Path TreeTypedDataVisitor::deserializePath(const QStringList& qpath) { ARMARX_CHECK_GREATER_EQUAL(qpath.size(), 2); std::vector<std::string> pathItems; @@ -36,7 +36,7 @@ namespace armarx::armem::gui { pathItems.push_back(qpath.at(i).toStdString()); } - aron::AronPath path(qpath.at(0).toStdString(), qpath.at(1).toStdString(), pathItems); + aron::Path path(qpath.at(0).toStdString(), qpath.at(1).toStdString(), pathItems); return path; } diff --git a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h b/source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.h similarity index 89% rename from source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h rename to source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.h index b38664fc4a814ac5df66e9522dc318189c220d26..b5493584b2c91eeed01fb6f9758d23a956b5225c 100644 --- a/source/RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h +++ b/source/RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.h @@ -6,20 +6,20 @@ #include <QTreeWidget> #include <QLabel> -#include <RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.h> -#include "InstanceTreeDataVisitorBase.h" +#include <RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.h> +#include "TreeDataVisitorBase.h" namespace armarx::armem::gui { - class InstanceTreeTypedDataVisitor : + class TreeTypedDataVisitor : public aron::visitor::TypedDataVisitor, - public InstanceTreeDataVisitorBase + public TreeDataVisitorBase { public: - using InstanceTreeDataVisitorBase::InstanceTreeDataVisitorBase; + using TreeDataVisitorBase::TreeDataVisitorBase; bool visitEnter(DictTypeNavigator& type, const std::string& key, DictDataNavigator& data) override @@ -116,7 +116,7 @@ namespace armarx::armem::gui QTreeWidgetItem* item = new QTreeWidgetItem(this->makeValueRowStrings(key, dataNavigator, sanitizeTypeName(type.getName()))); items.top()->addChild(item); - item->setData(columnKey, Qt::UserRole, serializeAronPath(dataNavigator.getPath())); + item->setData(columnKey, Qt::UserRole, serializePath(dataNavigator.getPath())); item->setData(columnType, Qt::UserRole, int(type.getDescriptor())); } return true; @@ -124,8 +124,8 @@ namespace armarx::armem::gui public: - static QStringList serializeAronPath(const aron::AronPath& path); - static aron::AronPath deserializeAronPath(const QStringList& qpath); + static QStringList serializePath(const aron::Path& path); + static aron::Path deserializePath(const QStringList& qpath); }; diff --git a/source/RobotAPI/libraries/armem_gui/lifecycle.cpp b/source/RobotAPI/libraries/armem_gui/lifecycle.cpp new file mode 100644 index 0000000000000000000000000000000000000000..508ec50924baacdfe90df941a8f55ac730620837 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/lifecycle.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "lifecycle.h" + +#include <ArmarXCore/core/ManagedIceObject.h> + + +namespace armarx::gui +{ + LifecycleClient::~LifecycleClient() + { + } + + void LifecycleClient::onInit(ManagedIceObject* component) + { + if (component) + { + onInit(*component); + } + } + + void LifecycleClient::onConnect(ManagedIceObject* component) + { + if (component) + { + onConnect(*component); + } + } + + void LifecycleClient::onDisconnect(ManagedIceObject* component) + { + if (component) + { + onDisconnect(*component); + } + } + + void LifecycleClient::onInit(ManagedIceObject& component) + { + (void) component; + } + + void LifecycleClient::onConnect(ManagedIceObject& component) + { + (void) component; + } + + void LifecycleClient::onDisconnect(ManagedIceObject& component) + { + (void) component; + } + +} + +void armarx::gui::connectLifecycle(LifecycleServer* server, LifecycleClient* client) +{ + if (server && client) + { + server->connect(server, &LifecycleServer::initialized, [client](ManagedIceObject * o) + { + client->onInit(o); + }); + server->connect(server, &LifecycleServer::connected, [client](ManagedIceObject * o) + { + client->onConnect(o); + }); + server->connect(server, &LifecycleServer::disconnected, [client](ManagedIceObject * o) + { + client->onDisconnect(o); + }); + } +} diff --git a/source/RobotAPI/libraries/armem_gui/lifecycle.h b/source/RobotAPI/libraries/armem_gui/lifecycle.h new file mode 100644 index 0000000000000000000000000000000000000000..0bc404387b3165841526c12a09a9fa6bbad0fdd9 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/lifecycle.h @@ -0,0 +1,78 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package SpeechX::ArmarXObjects::gui + * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <QObject> + + +namespace armarx +{ + class ManagedIceObject; +} +namespace armarx::gui +{ + + class LifecycleServer : public QObject + { + Q_OBJECT + public: + + using QObject::QObject; + + + public slots: + + signals: + + void initialized(ManagedIceObject* component); + void connected(ManagedIceObject* component); + void disconnected(ManagedIceObject* component); + + }; + + + class LifecycleClient + { + public: + + virtual ~LifecycleClient(); + + + public: + + // Used by QtSignals. + virtual void onInit(ManagedIceObject* component); + virtual void onConnect(ManagedIceObject* component); + virtual void onDisconnect(ManagedIceObject* component); + + // To be overriden by deriving classes. + virtual void onInit(ManagedIceObject& component); + virtual void onConnect(ManagedIceObject& component); + virtual void onDisconnect(ManagedIceObject& component); + + }; + + + void connectLifecycle(LifecycleServer* server, LifecycleClient* client); + +} diff --git a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9503704148ea664acec8e99397b9c4f77822df60 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp @@ -0,0 +1,65 @@ +#include "GroupBox.h" + +#include <QCheckBox> +#include <QGuiApplication> +#include <QHBoxLayout> +#include <QScreen> +#include <QSplitter> +#include <QVBoxLayout> + + +namespace armarx::armem::gui::memory +{ + + GroupBox::GroupBox() + { + QVBoxLayout* layout = new QVBoxLayout(); + this->setLayout(layout); + + QSplitter* splitter = new QSplitter(Qt::Orientation::Vertical); + layout->addWidget(splitter); + + this->setTitle("Memory"); + int margin = 3; + this->layout()->setContentsMargins(margin, margin, margin, margin); + + + _tree = new armem::gui::MemoryTreeWidget(); + + { + _queryWidget = new armem::gui::QueryWidget(); + _queryWidget->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum); + + _queryGroup = new QGroupBox("Queries"); + _queryGroup->setLayout(new QVBoxLayout()); + + margin = 0; + _queryGroup->setContentsMargins(margin, margin, margin, margin); + _queryGroup->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum); + + _queryGroup->layout()->addWidget(_queryWidget); + } + + splitter->addWidget(_tree); + splitter->addWidget(_queryGroup); + // Prevent QueryGroup from growing. + const int largeHeight = QGuiApplication::primaryScreen()->size().height(); + splitter->setSizes({largeHeight, 1}); + } + + QueryWidget* GroupBox::queryWidget() const + { + return _queryWidget; + } + + QGroupBox* GroupBox::queryGroup() const + { + return _queryGroup; + } + + MemoryTreeWidget* GroupBox::tree() const + { + return _tree; + } + +} diff --git a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h new file mode 100644 index 0000000000000000000000000000000000000000..ff7a4800f2612f4e64d792d0036372805205ce10 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h @@ -0,0 +1,53 @@ +#pragma once + +#include <QGroupBox> + +#include <RobotAPI/libraries/armem_gui/memory/TreeWidget.h> +#include <RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h> + + +class QCheckBox; +class QLabel; + + +namespace armarx::armem::gui::memory +{ + + class GroupBox : public QGroupBox + { + Q_OBJECT + using This = GroupBox; + + public: + + GroupBox(); + + TreeWidget* tree() const; + QGroupBox* queryGroup() const; + QueryWidget* queryWidget() const; + + + public slots: + + signals: + + private slots: + + signals: + + + private: + + TreeWidget* _tree; + + QGroupBox* _queryGroup; + QueryWidget* _queryWidget; + + }; + +} + +namespace armarx::armem::gui +{ + using MemoryGroupBox = memory::GroupBox; +} diff --git a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp similarity index 84% rename from source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp rename to source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp index d494cd315ade75ccc758ebebd5943a8144dafdce..e622a3a44601e6abc1e2e7f428f58c2dd1346169 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.cpp @@ -1,24 +1,24 @@ -#include "MemoryTreeWidget.h" +#include "TreeWidget.h" -#include <QHeaderView> - -#include <SimoxUtility/algorithm/string.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <SimoxUtility/algorithm/string.h> + +#include <QHeaderView> -namespace armarx::armem::gui +namespace armarx::armem::gui::memory { - MemoryTreeWidget::MemoryTreeWidget() + TreeWidget::TreeWidget() { initBuilders(); initWidget(); } - void MemoryTreeWidget::initWidget() + void TreeWidget::initWidget() { clear(); QStringList columns; @@ -47,7 +47,7 @@ namespace armarx::armem::gui connect(this, &This::instanceSelected, this, &This::itemSelected); } - void MemoryTreeWidget::initBuilders() + void TreeWidget::initBuilders() { memoryBuilder.setExpand(true); memoryBuilder.setMakeItemFn([this](const std::string & name, const Memory * memory) @@ -139,7 +139,7 @@ namespace armarx::armem::gui } - void MemoryTreeWidget::update(const armem::Memory& memory) + void TreeWidget::update(const armem::Memory& memory) { // Removing elements during the update can create unwanted signals triggering selection handling. handleSelections = false; @@ -148,7 +148,7 @@ namespace armarx::armem::gui emit updated(); } - void MemoryTreeWidget::update(const std::map<std::string, const armem::Memory*>& memories) + void TreeWidget::update(const std::map<std::string, const armem::Memory*>& memories) { handleSelections = false; updateChildren(memories, this); @@ -156,12 +156,12 @@ namespace armarx::armem::gui emit updated(); } - std::optional<MemoryID> MemoryTreeWidget::selectedID() const + std::optional<MemoryID> TreeWidget::selectedID() const { return _selectedID; } - void MemoryTreeWidget::handleSelection() + void TreeWidget::handleSelection() { if (!handleSelections) { @@ -212,48 +212,48 @@ namespace armarx::armem::gui } - void MemoryTreeWidget::updateChildren(const armem::Memory& memory, QTreeWidget* tree) + void TreeWidget::updateChildren(const armem::Memory& memory, QTreeWidget* tree) { updateChildren(std::map<std::string, const armem::Memory*> {{memory.name(), &memory}}, tree); } - void MemoryTreeWidget::updateChildren(const std::map<std::string, const armem::Memory*>& memories, QTreeWidget* tree) + void TreeWidget::updateChildren(const std::map<std::string, const armem::Memory*>& memories, QTreeWidget* tree) { memoryBuilder.updateTree(tree, memories); } - void MemoryTreeWidget::updateChildren(const armem::Memory& memory, QTreeWidgetItem* memoryItem) + void TreeWidget::updateChildren(const armem::Memory& memory, QTreeWidgetItem* memoryItem) { coreSegmentBuilder.updateTree(memoryItem, memory.coreSegments); } - void MemoryTreeWidget::updateChildren(const armem::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem) + void TreeWidget::updateChildren(const armem::CoreSegment& coreSeg, QTreeWidgetItem* coreSegItem) { provSegmentBuilder.updateTree(coreSegItem, coreSeg.providerSegments); } - void MemoryTreeWidget::updateChildren(const armem::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem) + void TreeWidget::updateChildren(const armem::ProviderSegment& provSeg, QTreeWidgetItem* provSegItem) { entityBuilder.updateTree(provSegItem, provSeg.entities); } - void MemoryTreeWidget::updateChildren(const armem::Entity& entity, QTreeWidgetItem* entityItem) + void TreeWidget::updateChildren(const armem::Entity& entity, QTreeWidgetItem* entityItem) { snapshotBuilder.updateTree(entityItem, entity.history); } - void MemoryTreeWidget::updateChildren(const armem::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem) + void TreeWidget::updateChildren(const armem::EntitySnapshot& snapshot, QTreeWidgetItem* snapshotItem) { instanceBuilder.updateTree(snapshotItem, snapshot.instances); } - void MemoryTreeWidget::updateChildren(const armem::EntityInstance& data, QTreeWidgetItem* dataItem) + void TreeWidget::updateChildren(const armem::EntityInstance& data, QTreeWidgetItem* dataItem) { (void) data, (void) dataItem; } - QTreeWidgetItem* MemoryTreeWidget::makeItem(const std::string& key, const armem::detail::MemoryItem& memoryItem) + QTreeWidgetItem* TreeWidget::makeItem(const std::string& key, const armem::detail::MemoryItem& memoryItem) { (void) key; QStringList columns; @@ -270,13 +270,13 @@ namespace armarx::armem::gui return item; } - void MemoryTreeWidget::updateItemItem(const armem::detail::MemoryItem& level, QTreeWidgetItem* item) + void TreeWidget::updateItemItem(const armem::detail::MemoryItem& level, QTreeWidgetItem* item) { (void) level, (void) item; } template <class... T> - void MemoryTreeWidget::updateContainerItem( + void TreeWidget::updateContainerItem( const armem::detail::MemoryContainer<T...>& container, QTreeWidgetItem* item) { updateItemItem(container, item); @@ -284,14 +284,14 @@ namespace armarx::armem::gui } template <class... T> - void MemoryTreeWidget::updateTypedContainerItem( + void TreeWidget::updateTypedContainerItem( const armem::detail::TypedEntityContainer<T...>& container, QTreeWidgetItem* item) { updateContainerItem(container, item); std::string typeName; if (container.aronType()) { - typeName = container.aronType()->getObjectName(); + typeName = container.aronType()->getName(); std::string del = "::"; size_t find = typeName.rfind(del); diff --git a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h similarity index 93% rename from source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h rename to source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h index ae41d701f3e18b3c05c42d9a31ba6768e7c8ce17..be73a68b6a9fb482c57f8262c3fb514638dfb3d9 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryTreeWidget.h +++ b/source/RobotAPI/libraries/armem_gui/memory/TreeWidget.h @@ -2,26 +2,23 @@ #include <map> -#include <QObject> +#include <QTreeWidget> #include <RobotAPI/libraries/armem/core/Memory.h> #include <RobotAPI/libraries/armem_gui/TreeWidgetBuilder.h> -class QTreeWidget; - - -namespace armarx::armem::gui +namespace armarx::armem::gui::memory { - class MemoryTreeWidget : public QTreeWidget + class TreeWidget : public QTreeWidget { Q_OBJECT - using This = MemoryTreeWidget; + using This = TreeWidget; public: - MemoryTreeWidget(); + TreeWidget(); void update(const armem::Memory& memory); void update(const std::map<std::string, const armem::Memory*>& memories); @@ -102,3 +99,8 @@ namespace armarx::armem::gui }; } + +namespace armarx::armem::gui +{ + using MemoryTreeWidget = memory::TreeWidget; +} diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp index b36d07f4b64edb1c0fbb5254a9aed46e3df80ccf..6ac42aee3f0870279f8f8fe823fdb9ca5340c4c7 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp @@ -11,11 +11,6 @@ namespace armarx::armem::gui { QueryWidget::QueryWidget() - { - initWidget(); - } - - void QueryWidget::initWidget() { QVBoxLayout* layout = new QVBoxLayout(); setLayout(layout); @@ -31,6 +26,10 @@ namespace armarx::armem::gui layout->addWidget(_dataCheckBox); layout->addWidget(_tabWidget); + const int margin = 0; + layout->setContentsMargins(margin, margin, margin, margin); + + // connect to queryChanged } diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h index 13f93063c98ff39c7951d98a7d29974e48e80adf..37e5fca58b80d54592d4eb6443e8e624bd0a613d 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h @@ -37,10 +37,6 @@ namespace armarx::armem::gui signals: - private: - - void initWidget(); - private: diff --git a/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp b/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp index 057ce3fdf29e91c7207653ab67e86e1ad73d4655..5ecf962dbef91f033435c532149c49285c408bc2 100644 --- a/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp +++ b/source/RobotAPI/libraries/armem_gui/test/ArMemGuiTest.cpp @@ -29,12 +29,12 @@ #include <iostream> -#include <RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h> +#include <RobotAPI/libraries/armem_gui/instance/TreeTypedDataVisitor.h> -BOOST_AUTO_TEST_CASE(testExample) +BOOST_AUTO_TEST_CASE(test_sanitizeTypeName) { - armarx::armem::gui::InstanceTreeTypedDataVisitor v; + armarx::armem::gui::TreeTypedDataVisitor v; BOOST_CHECK_EQUAL(v.sanitizeTypeName("AronDictType<AronFloatType>"), "Dict<Float>"); BOOST_CHECK_EQUAL(v.sanitizeTypeName("AronListType<AronFloatType>"), "List<Float>"); diff --git a/source/RobotAPI/libraries/armem_robot_localization/CMakeLists.txt b/source/RobotAPI/libraries/armem_robot_localization/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..19a7f00199d06462123d94d345f54fec030672cc --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/CMakeLists.txt @@ -0,0 +1,43 @@ +set(LIB_NAME armem_robot_localization) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +armarx_add_library( + LIBS + # ArmarX + ArmarXCore + ArmarXCoreInterfaces + ArmarXGuiComponentPlugins + # This package + RobotAPICore + RobotAPIInterfaces + RobotAPI::libraries::armem + # System / External + Eigen3::Eigen + HEADERS + ./TransformInterfaces.h + ./TransformReader.h + ./TransformWriter.h + ./MemoryConnector.h + ./aron_conversions.h + SOURCES + ./TransformReader.cpp + ./TransformWriter.cpp + ./MemoryConnector.cpp + ./aron_conversions.cpp +) + + +armarx_enable_aron_file_generation_for_target( + TARGET_NAME + "${LIB_NAME}" + ARON_FILES + aron/Transform.xml +) + + +add_library(RobotAPI::armem_robot_localization ALIAS armem_robot_localization) diff --git a/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.cpp b/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c66b568c89a28e714bffbe4df1fcba00ccdfd666 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.cpp @@ -0,0 +1,43 @@ +#include "MemoryConnector.h" + +#include <ArmarXCore/core/ManagedIceObject.h> +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> + +namespace armarx +{ + + MemoryConnector::MemoryConnector(ManagedIceObject& component) : component(component) {} + + void MemoryConnector::registerPropertyDefinitions(PropertyDefinitionsPtr& def) + { + ARMARX_INFO << "Memory connector: registerPropertyDefinitions"; + + const std::string prefix = getPropertyPrefix(); + + def->component(memoryNameSystem, "ArMemMemoryNameSystem", prefix + "ArMemMemoryNameSystem"); + } + + armem::data::WaitForMemoryResult MemoryConnector::useMemory(const std::string& memoryName) + { + armem::data::WaitForMemoryInput input; + input.name = memoryName; + + ARMARX_CHECK_NOT_NULL(memoryNameSystem); + + ARMARX_INFO << "Waiting for memory ..."; + armem::data::WaitForMemoryResult result = memoryNameSystem->waitForMemory(input); + + if (result.success) + { + // Add dependency. + component.usingProxy(result.proxy->ice_getIdentity().name); + } + else + { + ARMARX_WARNING << "Use memory: Failure"; + } + return result; + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.h b/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.h new file mode 100644 index 0000000000000000000000000000000000000000..1af5ec5d889f520c62e0dc5e4d89948cba268d3d --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/MemoryConnector.h @@ -0,0 +1,62 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + + +// TODO(fabian.reister): remove +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> + +#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> + +namespace armarx +{ + + class ManagedIceObject; + + // TODO(fabian.reister): add + // class PropertyDefinitionsPtr; + + class MemoryConnector + { + + public: + MemoryConnector(ManagedIceObject& component); + + protected: + armem::data::WaitForMemoryResult useMemory(const std::string& memoryName); + void registerPropertyDefinitions(PropertyDefinitionsPtr& def); + + void waitForMemory(); + + virtual std::string getPropertyPrefix() + { + return "mem."; + } + + private: + ManagedIceObject& component; + + armem::mns::MemoryNameSystemInterfacePrx memoryNameSystem; + }; + +} // namespace armarx \ No newline at end of file diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformInterfaces.h b/source/RobotAPI/libraries/armem_robot_localization/TransformInterfaces.h new file mode 100644 index 0000000000000000000000000000000000000000..cb353f57d73561dfdda4a96ce60137e988e5db09 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformInterfaces.h @@ -0,0 +1,105 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <Eigen/Geometry> + +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> + +namespace armarx +{ + + struct TransformHeader + { + std::string parentFrame; + std::string frame; + + std::string agent; + + std::int64_t timestamp; // [µs] + }; + + struct Transform + { + TransformHeader header; + + Eigen::Affine3f transform = Eigen::Affine3f::Identity(); + }; + + struct TransformResult + { + Transform transform; + + enum class Status + { + success, + errorLookupIntoFuture, + errorFrameNotAvailable + } status; + + explicit operator bool() const + { + return status == Status::success; + } + + std::string errorMessage = ""; + }; + + struct TransformQuery + { + TransformHeader header; + + // bool exact; + }; + + class TransformInterface + { + public: + virtual ~TransformInterface() = default; + + virtual void registerPropertyDefinitions(PropertyDefinitionsPtr& def) = 0; + virtual void connect() = 0; + }; + + class TransformReaderInterface : virtual public TransformInterface + { + public: + virtual ~TransformReaderInterface() = default; + + virtual TransformResult getGlobalPose(const std::string& agentName, + const std::string& robotRootFrame, + const std::int64_t& timestamp) const = 0; + + virtual TransformResult lookupTransform(const TransformQuery& query) const = 0; + // waitForTransform() + }; + + class TransformWriterInterface : virtual public TransformInterface + { + public: + ~TransformWriterInterface() override = default; + + virtual bool commitTransform(const Transform& transform) = 0; + }; + +} // namespace armarx \ No newline at end of file diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80b242b1204a28b255283939cd64588f1c251c01 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.cpp @@ -0,0 +1,446 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TransformReader.h" + +#include <Eigen/src/Geometry/Transform.h> +#include <algorithm> +#include <iterator> +#include <numeric> + +// Ice +#include <IceUtil/Time.h> + +// Eigen +#include <Eigen/Geometry> + +// Simox +#include <SimoxUtility/algorithm/get_map_keys_values.h> +#include <SimoxUtility/algorithm/string/string_tools.h> +#include <SimoxUtility/color/cmaps.h> +#include <SimoxUtility/math/pose/interpolate.h> + +// ArmarX +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/time/CycleUtil.h> + +// this package +#include <RobotAPI/libraries/armem/client/query/Builder.h> +#include <RobotAPI/libraries/armem/client/query/query_fns.h> +#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/ProviderSegment.h> +#include <RobotAPI/libraries/armem/core/ice_conversions.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> +#include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> +#include <RobotAPI/libraries/core/FramedPose.h> +#include <RobotAPI/libraries/armem_robot_localization/aron_conversions.h> +#include <RobotAPI/libraries/armem_robot_localization/aron/Transform.aron.generated.h> + +namespace armarx +{ + + TransformReader::TransformReader(ManagedIceObject& component) : MemoryConnector(component) {} + + TransformReader::~TransformReader() = default; + + void TransformReader::registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def) + { + ARMARX_INFO << "TransformReader: registerPropertyDefinitions"; + MemoryConnector::registerPropertyDefinitions(def); + + const std::string prefix = getPropertyPrefix(); + + def->optional(properties.localizationMemoryName, + prefix + "LocalizationMemoryName", + "Name of the localization memory core segment to use."); + + def->optional(properties.memoryName, prefix + "MemoryName"); + } + + void TransformReader::connect() + { + // Wait for the memory to become available and add it as dependency. + ARMARX_IMPORTANT << "TransformReader: Waiting for memory '" << properties.memoryName + << "' ..."; + auto result = useMemory(properties.memoryName); + if (not result.success) + { + ARMARX_ERROR << result.errorMessage; + return; + } + + ARMARX_IMPORTANT << "TransformReader: Connected to memory '" << properties.memoryName; + + memoryReader.setReadingMemory(result.proxy); + } + + TransformResult TransformReader::getGlobalPose(const std::string& agentName, + const std::string& robotRootFrame, + const std::int64_t& timestamp) const + { + const TransformQuery query{.header = {.parentFrame = GlobalFrame, + .frame = robotRootFrame, + .agent = agentName, + .timestamp = timestamp + }}; + + return lookupTransform(query); + } + + // std::vector<std::string> buildTransformChainArbitrary(const + // std::map<std::string, armem::ProviderSegment>& providerSegments, const + // std::string& parentFrame, const std::string& frame){ + + // std::map<std::string, std::string> tf; + + // // build string representation of transforms + // for(const auto& [name, segment]: providerSegments){ + // const auto frames = simox::alg::split(name, ","); + // if (frames.size() != 2){ + // ARMARX_WARNING << "Segment name " << name << " not understood"; + // continue; + // } + + // tf.insert(frame[0], frame[1]); + // } + + // // find + + // } + + std::vector<std::string> TransformReader::buildTransformChain(const armem::Memory& memory, + const TransformQuery& query) const + { + ARMARX_INFO << "Building transform chain"; + + auto join = [](const std::string & parentFrame, const std::string & frame) + { + return parentFrame + "," + frame; + }; + + std::vector<std::string> chain; + + const auto& agentProviderSegment = memory.getCoreSegment(properties.localizationMemoryName) + .getProviderSegment(query.header.agent); + + auto addToChain = [&](const std::string & parentFrame, const std::string & frame) + { + const auto entityName = join(parentFrame, frame); + + if (agentProviderSegment.hasEntity(entityName)) + { + chain.push_back(entityName); + } + else + { + ARMARX_WARNING << "Cannot perform tf lookup '" << parentFrame << " -> " << frame + << "'"; + } + }; + + std::array<std::string, 3> knownChain + { + GlobalFrame, MapFrame, OdometryFrame}; // Robot comes next + + auto* frameBeginIt = + std::find(knownChain.begin(), knownChain.end(), query.header.parentFrame); + auto* const frameEndIt = + std::find(knownChain.begin(), knownChain.end(), query.header.frame); + + if (frameBeginIt == knownChain.end()) + { + ARMARX_WARNING << "Parent frame '" << query.header.parentFrame << "' unknown"; + return {}; + } + + if (frameEndIt == knownChain.end()) + { + ARMARX_DEBUG << "Frame '" << query.header.frame << "' must be robot frame"; + } + + const size_t nFrames = std::distance(frameBeginIt, frameEndIt); + ARMARX_DEBUG << "Lookup '" << query.header.parentFrame << " -> " << query.header.frame + << "' across " << nFrames << " frames"; + + for (; frameBeginIt != knownChain.end() - 1; frameBeginIt++) + { + addToChain(*frameBeginIt, *(frameBeginIt + 1)); + } + + if (frameEndIt == knownChain.end()) + { + addToChain(knownChain.back(), query.header.frame); + } + + if (chain.empty()) + { + ARMARX_WARNING << "Cannot create tf lookup chain '" << query.header.parentFrame + << " -> " << query.header.frame << "'"; + return {}; + } + + return chain; + } + + inline Transform convertEntityToTransform(const armem::EntityInstance& item) + { + aron::Transform aronTransform; + aronTransform.fromAron(item.data()); + + Transform transform; + fromAron(aronTransform, transform); + + return transform; + } + + decltype(auto) findFirstElementAfter(const std::vector<Transform>& transforms, + const int64_t timestamp) + { + auto timestampBeyond = [timestamp](const Transform & transform) + { + return transform.header.timestamp > timestamp; + }; + + const auto poseNextIt = std::find_if(transforms.begin(), transforms.end(), timestampBeyond); + return poseNextIt; + } + + Eigen::Affine3f interpolateTransform(const std::vector<Transform>& queue, int64_t timestamp) + { + ARMARX_TRACE; + + ARMARX_INFO << "Entering"; + + + ARMARX_CHECK(not queue.empty()) + << "The queue has to contain at least two items to perform a lookup"; + + + ARMARX_INFO << "Entering ... " + << "Q front " << queue.front().header.timestamp << " " + << "Q back " << queue.back().header.timestamp << " " + << "query timestamp " << timestamp; + + // TODO(fabian.reister): sort queue. + + + ARMARX_CHECK(queue.back().header.timestamp > timestamp) + << "Cannot perform lookup into the future!"; + + // ARMARX_INFO << "Entering 1.5 " << queue.front().timestamp << " " << timestamp; + ARMARX_CHECK(queue.front().header.timestamp < timestamp) + << "Cannot perform lookup. Timestamp too old"; + // => now we know that there is an element right after and before the timestamp within our queue + + ARMARX_INFO << "Entering 2"; + + const auto poseNextIt = findFirstElementAfter(queue, timestamp); + + ARMARX_INFO << "it ari"; + + const auto posePreIt = poseNextIt - 1; + + ARMARX_INFO << "deref"; + + // the time fraction [0..1] of the lookup wrt to posePre and poseNext + const float t = static_cast<float>(timestamp - posePreIt->header.timestamp) / + (poseNextIt->header.timestamp - posePreIt->header.timestamp); + + ARMARX_INFO << "interpolate"; + + return simox::math::interpolatePose(posePreIt->transform, poseNextIt->transform, t); + } + + Eigen::Affine3f TransformReader::obtainTransform(const std::string& entityName, const armem::ProviderSegment& agentProviderSegment, const int64_t timestamp) const + { + + ARMARX_DEBUG << "getEntity:" + entityName; + const auto& entity = agentProviderSegment.getEntity(entityName); + + ARMARX_DEBUG << "History (size: " << entity.history.size() << ")" + << simox::alg::get_keys(entity.history); + + // if (entity.history.empty()) + // { + // // TODO(fabian.reister): fixme boom + // ARMARX_ERROR << "No snapshots received."; + // return Eigen::Affine3f::Identity(); + // } + + + std::vector<Transform> transforms; + transforms.reserve(entity.history.size()); + + const auto entitySnapshots = simox::alg::get_values(entity.history); + std::transform(entitySnapshots.begin(), + entitySnapshots.end(), + std::back_inserter(transforms), + [](const auto & entity) + { + return convertEntityToTransform(entity.getInstance(0)); + }); + + ARMARX_INFO << "obtaining transform"; + + if (transforms.size() > 1) + { + ARMARX_INFO << "More than one snapshots received: " << transforms.size(); + const auto p = interpolateTransform(transforms, timestamp); + ARMARX_INFO << "Done interpolating transform"; + return p; + } + + + // accept this to fail (will raise armem::error::MissingEntry) + if (transforms.empty()) + { + ARMARX_INFO << "empty transform"; + + throw armem::error::MissingEntry("foo", "bar", "foo2", "bar2"); + } + + ARMARX_INFO << "single transform"; + + + return transforms.front().transform; + } + + std::vector<Eigen::Affine3f> + TransformReader::obtainTransforms(const armem::Memory& memory, + const std::vector<std::string>& tfChain, + const std::string& agent, + const std::int64_t& timestamp) const + { + + ARMARX_DEBUG << "Core segments" << simox::alg::get_keys(memory.coreSegments); + + const auto& agentProviderSegment = + memory.getCoreSegment(properties.localizationMemoryName).getProviderSegment(agent); + + ARMARX_DEBUG << "Provider segments" + << simox::alg::get_keys( + memory.getCoreSegment(properties.localizationMemoryName) + .providerSegments); + + ARMARX_DEBUG << "Entities: " << simox::alg::get_keys(agentProviderSegment.entities); + + try + { + std::vector<Eigen::Affine3f> transforms; + transforms.reserve(tfChain.size()); + std::transform(tfChain.begin(), + tfChain.end(), + std::back_inserter(transforms), + [&](const std::string & entityName) + { + return obtainTransform(entityName, agentProviderSegment, timestamp); + }); + return transforms; + } + catch (const armem::error::MissingEntry& missingEntryError) + { + ARMARX_WARNING << missingEntryError.what(); + } + catch (const ::armarx::exceptions::local::ExpressionException& ex) + { + ARMARX_WARNING << "local exception: " << ex.what(); + } + + return {}; + + } + + TransformResult TransformReader::lookupTransform(const TransformQuery& query) const + { + + const auto timestamp = IceUtil::Time::microSeconds(query.header.timestamp); + + const auto durationEpsilon = IceUtil::Time::milliSeconds(100); + + ARMARX_INFO << "Looking up transform at timestamp " << timestamp; + + // Query all entities from provider. + armem::client::query::Builder qb; + + // clang-format off + qb + .coreSegments().withName(properties.localizationMemoryName) + .providerSegments().withName(query.header.agent) // agent + .entities().all() // parentFrame,frame + .snapshots().timeRange(timestamp - durationEpsilon, timestamp + durationEpsilon); + // clang-format on + + // TODO(fabian.reister): remove latest() and add atTime + // .atTime(timestamp); // transformation + + const armem::client::QueryResult qResult = memoryReader.query(qb.buildQueryInput()); + + ARMARX_INFO << "Lookup result in reader: " << qResult; + + if (not qResult.success) + { + return {.transform = + { + .header = query.header, + }, + .status = TransformResult::Status::errorFrameNotAvailable, + .errorMessage = "Error in tf lookup '" + query.header.parentFrame + " -> " + + query.header.frame + "' : " + qResult.errorMessage}; + } + + const std::vector<std::string> tfChain = buildTransformChain(qResult.memory, query); + + if (tfChain.empty()) + { + return {.transform = {.header = query.header}, + .status = TransformResult::Status::errorFrameNotAvailable, + .errorMessage = "Cannot create tf lookup chain '" + + query.header.parentFrame + " -> " + query.header.frame + + "'"}; + } + + const std::vector<Eigen::Affine3f> transforms = obtainTransforms( + qResult.memory, tfChain, query.header.agent, timestamp.toMicroSeconds()); + + if (transforms.empty()) + { + ARMARX_WARNING << "No transform available."; + return {.transform = {.header = query.header}, + .status = TransformResult::Status::errorFrameNotAvailable, + .errorMessage = "Error in TF loookup: '" + + query.header.parentFrame + " -> " + query.header.frame + + "'. No memory data in time range."}; + } + + const Eigen::Affine3f transform = std::accumulate(transforms.begin(), + transforms.end(), + Eigen::Affine3f::Identity(), + std::multiplies<>()); + + ARMARX_INFO << "Found valid transform"; + + return {.transform = {.header = query.header, .transform = transform}, + .status = TransformResult::Status::success}; + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h new file mode 100644 index 0000000000000000000000000000000000000000..458ce5d89a7ec56a5f34f3d8b49a608158e69fde --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformReader.h @@ -0,0 +1,86 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/Reader.h> + +#include "MemoryConnector.h" +#include "TransformInterfaces.h" + +namespace armarx +{ + /** + * @defgroup Component-ExampleClient ExampleClient + * @ingroup RobotAPI-Components + * A description of the component ExampleClient. + * + * @class ExampleClient + * @ingroup Component-ExampleClient + * @brief Brief description of class ExampleClient. + * + * Detailed description of class ExampleClient. + */ + class TransformReader : + virtual public armarx::TransformReaderInterface, + virtual public armarx::MemoryConnector + { + public: + TransformReader(ManagedIceObject& component); + + ~TransformReader() override; + + void connect() override; + + TransformResult getGlobalPose(const std::string& agentName, + const std::string& robotRootFrame, + const std::int64_t& timestamp) const override; + TransformResult lookupTransform(const TransformQuery& query) const override; + + void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def) override; + + std::string getPropertyPrefix() override + { + return "mem.read."; + } + + private: + std::vector<std::string> buildTransformChain(const armem::Memory& memory, + const TransformQuery& query) const; + + std::vector<Eigen::Affine3f> obtainTransforms(const armem::Memory& memory, + const std::vector<std::string>& tfChain, + const std::string& agent, const std::int64_t& timestamp) const; + + Eigen::Affine3f obtainTransform(const std::string& entityName, const armem::ProviderSegment& agentProviderSegment, int64_t timestamp) const; + + + armem::client::Reader memoryReader; + + // Properties + struct Properties + { + std::string memoryName = "RobotState"; + std::string localizationMemoryName = "Localization"; + } properties; + }; +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55100c09eeee08293fac3ca455a04ba31bcbeaea --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.cpp @@ -0,0 +1,137 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TransformWriter.h" + +#include <algorithm> +#include <iterator> +#include <numeric> + +#include <Eigen/Geometry> + +#include <IceUtil/Time.h> + +#include <ArmarXCore/core/application/properties/PropertyDefinitionContainer.h> +#include <ArmarXCore/core/logging/Logging.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/time/CycleUtil.h> + +#include <RobotAPI/libraries/armem/client/query/Builder.h> +#include <RobotAPI/libraries/armem/client/query/query_fns.h> +#include <RobotAPI/libraries/armem/core/ice_conversions.h> +#include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> +#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/ProviderSegment.h> +#include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> +#include <RobotAPI/libraries/core/FramedPose.h> + +#include <RobotAPI/libraries/armem_robot_localization/aron/Transform.aron.generated.h> + +#include "aron_conversions.h" + + +namespace armarx +{ + + TransformWriter::TransformWriter(ManagedIceObject& component) : MemoryConnector(component) {} + + TransformWriter::~TransformWriter() = default; + + void TransformWriter::registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def) + { + ARMARX_INFO << "TransformWriter: registerPropertyDefinitions"; + + MemoryConnector::registerPropertyDefinitions(def); + + const std::string prefix = getPropertyPrefix(); + + def->optional(properties.localizationMemoryName, + prefix + "LocalizationMemoryName", + "Name of the localization memory core segment to use."); + + def->optional(properties.memoryName, prefix + "MemoryName"); + } + + void TransformWriter::connect() + { + // Wait for the memory to become available and add it as dependency. + ARMARX_IMPORTANT << "TransformWriter: Waiting for memory '" << properties.memoryName + << "' ..."; + auto result = useMemory(properties.memoryName); + if (not result.success) + { + ARMARX_ERROR << result.errorMessage; + return; + } + + ARMARX_IMPORTANT << "TransformWriter: Connected to memory '" << properties.memoryName; + + memoryWriter.setWritingMemory(result.proxy); + } + + bool TransformWriter::commitTransform(const Transform& transform) + { + std::lock_guard g{memoryWriterMutex}; + + ARMARX_DEBUG << "Trying to create core segment + provider segment"; + + const auto result = + memoryWriter.addSegment(properties.localizationMemoryName, transform.header.agent); + + if (not result.success) + { + ARMARX_ERROR << result.errorMessage; + + // TODO(fabian.reister): message + return false; + } + + const auto timestamp = IceUtil::Time::microSeconds(transform.header.timestamp); + + const auto providerId = armem::MemoryID(result.segmentID); + const auto entityID = providerId.withEntityName(transform.header.parentFrame + "," + + transform.header.frame).withTimestamp(timestamp); + + armem::EntityUpdate update; + update.entityID = entityID; + update.timeCreated = armem::Time::now(); + + aron::Transform aronTransform; + toAron(transform, aronTransform); + + update.instancesData = {aronTransform.toAron()}; + update.timeCreated = IceUtil::Time::microSeconds(aronTransform.header.timestamp); + + ARMARX_INFO << "Committing " << update << " at time " << IceUtil::Time::microSeconds(transform.header.timestamp); + armem::EntityUpdateResult updateResult = memoryWriter.commit(update); + + ARMARX_INFO << updateResult; + + if (not updateResult.success) + { + ARMARX_ERROR << updateResult.errorMessage; + } + + return updateResult.success; + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.h b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..cc7be8737647cd86a19109ab77da3b5ee2ea2afc --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/TransformWriter.h @@ -0,0 +1,80 @@ +/* + * This file is part of ArmarX. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @package RobotAPI::ArmarXObjects:: + * @author Fabian Reister ( fabian dot reister at kit dot edu ) + * @date 2021 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <RobotAPI/libraries/armem/client/Writer.h> +#include <mutex> + +#include "MemoryConnector.h" +#include "TransformInterfaces.h" + +namespace armarx +{ + + /** + * @defgroup Component-ExampleClient ExampleClient + * @ingroup RobotAPI-Components + * A description of the component ExampleClient. + * + * @class ExampleClient + * @ingroup Component-ExampleClient + * @brief Brief description of class ExampleClient. + * + * Detailed description of class ExampleClient. + */ + class TransformWriter : + virtual public armarx::TransformWriterInterface, + virtual public armarx::MemoryConnector + { + public: + TransformWriter(ManagedIceObject& component); + + ~TransformWriter() override; + + // TransformWriterInterface + /// to be called in Component::onConnectComponent + void connect() override; + + /// to be called in Component::addPropertyDefinitions + void registerPropertyDefinitions(armarx::PropertyDefinitionsPtr& def) override; + + bool commitTransform(const Transform& transform) override; + + std::string getPropertyPrefix() override + { + return "mem.write."; + } + + private: + armem::client::Writer memoryWriter; + + // Properties + struct Properties + { + std::string memoryName = "RobotState"; + std::string localizationMemoryName = "Localization"; + } properties; + + std::mutex memoryWriterMutex; + }; +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/aron/Transform.xml b/source/RobotAPI/libraries/armem_robot_localization/aron/Transform.xml new file mode 100644 index 0000000000000000000000000000000000000000..1e4e4c7d61c14d70a94499f8491254a20d336c89 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/aron/Transform.xml @@ -0,0 +1,34 @@ +<!--This class contains the data structure for ObjectPose --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + <GenerateTypes> + + <Object name="armarx::aron::TransformHeader"> + <ObjectChild key='parentFrame'> + <string /> + </ObjectChild> + <ObjectChild key='frame'> + <string /> + </ObjectChild> + <ObjectChild key='agent'> + <string /> + </ObjectChild> + <ObjectChild key='timestamp'> + <Time /> + </ObjectChild> + </Object> + + <Object name="armarx::aron::Transform"> + <ObjectChild key='header'> + <armarx::aron::TransformHeader /> + </ObjectChild> + <ObjectChild key='transform'> + <Pose /> + </ObjectChild> + </Object> + + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.cpp b/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..40832ae90e2686d76a1d2256b8e427c2cafc88a2 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.cpp @@ -0,0 +1,55 @@ +#include "aron_conversions.h" + +// STL +#include <string> + +// Ice +#include <IceUtil/Time.h> + +// RobotAPI +#include <RobotAPI/libraries/armem_robot_localization/TransformInterfaces.h> +#include <RobotAPI/libraries/armem_robot_localization/aron/Transform.aron.generated.h> + + +namespace armarx +{ + + TransformHeader fromAron(const aron::TransformHeader& aronHeader) + { + TransformHeader header; + + header.parentFrame = aronHeader.parentFrame; + header.frame = aronHeader.frame; + header.agent = aronHeader.agent; + header.timestamp = aronHeader.timestamp; + + return header; + } + + + void fromAron(const aron::Transform& aronTransform, Transform& transform) + { + transform.header = fromAron(aronTransform.header); + transform.transform = aronTransform.transform; + } + + + aron::TransformHeader toAron(const TransformHeader& header) + { + aron::TransformHeader aronHeader; + + aronHeader.parentFrame = header.parentFrame; + aronHeader.frame = header.frame; + aronHeader.agent = header.agent; + aronHeader.timestamp = header.timestamp; + + return aronHeader; + } + + void toAron(const Transform& transform, aron::Transform& aronTransform) + { + aronTransform.header = toAron(transform.header); + aronTransform.transform = transform.transform.matrix(); + } + +} // namespace armarx diff --git a/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.h b/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.h new file mode 100644 index 0000000000000000000000000000000000000000..bca16f71ea33e944fdbf77de9751361895882e33 --- /dev/null +++ b/source/RobotAPI/libraries/armem_robot_localization/aron_conversions.h @@ -0,0 +1,16 @@ +#pragma once + + +namespace armarx +{ + struct Transform; + + namespace aron + { + struct Transform; + } + + void fromAron(const aron::Transform& aronTransform, Transform& transform); + void toAron(const Transform& transform, aron::Transform& aronTransform); + +} // namespace armarx \ No newline at end of file diff --git a/source/RobotAPI/libraries/aron/CMakeLists.txt b/source/RobotAPI/libraries/aron/CMakeLists.txt index ccdf58635c5cb8b772882dd5ca16b0769b429177..124be827dda9a63c01b5af5da088806dbf99d47b 100644 --- a/source/RobotAPI/libraries/aron/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/CMakeLists.txt @@ -1,2 +1,3 @@ -add_subdirectory(aroncore) -add_subdirectory(aroncodegeneration) +add_subdirectory(core) +add_subdirectory(converter) +add_subdirectory(codegenerationhelper) diff --git a/source/RobotAPI/libraries/aron/aroncore/AronConcepts.h b/source/RobotAPI/libraries/aron/aroncore/AronConcepts.h deleted file mode 100644 index 086d630375eda8fdccc5d73bc07428a7bb30ebf9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronConcepts.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> - -// ArmarX -#include <RobotAPI/interface/aron.h> - - - -// TODO: REMOVE!!! -namespace armarx -{ - namespace aron - { - - - /* // General Concepts - template <typename CppType> - concept IsAronPrimitiveCppType = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<CppType, lowerType>::value) - - HANDLE_PRIMITIVE_TYPES - #undef RUN_ARON_MACRO - ; - - template <typename AronData, typename CppType> - concept AreAronPrimitiveDependent = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronData, Aron##upperType>::value && std::is_same<CppType, lowerType>::value) - - HANDLE_PRIMITIVE_TYPES - #undef RUN_ARON_MACRO - ; - - template <typename AronData> - concept IsAronData = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronData, Aron##upperType>::value) - - HANDLE_ALL_ARON_DATA - #undef RUN_ARON_MACRO - ; - - template <typename AronAbstractTypeType> - concept IsAronAbstractType = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronAbstractTypeType, Aron##upperType##Type>::value) - - HANDLE_ALL_ARON_TYPES - #undef RUN_ARON_MACRO - ; - - template <typename AronAbstractTypeType, typename AronData, typename CppType> - concept AreAronAbstractTypeAndPrimitiveDependent = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronAbstractTypeType, Aron##upperType##Type>::value && std::is_same<AronData, Aron##upperType>::value && std::is_same<CppType, lowerType>::value) - - HANDLE_PRIMITIVE_TYPES - #undef RUN_ARON_MACRO - ; - - - - // Compound - template <typename Aron> - concept isAron = IsAronData<Aron> || IsAronAbstractType<Aron>; - - - - - - // AronDataNavigator Concepts - namespace data - { - class AronDataNavigator; - - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##DataNavigator; - - HANDLE_CONTAINER_DATA - #undef RUN_ARON_MACRO - - template<typename AronDataType, typename CppType> requires AreAronPrimitiveDependent<AronDataType, CppType> - class AronPrimitiveDataNavigator; - - template <typename AronDataNavigator> - concept IsAronDataNavigator = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronDataNavigator, Aron##upperType##DataNavigator>::value) - - HANDLE_CONTAINER_DATA - #undef RUN_ARON_MACRO - - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronDataNavigator, AronPrimitiveDataNavigator<Aron##upperType, lowerType>>::value) - - HANDLE_PRIMITIVE_TYPES - #undef RUN_ARON_MACRO - ; - } - - - - - - // AronAbstractTypeNavigator Concepts - namespace types - { - class AronAbstractTypeNavigator; - - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeNavigator; - - HANDLE_CONTAINER_TYPES - #undef RUN_ARON_MACRO - - template<typename AronAbstractTypeType, typename AronDataType, typename CppType> requires AreAronAbstractTypeAndPrimitiveDependent<AronAbstractTypeType, AronDataType, CppType> - class AronPrimitiveTypeNavigator; - - template <typename AronAbstractTypeNavigator> - concept IsAronAbstractTypeNavigator = false - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronAbstractTypeNavigator, Aron##upperType##TypeNavigator>::value) - - HANDLE_CONTAINER_TYPES - #undef RUN_ARON_MACRO - - #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - || (std::is_same<AronAbstractTypeNavigator, AronPrimitiveTypeNavigator<Aron##upperType##Type, Aron##upperType, lowerType>>::value) - - HANDLE_PRIMITIVE_TYPES - #undef RUN_ARON_MACRO - ; - }*/ - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronDebug.h b/source/RobotAPI/libraries/aron/aroncore/AronDebug.h deleted file mode 100644 index b879d8b82ac70ab688ef5f7b7b046af565ff5c7c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronDebug.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h> - -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h> - -namespace armarx -{ - namespace aron - { - class AronDebug - { - public: - AronDebug() = delete; - - static std::string AronDataPtrToString(const data::AronDataPtr& data) - { - io::AronDataNlohmannJSONWriter w; - io::AronDataWriterVisitor::SetupWriterFromAronDataPtr(w, data); - return w.getResult().dump(2); - } - - static std::string AronDataNavigatorPtrToString(const datanavigator::AronDataNavigatorPtr& data) - { - if (data == nullptr) - { - return ""; - } - io::AronDataNlohmannJSONWriter w; - io::AronDataWriterVisitor::SetupWriterFromAronDataPtr(w, data); - return w.getResult().dump(2); - } - - static std::string AronTypePtrToString(const type::AronTypePtr& data) - { - io::AronTypeNlohmannJSONWriter w; - io::AronTypeWriterVisitor::SetupWriterFromAronTypePtr(w, data); - return w.getResult().dump(2); - } - - static std::string AronTypeNavigatorPtrToString(const typenavigator::AronTypeNavigatorPtr& data) - { - if (data == nullptr) - { - return ""; - } - io::AronTypeNlohmannJSONWriter w; - io::AronTypeWriterVisitor::SetupWriterFromAronTypePtr(w, data); - return w.getResult().dump(2); - } - }; - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronException.h b/source/RobotAPI/libraries/aron/aroncore/AronException.h deleted file mode 100644 index 54fc0b95bb455ecaac4b0b9e065d53379a16e464..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronException.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace exception - { - class AronException : - public armarx::LocalException - { - public: - AronException() = delete; - AronException(const std::string& caller, const std::string& method, const std::string& reason) : - LocalException(caller + "::" + method + ": " + reason) - { - - } - }; - - class AronNotImplementedYetException : - public AronException - { - public: - AronNotImplementedYetException() = delete; - AronNotImplementedYetException(const std::string& caller, const std::string& method) : - AronException(caller, method, "This method is not yet implemented!") - { - - } - }; - - class AronExceptionWithPathInfo : - public AronException - { - public: - AronExceptionWithPathInfo() = delete; - AronExceptionWithPathInfo(const std::string& caller, const std::string& method, const std::string& reason, const AronPath& path) : - AronException(caller, method, reason + ". The path was: " + path.toString()) - { - - } - }; - - class AronDataNotValidException : - public AronException - { - public: - AronDataNotValidException() = delete; - AronDataNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const data::AronDataPtr& data) : - AronException(caller, method, reason + ". The ice_id of the data was: " + data->ice_id()) - { - - } - }; - - class AronTypeNotValidException : - public AronException - { - public: - AronTypeNotValidException() = delete; - AronTypeNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const type::AronTypePtr& type) : - AronException(caller, method, reason + ". The ice_id of the type was: " + type->ice_id()) - { - - } - }; - - class AronTypeDescriptorNotValidException : - public AronException - { - public: - AronTypeDescriptorNotValidException() = delete; - AronTypeDescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const AronTypeDescriptor& type) : - AronException(caller, method, reason + ". The name of the type-enum was: " + AronTypeDescriptorToString.at(type)) - { - - } - }; - - class AronDataDescriptorNotValidException : - public AronException - { - public: - AronDataDescriptorNotValidException() = delete; - AronDataDescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const AronDataDescriptor& data) : - AronException(caller, method, reason + ". The name of the data-enum was: " + AronDataDescriptorToString.at(data)) - { - - } - }; - - class AronStringNotValidException : - public AronException - { - public: - AronStringNotValidException() = delete; - AronStringNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const std::string& input) : - AronException(caller, method, reason + ". Got: " + input) - { - - } - }; - - class AronIndexNotValidException : - public AronException - { - public: - AronIndexNotValidException() = delete; - AronIndexNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected) : - AronException(caller, method, reason + ". The measured size is: " + std::to_string(real) + ". The maximum index was: " + std::to_string(expected)) - { - - } - }; - - class AronSizeNotValidException : - public AronException - { - public: - AronSizeNotValidException() = delete; - AronSizeNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected) : - AronException(caller, method, reason + ". The measured size is: " + std::to_string(real) + ". The expected size was: " + std::to_string(expected)) - { - - } - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronFactory.h b/source/RobotAPI/libraries/aron/aroncore/AronFactory.h deleted file mode 100644 index 6ec2b1604afa7fd576895326a9828c6b466647c5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronFactory.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <unordered_map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - -namespace armarx -{ - namespace aron - { - template <typename Input, typename Output> - class AronFactory - { - public: - AronFactory() = default; - - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - }; - - template <typename Input, typename Output> - class AronPtrInputFactory : - virtual public AronFactory<Input, Output> - { - public: - AronPtrInputFactory() = default; - - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - - protected: - static void CheckIfInputIsNull(const std::string& c, const std::string& m, const AronPath& p, const Input& i) - { - if (i.get() == nullptr) - { - throw exception::AronExceptionWithPathInfo(c, m, "The used input is NULL", p); - } - } - }; - - template <typename Input, typename Output> - class AronPtrOutputFactory : - virtual public AronFactory<Input, Output> - { - public: - AronPtrOutputFactory() = default; - - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - - protected: - static void CheckIfOutputIsNull(const std::string& c, const std::string& m, const AronPath& p, const Output& o) - { - if (o.get() == nullptr) - { - throw exception::AronExceptionWithPathInfo(c, m, "The used output is NULL", p); - } - } - }; - - template <typename Input, typename Output> - class AronPtrInputPtrOutputFactory : - virtual public AronPtrInputFactory<Input, Output>, - virtual public AronPtrOutputFactory<Input, Output> - { - public: - AronPtrInputPtrOutputFactory() = default; - - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - }; - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronPath.cpp b/source/RobotAPI/libraries/aron/aroncore/AronPath.cpp deleted file mode 100644 index 6c01b59e43a5c632541fe808ac113319dfe51874..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronPath.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronPath.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - -namespace armarx -{ - namespace aron - { - AronPath::AronPath() : - rootIdentifier("\\"), - delimeter("->") - { - - } - - AronPath::AronPath(const std::vector<std::string>& p) : - path(p) - { - - } - - AronPath::AronPath(const std::string& s, const std::string& d): - rootIdentifier(s), - delimeter(d) - { - - } - - AronPath::AronPath(const std::string& s, const std::string& d, const std::vector<std::string>& p) : - rootIdentifier(s), - delimeter(d), - path(p) - { - - } - - AronPath::AronPath(const AronPath& p) : - rootIdentifier(p.getRootIdentifier()), - delimeter(p.getDelimeter()), - path(p.getPath()) - { - - } - - AronPath::AronPath(const AronPath& p, const std::string& s) : - AronPath(p) - { - appendPath(s); - } - - AronPath::AronPath(const AronPath& p, const std::string& s, const std::string& s2) : - AronPath(p) - { - appendPath(s); - appendPath(s2); - } - - AronPath::AronPath(const AronPath& pa, const std::vector<std::string>& p) : - AronPath(pa) - { - for (const std::string& s : p) - { - appendPath(s); - } - } - - void AronPath::setRootIdentifier(const std::string& s) - { - rootIdentifier = s; - } - - std::string AronPath::getRootIdentifier() const - { - return rootIdentifier; - } - - void AronPath::setDelimeter(const std::string& d) - { - delimeter = d; - } - - std::string AronPath::getDelimeter() const - { - return delimeter; - } - - void AronPath::appendPath(const std::string& str) - { - path.push_back(str); - } - - std::vector<std::string> AronPath::getPath() const - { - return path; - } - - std::string AronPath::getLastElement() const - { - if (!hasElement()) - { - throw exception::AronException("AronNavigatorPath", "getLastElement", "Try to access last element of empty vector."); - } - return path.back(); - } - - std::string AronPath::getFirstElement() const - { - if (!hasElement()) - { - throw exception::AronException("AronNavigatorPath", "getFirstElement", "Try to access last element of empty vector."); - } - return path[0]; - } - - bool AronPath::hasElement() const - { - return path.size() > 0; - } - - size_t AronPath::size() const - { - return path.size(); - } - - std::string AronPath::toString() const - { - std::stringstream ss; - ss << rootIdentifier; - for (const std::string& s : path) - { - ss << delimeter << s; - } - return ss.str(); - } - - AronPath AronPath::withDetachedLastElement() const - { - std::vector<std::string> p = path; - p.pop_back(); - return AronPath(rootIdentifier, delimeter, p); - } - - AronPath AronPath::withDetachedFirstElement() const - { - std::vector<std::string> p = path; - p.erase(p.begin()); - return AronPath(rootIdentifier, delimeter, p); - } - - AronPath AronPath::getWithoutPrefix(const AronPath& pref) const - { - unsigned int firstWithoutMatch = 0; - for (const std::string& el : pref.getPath()) - { - if (path.size() <= firstWithoutMatch || el != path[firstWithoutMatch]) - { - break; - } - else - { - firstWithoutMatch++; - } - } - std::vector<std::string> elementsWithoutPrefix(path.begin() + firstWithoutMatch, path.end()); - return AronPath(rootIdentifier, delimeter, elementsWithoutPrefix); - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronPath.h b/source/RobotAPI/libraries/aron/aroncore/AronPath.h deleted file mode 100644 index 31a5dcdf3eb8c975fe276e921ba000411a149b55..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronPath.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include<vector> -#include<string> - -// ArmarX -#include <RobotAPI/interface/aron.h> - -namespace armarx -{ - namespace aron - { - class AronPath - { - public: - AronPath(); - AronPath(const std::vector<std::string>&); - AronPath(const std::string&, const std::string&); - AronPath(const std::string&, const std::string&, const std::vector<std::string>&); - AronPath(const AronPath&); - AronPath(const AronPath&, const std::string&); - AronPath(const AronPath&, const std::string&, const std::string&); - AronPath(const AronPath&, const std::vector<std::string>&); - AronPath& operator=(const armarx::aron::AronPath&) = default; - - std::vector<std::string> getPath() const; - std::string getFirstElement() const; - std::string getLastElement() const; - bool hasElement() const; - size_t size() const; - - void setRootIdentifier(const std::string&); - std::string getRootIdentifier() const; - - void setDelimeter(const std::string&); - std::string getDelimeter() const; - - std::string toString() const; - - AronPath withDetachedFirstElement() const; - AronPath withDetachedLastElement() const; - AronPath getWithoutPrefix(const AronPath&) const; - - private: - void appendPath(const std::string&); - - private: - std::string rootIdentifier; - std::string delimeter; - std::vector<std::string> path; - }; - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronRandomizer.h b/source/RobotAPI/libraries/aron/aroncore/AronRandomizer.h deleted file mode 100644 index 166eb496abb99e28f5bb8f229e1d95a085f86bc1..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronRandomizer.h +++ /dev/null @@ -1,349 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <numeric> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> - -namespace armarx -{ - namespace aron - { - class AronRandomizer - { - public: - AronRandomizer() - { - initialize_random(); - }; - - typenavigator::AronTypeNavigatorPtr generateRandomType(bool mustBeObject = false) const - { - AronTypeDescriptor nextType = eAronObjectType; - if (!mustBeObject) - { - std::vector<AronTypeDescriptor> descriptors = - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - eAron##upperType##Type, - - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - }; - - int randomType = generateRandom(descriptors.size(), 0); - nextType = descriptors[randomType]; - } - - switch (nextType) - { - case eAronObjectType: - { - typenavigator::AronObjectTypeNavigatorPtr t = typenavigator::AronObjectTypeNavigatorPtr(new typenavigator::AronObjectTypeNavigator(AronPath())); - std::string objectName = generateRandomWord(); - t->setObjectName(objectName); - - std::vector<std::string> usedNames({objectName}); - int members = generateRandom(4, 2); - std::set<std::string> usedKeys; - for (int i = 0; i < members; ++i) - { - std::string key = generateRandomWord(usedKeys); - usedKeys.insert(key); - - typenavigator::AronTypeNavigatorPtr m = generateRandomType(false); - t->addAcceptedType(key, m); - } - return t; - } - case eAronDictType: - { - typenavigator::AronDictTypeNavigatorPtr t = typenavigator::AronDictTypeNavigatorPtr(new typenavigator::AronDictTypeNavigator(AronPath())); - typenavigator::AronTypeNavigatorPtr a = generateRandomType(false); - - t->setAcceptedType(a); - return t; - } - case eAronTupleType: - { - typenavigator::AronTupleTypeNavigatorPtr t = typenavigator::AronTupleTypeNavigatorPtr(new typenavigator::AronTupleTypeNavigator(AronPath())); - - int members = generateRandom(4, 2); - for (int i = 0; i < members; ++i) - { - typenavigator::AronTypeNavigatorPtr m = generateRandomType(false); - t->addAcceptedType(m); - } - return t; - } - case eAronListType: - { - typenavigator::AronListTypeNavigatorPtr t = typenavigator::AronListTypeNavigatorPtr(new typenavigator::AronListTypeNavigator(AronPath())); - typenavigator::AronTypeNavigatorPtr a = generateRandomType(false); - - t->setAcceptedType(a); - return t; - } -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr t = typenavigator::Aron##upperType##TypeNavigatorPtr(new typenavigator::Aron##upperType##TypeNavigator(AronPath())); \ - return t; \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - default: - { - throw armarx::aron::exception::AronTypeDescriptorNotValidException("AronTest", "generateRandomType", "No valid type found!", nextType); - } - } - } - - datanavigator::AronDataNavigatorPtr generateAronDataFromType(const typenavigator::AronTypeNavigatorPtr& type) const - { - const AronTypeDescriptor desc = type->getDescriptor(); - switch (desc) - { - // In an object, we do not want to edit the keys. - case eAronObjectType: - { - typenavigator::AronObjectTypeNavigatorPtr t = typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(type); - datanavigator::AronDictDataNavigatorPtr d = datanavigator::AronDictDataNavigatorPtr(new datanavigator::AronDictDataNavigator()); - for (const auto& [k, tt] : t->getAcceptedTypes()) - { - d->addElement(k, generateAronDataFromType(tt)); - } - return d; - } - - // here all totally random - case eAronDictType: - { - typenavigator::AronDictTypeNavigatorPtr t = typenavigator::AronDictTypeNavigator::DynamicCastAndCheck(type); - return datanavigator::AronDataNavigatorPtr(new datanavigator::AronDictDataNavigator()); - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr t = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(type); \ - return datanavigator::AronDataNavigatorPtr(new datanavigator::AronListDataNavigator()); \ -} - - HANDLE_LIST_SERIALIZER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr t = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(type); \ - return datanavigator::AronDataNavigatorPtr(new datanavigator::AronNDArrayDataNavigator()); \ -} - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr t = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(type); \ - return datanavigator::AronDataNavigatorPtr(new datanavigator::Aron##upperType##DataNavigator()); \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - default: - { - throw armarx::aron::exception::AronTypeDescriptorNotValidException("AronTest", "generateAronDataFromType", "No valid type found!", desc); - } - } - } - - - void initializeRandomly(datanavigator::AronDictDataNavigatorPtr& data, const typenavigator::AronObjectTypeNavigatorPtr& type) const - { - for (auto& [key, nextData] : data->getElements()) - { - initializeRandomly(nextData, type->getAcceptedTypes()[key]); - } - } - - void initializeRandomly(datanavigator::AronDictDataNavigatorPtr& data, const typenavigator::AronDictTypeNavigatorPtr& type) const - { - data->clear(); - int numElements = generateRandom(5, 1); - std::set<std::string> usedKeys; - for (int i = 0; i < numElements; ++i) - { - std::string key = generateRandomWord(usedKeys); - usedKeys.insert(key); - datanavigator::AronDataNavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); - initializeRandomly(newData, type->getAcceptedType()); - data->addElement(key, newData); - } - } - - void initializeRandomly(datanavigator::AronListDataNavigatorPtr& data, const typenavigator::AronTupleTypeNavigatorPtr& type) const - { - unsigned int i = 0; - for (auto& nextData : data->getElements()) - { - initializeRandomly(nextData, type->getAcceptedTypes()[i++]); - } - } - - void initializeRandomly(datanavigator::AronListDataNavigatorPtr& data, const typenavigator::AronListTypeNavigatorPtr& type) const - { - data->clear(); - int numElements = generateRandom(5, 1); - for (int i = 0; i < numElements; ++i) - { - datanavigator::AronDataNavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); - initializeRandomly(newData, type->getAcceptedType()); - data->addElement(newData); - } - } - - void initializeRandomly(datanavigator::AronNDArrayDataNavigatorPtr& data, const typenavigator::AronNDArraySerializerTypeNavigatorPtr& type) const - { - std::vector<int> dims = data->getDimensions(); - int bytes = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); - std::vector<unsigned char> blob = generateRandomBlob(bytes); - data->setData(bytes, blob.data()); - } - - void initializeRandomly(datanavigator::AronIntDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandom(1000, -1000)); - } - - void initializeRandomly(datanavigator::AronLongDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandom(1000, -1000)); - } - - void initializeRandomly(datanavigator::AronFloatDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandom(1000, -1000)); - } - - void initializeRandomly(datanavigator::AronDoubleDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandom(1000, -1000)); - } - - void initializeRandomly(datanavigator::AronBoolDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandom(1, 0)); - } - - void initializeRandomly(datanavigator::AronStringDataNavigatorPtr& data, const typenavigator::AronPrimitiveTypeNavigatorPtr& type) const - { - data->setValue(generateRandomWord()); - } - - void initializeRandomly(datanavigator::AronDataNavigatorPtr& data, const typenavigator::AronTypeNavigatorPtr& type) const - { - // Containers - AronTypeDescriptor desc = type->getDescriptor(); - switch (desc) - { - -#define RUN_ARON_MACRO(upperType, lowerType, capsType, upperData, lowerData, capsData) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr t = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(type); \ - datanavigator::Aron##upperData##DataNavigatorPtr d = datanavigator::Aron##upperData##DataNavigator::DynamicCastAndCheck(data); \ - initializeRandomly(d, t); \ - break; \ -} - - HANDLE_ALL_CORRESPONDING -#undef RUN_ARON_MACRO - - default: - { - throw armarx::aron::exception::AronTypeDescriptorNotValidException("AronTest", "initializeRandomly", "No valid type found!", desc); - } - } - } - - int generateRandom(int max, int min) const - { - max += 1; - int random = (std::rand() % (max - min)) + min; - return random; - } - - std::string generateRandomWord(const std::set<std::string>& usedKeys = {}) const - { - std::vector<string> words = - { - "Lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr" - "sed", "diam", "nonumy", "eirmod", "tempor", "invidunt", "ut", "labore", "et" - "dolore", "magna", "aliquyam", "eratsed" - }; - - int i = generateRandom(words.size() - 1, 0); - std::string key = words[i]; - - while (usedKeys.count(key) > 0) - { - key = generateRandomWord(usedKeys); - } - - return key; - } - - std::vector<unsigned char> generateRandomBlob(unsigned int size) const - { - std::vector<unsigned char> new_blob(size, 0); - for (unsigned int i = 0; i < size; ++i) - { - new_blob[i] = (generateRandom(127, 0)); - } - return new_blob; - } - - protected: - void initialize_random() const - { - std::srand(std::time(nullptr)); - } - }; - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronResolver.cpp b/source/RobotAPI/libraries/aron/aroncore/AronResolver.cpp deleted file mode 100644 index ad82cfb7bcbaff9b8c60a545626895ca74cdd0e0..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronResolver.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Simox -#include <SimoxUtility/meta/type_name.h> - -// Header -#include "AronResolver.h" - -namespace armarx -{ - namespace aron - { - AronTypeDescriptor AronResolver::GetDescriptorForAronType(const type::AronTypePtr& a) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { \ - type::Aron##upperType##TypePtr aron = type::Aron##upperType##TypePtr::dynamicCast(a); \ - if(aron.get() != nullptr) \ - { \ - return eAron##upperType##Type; \ - } \ - } - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - throw exception::AronTypeNotValidException("AronTypeResolver", "GetTypeForAronAbstractType", "Could not cast AronAbstractType to a valid type", a); - } - - AronTypeDescriptor AronResolver::GetDescriptorForAronTypeId(const std::type_index& a) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { \ - if(a == std::type_index(typeid(type::Aron##upperType##Type))) \ - { \ - return eAron##upperType##Type; \ - } \ - } - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - throw exception::AronException("AronTypeResolver", "GetTypeForAronTypeId", "Could not cast AronAbstractTypeId to a valid type. The typeid was " + simox::meta::get_type_name(a)); - } - - AronDataDescriptor AronResolver::GetDescriptorForAronData(const data::AronDataPtr& a) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { \ - data::Aron##upperType##Ptr aron = data::Aron##upperType##Ptr::dynamicCast(a); \ - if(aron.get() != nullptr) \ - { \ - return eAron##upperType; \ - } \ - } - HANDLE_ALL_ARON_DATA -#undef RUN_ARON_MACRO - throw exception::AronDataNotValidException("AronTypeResolver", "GetTypeForAronData", "Could not cast AronData to a valid type", a); - } - - AronDataDescriptor AronResolver::GetDescriptorForAronDataId(const std::type_index& a) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { \ - if(a == std::type_index(typeid(data::Aron##upperType))) \ - { \ - return eAron##upperType; \ - } \ - } - HANDLE_ALL_ARON_DATA -#undef RUN_ARON_MACRO - throw exception::AronException("AronTypeResolver", "GetTypeForAronDataTypeId", "Could not cast AronDataTypeId to a valid type. The typeid was " + simox::meta::get_type_name(a)); - } - - bool AronResolver::TypesAreCorresponding(const AronTypeDescriptor& t, const AronDataDescriptor& d) - { -#define RUN_ARON_MACRO(typeUpperType, typeLowerType, typeCapsType, dataUpperType, dataLowerType, dataCapsType) \ - if(t == AronTypeDescriptor::eAron##typeUpperType##Type && d == AronDataDescriptor::eAron##dataUpperType) \ - { \ - return true; \ - } - - HANDLE_ALL_CORRESPONDING -#undef RUN_ARON_MACRO - return false; - } - - AronDataDescriptor AronResolver::GetCorrespondingDataDescriptor(const AronTypeDescriptor& d) - { -#define RUN_ARON_MACRO(typeUpperType, typeLowerType, typeCapsType, dataUpperType, dataLowerType, dataCapsType) \ - { \ - if(d == eAron##typeUpperType##Type) \ - { \ - return eAron##dataUpperType; \ - } \ - } - HANDLE_ALL_CORRESPONDING -#undef RUN_ARON_MACRO - return eAronUnknown; - } - - bool AronResolver::DescriptorsAreRelated(const AronDataDescriptor& d, const AronDataDescriptor& d2) - { - if (d == d2) - { - return true; - } -#define RUN_ARON_MACRO(data1UpperType, data1LowerType, data1CapsType, data2UpperType, data2LowerType, data2CapsType) \ - if( \ - (d == AronDataDescriptor::eAron##data1UpperType && d2 == AronDataDescriptor::eAron##data2UpperType) || \ - (d2 == AronDataDescriptor::eAron##data1UpperType && d == AronDataDescriptor::eAron##data2UpperType) \ - ) \ - { \ - return true; \ - } - - HANDLE_ARON_PRIMITIVE_DATA_RELATED -#undef RUN_ARON_MACRO - return false; - } - - bool AronResolver::DescriptorsAreRelated(const AronTypeDescriptor& t, const AronTypeDescriptor& t2) - { - if (t == t2) - { - return true; - } -#define RUN_ARON_MACRO(type1UpperType, type1LowerType, type1CapsType, type2UpperType, type2LowerType, type2CapsType) \ - if( \ - (t == AronTypeDescriptor::eAron##type1UpperType##Type && t2 == AronTypeDescriptor::eAron##type2UpperType##Type) || \ - (t2 == AronTypeDescriptor::eAron##type1UpperType##Type && t == AronTypeDescriptor::eAron##type2UpperType##Type) \ - ) \ - { \ - return true; \ - } - - HANDLE_ARON_PRIMITIVE_DATA_RELATED -#undef RUN_ARON_MACRO - return false; - } - - AronDataDescriptor AronResolver::GetFirstIfDescriptorsAreRelated(const AronDataDescriptor& d, const AronDataDescriptor& d2) - { - if (DescriptorsAreRelated(d, d2)) - { - return d; - } - return d2; - } - - AronTypeDescriptor AronResolver::GetFirstIfDescriptorsAreRelated(const AronTypeDescriptor& t, const AronTypeDescriptor& t2) - { - if (DescriptorsAreRelated(t, t2)) - { - return t; - } - return t2; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronResolver.h b/source/RobotAPI/libraries/aron/aroncore/AronResolver.h deleted file mode 100644 index 9bbdf6e15bcb98e5de63e5b93f49a8b0ba5ad481..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/AronResolver.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <typeindex> -#include <typeinfo> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - class AronResolver - { - private: // disallow creating this object. static use only - AronResolver() = delete; - - public: - static AronTypeDescriptor GetDescriptorForAronType(const type::AronTypePtr&); - - static AronTypeDescriptor GetDescriptorForAronTypeId(const std::type_index&); - - static AronDataDescriptor GetDescriptorForAronData(const data::AronDataPtr&); - - static AronDataDescriptor GetDescriptorForAronDataId(const std::type_index&); - - static bool TypesAreCorresponding(const AronTypeDescriptor&, const AronDataDescriptor&); - - static AronDataDescriptor GetCorrespondingDataDescriptor(const AronTypeDescriptor&); - - static bool DescriptorsAreRelated(const AronDataDescriptor&, const AronDataDescriptor&); - static bool DescriptorsAreRelated(const AronTypeDescriptor&, const AronTypeDescriptor&); - - static AronDataDescriptor GetFirstIfDescriptorsAreRelated(const AronDataDescriptor&, const AronDataDescriptor&); - static AronTypeDescriptor GetFirstIfDescriptorsAreRelated(const AronTypeDescriptor&, const AronTypeDescriptor&); - }; - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/CMakeLists.txt b/source/RobotAPI/libraries/aron/aroncore/CMakeLists.txt deleted file mode 100644 index fb75e9b7c50bbdd4d6769d3a371a3c47b24a7e9a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/CMakeLists.txt +++ /dev/null @@ -1,209 +0,0 @@ -set(LIB_NAME aron) - -armarx_component_set_name("${LIB_NAME}") -armarx_set_target("Library: ${LIB_NAME}") - -find_package(Eigen3 QUIET) -armarx_build_if(Eigen3_FOUND "Eigen3 not available") -if(Eigen3_FOUND) - include_directories(${Eigen3_INCLUDE_DIR}) -endif() - -find_package(Simox QUIET) -armarx_build_if(Simox_FOUND "Simox not available") -if(Simox_FOUND) - include_directories(${Simox_INCLUDE_DIR}) -endif() - - -set(LIBS - ArmarXCoreInterfaces - ArmarXCore - RobotAPIInterfaces - cppgen - ${Simox_LIBS} -) - -set(LIB_FILES - AronResolver.cpp - AronPath.cpp - - navigators/datanavigator/AronDataNavigator.cpp - navigators/datanavigator/AronListDataNavigator.cpp - navigators/datanavigator/AronDictDataNavigator.cpp - navigators/datanavigator/AronNDArrayDataNavigator.cpp - navigators/datanavigator/AronPrimitiveDataNavigator.cpp - navigators/datanavigator/AronDataNavigatorFactory.cpp - - navigators/typenavigator/AronTypeNavigator.cpp - navigators/typenavigator/AronObjectTypeNavigator.cpp - navigators/typenavigator/AronListTypeNavigator.cpp - navigators/typenavigator/AronDictTypeNavigator.cpp - navigators/typenavigator/AronTupleTypeNavigator.cpp - navigators/typenavigator/AronEigenMatrixTypeNavigator.cpp - navigators/typenavigator/AronIVTCByteImageTypeNavigator.cpp - navigators/typenavigator/AronOpenCVMatTypeNavigator.cpp - navigators/typenavigator/AronPCLPointCloudTypeNavigator.cpp - navigators/typenavigator/AronPrimitiveTypeNavigator.cpp - navigators/typenavigator/AronTypeNavigatorFactory.cpp - - navigators/visitors/DataVisitor.cpp - navigators/visitors/TypedDataVisitor.cpp - - io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.cpp - io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.cpp - io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.cpp - - io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.cpp - io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.cpp - - io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.cpp - io/AronDataIO/AronDataConverter/AronDataConverter.cpp - - io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.cpp - io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.cpp - io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.cpp - - io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.cpp - io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.cpp - - io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.cpp - io/AronTypeIO/AronTypeConverter/AronTypeConverter.cpp - - codegenerator/codeWriters/cppWriter/AronCppWriter.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.cpp - codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.cpp - - codegenerator/typeReaders/xmlReader/AronTypeXMLData.cpp - codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.cpp - codegenerator/typeReaders/xmlReader/AronTypeXMLReader.cpp -) - -set(LIB_HEADERS - AronDebug.h - AronConfig.h - AronConcepts.h - AronDescriptor.h - AronResolver.h - AronRandomizer.h - AronException.h - AronFactory.h - AronPath.h - - navigators/AronNavigator.h - navigators/AronNavigatorFactory.h - - navigators/datanavigator/AronAllDataNavigators.h - navigators/datanavigator/AronDataNavigator.h - navigators/datanavigator/AronListDataNavigator.h - navigators/datanavigator/AronDictDataNavigator.h - navigators/datanavigator/AronNDArrayDataNavigator.h - navigators/datanavigator/AronPrimitiveDataNavigator.h - navigators/datanavigator/AronDataNavigatorFactory.h - - navigators/typenavigator/AronAllTypeNavigators.h - navigators/typenavigator/AronTypeNavigator.h - navigators/typenavigator/AronObjectTypeNavigator.h - navigators/typenavigator/AronListTypeNavigator.h - navigators/typenavigator/AronDictTypeNavigator.h - navigators/typenavigator/AronTupleTypeNavigator.h - navigators/typenavigator/AronEigenMatrixTypeNavigator.h - navigators/typenavigator/AronIVTCByteImageTypeNavigator.h - navigators/typenavigator/AronOpenCVMatTypeNavigator.h - navigators/typenavigator/AronPCLPointCloudTypeNavigator.h - navigators/typenavigator/AronPrimitiveTypeNavigator.h - navigators/typenavigator/AronTypeNavigatorFactory.h - - navigators/visitors/DataVisitor.h - navigators/visitors/TypedDataVisitor.h - - io/AronReaderWriter.h - io/AronReaderWriterToken.h - io/AronWriterToken.h - io/AronReaderToken.h - - io/AronDataIO/AronDataReaderWriter.h - io/AronDataIO/AronDataWriter.h - io/AronDataIO/classWriters/AronDataClassWriter.h - io/AronDataIO/classWriters/AronDataClassWriterToken.h - io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriterToken.h - io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h - io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h - io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriterToken.h - io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.h - io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriterToken.h - - io/AronDataIO/AronDataReader.h - io/AronDataIO/classReaders/AronDataClassReader.h - io/AronDataIO/classReaders/AronDataClassReaderToken.h - io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReaderToken.h - io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h - io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReaderToken.h - io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h - - io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h - io/AronDataIO/AronDataConverter/AronDataConverter.h - - io/AronTypeIO/AronTypeReaderWriter.h - io/AronTypeIO/AronTypeWriter.h - io/AronTypeIO/classWriters/AronTypeClassWriter.h - io/AronTypeIO/classWriters/AronTypeClassWriterToken.h - io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriterToken.h - io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h - io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h - io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriterToken.h - io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.h - io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriterToken.h - - io/AronTypeIO/AronTypeReader.h - io/AronTypeIO/classReaders/AronTypeClassReader.h - io/AronTypeIO/classReaders/AronTypeClassReaderToken.h - io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.h - io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReaderToken.h - io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h - io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReaderToken.h - - io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h - io/AronTypeIO/AronTypeConverter/AronTypeConverter.h - - codegenerator/AronCppClass.h - codegenerator/AronWriterInfo.h - codegenerator/AronReaderInfo.h - codegenerator/AronGenerateTypeInfo.h - - codegenerator/codeWriters/AronCodeWriter.h - codegenerator/codeWriters/AronSerializerFactory.h - - codegenerator/codeWriters/cppWriter/AronCppWriter.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.h - codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.h - - codegenerator/typeReaders/AronTypeReader.h - codegenerator/typeReaders/xmlReader/AronTypeXMLData.h - codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.h - codegenerator/typeReaders/xmlReader/AronTypeXMLReader.h -) - -armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") - -# add unit tests -add_subdirectory(test) diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronCppClass.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronCppClass.h deleted file mode 100644 index 61d72f288131240ebd45103cf39b72939128726f..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronCppClass.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - class AronCppClass; - typedef std::shared_ptr<AronCppClass> AronCppClassPtr; - - class AronCppClass - { - public: - using PointerType = AronCppClassPtr; - - public: - AronCppClass() = default; - virtual void reset() = 0; - virtual void initialize() = 0; - virtual void read(io::AronDataReader& r) = 0; - virtual void write(io::AronDataWriter& w) const = 0; - virtual void writeCurrentType(armarx::aron::io::AronTypeWriter& w) const = 0; - static void writeType(io::AronTypeWriter& w) - { - throw exception::AronException("AronCppClass", "writeType", "You are not allowed to call this method directly. Each class must inheriting from AronCppClass must implement this static method!"); - }; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronCodeWriter.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronCodeWriter.h deleted file mode 100644 index aeb41664b8876eaddd1b1ab223c8abffb3f76a71..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronCodeWriter.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <map> -#include <vector> -#include <typeinfo> -#include <typeindex> - -// ArmarX -#include <ArmarXCore/libraries/cppgen/MetaClass.h> - -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronWriterInfo.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronReaderInfo.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - class AronCodeWriter - { - public: - AronCodeWriter() = delete; - AronCodeWriter(const std::string& producerName, const std::vector<std::string>& additionalIncludesFromXMLFile): - producerName(producerName), - additionalIncludes(additionalIncludesFromXMLFile) - {} - virtual void generateTypeClasses(const std::vector<AronGenerateTypeInfoPtr>&) = 0; - - std::vector<MetaClassPtr> getTypeClasses() const - { - return typeClasses; - } - - protected: - virtual void addFromAronMethod() = 0; - virtual void addToAronMethod() = 0; - virtual void addToAronTypeMethod() = 0; - - protected: - std::vector<MetaClassPtr> typeClasses; - - std::string producerName; - std::vector<AronWriterInfoPtr> dataWriters; - std::vector<AronReaderInfoPtr> dataReaders; - std::vector<AronWriterInfoPtr> initialTypeWriters; - std::vector<AronWriterInfoPtr> currentTypeWriters; - std::vector<AronReaderInfoPtr> typeReaders; - std::vector<std::string> additionalIncludes; - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronSerializerFactory.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronSerializerFactory.h deleted file mode 100644 index c595c4e7a8d09058b01f2fd9731f496ce04a8a27..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronSerializerFactory.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <unordered_map> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/AronFactory.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - template <typename Input, typename Output> - class AronSerializerFactory : - virtual public AronPtrInputPtrOutputFactory<Input, Output> - { - public: - AronSerializerFactory() = default; - - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.cpp deleted file mode 100644 index c22a9cd656de7f76538238e32679e80fdb8e59e9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - - -// Simox -#include <SimoxUtility/algorithm/string.h> - -// Header -#include "AronCppWriter.h" - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - AronTypeClassCppWriter::AronTypeClassCppWriter(const std::string& producerName, const std::vector<std::string>& additionalIncludesFromXMLFile) : - AronCodeWriter(producerName, additionalIncludesFromXMLFile) - { - addToAronMethod(); - addFromAronMethod(); - addToAronTypeMethod(); - } - - void AronTypeClassCppWriter::addToAronMethod() - { - // The toAron Serializer is visible by default - { - AronWriterInfoPtr toAron = AronWriterInfoPtr(new AronWriterInfo()); - toAron->methodName = "toAron"; - toAron->returnType = "armarx::aron::datanavigator::AronDictDataNavigatorPtr"; - toAron->writerClassType = "armarx::aron::io::AronDataNavigatorWriter"; - toAron->include = "<RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h>"; - dataWriters.push_back(toAron); - } - } - - void AronTypeClassCppWriter::addFromAronMethod() - { - // The toAron Serializer is visible by default - { - AronReaderInfoPtr fromAron = AronReaderInfoPtr(new AronReaderInfo()); - fromAron->methodName = "fromAron"; - fromAron->argumentType = "armarx::aron::datanavigator::AronDictDataNavigatorPtr"; - fromAron->readerClassType = "armarx::aron::io::AronDataNavigatorReader"; - fromAron->include = "<RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h>"; - dataReaders.push_back(fromAron); - } - { - AronReaderInfoPtr fromAron = AronReaderInfoPtr(new AronReaderInfo()); - fromAron->methodName = "fromAron"; - fromAron->argumentType = "armarx::aron::data::AronDictPtr"; - fromAron->readerClassType = "armarx::aron::io::AronDataNavigatorReader"; - dataReaders.push_back(fromAron); - } - } - - void AronTypeClassCppWriter::addToAronTypeMethod() - { - // The toAron Serializer is visible by default - AronWriterInfoPtr toAronType = AronWriterInfoPtr(new AronWriterInfo()); - toAronType->methodName = "toInitialAronType"; - toAronType->returnType = "armarx::aron::typenavigator::AronObjectTypeNavigatorPtr"; - toAronType->writerClassType = "armarx::aron::io::AronTypeNavigatorWriter"; - toAronType->include = "<RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h>"; - initialTypeWriters.push_back(toAronType); - - // The toAron Serializer is visible by default - AronWriterInfoPtr toAronType2 = AronWriterInfoPtr(new AronWriterInfo()); - toAronType2->methodName = "toCurrentAronType"; - toAronType2->returnType = "armarx::aron::typenavigator::AronObjectTypeNavigatorPtr"; - toAronType2->writerClassType = "armarx::aron::io::AronTypeNavigatorWriter"; - currentTypeWriters.push_back(toAronType2); - } - - void AronTypeClassCppWriter::generateTypeClasses(const std::vector<AronGenerateTypeInfoPtr>& generateTypes) - { - for (const auto& publicGenerateObjectType : generateTypes) - { - // Convert to Object type and create class object - if (publicGenerateObjectType->correspondingObjectType == nullptr) - { - throw exception::AronException("AronTypeClassCppWriter", "generateTypeClasses", "An received public type is null. Abort due to error!"); - } - - cppSerializer::AronObjectTypeCppSerializerPtr objectSerializer = cppSerializer::AronObjectTypeCppSerializerPtr(new cppSerializer::AronObjectTypeCppSerializer(publicGenerateObjectType->correspondingObjectType)); - - CppClassPtr c = setupCppClassFromObjectType(publicGenerateObjectType->correspondingObjectType); - if (publicGenerateObjectType->correspondingObjectType->getExtends() != nullptr) - { - cppSerializer::AronObjectTypeCppSerializerPtr extendsSerializer = cppSerializer::AronObjectTypeCppSerializerPtr(new cppSerializer::AronObjectTypeCppSerializer(publicGenerateObjectType->correspondingObjectType->getExtends())); - c->addInherit(extendsSerializer->getCppTypename()); - } - else - { - c->addInherit("virtual public armarx::aron::codegeneration::AronCppClass"); - c->addInclude("<RobotAPI/libraries/aron/aroncore/codegenerator/AronCppClass.h>"); - } - - // Add includes and guard - c->addClassDoc("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" - "!!!!!!AUTOGENERATED CLASS. Please do NOT edit. Instead, edit the corresponding .xml file!!!!!!\n" - "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); - c->setPragmaOnceIncludeGuard(true); - c->addInclude("<memory>"); - c->addInclude("<string>"); - c->addInclude("<vector>"); - c->addInclude("<map>"); - c->addInclude("<RobotAPI/interface/aron.h>"); - for (const std::string& s : additionalIncludes) - { - if (!s.empty()) - { - c->addInclude(s); - } - } - - generateInnerTypeClasses(c, publicGenerateObjectType->nestedObjects); - - // ctor - c->addCtor(objectSerializer->toCtor(c->getName())); - - // Generic methods - CppMethodPtr equals = objectSerializer->toEqualsMethod(); - c->addMethod(equals); - - CppMethodPtr reset = objectSerializer->toResetMethod(); - c->addMethod(reset); - - CppMethodPtr setup = objectSerializer->toInitializeMethod(); - c->addMethod(setup); - - CppMethodPtr writeInitialType = objectSerializer->toWriteInitialTypeMethod(); - c->addMethod(writeInitialType); - - CppMethodPtr writeCurrentType = objectSerializer->toWriteCurrentTypeMethod(); - c->addMethod(writeCurrentType); - - CppMethodPtr write = objectSerializer->toWriteMethod(); - c->addMethod(write); - - CppMethodPtr read = objectSerializer->toReadMethod(); - c->addMethod(read); - - // Writermethods - for (const AronWriterInfoPtr& info : dataWriters) - { - if (!info->include.empty()) - { - c->addInclude(info->include); - } - CppMethodPtr convert = objectSerializer->toSpecializedDataWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::datanavigator::AronDictDataNavigator::DynamicCast"); - c->addMethod(convert); - } - - // Add methods to set the member variables - for (const AronReaderInfoPtr& info : dataReaders) - { - if (!info->include.empty()) - { - c->addInclude(info->include); - } - CppMethodPtr convert = objectSerializer->toSpecializedDataReaderMethod(info->argumentType, info->methodName, info->readerClassType); - c->addMethod(convert); - } - - // Typewritermethods - for (const AronWriterInfoPtr& info : initialTypeWriters) - { - if (!info->include.empty()) - { - c->addInclude(info->include); - } - CppMethodPtr convert = objectSerializer->toSpecializedInitialTypeWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::typenavigator::AronObjectTypeNavigator::DynamicCast"); - c->addMethod(convert); - } - - // Typewritermethods - for (const AronWriterInfoPtr& info : currentTypeWriters) - { - if (!info->include.empty()) - { - c->addInclude(info->include); - } - CppMethodPtr convert = objectSerializer->toSpecializedCurrentTypeWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::typenavigator::AronObjectTypeNavigator::DynamicCast"); - c->addMethod(convert); - } - - // Add methods to set the member variables - for (const AronReaderInfoPtr& info : typeReaders) - { - if (!info->include.empty()) - { - c->addInclude(info->include); - } - CppMethodPtr convert = objectSerializer->toSpecializedCurrentTypeReaderMethod(info->argumentType, info->methodName, info->readerClassType); - c->addMethod(convert); - } - - typeClasses.push_back(c); - } - } - - void AronTypeClassCppWriter::generateInnerTypeClasses(CppClassPtr& classToAdd, const std::map<std::string, AronGenerateTypeInfoPtr>& localGenerateTypes) - { - // setup inner classes - for (const auto& [_, localGenerateObjectType] : localGenerateTypes) - { - cppSerializer::AronObjectTypeCppSerializerPtr objectSerializer = cppSerializer::AronObjectTypeCppSerializerPtr(new cppSerializer::AronObjectTypeCppSerializer(localGenerateObjectType->correspondingObjectType)); - - CppClassPtr c = setupCppClassFromObjectType(localGenerateObjectType->correspondingObjectType); - if (localGenerateObjectType->correspondingObjectType->getExtends() != nullptr) - { - cppSerializer::AronObjectTypeCppSerializerPtr extendsSerializer = cppSerializer::AronObjectTypeCppSerializerPtr(new cppSerializer::AronObjectTypeCppSerializer(localGenerateObjectType->correspondingObjectType->getExtends())); - c->addInherit(extendsSerializer->getCppTypename()); - } - else - { - c->addInherit("virtual public armarx::aron::codegeneration::AronCppClass"); - } - - CppMethodPtr equals = objectSerializer->toEqualsMethod(); - c->addMethod(equals); - - CppMethodPtr reset = objectSerializer->toResetMethod(); - c->addMethod(reset); - - CppMethodPtr setup = objectSerializer->toInitializeMethod(); - c->addMethod(setup); - - CppMethodPtr writeInitialType = objectSerializer->toWriteInitialTypeMethod(); - c->addMethod(writeInitialType); - - CppMethodPtr writeCurrentType = objectSerializer->toWriteCurrentTypeMethod(); - c->addMethod(writeCurrentType); - - CppMethodPtr write = objectSerializer->toWriteMethod(); - c->addMethod(write); - - CppMethodPtr read = objectSerializer->toReadMethod(); - c->addMethod(read); - - generateInnerTypeClasses(c, localGenerateObjectType->nestedObjects); - classToAdd->addInnerClass(c); - } - } - - CppClassPtr AronTypeClassCppWriter::setupCppClassFromObjectType(const typenavigator::AronObjectTypeNavigatorPtr& o) const - { - cppSerializer::AronObjectTypeCppSerializerPtr objectSerializer = cppSerializer::AronObjectTypeCppSerializerPtr(new cppSerializer::AronObjectTypeCppSerializer(o)); - - std::string cppTypename = objectSerializer->getCppTypename(); - std::vector<std::string> split = simox::alg::split(cppTypename, "::"); - if (split.size() < 1) - { - throw exception::AronException("AronTypeClassCppWriter", "setupCppClassFromObjectType", "The cpp name of an inner type was empty. Please check the type definition file if all object names are set correctly."); - } - - std::vector<std::string> namespaces(split); - namespaces.pop_back(); - - CppClassPtr c = CppClassPtr(new CppClass(namespaces, split[split.size() - 1])); - - for (const auto& [key, child] : o->getAcceptedTypes()) - { - cppSerializer::AronTypeCppSerializerPtr child_s = cppSerializer::AronTypeCppSerializer::FromAronTypeNaviagtorPtr(child); - c->addPublicField(child_s->getCppTypename() + " " + key + ";"); - } - return c; - } - } - } - } -} - - - - - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.h deleted file mode 100644 index 227392d597aaa068444d4546adf6f73f4ce26351..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/AronCppWriter.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <set> -#include <map> -#include <vector> - -// Parent class -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronCodeWriter.h> - -// ArmarX -#include <ArmarXCore/libraries/cppgen/CppMethod.h> -#include <ArmarXCore/libraries/cppgen/CppClass.h> - -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - class AronTypeClassCppWriter; - typedef std::shared_ptr<AronTypeClassCppWriter> AronConnectorCppWriterPtr; - - class AronTypeClassCppWriter : - virtual public AronCodeWriter - { - public: - AronTypeClassCppWriter() = delete; - AronTypeClassCppWriter(const std::string&, const std::vector<std::string>&); - - virtual void generateTypeClasses(const std::vector<AronGenerateTypeInfoPtr>&) override; - - protected: - virtual void addToAronMethod() override; - virtual void addFromAronMethod() override; - virtual void addToAronTypeMethod() override; - - private: - void generateInnerTypeClasses(CppClassPtr& classToAdd, const std::map<std::string, AronGenerateTypeInfoPtr>& localGenerateTypes); - CppClassPtr setupCppClassFromObjectType(const typenavigator::AronObjectTypeNavigatorPtr&) const; - - private: - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h deleted file mode 100644 index 2154806d9f7646c151eb07472e733cbad9e80b6e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.h> diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.cpp deleted file mode 100644 index 2918f4035f29ad81d8fc9bbe60c82825dc1dc06e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronDictTypeCppSerializer.h" - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - const std::string AronDictTypeCppSerializer::DICT_ITERATOR_ACCESSOR = "_iterator"; - const std::string AronDictTypeCppSerializer::DICT_KEY_ACCESSOR = "_key"; - const std::string AronDictTypeCppSerializer::DICT_VALUE_ACCESSOR = "_value"; - - // constructors - AronDictTypeCppSerializer::AronDictTypeCppSerializer(const typenavigator::AronDictTypeNavigatorPtr& n) : - AronTypeCppSerializer("std::map<std::string, " + FromAronTypeNaviagtorPtr(n->getAcceptedType())->getCppTypename() + ">", simox::meta::get_type_name(typeid(data::AronDict)), simox::meta::get_type_name(typeid(type::AronDictType))), - typenavigator(n) - { - - } - - // virtual implementations - std::vector<CppFieldPtr> AronDictTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronDictTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronDictTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + ".clear();"); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = {};"); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getWriteInitialTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartDictType();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(type_s->getCppTypename()); - b->appendBlock(b2); - b->addLine("w.writeEndDictType();"); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartDictType();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - CppBlockPtr b2 = type_s->getWriteCurrentTypeBlock(type_s->getCppTypename()); - b->appendBlock(b2); - b->addLine("w.writeEndDictType();"); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartDict();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator_key = escaped_accessor + DICT_KEY_ACCESSOR; - std::string accessor_iterator_val = escaped_accessor + DICT_VALUE_ACCESSOR; - - b->addLine("for (const auto& [" + accessor_iterator_key + ", " + accessor_iterator_val + "] : " + accessor + ") "); - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - b2->addLine("w.writeKey(" + accessor_iterator_key + ");"); - b2 = CppBlock::MergeBlocks(b2, type_s->getWriteBlock(accessor_iterator_val)); - b->addBlock(b2); - - b->addLine("w.writeEndDict();"); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + ".clear();"); - b->addLine("r.readStartDict();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; - std::string accessor_iterator_key = escaped_accessor + DICT_KEY_ACCESSOR; - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - - b->addLine("while(!r.readEndDict())"); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - b2->addLine("std::string " + accessor_iterator_key + " = r.readKey();"); - b2->addLine(type_s->getCppTypename() + " " + accessor_iterator + ";"); - b2 = CppBlock::MergeBlocks(b2, type_s->getReadBlock(accessor_iterator)); - b2->addLine(accessor + "[" + accessor_iterator_key + "] = " + accessor_iterator + ";"); - - b->addBlock(b2); - return b; - } - - CppBlockPtr AronDictTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.h deleted file mode 100644 index bf0b9d031e474782b74842dca55f372ec347ca33..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronDictTypeCppSerializer.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h> - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronDictTypeCppSerializer; - typedef std::shared_ptr<AronDictTypeCppSerializer> AronDictTypeCppSerializerPtr; - - class AronDictTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronDictTypeCppSerializerPtr; - - public: - // constructors - AronDictTypeCppSerializer() = delete; - AronDictTypeCppSerializer(const typenavigator::AronDictTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // Members - static const std::string DICT_ITERATOR_ACCESSOR; - static const std::string DICT_KEY_ACCESSOR; - static const std::string DICT_VALUE_ACCESSOR; - - typenavigator::AronDictTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.cpp deleted file mode 100644 index e74e3b24b1bdbe5f111320376108242f9d9ac876..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronEigenMatrixTypeCppSerializer.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::map<std::string, std::pair<std::string, int>> AronEigenMatrixTypeCppSerializer::ACCEPTED_TYPES = - { - {"short", {"short", 2}}, - {"int", {"int", 4}}, - {"long", {"long", 8}}, - {"float", {"float", 4}}, - {"double", {"double", 8}}, - //{"complex float", {"std::complex<float>", ???}}, - //{"complex double", {"std::complex<double>", ???}} - }; - - // constructors - AronEigenMatrixTypeCppSerializer::AronEigenMatrixTypeCppSerializer(const typenavigator::AronEigenMatrixTypeNavigatorPtr& n) : - AronTypeCppSerializer("std::shared_ptr<::Eigen::Matrix<" + ACCEPTED_TYPES.at(n->getUsedType()).first + ", " + std::to_string(n->getRows()) + ", " + std::to_string(n->getCols()) + ">>", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronEigenMatrixType))), - typenavigator(n) - { - } - - std::vector<CppFieldPtr> AronEigenMatrixTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronEigenMatrixTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new ::Eigen::Matrix<" + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + ", " + std::to_string(typenavigator->getRows()) + ", " + std::to_string(typenavigator->getCols()) + ">());"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - simox::alg::to_string<int>(typenavigator->getDimensions(), ", "); - b->addLine("w.writeEigenMatrixType({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - simox::alg::to_string<int>(typenavigator->getDimensions(), ", "); - b->addLine("w.writeEigenMatrixType({" + accessor + "->rows(), " + accessor + "->cols()}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new ::Eigen::Matrix<" + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + ", " + std::to_string(typenavigator->getRows()) + ", " + std::to_string(typenavigator->getCols()) + ">());"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeNDArray({" + accessor + "->rows(), " + accessor + "->cols(), " + std::to_string(ACCEPTED_TYPES.at(typenavigator->getUsedType()).second) + "}, \"" + typenavigator->getUsedType() + "\", reinterpret_cast<unsigned char*>(" + accessor + "->data()));"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("r.readStartNDArray(); // We do not need the dims and type since a EigenMat can not change (templated)"); - b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + "->data()));"); - return b; - } - - CppBlockPtr AronEigenMatrixTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (not (" + accessor + "->isApprox(*" + otherInstanceAccessor + ")))"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.h deleted file mode 100644 index fbc998f7f3072cc385c37f3778b2d60f56e621b0..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronEigenMatrixTypeCppSerializer.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronEigenMatrixTypeCppSerializer; - typedef std::shared_ptr<AronEigenMatrixTypeCppSerializer> AronEigenMatrixTypeCppSerializerPtr; - - class AronEigenMatrixTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronEigenMatrixTypeCppSerializerPtr; - - public: - // constructors - AronEigenMatrixTypeCppSerializer(const typenavigator::AronEigenMatrixTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // Members - static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; - - typenavigator::AronEigenMatrixTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.cpp deleted file mode 100644 index 200ea10097b9e2685995d518648ebee31b442dcf..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronIVTCByteImageTypeCppSerializer.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::map<std::string, std::pair<std::string, int>> AronIVTCByteImageTypeCppSerializer::ACCEPTED_TYPES = - { - {"GrayScale", {"CByteImage::ImageType::eGrayScale", 1}}, - {"RGB24", {"CByteImage::ImageType::eRGB24", 3}}, - {"RGB24Split", {"CByteImage::ImageType::eRGB24Split", 3}} - }; - - // constructors - AronIVTCByteImageTypeCppSerializer::AronIVTCByteImageTypeCppSerializer(const typenavigator::AronIVTCByteImageTypeNavigatorPtr& e) : - AronTypeCppSerializer("std::shared_ptr<CByteImage>", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronIVTCByteImageType))), - typenavigator(e) - { - // check if type exists - ACCEPTED_TYPES.at(typenavigator->getUsedType()); - } - - std::vector<CppFieldPtr> AronIVTCByteImageTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronIVTCByteImageTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new CByteImage(" + accessor + "->width, " + accessor + "->height, " + accessor + "->type));"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new CByteImage(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + ", " + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + "));"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeIVTCByteImageType({" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + "}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeIVTCByteImageType({" + accessor + "->width, " + accessor + "->height} \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeNDArray({" + accessor + "->width, " + accessor + "->height, " + accessor + "->bytesPerPixel}, std::to_string(" + accessor + "->type), reinterpret_cast<unsigned char*>(" + accessor + "->pixels));"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("const auto [dims, type] = r.readStartNDArray();"); - b->addLine(accessor + " = " + getCppTypename() + "(new CByteImage(dims[0], dims[1], static_cast<CByteImage::ImageType>(std::stoi(type))));"); - b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + "->pixels));"); - return b; - } - - CppBlockPtr AronIVTCByteImageTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (not (" + accessor + "->IsCompatible(" + otherInstanceAccessor + ".get())))"); - b->addLine("\t return false;"); - b->addLine("if (not (memcmp(" + accessor + "->pixels, " + otherInstanceAccessor + "->pixels, " + accessor + "->width * " + accessor + "->height * " + accessor + "->bytesPerPixel) == 0))"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.h deleted file mode 100644 index da6382571b063134a9802ffd285ab1ece39c25d4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronIVTCByteImageTypeCppSerializer.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronIVTCByteImageTypeCppSerializer; - typedef std::shared_ptr<AronIVTCByteImageTypeCppSerializer> AronIVTCByteImageTypeCppSerializerPtr; - - class AronIVTCByteImageTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronIVTCByteImageTypeCppSerializerPtr; - - public: - // constructors - AronIVTCByteImageTypeCppSerializer(const typenavigator::AronIVTCByteImageTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; - - typenavigator::AronIVTCByteImageTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.cpp deleted file mode 100644 index b44448dcdf84777d6c6837e1b6e317d57559b7a2..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronListTypeCppSerializer.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - const std::string AronListTypeCppSerializer::LIST_ITERATOR_ACCESSOR = "_iterator"; - - // constructors - AronListTypeCppSerializer::AronListTypeCppSerializer(const typenavigator::AronListTypeNavigatorPtr& e) : - AronTypeCppSerializer("std::vector<" + FromAronTypeNaviagtorPtr(e->getAcceptedType())->getCppTypename() + ">", simox::meta::get_type_name(typeid(data::AronList)), simox::meta::get_type_name(typeid(type::AronListType))), - typenavigator(e) - { - - } - - std::vector<CppFieldPtr> AronListTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronListTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronListTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + ".clear();"); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = {};"); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartListType();"); - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - - CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(type_s->getCppTypename()); - b->appendBlock(b2); - - b->addLine("w.writeEndListType();"); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getWriteCurrentTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartListType();"); - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - - CppBlockPtr b2 = type_s->getWriteCurrentTypeBlock(type_s->getCppTypename()); - b->appendBlock(b2); - - b->addLine("w.writeEndListType();"); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartList();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR; - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - b->addLine("for(unsigned int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + ".size(); ++" + accessor_iterator + ")"); - CppBlockPtr b2 = type_s->getWriteBlock(accessor + "[" + accessor_iterator + "]"); - b->addBlock(b2); - b->addLine("w.writeEndList();"); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + ".clear();"); - b->addLine("r.readStartList();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR; - - b->addLine("while(!r.readEndList())"); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - - auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); - b2->addLine(type_s->getCppTypename() + " " + accessor_iterator + ";"); - b2 = CppBlock::MergeBlocks(b2, type_s->getReadBlock(accessor_iterator)); - b2->addLine(accessor + ".push_back(" + accessor_iterator + ");"); - - b->addBlock(b2); - return b; - } - - CppBlockPtr AronListTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.h deleted file mode 100644 index 0caa35d539eb10424541582638e8fe7cb3e0522c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronListTypeCppSerializer.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <vector> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - class AronListTypeCppSerializer; - typedef std::shared_ptr<AronListTypeCppSerializer> AronListTypeCppSerializerPtr; - - class AronListTypeCppSerializer : - public AronTypeCppSerializer - { - public: - using PointerType = AronListTypeCppSerializerPtr; - - public: - // constructors - AronListTypeCppSerializer(const typenavigator::AronListTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::string LIST_ITERATOR_ACCESSOR; - - typenavigator::AronListTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.cpp deleted file mode 100644 index 312847cef04a904fb014728558efdf6c2061aa67..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronObjectTypeCppSerializer.h" - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::string AronObjectTypeCppSerializer::EXTENDS_ITERATOR_ACCESSOR = "_extends"; - - // constructors - AronObjectTypeCppSerializer::AronObjectTypeCppSerializer(const typenavigator::AronObjectTypeNavigatorPtr& e) : - AronTypeCppSerializer(e->getObjectName(), simox::meta::get_type_name(typeid(data::AronDict)), simox::meta::get_type_name(typeid(type::AronObjectType))), - typenavigator(e) - { - //AddObjectTypeToAllObjectTypesList(AronObjectTypeNavigatorPtr(this)); - } - - std::vector<CppFieldPtr> AronObjectTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - if (name == "") // object defintiion - { - std::vector<CppFieldPtr> fields; - for (const auto& [key, member] : typenavigator->getAcceptedTypes()) - { - auto member_s = FromAronTypeNaviagtorPtr(member); - std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key); - fields.insert(fields.end(), member_fields.begin(), member_fields.end()); - } - return fields; - } - else // object usage - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - }; - } - - std::vector<std::pair<std::string, std::string>> AronObjectTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronObjectTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine(extends_s->getCppTypename() + "::reset();"); - } - - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - auto child_s = FromAronTypeNaviagtorPtr(child); - CppBlockPtr b2 = child_s->getResetBlock((accessor != "" ? (accessor + "." + key) : key)); - b->appendBlock(b2); - } - } - else - { - b->addLine(accessor + ".reset();"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine(extends_s->getCppTypename() + "::initialize();"); - } - - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - const auto child_s = FromAronTypeNaviagtorPtr(child); - CppBlockPtr b2 = child_s->getInitializeBlock((accessor != "" ? (accessor + "." + key) : key)); - b->appendBlock(b2); - } - } - else - { - b->addLine(accessor + ".initialize();"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getWriteInitialTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine(extends_s->getCppTypename() + "::writeInitialType(w);"); - } - - b->addLine("w.writeStartObjectType();"); - b->addLine("w.writeObjectName(\"" + typenavigator->getObjectName() + "\");"); - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - const auto child_s = FromAronTypeNaviagtorPtr(child); - b->addLine("w.writeKey(\"" + key + "\");"); - CppBlockPtr b2 = child_s->getWriteInitialTypeBlock(child_s->getCppTypename()); - b->appendBlock(b2); - } - b->addLine("w.writeEndObjectType();"); - } - else - { - b->addLine(accessor + "::writeInitialType(w);"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - //b->addLine(extends_s->getCppTypename() + ".writeCurrentType(w);"); TODO - } - - b->addLine("w.writeStartObjectType();"); - b->addLine("w.writeObjectName(\"" + typenavigator->getObjectName() + "\");"); - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - const auto child_s = FromAronTypeNaviagtorPtr(child); - b->addLine("w.writeKey(\"" + key + "\");"); - CppBlockPtr b2 = child_s->getWriteCurrentTypeBlock(child_s->getCppTypename()); - b->appendBlock(b2); - } - b->addLine("w.writeEndObjectType();"); - } - else - { - b->addLine(accessor + ".writeCurrentType(w);"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine(extends_s->getCppTypename() + "::write(w, aron_type);"); - } - - b->addLine("w.writeStartDict();"); - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - const auto child_s = FromAronTypeNaviagtorPtr(child); - b->addLine("w.writeKey(\"" + key + "\");"); - CppBlockPtr b2 = child_s->getWriteBlock((accessor != "" ? (accessor + "." + key) : key)); - b->appendBlock(b2); - } - b->addLine("w.writeEndDict();"); - } - else - { - b->addLine(accessor + ".write(w);"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - if (accessor == "") - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine(extends_s->getCppTypename() + "::read(r);"); - } - - b->addLine("r.readStartDict();"); - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - const auto child_s = FromAronTypeNaviagtorPtr(child); - b->addLine("r.readKey(\"" + key + "\");"); - CppBlockPtr b2 = child_s->getReadBlock((accessor != "" ? (accessor + "." + key) : key)); - b->appendBlock(b2); - } - b->addLine("r.readEndDict();"); - } - else - { - b->addLine(accessor + ".read(r);"); - } - return b; - } - - CppBlockPtr AronObjectTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - if (accessor == "") // object definition, so we are no member of some other class - { - if (typenavigator->getExtends() != nullptr) - { - const auto extends_s = FromAronTypeNaviagtorPtr(typenavigator->getExtends()); - b->addLine("if (not (" + extends_s->getCppTypename() + "::operator== (" + otherInstanceAccessor + ")))"); - b->addLine("\t return false;"); - } - for (const auto& [key, child] : typenavigator->getAcceptedTypes()) - { - auto child_s = FromAronTypeNaviagtorPtr(child); - CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key); - b->appendBlock(b2); - } - } - else // object usage with existing operator== - { - b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); - b->addLine("\t return false;"); - } - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.h deleted file mode 100644 index a1d6c27d2adb3ea775b559e777fc736554646064..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronObjectTypeCppSerializer.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronObjectTypeCppSerializer; - typedef std::shared_ptr<AronObjectTypeCppSerializer> AronObjectTypeCppSerializerPtr; - - class AronObjectTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronObjectTypeCppSerializerPtr; - - public: - // constructors - AronObjectTypeCppSerializer(const typenavigator::AronObjectTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::string EXTENDS_ITERATOR_ACCESSOR; - - typenavigator::AronObjectTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.cpp deleted file mode 100644 index 5b76c62e07283ac406bc8043c7c4cf057fcf672b..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronOpenCVMatTypeCppSerializer.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::map<std::string, std::pair<std::string, int>> AronOpenCVMatTypeCppSerializer::ACCEPTED_TYPES = - { - {"CV_8U", {"CV_8U", 1}}, - {"CV_8S", {"CV_8S", 1}}, - {"CV_16U", {"CV_16U", 2}}, - {"CV_16S", {"CV_16S", 2}}, - {"CV_32S", {"CV_32S", 4}}, - {"CV_32F", {"CV_32F", 4}}, - {"CV_64F", {"CV_64F", 8}}, - }; - - const std::string AronOpenCVMatTypeCppSerializer::OPENCVMAT_ITERATOR_ACCESSOR = "_iterator"; - const std::string AronOpenCVMatTypeCppSerializer::OPENCVMAT_DIMENSIONS_ACCESSOR = "_dimensions"; - const std::string AronOpenCVMatTypeCppSerializer::OPENCVMAT_DIFF_ACCESSOR = "_dimensions"; - - // constructors - AronOpenCVMatTypeCppSerializer::AronOpenCVMatTypeCppSerializer(const typenavigator::AronOpenCVMatTypeNavigatorPtr& e) : - AronTypeCppSerializer("std::shared_ptr<cv::Mat>", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronOpenCVMatType))), - typenavigator(e) - { - // check if type exists - ACCEPTED_TYPES.at(e->getUsedType()); - } - - std::vector<CppFieldPtr> AronOpenCVMatTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronOpenCVMatTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_dimensions = escaped_accessor + OPENCVMAT_DIMENSIONS_ACCESSOR; - std::string accessor_iterator = escaped_accessor + OPENCVMAT_ITERATOR_ACCESSOR; - - b->addLine("std::vector<int> " + accessor_dimensions + ";"); - b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + "->dims; ++" + accessor_iterator + ")"); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - b2->addLine(accessor_dimensions + ".push_back(" + accessor + "->size[" + accessor_iterator + "]);"); - b->appendBlock(b2); - b->addLine(accessor + " = " + getCppTypename() + "(new cv::Mat(" + accessor_dimensions + ", " + accessor + "->type()));"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new cv::Mat(std::vector<int>({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}), " + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + "));"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeOpenCVMatType({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_dimensions = escaped_accessor + OPENCVMAT_DIMENSIONS_ACCESSOR; - std::string accessor_iterator = escaped_accessor + OPENCVMAT_ITERATOR_ACCESSOR; - - b->addLine("std::vector<int> " + accessor_dimensions + ";"); - b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + "->dims; ++" + accessor_iterator + ")"); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - b2->addLine(accessor_dimensions + ".push_back(" + accessor + "->size[" + accessor_iterator + "]);"); - b->appendBlock(b2); - b->addLine("w.writeOpenCVMatType(" + accessor_dimensions + ", std::to_string(" + accessor + "->type()));"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - std::string escaped_accessor = EscapeAccessor(accessor); - std::string accessor_dimensions = escaped_accessor + OPENCVMAT_DIMENSIONS_ACCESSOR; - std::string accessor_iterator = escaped_accessor + OPENCVMAT_ITERATOR_ACCESSOR; - - b->addLine("std::vector<int> " + accessor_dimensions + ";"); - b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + "->dims; ++" + accessor_iterator + ")"); - CppBlockPtr b2 = CppBlockPtr(new CppBlock()); - b2->addLine(accessor_dimensions + ".push_back(" + accessor + "->size[" + accessor_iterator + "]);"); - b->appendBlock(b2); - b->addLine(accessor_dimensions + ".push_back(" + accessor + "->elemSize());"); - b->addLine("w.writeNDArray(" + accessor_dimensions + ", std::to_string(" + accessor + "->type()), reinterpret_cast<unsigned char*>(" + accessor + "->data));"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("const auto [dims, type] = r.readStartNDArray();"); - b->addLine(accessor + " = " + getCppTypename() + "(new cv::Mat(std::vector<int>({dims.begin(), std::prev(dims.end())}), std::stoi(type)));"); - b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + "->data));"); - return b; - } - - CppBlockPtr AronOpenCVMatTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (cv::countNonZero(*" + accessor + " != *" + otherInstanceAccessor + ") != 0)"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.h deleted file mode 100644 index d786070b8165b567a2da3de59256d96e3cf3ef46..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronOpenCVMatTypeCppSerializer.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronOpenCVMatTypeCppSerializer; - typedef std::shared_ptr<AronOpenCVMatTypeCppSerializer> AronOpenCVMatTypeCppSerializerPtr; - - class AronOpenCVMatTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronOpenCVMatTypeCppSerializerPtr; - - public: - // constructors - AronOpenCVMatTypeCppSerializer(const typenavigator::AronOpenCVMatTypeNavigatorPtr& n); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; - static const std::string OPENCVMAT_ITERATOR_ACCESSOR; - static const std::string OPENCVMAT_DIMENSIONS_ACCESSOR; - static const std::string OPENCVMAT_DIFF_ACCESSOR; - - typenavigator::AronOpenCVMatTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.cpp deleted file mode 100644 index d4d7f8f70891607b20d437bb50793f8737f8be73..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronPCLPointCloudTypeCppSerializer.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::map<std::string, std::pair<std::string, int>> AronPCLPointCloudTypeCppSerializer::ACCEPTED_TYPES = - { - // see http://docs.ros.org/en/groovy/api/pcl/html/point__types_8hpp_source.html - {"PointXYZ", {"pcl::PointXYZ", 16}}, - {"PointXYZI", {"pcl::PointXYZI", 32}}, - {"PointXYZL", {"pcl::PointXYZL", 32}}, - {"PointXYZRGB", {"pcl::PointXYZRGB", 32}}, - {"PointXYZRGBL", {"pcl::PointXYZRGBL", 32}}, - {"PointXYZRGBA", {"pcl::PointXYZRGBA", 32}}, - {"PointXYZHSV", {"pcl::PointXYZHSV", 32}}, - }; - - // constructors - AronPCLPointCloudTypeCppSerializer::AronPCLPointCloudTypeCppSerializer(const typenavigator::AronPCLPointCloudTypeNavigatorPtr& n) : - AronTypeCppSerializer("std::shared_ptr<pcl::PointCloud<" + ACCEPTED_TYPES.at(n->getUsedType()).first + ">>", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronPCLPointCloudType))), - typenavigator(n) - { - } - - std::vector<CppFieldPtr> AronPCLPointCloudTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronPCLPointCloudTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new pcl::PointCloud<" + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + ">(" + accessor + "->width, " + accessor + "->height));"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = " + getCppTypename() + "(new pcl::PointCloud<" + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + ">(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + "));"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writePCLPointCloudType({" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + "}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writePCLPointCloudType({" + accessor + "->width, " + accessor + "->height}, \"" + typenavigator->getUsedType() + "\");"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeNDArray({" + accessor + "->width, " + accessor + "->height, " + std::to_string(ACCEPTED_TYPES.at(typenavigator->getUsedType()).second) + "}, \"" + typenavigator->getUsedType() + "\", reinterpret_cast<unsigned char*>(" + accessor + "->points.data()));"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("const auto [dims, _] = r.readStartNDArray();"); - b->addLine(accessor + " = " + getCppTypename() + "(new pcl::PointCloud<" + ACCEPTED_TYPES.at(typenavigator->getUsedType()).first + ">(dims[0], dims[1]));"); - b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + "->points.data()));"); - return b; - } - - CppBlockPtr AronPCLPointCloudTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (" + accessor + "->width != " + otherInstanceAccessor + "->width || " + accessor + "->height != " + otherInstanceAccessor + "->height)"); - b->addLine("\t return false;"); - //b->addLine("if (" + accessor + "->points != " + otherInstanceAccessor + "->points)"); - //b->addLine("\t return false;"); - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.h deleted file mode 100644 index de9c97d18420f43b34fdf081377e40769f1a92bd..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPCLPointCloudTypeCppSerializer.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - class AronPCLPointCloudTypeCppSerializer; - typedef std::shared_ptr<AronPCLPointCloudTypeCppSerializer> AronPCLPointCloudTypeCppSerializerPtr; - - class AronPCLPointCloudTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronPCLPointCloudTypeCppSerializerPtr; - - public: - // constructors - AronPCLPointCloudTypeCppSerializer(const typenavigator::AronPCLPointCloudTypeNavigatorPtr&); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; - - typenavigator::AronPCLPointCloudTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.cpp deleted file mode 100644 index c74685ad977771f6861422907ea6d7e2253915dd..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronTupleTypeCppSerializer.h" - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - const std::string AronTupleTypeCppSerializer::TUPLE_ITERATOR_ACCESSOR = "_iterator"; - - // constructors - AronTupleTypeCppSerializer::AronTupleTypeCppSerializer(const typenavigator::AronTupleTypeNavigatorPtr& e) : - AronTypeCppSerializer("std::tuple<" + simox::alg::join(ExtractCppTypenamesFromList(e->getAcceptedTypes()), ", ") + ">", simox::meta::get_type_name(typeid(data::AronList)), simox::meta::get_type_name(typeid(type::AronTupleType))), - typenavigator(e) - { - - } - - std::vector<CppFieldPtr> AronTupleTypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const - { - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); - return {field}; - } - - std::vector<std::pair<std::string, std::string>> AronTupleTypeCppSerializer::getCtorInitializers(const std::string&) const - { - return {}; - } - - CppBlockPtr AronTupleTypeCppSerializer::getCtorBlock(const std::string&) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getInitializeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - unsigned int i = 0; - for (const auto& child : typenavigator->getAcceptedTypes()) - { - auto child_s = FromAronTypeNaviagtorPtr(child); - CppBlockPtr b2 = child_s->getInitializeBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); - b->appendBlock(b2); - } - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getWriteInitialTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartTupleType();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - unsigned int i = 0; - for (const auto& type : typenavigator->getAcceptedTypes()) - { - std::string accessor_iterator = escaped_accessor + TUPLE_ITERATOR_ACCESSOR + std::to_string(i++); - auto type_s = FromAronTypeNaviagtorPtr(type); - b->addLine("w.writeKey(\"" + std::to_string(i) + "\");"); - CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(accessor_iterator); - b->appendBlock(b2); - } - b->addLine("w.writeEndTupleType();"); - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartTupleType();"); - - std::string escaped_accessor = EscapeAccessor(accessor); - unsigned int i = 0; - for (const auto& type : typenavigator->getAcceptedTypes()) - { - std::string accessor_iterator = escaped_accessor + TUPLE_ITERATOR_ACCESSOR + std::to_string(i++); - auto type_s = FromAronTypeNaviagtorPtr(type); - b->addLine("w.writeKey(\"" + std::to_string(i) + "\");"); - CppBlockPtr b2 = type_s->getWriteCurrentTypeBlock(accessor_iterator); - b->appendBlock(b2); - } - b->addLine("w.writeEndTupleType();"); - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getResetBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - - unsigned int i = 0; - for (const auto& type : typenavigator->getAcceptedTypes()) - { - auto type_s = FromAronTypeNaviagtorPtr(type); - CppBlockPtr b2 = type_s->getResetBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); - b->appendBlock(b2); - } - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getWriteBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("w.writeStartList();"); - - unsigned int i = 0; - for (const auto& type : typenavigator->getAcceptedTypes()) - { - auto type_s = FromAronTypeNaviagtorPtr(type); - CppBlockPtr b2 = type_s->getWriteBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); - b->appendBlock(b2); - } - b->addLine("w.writeEndList();"); - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getReadBlock(const std::string& accessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine(accessor + " = {};"); - b->addLine("r.readStartList();"); - - unsigned int i = 0; - for (const auto& type : typenavigator->getAcceptedTypes()) - { - auto type_s = FromAronTypeNaviagtorPtr(type); - CppBlockPtr b2 = type_s->getReadBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); - b->appendBlock(b2); - } - b->addLine("r.readEndList();"); - return b; - } - - CppBlockPtr AronTupleTypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const - { - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); - b->addLine("\t return false;"); - return b; - } - } - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.h deleted file mode 100644 index 1c49e328143eaf9dfa9ee2b34bc3e6a2f7653d7c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTupleTypeCppSerializer.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - - class AronTupleTypeCppSerializer; - typedef std::shared_ptr<AronTupleTypeCppSerializer> AronTupleTypeCppSerializerPtr; - - class AronTupleTypeCppSerializer : - virtual public AronTypeCppSerializer - { - public: - using PointerType = AronTupleTypeCppSerializerPtr; - - public: - // constructors - AronTupleTypeCppSerializer(const typenavigator::AronTupleTypeNavigatorPtr& e); - - // virtual implementations - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; - virtual CppBlockPtr getCtorBlock(const std::string&) const override; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; - virtual CppBlockPtr getInitializeBlock(const std::string&) const override; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; - virtual CppBlockPtr getResetBlock(const std::string&) const override; - virtual CppBlockPtr getWriteBlock(const std::string&) const override; - virtual CppBlockPtr getReadBlock(const std::string&) const override; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; - - private: - // members - static const std::string TUPLE_ITERATOR_ACCESSOR; - - typenavigator::AronTupleTypeNavigatorPtr typenavigator; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.cpp deleted file mode 100644 index a64a9a0a962bf587782b552f1fcd6e2615bcab2b..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Header -#include "AronTypeCppSerializer.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - // constantes - const std::string AronTypeCppSerializer::ARON_DATA_NAME = simox::meta::get_type_name(typeid(armarx::aron::data::AronData)); - const std::string AronTypeCppSerializer::ARON_DATA_PTR_NAME = AronTypeCppSerializer::ARON_DATA_NAME + "::PointerType"; - - const std::string AronTypeCppSerializer::ARON_TYPE_NAME = simox::meta::get_type_name(typeid(armarx::aron::type::AronType)); - const std::string AronTypeCppSerializer::ARON_TYPE_PTR_NAME = AronTypeCppSerializer::ARON_TYPE_NAME + "::PointerType"; - - const std::map<std::string, std::string> AronTypeCppSerializer::RESOLVE_TYPENAMES = - { - {"string", "std::string"}, - }; - - const std::map<std::string, std::string> AronTypeCppSerializer::ESCAPE_ACCESSORS = - { - {"->", "_ptr_"}, - {".", "_dot_"}, - {"[", "_lbr_"}, - {"]", "_rbr_"}, - }; - - const AronTypeCppSerializerFactoryPtr AronTypeCppSerializer::FACTORY = AronTypeCppSerializerFactoryPtr(new AronTypeCppSerializerFactory()); - - - // static methods - std::string AronTypeCppSerializer::ResolveCppTypename(const std::string& enteredTypeName) - { - auto i = AronTypeCppSerializer::RESOLVE_TYPENAMES.find(enteredTypeName); - if (i != AronTypeCppSerializer::RESOLVE_TYPENAMES.end()) - { - return i->second; - } - return enteredTypeName; - } - - std::vector<std::string> AronTypeCppSerializer::ResolveCppTypenames(const std::vector<std::string>& enteredTypeNames) - { - std::vector<std::string> ret; - for (const auto& t : enteredTypeNames) - { - ret.push_back(AronTypeCppSerializer::ResolveCppTypename(t)); - } - return ret; - } - - std::string AronTypeCppSerializer::EscapeAccessor(const std::string& accessor) - { - std::string escaped_accessor = accessor; - for (const auto& [key, value] : ESCAPE_ACCESSORS) - { - escaped_accessor = simox::alg::replace_all(escaped_accessor, key, value); - } - return escaped_accessor; - } - - std::string AronTypeCppSerializer::UnescapeAccessor(const std::string& accessor) - { - std::string unescaped_accessor = accessor; - for (const auto& [key, value] : ESCAPE_ACCESSORS) - { - unescaped_accessor = simox::alg::replace_all(unescaped_accessor, value, key); - } - return unescaped_accessor; - } - - std::string AronTypeCppSerializer::ExtractCppTypenamesFromNavigator(const typenavigator::AronTypeNavigatorPtr& n) - { - AronTypeCppSerializerPtr cpp = AronTypeCppSerializer::FromAronTypeNaviagtorPtr(n); - return cpp->getCppTypename(); - } - std::vector<std::string> AronTypeCppSerializer::ExtractCppTypenamesFromList(const std::vector<typenavigator::AronTypeNavigatorPtr>& n) - { - std::vector<std::string> ret; - for (const auto& typenav : n) - { - ret.push_back(AronTypeCppSerializer::ExtractCppTypenamesFromNavigator(typenav)); - } - return ret; - } - - AronTypeCppSerializerPtr AronTypeCppSerializer::FromAronTypeNaviagtorPtr(const typenavigator::AronTypeNavigatorPtr& n) - { - return FACTORY->create(n, n->getPath()); - } - - // constructors - AronTypeCppSerializer::AronTypeCppSerializer(const std::string& cppName, const std::string& aronDataTypename, const std::string& aronTypeTypename) : - cppTypename(cppName), - aronDataTypename(aronDataTypename), - aronTypeTypename(aronTypeTypename) - { - - } - - std::string AronTypeCppSerializer::getCppTypename() const - { - return cppTypename; - } - - std::string AronTypeCppSerializer::getAronDataTypename() const - { - return aronDataTypename; - } - - std::string AronTypeCppSerializer::getAronDataPtrTypename() const - { - return getAronDataTypename() + "::PointerType"; - } - - std::string AronTypeCppSerializer::getAronTypeTypename() const - { - return aronTypeTypename; - } - - std::string AronTypeCppSerializer::getAronTypePtrTypename() const - { - return getAronTypeTypename() + "::PointerType"; - } - - CppCtorPtr AronTypeCppSerializer::toCtor(const std::string& name) const - { - CppCtorPtr c = CppCtorPtr(new CppCtor(name + "()")); - std::vector<std::pair<std::string, std::string>> initList = this->getCtorInitializers(""); - CppBlockPtr b = CppBlockPtr(new CppBlock()); - b->addLine("initialize();"); - b->appendBlock(this->getCtorBlock("")); - c->addInitListEntries(initList); - c->setBlock(b); - - return c; - } - - CppMethodPtr AronTypeCppSerializer::toResetMethod() const - { - std::stringstream doc; - doc << "@brief reset() - This method resets all member variables to default. \n"; - doc << "@return - nothing"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void reset() override", doc.str())); - CppBlockPtr b = this->getResetBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toInitializeMethod() const - { - std::stringstream doc; - doc << "@brief initialize() - This method initializes member variables according to the XML type description. \n"; - doc << "@return - nothing"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void initialize() override", doc.str())); - CppBlockPtr b = this->getInitializeBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toWriteInitialTypeMethod() 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 << "@return - the result of the writer implementation"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("static void writeInitialType(armarx::aron::io::AronTypeWriter& w)", doc.str())); - CppBlockPtr b = this->getWriteInitialTypeBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toWriteCurrentTypeMethod() const - { - std::stringstream doc; - doc << "@brief writeType() - This method returns a new type from the current class structure using a type writer implementation. \n"; - doc << "@return - the result of the writer implementation"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("void writeCurrentType(armarx::aron::io::AronTypeWriter& w) const override", doc.str())); - CppBlockPtr b = this->getWriteInitialTypeBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::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 << "@param w - The writer implementation\n"; - doc << "@return - the result of the writer implementation"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void write(armarx::aron::io::AronDataWriter& w) const override", doc.str())); - CppBlockPtr b = this->getWriteBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::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 << "@param r - The reader implementation\n"; - doc << "@return - nothing"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void read(armarx::aron::io::AronDataReader& r) override", doc.str())); - CppBlockPtr b = this->getReadBlock(""); - m->setBlock(b); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toSpecializedDataWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const - { - std::stringstream doc; - doc << "@brief specializedDataWrite() - 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(returnname + " " + methodname + "() const", doc.str())); - m->addLine(writerName + " writer;"); - m->addLine("this->write(writer);"); - m->addLine("return " + enforceConversion + "(writer.getResult());"); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toSpecializedDataReaderMethod(const std::string& argumentname, const std::string& methodname, const std::string& readerName, const std::string& enforceConversion) const - { - std::stringstream doc; - doc << "@brief specializedDataRead() - This method sets the struct members to new values given in a reader implementation. \n"; - doc << "@return - nothing"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("void " + methodname + "(const " + argumentname + "& input)", doc.str())); - m->addLine(readerName + " reader(" + enforceConversion + "(input));"); - m->addLine("this->read(reader);"); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toSpecializedInitialTypeWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const - { - std::stringstream doc; - doc << "@brief specializedTypeWrite() - 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 " + returnname + " " + methodname + "()", doc.str())); - m->addLine(writerName + " writer;"); - m->addLine(getCppTypename() + "::writeInitialType(writer);"); - m->addLine("return " + enforceConversion + "(writer.getResult());"); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toSpecializedCurrentTypeWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const - { - std::stringstream doc; - doc << "@brief specializedTypeWrite() - This method returns a new type from the current member data types using a writer implementation. \n"; - doc << "@return - the result of the writer implementation"; - - CppMethodPtr m = CppMethodPtr(new CppMethod(returnname + " " + methodname + "()", doc.str())); - m->addLine(writerName + " writer;"); - m->addLine("this->writeCurrentType(writer);"); - m->addLine("return " + enforceConversion + "(writer.getResult());"); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toSpecializedCurrentTypeReaderMethod(const std::string& argumentname, const std::string& methodname, const std::string& readerName, const std::string& enforceConversion) const - { - std::stringstream doc; - doc << "@brief specializedTypeRead() - This method sets the structure of the members to new values given in a reader implementation. \n"; - doc << "@return - nothing"; - - CppMethodPtr m = CppMethodPtr(new CppMethod("void " + methodname + "(const " + argumentname + "& input)", doc.str())); - m->addLine(readerName + " reader(" + enforceConversion + "(input));"); - m->addLine("this->readType(reader);"); - return m; - } - - CppMethodPtr AronTypeCppSerializer::toEqualsMethod() const - { - std::stringstream doc; - 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->getCppTypename() + "& i) const", doc.str())); - CppBlockPtr b = this->getEqualsBlock("", "i"); - b->addLine("return true;"); - m->setBlock(b); - return m; - } - } - } - } - } -} - - diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.h deleted file mode 100644 index 51bab528dacaf7e873dfe795c510540886412a48..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializer.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <vector> -#include <map> -#include <string> - -// Simox -#include <SimoxUtility/meta/type_name.h> -#include <SimoxUtility/algorithm/string.h> - -// ArmarX -#include <ArmarXCore/libraries/cppgen/CppBlock.h> -#include <ArmarXCore/libraries/cppgen/CppField.h> -#include <ArmarXCore/libraries/cppgen/CppCtor.h> -#include <ArmarXCore/libraries/cppgen/CppMethod.h> -#include <ArmarXCore/libraries/cppgen/CppClass.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - class AronTypeCppSerializerFactory; - typedef std::shared_ptr<AronTypeCppSerializerFactory> AronTypeCppSerializerFactoryPtr; - - class AronTypeCppSerializer; - typedef std::shared_ptr<AronTypeCppSerializer> AronTypeCppSerializerPtr; - - class AronTypeCppSerializer - { - public: - using PointerType = AronTypeCppSerializerPtr; - - public: - // constructors - AronTypeCppSerializer(const std::string& cppName, const std::string& aronDataTypename, const std::string& aronTypeTypename); - - // public member methods - std::string getCppTypename() const; - - std::string getAronDataTypename() const; - std::string getAronDataPtrTypename() const; - - std::string getAronTypeTypename() const; - std::string getAronTypePtrTypename() const; - - CppMethodPtr toSpecializedDataWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; - CppMethodPtr toSpecializedDataReaderMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; - - CppMethodPtr toSpecializedInitialTypeWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; - CppMethodPtr toSpecializedCurrentTypeWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; - CppMethodPtr toSpecializedCurrentTypeReaderMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; - - // virtual override definitions - virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const = 0; - - CppCtorPtr toCtor(const std::string&) const; - virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const = 0; - virtual CppBlockPtr getCtorBlock(const std::string&) const = 0; - - CppMethodPtr toResetMethod() const; - virtual CppBlockPtr getResetBlock(const std::string&) const = 0; - - CppMethodPtr toWriteInitialTypeMethod() const; - virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const = 0; - - CppMethodPtr toWriteCurrentTypeMethod() const; - virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const = 0; - - CppMethodPtr toInitializeMethod() const; - virtual CppBlockPtr getInitializeBlock(const std::string&) const = 0; - - CppMethodPtr toWriteMethod() const; - virtual CppBlockPtr getWriteBlock(const std::string&) const = 0; - - CppMethodPtr toReadMethod() const; - virtual CppBlockPtr getReadBlock(const std::string&) const = 0; - - CppMethodPtr toEqualsMethod() const; - virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const = 0; - - // static methods - static std::string ResolveCppTypename(const std::string&); - static std::vector<std::string> ResolveCppTypenames(const std::vector<std::string>&); - static std::string EscapeAccessor(const std::string&); - static std::string UnescapeAccessor(const std::string&); - - static std::string ExtractCppTypenamesFromNavigator(const typenavigator::AronTypeNavigatorPtr&); - static std::vector<std::string> ExtractCppTypenamesFromList(const std::vector<typenavigator::AronTypeNavigatorPtr>&); - - static AronTypeCppSerializerPtr FromAronTypeNaviagtorPtr(const typenavigator::AronTypeNavigatorPtr&); - - private: - // members - const static std::string ARON_DATA_NAME; - const static std::string ARON_DATA_PTR_NAME; - - const static std::string ARON_TYPE_NAME; - const static std::string ARON_TYPE_PTR_NAME; - - static const std::map<std::string, std::string> RESOLVE_TYPENAMES; - static const std::map<std::string, std::string> ESCAPE_ACCESSORS; - - static const AronTypeCppSerializerFactoryPtr FACTORY; - - std::string cppTypename; - std::string aronDataTypename; - std::string aronTypeTypename; - }; - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.cpp deleted file mode 100644 index 9bc980d9fc8816a2c4a40f6fb1a6cb4f1bf6eefb..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Header -#include "AronTypeCppSerializerFactory.h" - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - // Map types to factories - const std::unordered_map<AronTypeDescriptor, AronTypeCppSerializerFactoryPtr> AronTypeCppSerializerFactory::FACTORIES = - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - {AronTypeDescriptor::eAron##upperType##Type, AronTypeCppSerializerFactoryPtr(new Aron##upperType##TypeCppSerializerFactory())}, \ - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - }; - - // Access method - cppSerializer::AronTypeCppSerializerPtr AronTypeCppSerializerFactory::create(const typenavigator::AronTypeNavigatorPtr& n, const AronPath& path) const - { - CheckIfInputIsNull("AronDataNavigatorFactory", "create", path, n); - - auto res = n->getResult(); - auto factory_iterator = FACTORIES.find(AronResolver::GetDescriptorForAronType(res)); - if (factory_iterator == FACTORIES.end()) - { - throw exception::AronExceptionWithPathInfo("AronDataNavigatorFactory", "create", "Cannot find the desired factory for input (ice_id): " + res->ice_id() + ". Cannot create navigator", path); - } - return factory_iterator->second->createSpecific(n, path); - } - - cppSerializer::AronTypeCppSerializerPtr AronTypeCppSerializerFactory::createSpecific(const typenavigator::AronTypeNavigatorPtr&, const AronPath&) const - { - throw exception::AronException("AronDataNavigatorFactory", "createSpecific", "Called disallowed method. Use child class instead!"); - } - - // Container Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - cppSerializer::AronTypeCppSerializerPtr Aron##upperType##TypeCppSerializerFactory::createSpecific(const typenavigator::AronTypeNavigatorPtr& n, const AronPath& path) const \ - { \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeCppSerializerFactory", "createSpecific[BeforeCast]", path, n); \ - typenavigator::Aron##upperType##TypeNavigatorPtr casted = typenavigator::Aron##upperType##TypeNavigator::DynamicCast(n); \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeCppSerializerFactory", "createSpecific[AfterCast]", path, casted); \ - return cppSerializer::AronTypeCppSerializerPtr(new cppSerializer::Aron##upperType##TypeCppSerializer(casted)); \ - } - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.h deleted file mode 100644 index e9c26d88abcaf7f26ca7e516ec9c0dd7a12a456c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronTypeCppSerializerFactory.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <unordered_map> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/AronSerializerFactory.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronAllCppSerializers.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { - class AronTypeCppSerializerFactory; - typedef std::shared_ptr<AronTypeCppSerializerFactory> AronTypeCppSerializerFactoryPtr; - - class AronTypeCppSerializerFactory : - virtual public classwriter::AronSerializerFactory<typenavigator::AronTypeNavigatorPtr, cppSerializer::AronTypeCppSerializerPtr> - { - public: - AronTypeCppSerializerFactory() = default; - virtual cppSerializer::AronTypeCppSerializerPtr create(const typenavigator::AronTypeNavigatorPtr&, const AronPath&) const override; - virtual cppSerializer::AronTypeCppSerializerPtr createSpecific(const typenavigator::AronTypeNavigatorPtr&, const AronPath&) const override; - - private: - static const std::unordered_map<AronTypeDescriptor, AronTypeCppSerializerFactoryPtr> FACTORIES; - }; - - // Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeCppSerializerFactory : \ - virtual public AronTypeCppSerializerFactory \ - { \ - public: \ - Aron##upperType##TypeCppSerializerFactory() = default; \ - virtual cppSerializer::AronTypeCppSerializerPtr createSpecific(const typenavigator::AronTypeNavigatorPtr&, const AronPath&) const override; \ - }; - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/AronTypeReader.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/AronTypeReader.h deleted file mode 100644 index fb82683a0bd93ef64bf645da121c4b0f81dc3365..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/AronTypeReader.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <filesystem> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronReaderInfo.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronWriterInfo.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - template <typename Input> - class AronTypeReader; - - template <typename Input> - using AronTypeReaderPtr = std::shared_ptr<AronTypeReader<Input>>; - - template <typename Input> - class AronTypeReader - { - public: - AronTypeReader() = default; - - virtual void parseFile(const std::string& filename) = 0; - virtual void parseFile(const std::filesystem::path& file) = 0; - - std::vector<std::string> getCodeIncludes() const - { - return codeIncludes; - } - std::vector<std::string> getAronIncludes() const - { - return aronIncludes; - } - std::vector<AronWriterInfoPtr> getWriters() const - { - return writers; - } - std::vector<AronReaderInfoPtr> getReaders() const - { - return readers; - } - std::vector<AronGenerateTypeInfoPtr> getGenerateTypes() const - { - return generateTypes; - } - - protected: - std::vector<std::string> alreadyParsedXMLFiles; - - std::vector<std::string> codeIncludes; - std::vector<std::string> aronIncludes; - std::vector<AronReaderInfoPtr> readers; - std::vector<AronWriterInfoPtr> writers; - std::vector<AronGenerateTypeInfoPtr> generateTypes; - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.cpp deleted file mode 100644 index 6779b170af7fa321ccc35e5d5766e9b7ec4ec144..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - - -// String -#include <SimoxUtility/algorithm/string.h> - -// Header -#include "AronTypeXMLData.h" - -// ArmarX -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - const std::string AronTypeXMLReaderData::ARON_TYPE_DEFINITION_TAG = "arontypedefinition"; - - const std::string AronTypeXMLReaderData::ARON_CODE_INCLUDES_TAG = "codeincludes"; - const std::string AronTypeXMLReaderData::ARON_ARON_INCLUDES_TAG = "aronincludes"; - const std::string AronTypeXMLReaderData::ARON_GENERATE_TYPES_TAG = "generatetypes"; - - const std::string AronTypeXMLReaderData::ARON_INCLUDE_TAG = "include"; - const std::string AronTypeXMLReaderData::ARON_GENERATE_TYPE_TAG = "generatetype"; - - const std::string AronTypeXMLReaderData::ARON_INCLUDE_ATTRIBUTE_NAME = "include"; - const std::string AronTypeXMLReaderData::ARON_METHOD_ATTRIBUTE_NAME = "method"; - const std::string AronTypeXMLReaderData::ARON_RETURN_ATTRIBUTE_NAME = "return"; - const std::string AronTypeXMLReaderData::ARON_ARGUMENT_TYPE_ATTRIBUTE_NAME = "argumenttype"; - const std::string AronTypeXMLReaderData::ARON_WRITER_ATTRIBUTE_NAME = "writer"; - const std::string AronTypeXMLReaderData::ARON_READER_ATTRIBUTE_NAME = "reader"; - const std::string AronTypeXMLReaderData::ARON_EXTENDS_ATTRIBUTE_NAME = "extends"; - const std::string AronTypeXMLReaderData::ARON_NAME_ATTRIBUTE_NAME = "name"; - const std::string AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME = "type"; - const std::string AronTypeXMLReaderData::ARON_KEY_ATTRIBUTE_NAME = "key"; - const std::string AronTypeXMLReaderData::ARON_WIDTH_ATTRIBUTE_NAME = "width"; - const std::string AronTypeXMLReaderData::ARON_HEIGHT_ATTRIBUTE_NAME = "height"; - const std::string AronTypeXMLReaderData::ARON_ROWS_ATTRIBUTE_NAME = "rows"; - const std::string AronTypeXMLReaderData::ARON_COLS_ATTRIBUTE_NAME = "cols"; - const std::string AronTypeXMLReaderData::ARON_DIMENSIONS_ATTRIBUTE_NAME = "dimensions"; - - const std::string AronTypeXMLReaderData::ARON_OBJECT_CHILD_TAG = "objectchild"; - - // Top Level type tags -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - const std::string AronTypeXMLReaderData::ARON_GENERATE_##capsType##_TAG = #lowerType; - - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - - void AronTypeXMLReaderData::EnforceAttribute(const RapidXmlReaderNode& node, const std::string& att) - { - if (!HasAttribute(node, att)) - { - throw exception::AronStringNotValidException("AronTypeXMLReaderData", "EnforceAttribute", "A <" + node.name() + ">-tag does not have the correct attribute", att); - } - } - - bool AronTypeXMLReaderData::HasAttribute(const RapidXmlReaderNode& node, const std::string& att) - { - return node.has_attribute(att.c_str()); - } - - std::string AronTypeXMLReaderData::GetAttribute(const RapidXmlReaderNode& node, const std::string& att) - { - EnforceAttribute(node, att); - return node.attribute_value(att.c_str()); - } - - std::string AronTypeXMLReaderData::GetAttributeWithDefault(const RapidXmlReaderNode& node, const std::string& att, const std::string def) - { - if (!(HasAttribute(node, att))) - { - return def; - } - return node.attribute_value(att.c_str()); - } - - bool AronTypeXMLReaderData::HasTagName(const RapidXmlReaderNode& node, const std::string& name) - { - return (simox::alg::to_lower(name) == simox::alg::to_lower(node.name())); - } - - void AronTypeXMLReaderData::EnforceTagName(const RapidXmlReaderNode& node, const std::string& name) - { - if (!(HasTagName(node, name))) - { - throw exception::AronStringNotValidException("AronTypeXMLReaderData", "EnforceTagName", "The node <" + node.name() + "> has the wrong tag", name); - } - } - - std::string AronTypeXMLReaderData::GetTagName(const RapidXmlReaderNode& node) - { - return simox::alg::to_lower(node.name()); - } - - bool AronTypeXMLReaderData::CheckMinChildSize(const RapidXmlReaderNode& node, const size_t size) - { - std::vector<RapidXmlReaderNode> children = node.nodes(); - return children.size() >= size; - } - - bool AronTypeXMLReaderData::CheckMaxChildSize(const RapidXmlReaderNode& node, const size_t size) - { - std::vector<RapidXmlReaderNode> children = node.nodes(); - return children.size() <= size; - } - - bool AronTypeXMLReaderData::CheckExactChildSize(const RapidXmlReaderNode& node, const size_t size) - { - std::vector<RapidXmlReaderNode> children = node.nodes(); - return children.size() == size; - } - - void AronTypeXMLReaderData::EnforceChildSize(const RapidXmlReaderNode& node, const size_t size) - { - if (!AronTypeXMLReaderData::CheckExactChildSize(node, size)) - { - throw exception::AronSizeNotValidException("AronTypeXMLReaderData", "EnforceChildSize", "The node <" + node.name() + "> has the wrong number of children", node.nodes().size(), size); - } - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.h deleted file mode 100644 index 38a27f5dab1ad4c78989fa6c07c1392380308f8c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <map> - -// ArmarX -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> - -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - class AronTypeXMLReaderData - { - public: - // Definition tags - const static std::string ARON_TYPE_DEFINITION_TAG; - - const static std::string ARON_CODE_INCLUDES_TAG; - const static std::string ARON_ARON_INCLUDES_TAG; - const static std::string ARON_GENERATE_TYPES_TAG; - - const static std::string ARON_INCLUDE_TAG; - const static std::string ARON_GENERATE_TYPE_TAG; - - // Attribute names - const static std::string ARON_METHOD_ATTRIBUTE_NAME; - const static std::string ARON_RETURN_ATTRIBUTE_NAME; - const static std::string ARON_ARGUMENT_TYPE_ATTRIBUTE_NAME; - const static std::string ARON_INCLUDE_ATTRIBUTE_NAME; - const static std::string ARON_READER_ATTRIBUTE_NAME; - const static std::string ARON_WRITER_ATTRIBUTE_NAME; - const static std::string ARON_EXTENDS_ATTRIBUTE_NAME; - const static std::string ARON_NAME_ATTRIBUTE_NAME; - const static std::string ARON_KEY_ATTRIBUTE_NAME; - const static std::string ARON_TYPE_ATTRIBUTE_NAME; - const static std::string ARON_WIDTH_ATTRIBUTE_NAME; - const static std::string ARON_HEIGHT_ATTRIBUTE_NAME; - const static std::string ARON_ROWS_ATTRIBUTE_NAME; - const static std::string ARON_COLS_ATTRIBUTE_NAME; - const static std::string ARON_DIMENSIONS_ATTRIBUTE_NAME; - - // Second level tags. Only important if in specific top level tag - const static std::string ARON_OBJECT_CHILD_TAG; - - // Top Level type tags -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - const static std::string ARON_GENERATE_##capsType##_TAG; - - HANDLE_ALL_ARON_TYPES -#undef RUN_ARON_MACRO - - static void EnforceAttribute(const RapidXmlReaderNode& node, const std::string& att); - static bool HasAttribute(const RapidXmlReaderNode& node, const std::string& att); - static std::string GetAttribute(const RapidXmlReaderNode& node, const std::string& att); - static std::string GetAttributeWithDefault(const RapidXmlReaderNode& node, const std::string& att, const std::string def); - static bool HasTagName(const RapidXmlReaderNode& node, const std::string& name); - static void EnforceTagName(const RapidXmlReaderNode& node, const std::string& name); - static std::string GetTagName(const RapidXmlReaderNode& node); - static bool CheckMinChildSize(const RapidXmlReaderNode& node, const size_t size); - static bool CheckMaxChildSize(const RapidXmlReaderNode& node, const size_t size); - static bool CheckExactChildSize(const RapidXmlReaderNode& node, const size_t size); - static void EnforceChildSize(const RapidXmlReaderNode& node, const size_t size); - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.h deleted file mode 100644 index 3677b04a4b95cabec5dbb350dec31bf10a85410c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <filesystem> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/AronTypeReader.h> - -// ArmarX -#include <SimoxUtility/xml.h> -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> - -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - class AronTypeXMLReader; - typedef std::shared_ptr<AronTypeXMLReader> AronTypeXMLReaderPtr; - - class AronTypeXMLReader : - virtual public codegeneration::typereader::AronTypeReader<std::string> - { - public: - AronTypeXMLReader() = default; - - virtual void parseFile(const std::string&) override; - virtual void parseFile(const std::filesystem::path&) override; - - private: - void parse(const RapidXmlReaderPtr& node); - - std::string readCppInclude(const RapidXmlReaderNode& node) const; - std::string readAronInclude(const RapidXmlReaderNode& node) const; - - typenavigator::AronObjectTypeNavigatorPtr readGenerateType(const RapidXmlReaderNode& node) const; - - private: - AronObjectTypeXMLReaderFactory factory; - }; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.cpp b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.cpp deleted file mode 100644 index 8d6a40b60d29d9f8aaccfd8a2d7412592daee89e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Simox -#include <SimoxUtility/algorithm/string.h> - -// Header -#include "AronTypeXMLReaderFactory.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.h> - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - std::stack<AronGenerateTypeInfoPtr> AronTypeXMLReaderFactory::TheObjectWeAreGoingToGenerateNowStack = {}; - std::map<std::string, AronGenerateTypeInfoPtr> AronTypeXMLReaderFactory::AllKnownGeneratedPublicObjects = {}; - - - typenavigator::AronTypeNavigatorPtr AronTypeXMLReaderFactory::create(const RapidXmlReaderNode& node, const AronPath& path) const - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - {AronTypeXMLReaderData::ARON_GENERATE_##capsType##_TAG, AronTypeXMLReaderFactoryPtr(new Aron##upperType##TypeXMLReaderFactory())}, - static const std::map<std::string, AronTypeXMLReaderFactoryPtr> Factories = - { - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES - }; -#undef RUN_ARON_MACRO - - const std::string tag = simox::alg::to_lower(node.name()); - if (tag == "") - { - throw exception::AronException("AronTypeXMLReaderFactory", "create", "An node is empty. Cannot find facory for empty nodes."); - } - auto factory_iterator = Factories.find(tag); - if (factory_iterator != Factories.end()) - { - return factory_iterator->second->createSpecific(node, path); - } - - // Search for known objects - return ResolveTypename(tag); - } - - std::map<std::string, AronGenerateTypeInfoPtr> AronTypeXMLReaderFactory::GetAllKnownGeneratedPublicObjects() - { - return AllKnownGeneratedPublicObjects; - } - - typenavigator::AronTypeNavigatorPtr AronTypeXMLReaderFactory::ResolveTypename(const std::string& name) - { - const auto public_it = AllKnownGeneratedPublicObjects.find(name); - if (public_it != AllKnownGeneratedPublicObjects.end()) - { - return public_it->second->correspondingObjectType; - } - - throw exception::AronStringNotValidException("AronTypeXMLReaderFactory", "ResolveTypename", "Could not find a tag. Please note that you cant make use of nested objects yet", name); - } - - // Object type - typenavigator::AronTypeNavigatorPtr AronObjectTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_NAME_ATTRIBUTE_NAME); - const std::string extends = AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_EXTENDS_ATTRIBUTE_NAME, ""); - const std::string name = AronTypeXMLReaderData::GetAttribute(node, AronTypeXMLReaderData::ARON_NAME_ATTRIBUTE_NAME); - - bool object_is_nested = TheObjectWeAreGoingToGenerateNowStack.size() > 0; - - // set the new object - typenavigator::AronObjectTypeNavigatorPtr aronObjectType = typenavigator::AronObjectTypeNavigatorPtr(new typenavigator::AronObjectTypeNavigator(path)); - if (object_is_nested) - { - if (name.rfind("::") != std::string::npos) - { - throw exception::AronStringNotValidException("AronObjectTypeXMLReaderFactory", "createSpecific", "Namespaces are not allowed in nested classes", name); - } - } - aronObjectType->setObjectName(name); - - AronGenerateTypeInfoPtr theObjectWeAreGoingToProduceNow = AronGenerateTypeInfoPtr(new AronGenerateTypeInfo()); - theObjectWeAreGoingToProduceNow->typeName = name; - theObjectWeAreGoingToProduceNow->correspondingObjectType = aronObjectType; - - if (extends != "") - { - auto it = AllKnownGeneratedPublicObjects.find(extends); - if (it != AllKnownGeneratedPublicObjects.end()) - { - AronGenerateTypeInfoPtr prodObj = it->second; - aronObjectType->setExtends(prodObj->correspondingObjectType); - } - else - { - throw exception::AronStringNotValidException("AronObjectTypeXMLReaderFactory", "createSpecific", "An extends name could not be found. Perhaps you need to change the order of your types or you have to add another UseType", extends); - } - } - - TheObjectWeAreGoingToGenerateNowStack.push(theObjectWeAreGoingToProduceNow); - for (const RapidXmlReaderNode& objectChild : node.nodes()) - { - AronTypeXMLReaderData::EnforceTagName(objectChild, AronTypeXMLReaderData::ARON_OBJECT_CHILD_TAG); - AronTypeXMLReaderData::EnforceChildSize(objectChild, 1); - - AronTypeXMLReaderData::EnforceAttribute(objectChild, AronTypeXMLReaderData::ARON_KEY_ATTRIBUTE_NAME); - const std::string key = objectChild.attribute_value(AronTypeXMLReaderData::ARON_KEY_ATTRIBUTE_NAME.c_str()); - - std::vector<RapidXmlReaderNode> children = objectChild.nodes(); - typenavigator::AronTypeNavigatorPtr childNavigator = create(children[0], AronPath(path, key)); - aronObjectType->addAcceptedType(key, childNavigator); - } - - // remove current item from stack - TheObjectWeAreGoingToGenerateNowStack.pop(); - - if (object_is_nested) - { - // We are in a local nested class since there is a parent class in stack - AronGenerateTypeInfoPtr parent = TheObjectWeAreGoingToGenerateNowStack.top(); - parent->nestedObjects.insert(std::make_pair(theObjectWeAreGoingToProduceNow->typeName, theObjectWeAreGoingToProduceNow)); - } - else - { - // We are a public top level class. Add to AllProducedPublicObjects - AllKnownGeneratedPublicObjects.insert(std::make_pair(theObjectWeAreGoingToProduceNow->typeName, theObjectWeAreGoingToProduceNow)); - } - - return aronObjectType; - } - - // List type (List) - typenavigator::AronTypeNavigatorPtr AronListTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_LIST_TAG); - - typenavigator::AronListTypeNavigatorPtr list(new typenavigator::AronListTypeNavigator(path)); - AronTypeXMLReaderData::EnforceChildSize(node, 1); - std::vector<RapidXmlReaderNode> listTypeNodeChildren = node.nodes(); - const RapidXmlReaderNode typeNode = listTypeNodeChildren[0]; - typenavigator::AronTypeNavigatorPtr type = create(typeNode, AronPath(path, "type")); - - list->setAcceptedType(type); - return list; - } - - // List type (Dict) - typenavigator::AronTypeNavigatorPtr AronDictTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_DICT_TAG); - - typenavigator::AronDictTypeNavigatorPtr dict(new typenavigator::AronDictTypeNavigator(path)); - AronTypeXMLReaderData::EnforceChildSize(node, 1); - std::vector<RapidXmlReaderNode> dictTypeNodeChildren = node.nodes(); - const RapidXmlReaderNode typeNode = dictTypeNodeChildren[0]; - typenavigator::AronTypeNavigatorPtr type = create(typeNode, AronPath(path, "type")); - dict->setAcceptedType(type); - - return dict; - } - - // List types (Tuple) - typenavigator::AronTypeNavigatorPtr AronTupleTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_TUPLE_TAG); - std::vector<RapidXmlReaderNode> nodeChildren = node.nodes(); - - if (nodeChildren.size() < 1) - { - throw exception::AronException("AronTupleTypeXMLReaderFactory", "createSpecific", "A tuple must have at least one type. Found child nodes size: " + std::to_string(nodeChildren.size())); - } - - typenavigator::AronTupleTypeNavigatorPtr tuple(new typenavigator::AronTupleTypeNavigator(path)); - unsigned int i = 0; - for (const RapidXmlReaderNode& tupleTypeDeclarationNode : nodeChildren) - { - AronTypeXMLReaderData::EnforceChildSize(tupleTypeDeclarationNode, 1); - - std::vector<RapidXmlReaderNode> typeNodeChildren = tupleTypeDeclarationNode.nodes(); - const RapidXmlReaderNode typeNode = typeNodeChildren[0]; - - typenavigator::AronTypeNavigatorPtr type = create(typeNode, AronPath(path, "<" + std::to_string(i++) + ">")); - tuple->addAcceptedType(type); - } - return tuple; - } - - // Complex type (IVTCByteImage) - typenavigator::AronTypeNavigatorPtr AronIVTCByteImageTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_IVT_CBYTE_IMAGE_TAG); - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME); - - int width = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_WIDTH_ATTRIBUTE_NAME, "1")); - int height = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_HEIGHT_ATTRIBUTE_NAME, "1")); - std::string type = node.attribute_value(AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME.c_str());; - - typenavigator::AronIVTCByteImageTypeNavigatorPtr complex(new typenavigator::AronIVTCByteImageTypeNavigator(path)); - complex->setWidth(width); - complex->setHeight(height); - complex->setUsedType(type); - return complex; - } - - // Complex type (EigenMatrix) - typenavigator::AronTypeNavigatorPtr AronEigenMatrixTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_EIGEN_MATRIX_TAG); - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME); - - int rows = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_ROWS_ATTRIBUTE_NAME, "1")); - int cols = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_COLS_ATTRIBUTE_NAME, "1")); - std::string type = node.attribute_value(AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME.c_str()); - - typenavigator::AronEigenMatrixTypeNavigatorPtr complex(new typenavigator::AronEigenMatrixTypeNavigator(path)); - complex->setRows(rows); - complex->setCols(cols); - complex->setUsedType(type); - return complex; - } - - // Complex type (OpenCVMat) - typenavigator::AronTypeNavigatorPtr AronOpenCVMatTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_OPENCV_MAT_TAG); - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME); - - std::vector<std::string> dimensions_as_strings = simox::alg::split(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_DIMENSIONS_ATTRIBUTE_NAME, "1"), ","); - std::vector<int> dimensions = simox::alg::to_vec<int>(dimensions_as_strings); - std::string type = node.attribute_value(AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME.c_str()); - - typenavigator::AronOpenCVMatTypeNavigatorPtr complex(new typenavigator::AronOpenCVMatTypeNavigator(path)); - complex->setDimensions(dimensions); - complex->setUsedType(type); - return complex; - } - - // Complex type (PCLPointCloud) - typenavigator::AronTypeNavigatorPtr AronPCLPointCloudTypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode& node, const AronPath& path) const - { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_PCL_POINTCLOUD_TAG); - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME); - - int width = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_WIDTH_ATTRIBUTE_NAME, "1")); - int height = std::stoi(AronTypeXMLReaderData::GetAttributeWithDefault(node, AronTypeXMLReaderData::ARON_HEIGHT_ATTRIBUTE_NAME, "1")); - std::string type = node.attribute_value(AronTypeXMLReaderData::ARON_TYPE_ATTRIBUTE_NAME.c_str());; - - typenavigator::AronPCLPointCloudTypeNavigatorPtr complex(new typenavigator::AronPCLPointCloudTypeNavigator(path)); - complex->setWidth(width); - complex->setHeight(height); - complex->setUsedType(type); - return complex; - } - - // Primitve Types -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - typenavigator::AronTypeNavigatorPtr Aron##upperType##TypeXMLReaderFactory::createSpecific(const RapidXmlReaderNode&, const AronPath& path) const \ - { \ - return typenavigator::AronTypeNavigatorPtr(new typenavigator::Aron##upperType##TypeNavigator(path)); \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.h b/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.h deleted file mode 100644 index 8347da4c914e1058b3c8be10f9b80417b31966a9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReaderFactory.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <map> -#include <vector> -#include <stack> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/AronTypeReader.h> - -// ArmarX -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> - -#include <RobotAPI/libraries/aron/aroncore/AronFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h> - - -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader - { - class AronTypeXMLReaderFactory; - typedef std::shared_ptr<AronTypeXMLReaderFactory> AronTypeXMLReaderFactoryPtr; - - class AronTypeXMLReaderFactory : - virtual public AronPtrOutputFactory<RapidXmlReaderNode, typenavigator::AronTypeNavigatorPtr> - { - public: - AronTypeXMLReaderFactory() = default; - - virtual typenavigator::AronTypeNavigatorPtr create(const RapidXmlReaderNode&, const AronPath&) const override; - virtual typenavigator::AronTypeNavigatorPtr createSpecific(const RapidXmlReaderNode&, const AronPath&) const override = 0; - - static std::map<std::string, AronGenerateTypeInfoPtr> GetAllKnownGeneratedPublicObjects(); - - protected: - static typenavigator::AronTypeNavigatorPtr ResolveTypename(const std::string&); - - protected: - static std::stack<AronGenerateTypeInfoPtr> TheObjectWeAreGoingToGenerateNowStack; - static std::map<std::string, AronGenerateTypeInfoPtr> AllKnownGeneratedPublicObjects; - }; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeXMLReaderFactory : \ - virtual public AronTypeXMLReaderFactory \ - { \ - public: \ - Aron##upperType##TypeXMLReaderFactory() = default; \ - virtual typenavigator::AronTypeNavigatorPtr createSpecific(const RapidXmlReaderNode&, const AronPath&) const override; \ - }; - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.cpp deleted file mode 100644 index c552a0c87cc2227b53f1dcce42c7b2cc77cf03a3..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronDataConverter.h" - -#include <RobotAPI/libraries/aron/aroncore/AronDebug.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - void AronDataConverter::ConvertFromReader(AronDataReader& reader, AronDataWriter& writer, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) - { - AronTypeDescriptor t_desc = expectedStructure != nullptr ? expectedStructure->getDescriptor() : eAronUnknownType; - AronDataDescriptor desc = reader.getTypeOfNextAron(t_desc); - switch (desc) - { - case eAronDict: - { - int elements = reader.readStartDict(); - writer.writeStartDict(); - - typenavigator::AronTypeNavigatorPtr childType = nullptr; - if (t_desc == eAronDictType) - { - auto t = typenavigator::AronDictTypeNavigator::DynamicCast(expectedStructure); - childType = t->getAcceptedType(); - } - - for (int i = 0; i < elements; ++i) - { - std::string key = reader.readKey(); - writer.writeKey(key); - - if (t_desc == eAronObjectType) - { - auto t = typenavigator::AronObjectTypeNavigator::DynamicCast(expectedStructure); - childType = t->getAcceptedType(key); - } - - AronDataConverter::ConvertFromReader(reader, writer, childType); - } - - writer.writeEndDict(); - reader.readEndDict(); - - break; - } - case eAronList: - { - int elements = reader.readStartList(); - writer.writeStartList(); - - typenavigator::AronTypeNavigatorPtr childType = nullptr; - if (t_desc == eAronListType) - { - auto t = typenavigator::AronListTypeNavigator::DynamicCast(expectedStructure); - childType = t->getAcceptedType(); - } - - for (int i = 0; i < elements; ++i) - { - if (t_desc == eAronObjectType) - { - auto t = typenavigator::AronTupleTypeNavigator::DynamicCast(expectedStructure); - childType = t->getAcceptedType(i); - } - - AronDataConverter::ConvertFromReader(reader, writer, childType); - } - - writer.writeEndList(); - reader.readEndList(); - break; - } -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType: \ -{ \ - auto [dims, type] = reader.readStart##upperType(); \ - int elements = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); \ - std::vector<unsigned char> data(elements); \ - reader.readEnd##upperType(data.data()); \ - \ - writer.write##upperType(dims, type, data.data()); \ - break; \ -} - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType: \ -{ \ - lowerType val = reader.readPrimitive<lowerType>(); \ - writer.writePrimitive(val); \ - break; \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - default: - { - throw exception::AronDataDescriptorNotValidException("LegacyAronDataReader", "SetupReaderAndGetResult", "Data-Type could not be resolved", desc); - } - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.h deleted file mode 100644 index f2ba2a0c573707004c5245d2b60777ccfc3b5a58..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataConverter/AronDataConverter.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataConverter; - typedef std::shared_ptr<AronDataConverter> AronDataConverterPtr; - - class AronDataConverter - { - private: - AronDataConverter() = delete; - - public: - static void ConvertFromReader(AronDataReader&, AronDataWriter&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr); - public: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h deleted file mode 100644 index 38b9c9123ed1dc858dfc6bd2970a4a8e72f8aa0e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReaderWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataReader; - typedef std::shared_ptr<AronDataReader> AronDataReaderPtr; - - class AronDataReader : - public AronDataReaderWriter - { - public: - AronDataReader() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType() = 0; \ - virtual bool readEnd##upperType() = 0; \ - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> readStart##upperType() = 0; \ - virtual void readEnd##upperType(unsigned char*) = 0; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void readPrimitive(lowerType&) = 0; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - template<class T> - T readPrimitive() - { - T p; - readPrimitive(p); - return p; - } - - virtual std::string readKey() = 0; - virtual bool readKey(const std::string&) = 0; - - // Helper functions - virtual AronDataDescriptor getTypeOfNextAron(const AronTypeDescriptor) const = 0; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h deleted file mode 100644 index c7d204840e15a42e18d05b7387eaa7d56c11e171..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReaderWriter.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataWriter; - typedef std::shared_ptr<AronDataWriter> AronDataWriterPtr; - - class AronDataWriter : - public AronDataReaderWriter - { - public: - AronDataWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType() = 0; \ - virtual bool writeEnd##upperType() = 0; \ - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType(const std::vector<int>&, const std::string&, const unsigned char*) = 0; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writePrimitive(const lowerType&) = 0; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - virtual bool writeKey(const std::string&) = 0; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.cpp deleted file mode 100644 index 91633187f53627ccb31d402fa037b6ac20fbc067..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronDataWriterVisitor.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - - void AronDataWriterVisitor::SetupWriterFromAronDataPtr(AronDataWriter& writer, const datanavigator::AronDataNavigatorPtr& aron) - { - SetupWriterFromAronDataPtr(writer, aron->getResult()); - } - - void AronDataWriterVisitor::SetupWriterFromAronDataPtr(AronDataWriter& writer, const data::AronDataPtr& aron) - { - AronDataDescriptor desc = AronResolver::GetDescriptorForAronData(aron); - switch (desc) - { - case eAronDict: - { - data::AronDictPtr casted = data::AronDictPtr::dynamicCast(aron); - writer.writeStartDict(); - for (const auto& [key, value] : casted->elements) - { - writer.writeKey(key); - AronDataWriterVisitor::SetupWriterFromAronDataPtr(writer, value); - } - writer.writeEndDict(); - break; - } - case eAronList: - { - data::AronListPtr casted = data::AronListPtr::dynamicCast(aron); - writer.writeStartList(); - for (const auto& value : casted->elements) - { - AronDataWriterVisitor::SetupWriterFromAronDataPtr(writer, value); - } - writer.writeEndList(); - break; - } -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType: \ -{ \ - data::Aron##upperType##Ptr casted = data::Aron##upperType##Ptr::dynamicCast(aron); \ - writer.write##upperType(casted->dimensions, casted->type, casted->data.data()); \ - break; \ -} - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType: \ -{ \ - data::Aron##upperType##Ptr casted = data::Aron##upperType##Ptr::dynamicCast(aron); \ - writer.writePrimitive(casted->value); \ - break; \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - default: - { - throw exception::AronDataDescriptorNotValidException("LegacyAronDataWriter", "SetupWriterFromAronDataPtr", "Data-Type could not be resolved. The ice_id of the input was: " + aron->ice_id(), desc); - } - } - } - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReader.h deleted file mode 100644 index 16fdc8c3712e756e4b65ff8d767e863eb27c56e9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReader.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <stack> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReader.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template <typename InputTypename, typename TokenPtrTypename> - class AronDataClassReader; - - template <typename InputTypename, typename TokenPtrTypename> - using AronDataClassReaderPtr = std::shared_ptr<AronDataClassReader<InputTypename, TokenPtrTypename>>; - - template <typename InputTypename, typename TokenPtrTypename> - class AronDataClassReader : - virtual public AronDataReader - { - public: - AronDataClassReader() = delete; - AronDataClassReader(const InputTypename& input) : - data(input) - { - } - - // ReadKey - std::string readKey() override - { - TokenPtrTypename token = stack.top(); - std::string k = token->resolveCurrentKey(); - return k; - } - - bool readKey(const std::string& k) override - { - TokenPtrTypename token = stack.top(); - token->setCurrentKey(k); - return true; - } - - AronDataDescriptor getTypeOfNextAron(const AronTypeDescriptor hint) const override - { - if (stack.empty()) - { - // completely unknown. We assume a dict on the top level - return eAronDict; - } - - TokenPtrTypename lastToken = stack.top(); - return lastToken->getTypeOfNextElement(hint); - } - - - protected: - InputTypename data; - bool readInitialStart = false; - std::stack<TokenPtrTypename> stack; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReaderToken.h deleted file mode 100644 index 472551a1d2e5ae0cfffefd75645c24cb35599ed4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReaderToken.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - class AronDataClassReaderToken; - - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - using AronDataClassReaderTokenPtr = std::shared_ptr<AronDataClassReaderToken<ElementReturnPtrTypename, ElementAddTypename>>; - - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - class AronDataClassReaderToken : - virtual public AronReaderToken<AronDataDescriptor, ElementReturnPtrTypename, ElementAddTypename> - { - public: - using PointerType = AronDataClassReaderTokenPtr<ElementReturnPtrTypename, ElementAddTypename>; - - public: - // constructors - AronDataClassReaderToken() = delete; - AronDataClassReaderToken(const AronDataDescriptor desc, const ElementAddTypename& data) : - AronReaderToken<AronDataDescriptor, ElementReturnPtrTypename, ElementAddTypename>(desc, data) - { } - - bool currentIsEligableForResolvingKey() const override - { - if (this->descriptor == AronDataDescriptor::eAronDict) - { - return true; - } - return false; - } - - virtual AronDataDescriptor getTypeOfNextElement(const AronTypeDescriptor) const = 0; - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.cpp deleted file mode 100644 index 36e59e623fd1a669b73f2d7291d6dfd68828e279..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronDataNavigatorReader.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - AronDataNavigatorReader::AronDataNavigatorReader(const datanavigator::AronContainerDataNavigatorPtr& n) : - AronDataClassReader<datanavigator::AronContainerDataNavigatorPtr, AronDataNavigatorReaderTokenPtr>(n) - { - } - - AronDataNavigatorReader::AronDataNavigatorReader(const data::AronContainerPtr& n) : - AronDataClassReader<datanavigator::AronContainerDataNavigatorPtr, AronDataNavigatorReaderTokenPtr>( - datanavigator::AronContainerDataNavigator::DynamicCast(datanavigator::AronDataNavigator::FromAronData(n)) - ) - { - } - - datanavigator::AronDataNavigatorPtr AronDataNavigatorReader::getCurrentAndGoToNext() - { - if (!readInitialStart) - { - readInitialStart = true; - return data; - } - auto lastToken = stack.top(); - return lastToken->getCurrentElementAndIncreaseCnt(); - } - - datanavigator::AronDataNavigatorPtr AronDataNavigatorReader::getCurrent() - { - if (!readInitialStart) - { - readInitialStart = true; - return data; - } - auto lastToken = stack.top(); - return lastToken->getCurrentElement(); - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - int AronDataNavigatorReader::readStart##upperType() \ - { \ - datanavigator::AronDataNavigatorPtr current_nav = getCurrentAndGoToNext(); \ - auto desc = current_nav->getDescriptor(); \ - if (desc != AronDataDescriptor::eAron##upperType) \ - { \ - throw exception::AronDataDescriptorNotValidException("AronDataNavigatorReader", "readStart" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType), desc); \ - return false; \ - } \ - datanavigator::Aron##upperType##DataNavigatorPtr current_nav_casted = datanavigator::Aron##upperType##DataNavigator::DynamicCast(current_nav); \ - int c = current_nav->childrenSize(); \ - AronDataNavigatorReaderTokenPtr newToken = AronDataNavigatorReaderTokenPtr(new AronDataNavigatorReaderToken(current_nav->getDescriptor(), current_nav_casted)); \ - stack.push(newToken); \ - return c; \ - } \ - \ - bool AronDataNavigatorReader::readEnd##upperType() \ - { \ - AronDataNavigatorReaderTokenPtr token = stack.top(); \ - auto desc = token->getDescriptor(); \ - if (desc != AronDataDescriptor::eAron##upperType) \ - { \ - throw exception::AronDataDescriptorNotValidException("AronDataNavigatorReader", "readEnd" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType), desc); \ - return false; \ - } \ - \ - if (token->checkedAllChildren()) \ - { \ - stack.pop(); \ - return true; \ - } \ - return false; \ - } - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - - // Complex Data -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - std::pair<std::vector<int>, std::string> AronDataNavigatorReader::readStart##upperType() \ - { \ - datanavigator::AronDataNavigatorPtr nav = getCurrent(); \ - datanavigator::AronNDArrayDataNavigatorPtr casted = datanavigator::AronNDArrayDataNavigator::DynamicCast(nav); \ - return std::make_pair(casted->getDimensions(), casted->getType()); \ - } \ - \ - void AronDataNavigatorReader::readEnd##upperType(unsigned char* data) \ - { \ - if(data == NULL) \ - { \ - throw exception::AronException("AronDataNavigatorReader", "readEnd" + std::string(#upperType), "The corresponding data pointer of an complex aron ptr is NULL."); \ - } \ - datanavigator::AronDataNavigatorPtr nav = getCurrentAndGoToNext(); \ - datanavigator::AronNDArrayDataNavigatorPtr casted = datanavigator::AronNDArrayDataNavigator::DynamicCast(nav); \ - std::vector<int> dims = casted->getDimensions(); \ - memcpy(data, casted->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); \ - } - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - - // Read primitives -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - void AronDataNavigatorReader::readPrimitive(lowerType& t) \ - { \ - datanavigator::AronDataNavigatorPtr nav = getCurrentAndGoToNext(); \ - datanavigator::Aron##upperType##DataNavigatorPtr casted = datanavigator::Aron##upperType##DataNavigator::DynamicCast(nav); \ - t = casted->getValue(); \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h deleted file mode 100644 index 80ae71d9955f8375a745d78c03084d4277bde873..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReader.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReaderToken.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNavigatorReader; - typedef std::shared_ptr<AronDataNavigatorReader> AronDataNavigatorReaderPtr; - - class AronDataNavigatorReader : - virtual public AronDataClassReader<datanavigator::AronContainerDataNavigatorPtr, AronDataNavigatorReaderTokenPtr> - { - public: - using PointerType = AronDataNavigatorReaderPtr; - - public: - // constructors - AronDataNavigatorReader() = delete; - AronDataNavigatorReader(const datanavigator::AronContainerDataNavigatorPtr& n); - AronDataNavigatorReader(const data::AronContainerPtr& n); - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType() override; \ - virtual bool readEnd##upperType() override; \ - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> readStart##upperType() override; \ - virtual void readEnd##upperType(unsigned char*) override; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void readPrimitive(lowerType&) override; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - datanavigator::AronDataNavigatorPtr getCurrent(); - datanavigator::AronDataNavigatorPtr getCurrentAndGoToNext(); - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReaderToken.h deleted file mode 100644 index 3dd510087246330e2a23e3668502f0eb99d09286..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReaderToken.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - // BaseClass - class AronDataNavigatorReaderToken; - typedef std::shared_ptr<AronDataNavigatorReaderToken> AronDataNavigatorReaderTokenPtr; - - class AronDataNavigatorReaderToken : - virtual public AronDataClassReaderToken<datanavigator::AronDataNavigatorPtr, datanavigator::AronContainerDataNavigatorPtr> - { - public: - using PointerType = AronDataNavigatorReaderTokenPtr; - - public: - // constructors - AronDataNavigatorReaderToken() = delete; - AronDataNavigatorReaderToken(const AronDataDescriptor desc, const datanavigator::AronContainerDataNavigatorPtr& data) : - AronReaderToken<AronDataDescriptor, datanavigator::AronDataNavigatorPtr, datanavigator::AronContainerDataNavigatorPtr>(desc, data), - AronDataClassReaderToken<datanavigator::AronDataNavigatorPtr, datanavigator::AronContainerDataNavigatorPtr>(desc, data) - { - switch (descriptor) - { - case eAronDict: - { - allKeys = datanavigator::AronDictDataNavigator::DynamicCastAndCheck(data)->getAllKeys(); - maxIndex = allKeys.size(); - break; - } - case eAronList: - { - maxIndex = datanavigator::AronListDataNavigator::DynamicCastAndCheck(data)->childrenSize(); - break; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNavigatorReaderToken", "AronDataNavigatorReaderToken", "Received an invalid instance for a reader token.", desc); - } - } - - AronDataDescriptor getTypeOfNextElement(const AronTypeDescriptor) const override - { - const datanavigator::AronDataNavigatorPtr next = getCurrentElement(); - return next->getDescriptor(); - } - - datanavigator::AronDataNavigatorPtr getCurrentElement() const override - { - switch (descriptor) - { - case eAronDict: - { - datanavigator::AronDictDataNavigatorPtr casted = datanavigator::AronDictDataNavigator::DynamicCast(element); - datanavigator::AronDataNavigatorPtr ret = casted->getElement(resolveCurrentKey()); - return ret; - } - case eAronList: - { - datanavigator::AronListDataNavigatorPtr casted = datanavigator::AronListDataNavigator::DynamicCast(element); - datanavigator::AronDataNavigatorPtr ret = casted->getElement(currentIndex); - return ret; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNavigatorReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.cpp deleted file mode 100644 index 9ed694579537a17152bd63a8af48b82c06b3dd91..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronDataNlohmannJSONReader.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - AronDataNlohmannJSONReader::AronDataNlohmannJSONReader(const nlohmann::json& n) : - AronDataClassReader<nlohmann::json, AronDataNlohmannJSONReaderTokenPtr>(n) - { - } - - AronDataNlohmannJSONReader::AronDataNlohmannJSONReader(const std::string& n) : - AronDataClassReader<nlohmann::json, AronDataNlohmannJSONReaderTokenPtr>(nlohmann::json::parse(n)) - { - } - - nlohmann::json AronDataNlohmannJSONReader::getCurrentAndGoToNext() - { - if (!readInitialStart) - { - readInitialStart = true; - return data; - } - AronDataNlohmannJSONReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElementAndIncreaseCnt(); - } - - nlohmann::json AronDataNlohmannJSONReader::getCurrent() - { - if (!readInitialStart) - { - readInitialStart = true; - return data; - } - AronDataNlohmannJSONReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElement(); - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - int AronDataNlohmannJSONReader::readStart##upperType() \ - { \ - nlohmann::json current_json = getCurrentAndGoToNext(); \ - int c = current_json.size(); \ - AronDataNlohmannJSONReaderTokenPtr newToken = AronDataNlohmannJSONReaderTokenPtr(new AronDataNlohmannJSONReaderToken(eAron##upperType, current_json)); \ - stack.push(newToken); \ - return c; \ - } \ - \ - bool AronDataNlohmannJSONReader::readEnd##upperType() \ - { \ - AronDataNlohmannJSONReaderTokenPtr token = stack.top(); \ - auto desc = token->getDescriptor(); \ - if (desc != AronDataDescriptor::eAron##upperType) \ - { \ - throw exception::AronDataDescriptorNotValidException("AronDataNlohmannJSONReader", "readEnd" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType), desc); \ - return false; \ - } \ - \ - if (token->checkedAllChildren()) \ - { \ - stack.pop(); \ - return true; \ - } \ - return false; \ - } - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - - // Complex Data -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - std::pair<std::vector<int>, std::string> AronDataNlohmannJSONReader::readStart##upperType() \ - { \ - nlohmann::json j = getCurrent(); \ - std::vector<int> dims = j[ARON_DATA_READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; \ - std::string type = j[ARON_DATA_READER_WRITER_NDARRAY_TYPE_SLUG]; \ - return std::make_pair(dims, type); \ - } \ - \ - void AronDataNlohmannJSONReader::readEnd##upperType(unsigned char* data) \ - { \ - if(data == NULL) \ - { \ - throw exception::AronException("AronDataNlohmannJSONReader", "readEnd" + std::string(#upperType), "The corresponding data pointer of an complex aron ptr is NULL."); \ - } \ - nlohmann::json j = getCurrentAndGoToNext(); \ - std::vector<int> dims = j[ARON_DATA_READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; \ - std::vector<unsigned char> d = j[ARON_DATA_READER_WRITER_NDARRAY_DATA_SLUG]; \ - memcpy(data, d.data(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); \ - } - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - - // Read primitives -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - void AronDataNlohmannJSONReader::readPrimitive(lowerType& t) \ - { \ - nlohmann::json j = getCurrentAndGoToNext(); \ - t = j; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h deleted file mode 100644 index 7cfee40ab0ed2c5ce6da420c826be04876c2dea6..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReader.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReaderToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNlohmannJSONReader; - typedef std::shared_ptr<AronDataNlohmannJSONReader> AronDataNlohmannJSONReaderPtr; - - class AronDataNlohmannJSONReader : - virtual public AronDataClassReader<nlohmann::json, AronDataNlohmannJSONReaderTokenPtr> - { - public: - using PointerType = AronDataNlohmannJSONReaderPtr; - - public: - // constructors - AronDataNlohmannJSONReader() = delete; - AronDataNlohmannJSONReader(const nlohmann::json& n); - AronDataNlohmannJSONReader(const std::string& n); - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType() override; \ - virtual bool readEnd##upperType() override; \ - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> readStart##upperType() override; \ - virtual void readEnd##upperType(unsigned char*) override; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void readPrimitive(lowerType&) override; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - nlohmann::json getCurrent(); - nlohmann::json getCurrentAndGoToNext(); - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReaderToken.h deleted file mode 100644 index e488481b77f69ebd2d636f5b8dfb2357b44bcf2e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReaderToken.h +++ /dev/null @@ -1,146 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/json.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/AronDataClassReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - // BaseClass - class AronDataNlohmannJSONReaderToken; - typedef std::shared_ptr<AronDataNlohmannJSONReaderToken> AronDataNlohmannJSONReaderTokenPtr; - - class AronDataNlohmannJSONReaderToken : - virtual public AronDataClassReaderToken<nlohmann::json, nlohmann::json> - { - public: - using PointerType = AronDataNlohmannJSONReaderTokenPtr; - - public: - // constructors - AronDataNlohmannJSONReaderToken() = delete; - AronDataNlohmannJSONReaderToken(const AronDataDescriptor desc, const nlohmann::json& data) : - AronReaderToken<AronDataDescriptor, nlohmann::json, nlohmann::json>(desc, data), - AronDataClassReaderToken<nlohmann::json, nlohmann::json>(desc, data) - { - switch (descriptor) - { - case eAronDict: - { - for (auto it = data.begin(); it != data.end(); ++it) - { - allKeys.push_back(it.key()); - } - maxIndex = allKeys.size(); - break; - } - case eAronList: - { - maxIndex = data.size(); - break; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNlohmannJSONReaderToken", "AronDataNlohmannJSONReaderToken", "Received an invalid instance for a reader token.", desc); - } - } - - AronDataDescriptor getTypeOfNextElement(const AronTypeDescriptor hint) const override - { - const nlohmann::json next = getCurrentElement(); - if (next.is_object()) - { - // Check if specific NDArray key exists - if (next.find(ARON_READER_WRITER_TOKEN_NDARRAY_DATA_SLUG) != next.end()) - { - return eAronNDArray; - } - return eAronDict; - } - if (next.is_array()) - { - return eAronList; - } - if (next.is_number_integer()) - { - - AronDataDescriptor d = AronResolver::GetFirstIfDescriptorsAreRelated( - AronResolver::GetCorrespondingDataDescriptor(hint), - eAronLong); - return d; - } - if (next.is_number_float()) - { - AronDataDescriptor d = AronResolver::GetFirstIfDescriptorsAreRelated( - AronResolver::GetCorrespondingDataDescriptor(hint), - eAronDouble); - return d; - } - if (next.is_boolean()) - { - return eAronBool; - } - if (next.is_string()) - { - return eAronString; - } - throw exception::AronException("AronDataNlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Could not convert to AronDataDescriptor enum."); - } - - nlohmann::json getCurrentElement() const override - { - switch (descriptor) - { - case eAronDict: - { - nlohmann::json ret = element[resolveCurrentKey()]; - return ret; - } - case eAronList: - { - nlohmann::json ret = element[currentIndex]; - return ret; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNlohmannJSONReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h deleted file mode 100644 index 700d55261442907d22f6a1c391e9e60c55b94568..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template <typename GeneratePtr, typename TokenPtr> - class AronDataClassWriter; - - template <typename GeneratePtr, typename TokenPtr> - using AronDataClassWriterPtr = std::shared_ptr<AronDataClassWriter<GeneratePtr, TokenPtr>>; - - template <typename GeneratePtr, typename TokenPtr> - class AronDataClassWriter : - virtual public AronDataWriter - { - public: - AronDataClassWriter() = default; - - virtual bool writeKey(const std::string& k) override - { - TokenPtr token = stack.top(); - token->setCurrentKey(k); - return true; - } - - GeneratePtr getResult() const - { - assertLastRemovedTokenIsSet(); - assertStackIsEmpty(); - return lastRemovedToken->getElement(); - } - - protected: - void assertLastRemovedTokenIsSet() const - { - if (lastRemovedToken == nullptr) - { - throw exception::AronException("AronDataClassWriter", "assertLastRemovedTokenIsSet", "lastRemovedToken is NULL. Perhaps you never called a writeEnd* method?"); - } - if (lastRemovedToken->getElement() == nullptr) - { - throw exception::AronException("AronDataClassWriter", "assertLastRemovedTokenIsSet", "lastRemovedToken->getElement() is NULL."); - } - } - void assertStackIsEmpty() const - { - if (stack.size() != 0) - { - throw exception::AronException("AronDataClassWriter", "assertStackIsEmpty", "The Size of the stack is not 0. Perhaps you never called a writeEnd* method?"); - } - } - - protected: - bool wroteInitialStartContainer = false; - TokenPtr lastRemovedToken = nullptr; - std::stack<TokenPtr> stack; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h deleted file mode 100644 index 3aeb7a9517133ed252e6c284a175f8b23b726aa2..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h +++ /dev/null @@ -1,80 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename ElementTypename, typename ElementAddTypename> - class AronDataClassWriterToken; - - template<typename ElementTypename, typename ElementAddTypename> - using AronDataClassWriterTokenPtr = std::shared_ptr<AronDataClassWriterToken<ElementTypename, ElementAddTypename>>; - - template<typename ElementTypename, typename ElementAddTypename> - class AronDataClassWriterToken : - virtual public AronWriterToken<AronDataDescriptor, ElementTypename, ElementAddTypename> - { - public: - using PointerType = AronDataClassWriterToken<ElementTypename, ElementAddTypename>; - - public: - // constructor - AronDataClassWriterToken() = delete; - AronDataClassWriterToken(const AronDataDescriptor desc, const ElementTypename& n) : - AronWriterToken<AronDataDescriptor, ElementTypename, ElementAddTypename>(desc, n) - {} - - // public member functions - virtual void addElement(const ElementAddTypename&) override = 0; - - virtual std::string toElementAccessor() const override - { - switch (this->descriptor) - { - case eAronDict: - return this->currentKey; - case eAronList: - return std::to_string(this->currentIndex); - default: - throw exception::AronDataDescriptorNotValidException("AronDataClassWriterToken", "toElementAccessor", "Could not resove a type of a navigator. Allowed are only container and complex types due to performance.", this->descriptor); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.cpp deleted file mode 100644 index a39b26b541809f6e5e2cfcadc50bc6005f50d059..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronDataNavigatorWriter.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - - AronPath AronDataNavigatorWriter::generateAronPath() - { - AronPath path; - if (!wroteInitialStartContainer) - { - wroteInitialStartContainer = true; - } - else - { - AronDataNavigatorWriterTokenPtr parent_token = stack.top(); - path = AronPath(parent_token->getElement()->getPath(), parent_token->toElementAccessor()); - } - return path; - } - - // Containers -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNavigatorWriter::writeStart##upperType() \ - { \ - AronPath path = generateAronPath(); \ - datanavigator::Aron##upperType##DataNavigatorPtr data = datanavigator::Aron##upperType##DataNavigatorPtr(new datanavigator::Aron##upperType##DataNavigator(path)); \ - AronDataNavigatorWriterTokenPtr new_token = AronDataNavigatorWriterTokenPtr(new AronDataNavigatorWriterToken(data->getDescriptor(), data)); \ - stack.push(new_token); \ - return true; \ - } \ - \ - bool AronDataNavigatorWriter::writeEnd##upperType() \ - { \ - lastRemovedToken = stack.top(); \ - stack.pop(); \ - \ - if (stack.size() > 0) \ - { \ - AronDataNavigatorWriterTokenPtr prevToken = stack.top(); \ - prevToken->addElement(lastRemovedToken->getElement()); \ - } \ - return true; \ - } - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - - // Complex Types -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNavigatorWriter::write##upperType(const std::vector<int>& dims, const std::string& t, const unsigned char* data) \ - { \ - AronPath path = generateAronPath(); \ - AronDataNavigatorWriterTokenPtr token = stack.top(); \ - datanavigator::Aron##upperType##DataNavigatorPtr aron(new datanavigator::Aron##upperType##DataNavigator(path)); \ - aron->setDimensions(dims); \ - aron->setType(t); \ - aron->setData(std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()), data); \ - token->addElement(aron); \ - return true; \ - } - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNavigatorWriter::writePrimitive(const lowerType& x) \ - { \ - AronPath path = generateAronPath(); \ - AronDataNavigatorWriterTokenPtr token = stack.top(); \ - datanavigator::Aron##upperType##DataNavigatorPtr aron(new datanavigator::Aron##upperType##DataNavigator(path)); \ - aron->setValue(x); \ - token->addElement(aron); \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h deleted file mode 100644 index ab1022c8f33f8dc7e1558e08e268f487d5f796e9..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNavigatorWriter; - typedef std::shared_ptr<AronDataNavigatorWriter> AronDataNavigatorWriterPtr; - - class AronDataNavigatorWriter : - virtual public AronDataClassWriter<datanavigator::AronContainerDataNavigatorPtr, AronDataNavigatorWriterTokenPtr> - { - public: - AronDataNavigatorWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType() override; \ - virtual bool writeEnd##upperType() override; - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType(const std::vector<int>&, const std::string&, const unsigned char*) override; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writePrimitive(const lowerType&) override; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - AronPath generateAronPath(); - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriterToken.h deleted file mode 100644 index 4ec86cfe30b7068ab1d7a00d8441e64deae609f5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriterToken.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNavigatorWriterToken; - typedef std::shared_ptr<AronDataNavigatorWriterToken> AronDataNavigatorWriterTokenPtr; - - class AronDataNavigatorWriterToken : - virtual public AronDataClassWriterToken<datanavigator::AronContainerDataNavigatorPtr, datanavigator::AronDataNavigatorPtr> - { - public: - using PointerType = AronDataNavigatorWriterTokenPtr; - - public: - // constructor - AronDataNavigatorWriterToken() = delete; - AronDataNavigatorWriterToken(const AronDataDescriptor desc, const datanavigator::AronContainerDataNavigatorPtr& d) : - AronWriterToken<AronDataDescriptor, datanavigator::AronContainerDataNavigatorPtr, datanavigator::AronDataNavigatorPtr>(desc, d), - AronDataClassWriterToken<datanavigator::AronContainerDataNavigatorPtr, datanavigator::AronDataNavigatorPtr>(desc, d) - { - - } - - // public member functions - virtual void addElement(const datanavigator::AronDataNavigatorPtr& n) override - { - auto desc = this->getDescriptor(); - switch (desc) - { - case eAronDict: - { - datanavigator::AronDictDataNavigatorPtr casted = datanavigator::AronDictDataNavigator::DynamicCastAndCheck(element); - casted->addElement(currentKey, n); - break; - } - case eAronList: - { - datanavigator::AronListDataNavigatorPtr casted = datanavigator::AronListDataNavigator::DynamicCastAndCheck(element); - casted->addElement(n); - currentIndex++; - break; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNavigatorWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers. The path was: " + element->pathToString(), desc); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.cpp deleted file mode 100644 index f3e54dbba44d39b157a4bff869a6a4ad38bf84a5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller (fabian dot peller at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include <numeric> - -#include "AronDataNlohmannJSONWriter.h" - -namespace armarx -{ - namespace aron - { - namespace io - { - - // Containers -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNlohmannJSONWriter::writeStart##upperType() \ - { \ - nlohmann::json data; \ - AronDataNlohmannJSONWriterTokenPtr new_token = AronDataNlohmannJSONWriterTokenPtr(new AronDataNlohmannJSONWriterToken(AronDataDescriptor::eAron##upperType, data)); \ - stack.push(new_token); \ - return true; \ - } \ - \ - bool AronDataNlohmannJSONWriter::writeEnd##upperType() \ - { \ - lastRemovedToken = stack.top(); \ - stack.pop(); \ - \ - if (stack.size() > 0) \ - { \ - AronDataNlohmannJSONWriterTokenPtr prevToken = stack.top(); \ - prevToken->addElement(lastRemovedToken->getElement()); \ - } \ - return true; \ - } - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - - // Complex Types -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNlohmannJSONWriter::write##upperType(const std::vector<int>& dims, const std::string& t, const unsigned char* data) \ - { \ - AronDataNlohmannJSONWriterTokenPtr token = stack.top(); \ - nlohmann::json j; \ - j[ARON_DATA_READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = dims; \ - j[ARON_DATA_READER_WRITER_NDARRAY_TYPE_SLUG] = t; \ - int elements = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); \ - std::vector<unsigned char> d = std::vector<unsigned char>(elements); \ - memcpy(d.data(), data, elements); \ - j[ARON_DATA_READER_WRITER_NDARRAY_DATA_SLUG] = d; \ - token->addElement(j); \ - return true; \ - } - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataNlohmannJSONWriter::writePrimitive(const lowerType& x) \ - { \ - AronDataNlohmannJSONWriterTokenPtr token = stack.top(); \ - nlohmann::json j(x); \ - token->addElement(j); \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h deleted file mode 100644 index 4324e1a94ae2ee0fb956f62c648d66dfdfe2add0..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD / STL -#include <memory> -#include <stack> -#include <sstream> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNlohmannJSONWriter; - typedef std::shared_ptr<AronDataNlohmannJSONWriter> AronDataNlohmannJSONWriterPtr; - - class AronDataNlohmannJSONWriter : - virtual public AronDataClassWriter<nlohmann::json, AronDataNlohmannJSONWriterTokenPtr> - { - public: - AronDataNlohmannJSONWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType() override; \ - virtual bool writeEnd##upperType() override; - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType(const std::vector<int>&, const std::string&, const unsigned char*) override; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writePrimitive(const lowerType&) override; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriterToken.h deleted file mode 100644 index 4246f10e36d3735c8ac55873976fe28cc1a09181..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriterToken.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/json.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataNlohmannJSONWriterToken; - typedef std::shared_ptr<AronDataNlohmannJSONWriterToken> AronDataNlohmannJSONWriterTokenPtr; - - class AronDataNlohmannJSONWriterToken : - virtual public AronDataClassWriterToken<nlohmann::json, nlohmann::json> - { - public: - using PointerType = AronDataNlohmannJSONWriterTokenPtr; - - public: - // constructor - AronDataNlohmannJSONWriterToken() = delete; - AronDataNlohmannJSONWriterToken(const AronDataDescriptor desc, const nlohmann::json& d) : - AronWriterToken<AronDataDescriptor, nlohmann::json, nlohmann::json>(desc, d), - AronDataClassWriterToken<nlohmann::json, nlohmann::json>(desc, d) - { - - } - - // public member functions - virtual void addElement(const nlohmann::json& n) override - { - auto desc = this->getDescriptor(); - switch (desc) - { - case eAronDict: - { - element[currentKey] = n; - break; - } - case eAronList: - { - element.push_back(n); - currentIndex++; - break; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataNlohmannJSONWriterToken", "addElement", "Could not resove a type of a token. Allowed are only containers.", desc); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.cpp deleted file mode 100644 index df6afd5b61fe220e2c23087edd70f671225963b6..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller (fabian dot peller at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include <numeric> - -#include "AronDataRapidXMLWriter.h" - -namespace armarx -{ - namespace aron - { - namespace io - { - // Containers -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataRapidXMLWriter::writeStart##upperType() \ - { \ - return true; \ - } \ - \ - bool AronDataRapidXMLWriter::writeEnd##upperType() \ - { \ - return true; \ - } - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - - // Complex Types -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataRapidXMLWriter::write##upperType(const std::vector<int>& dims, const std::string& t, const unsigned char* data) \ - { \ - return true; \ - } - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronDataRapidXMLWriter::writePrimitive(const lowerType& x) \ - { \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.h deleted file mode 100644 index 480bddb1d1f9bc2f7c857c3cf8b1d846bd294e28..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD / STL -#include <memory> -#include <stack> -#include <sstream> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataRapidXMLWriter; - typedef std::shared_ptr<AronDataRapidXMLWriter> AronDataRapidXMLWriterPtr; - - class AronDataRapidXMLWriter : - virtual public AronDataClassWriter<RapidXmlReaderNode, AronDataRapidXMLWriterTokenPtr> - { - public: - AronDataRapidXMLWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType() override; \ - virtual bool writeEnd##upperType() override; - - HANDLE_CONTAINER_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType(const std::vector<int>&, const std::string&, const unsigned char*) override; \ - - HANDLE_COMPLEX_DATA -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writePrimitive(const lowerType&) override; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriterToken.h deleted file mode 100644 index 9e2959e8d17caeb60eb03150773e394633137a32..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriterToken.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/xml.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/AronDataClassWriterToken.h> - -// ArmarX -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronDataRapidXMLWriterToken; - typedef std::shared_ptr<AronDataRapidXMLWriterToken> AronDataRapidXMLWriterTokenPtr; - - class AronDataRapidXMLWriterToken : - virtual public AronDataClassWriterToken<RapidXmlReaderNode, RapidXmlReaderNode> - { - public: - using PointerType = AronDataRapidXMLWriterTokenPtr; - - public: - // constructor - AronDataRapidXMLWriterToken() = delete; - AronDataRapidXMLWriterToken(const AronDataDescriptor desc, const RapidXmlReaderNode& d) : - AronWriterToken<AronDataDescriptor, RapidXmlReaderNode, RapidXmlReaderNode>(desc, d), - AronDataClassWriterToken<RapidXmlReaderNode, RapidXmlReaderNode>(desc, d) - { - - } - - // public member functions - virtual void addElement(const RapidXmlReaderNode& n) override - { - auto desc = this->getDescriptor(); - switch (desc) - { - case eAronDict: - { - break; - } - case eAronList: - { - break; - } - default: - throw exception::AronDataDescriptorNotValidException("AronDataRapidXMLWriterToken", "addElement", "Could not resove a type of a token. Allowed are only containers.", desc); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronReaderToken.h deleted file mode 100644 index 8c607047c398bbfcdd66255bd2a1b81024ac9fab..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderToken.h +++ /dev/null @@ -1,132 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base class -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename AronDescriptorTypename, typename ElementReturnPtrTypename, typename ElementTypename> - class AronReaderToken; - - template<typename AronDescriptorTypename, typename ElementReturnPtrTypename, typename ElementTypename> - using AronReaderTokenPtr = std::shared_ptr<AronReaderToken<AronDescriptorTypename, ElementReturnPtrTypename, ElementTypename>> ; - - template<typename AronDescriptorTypename, typename ElementReturnPtrTypename, typename ElementTypename> - class AronReaderToken : - public AronReaderWriterToken - { - public: - AronReaderToken() = delete; - AronReaderToken(const AronDescriptorTypename& desc, const ElementTypename& e) : - descriptor(desc), element(e), currentIndex(0), maxIndex(0), currentKey("") - { - }; - - bool checkedAllChildren() const - { - return currentIndex >= allKeys.size() && currentIndex >= maxIndex; - } - - AronDescriptorTypename getDescriptor() const - { - return descriptor; - } - - unsigned int getChildrenSize() const - { - return maxIndex; - } - - void setCurrentKey(const std::string& s) - { - if (s.empty()) - { - throw exception::AronException("AronReaderToken", "setCurrentKey", "The passed key is empty."); - } - currentKey = s; - } - - virtual bool currentIsEligableForResolvingKey() const = 0; - std::string resolveCurrentKey() const - { - if (!this->currentIsEligableForResolvingKey()) - { - throw exception::AronException("AronReaderToken", "resolveCurrentKey", "Cant get key of token."); - } - - // check outOfBounds - if (this->currentIndex >= this->maxIndex) - { - throw exception::AronSizeNotValidException("AronReaderToken", "resolveCurrentKey", "Index out of bounds.", this->currentIndex, this->maxIndex); - } - - // ugly workaround - if (this->currentKey == "") // probably in a dict where the caller does not know which keys are there - { - if (this->allKeys.size() == 0) - { - throw exception::AronException("AronReaderToken", "resolveCurrentKey", "The currentKey is not set and the list of all keys is empty!"); - } - return this->allKeys[this->currentIndex]; - } - return this->currentKey; - } - - - virtual ElementReturnPtrTypename getCurrentElement() const = 0; - ElementReturnPtrTypename getCurrentElementAndIncreaseCnt() - { - ElementReturnPtrTypename next = getCurrentElement(); - this->currentIndex++; - return next; - } - - protected: - // members - AronDescriptorTypename descriptor; - ElementTypename element; - - unsigned int currentIndex; - unsigned int maxIndex; - - // dict and object members - std::string currentKey; - std::vector<std::string> allKeys; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriterToken.h deleted file mode 100644 index b887020db836ed7a2336d4c8f016c7a315b90ae4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriterToken.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronReaderWriterToken; - typedef std::shared_ptr<AronReaderWriterToken> AronReaderWriterTokenPtr; - - class AronReaderWriterToken - { - public: - AronReaderWriterToken() = default; - - protected: - // TODO: Remove copy from ReaderWriter - const std::string ARON_READER_WRITER_TOKEN_OBJECT_NAME_SLUG = "ARON_OBJECT_NAME"; - const std::string ARON_READER_WRITER_TOKEN_DICT_ACCEPTED_TYPE_SLUG = "ARON_DICT_ACCEPTED_TYPE"; - const std::string ARON_READER_WRITER_TOKEN_LIST_ACCEPTED_TYPE_SLUG = "ARON_LIST_ACCEPTED_TYPE"; - - const std::string ARON_READER_WRITER_TOKEN_NDARRAY_NAME_SLUG = "ARON_NDARRAY_NAME"; - const std::string ARON_READER_WRITER_TOKEN_NDARRAY_DIMENSIONS_SLUG = "ARON_NDARRAY_DIMESIONS"; - const std::string ARON_READER_WRITER_TOKEN_NDARRAY_TYPE_SLUG = "ARON_NDARRAY_TYPE"; - const std::string ARON_READER_WRITER_TOKEN_NDARRAY_DATA_SLUG = "ARON_NDARRAY_DATA"; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - const std::string ARON_READER_WRITER_TOKEN_##capsType##_TYPENAME_SLUG = "ARON_" + std::string(#capsType) + "_TYPE"; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.cpp deleted file mode 100644 index 6db59a989d2e05fafb843baef278a21fae8108d8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronTypeConverter.h" - - - - -namespace armarx -{ - namespace aron - { - namespace io - { - void AronTypeConverter::ConvertFromReader(AronTypeReader& reader, AronTypeWriter& writer) - { - AronTypeDescriptor desc = reader.getTypeOfNextAron(); - switch (desc) - { - case eAronObjectType: - { - const int elements = reader.readStartObjectType(); - const std::string name = reader.readObjectName(); - - writer.writeStartObjectType(); - writer.writeObjectName(name); - - for (int i = 0; i < elements; ++i) - { - std::string key = reader.readKey(); - writer.writeKey(key); - AronTypeConverter::ConvertFromReader(reader, writer); - } - - writer.writeEndObjectType(); - reader.readEndObjectType(); - break; - } - case eAronDictType: - { - reader.readStartDictType(); - writer.writeStartDictType(); - - AronTypeConverter::ConvertFromReader(reader, writer); - - writer.writeEndDictType(); - reader.readEndDictType(); - break; - } - case eAronTupleType: - { - int elements = reader.readStartTupleType(); - writer.writeStartTupleType(); - - for (int i = 0; i < elements; ++i) - { - AronTypeConverter::ConvertFromReader(reader, writer); - } - - writer.writeEndTupleType(); - reader.readEndTupleType(); - break; - } - case eAronListType: - { - reader.readStartListType(); - writer.writeStartListType(); - - AronTypeConverter::ConvertFromReader(reader, writer); - - writer.writeEndListType(); - reader.readEndListType(); - break; - } -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - auto [dims, type] = reader.read##upperType##Type(); \ - writer.write##upperType##Type(dims, type); \ - break; \ -} - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - reader.read##upperType##Type(); \ - writer.write##upperType##Type(); \ - break; \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - default: - { - throw exception::AronTypeDescriptorNotValidException("LegacyAronTypeReader", "SetupReaderAndGetResult", "Type-Type could not be resolved", desc); - } - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReader.h deleted file mode 100644 index 5d8034c983c76a5c2b32de7e9b92d2a0e5b17b5e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReader.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReaderWriter.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeReader; - typedef std::shared_ptr<AronTypeReader> AronTypeReaderPtr; - - class AronTypeReader : - public AronTypeReaderWriter - { - public: - AronTypeReader() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType##Type() = 0; \ - virtual bool readEnd##upperType##Type() = 0; \ - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> read##upperType##Type() = 0; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void read##upperType##Type() = 0; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - virtual std::string readKey() = 0; - virtual bool readKey(const std::string&) = 0; - virtual std::string readObjectName() = 0; - - // Helper functions - virtual AronTypeDescriptor getTypeOfNextAron() const = 0; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReaderWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReaderWriter.h deleted file mode 100644 index 47a78243317b382a4ef7b818ee23dd8a788e0b3a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReaderWriter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderWriter.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeReaderWriter; - typedef std::shared_ptr<AronTypeReaderWriter> AronTypeReaderWriterPtr; - - class AronTypeReaderWriter : - public AronReaderWriter - { - public: - AronTypeReaderWriter() = default; - - protected: - const std::string ARON_TYPE_READER_WRITER_NDARRAY_NAME_SLUG = "ARON_NDARRAY_NAME"; - const std::string ARON_TYPE_READER_WRITER_NDARRAY_DIMENSIONS_SLUG = "ARON_NDARRAY_DIMESIONS"; - const std::string ARON_TYPE_READER_WRITER_NDARRAY_TYPE_SLUG = "ARON_NDARRAY_TYPE"; - const std::string ARON_TYPE_READER_WRITER_NDARRAY_DATA_SLUG = "ARON_NDARRAY_DATA"; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - const std::string ARON_TYPE_READER_WRITER_##capsType##_TYPENAME = "ARON_" + std::string(#capsType) + "_TYPE"; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h deleted file mode 100644 index 1a9f64515ac3c1631bc527c1d3f1d1296b7b2852..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReaderWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeWriter; - typedef std::shared_ptr<AronTypeWriter> AronTypeWriterPtr; - - class AronTypeWriter : - public AronTypeReaderWriter - { - public: - AronTypeWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType##Type() = 0; \ - virtual bool writeEnd##upperType##Type() = 0; \ - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type(const std::vector<int>&, const std::string&) = 0; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type() = 0; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - virtual bool writeKey(const std::string&) = 0; - virtual bool writeObjectName(const std::string&) = 0; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.cpp deleted file mode 100644 index 3c3d099d8df5c6a67a12c643d91490ddf4412f2f..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronTypeWriterVisitor.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - - void AronTypeWriterVisitor::SetupWriterFromAronTypePtr(AronTypeWriter& writer, const typenavigator::AronTypeNavigatorPtr& aron) - { - SetupWriterFromAronTypePtr(writer, aron->getResult()); - } - - void AronTypeWriterVisitor::SetupWriterFromAronTypePtr(AronTypeWriter& writer, const type::AronTypePtr& aron) - { - AronTypeDescriptor desc = AronResolver::GetDescriptorForAronType(aron); - switch (desc) - { - case eAronObjectType: - { - type::AronObjectTypePtr casted = type::AronObjectTypePtr::dynamicCast(aron); - writer.writeStartObjectType(); - writer.writeObjectName(casted->objectName); - for (const auto& [key, value] : casted->elementTypes) - { - writer.writeKey(key); - AronTypeWriterVisitor::SetupWriterFromAronTypePtr(writer, value); - } - writer.writeEndObjectType(); - break; - } - case eAronDictType: - { - type::AronDictTypePtr casted = type::AronDictTypePtr::dynamicCast(aron); - writer.writeStartDictType(); - AronTypeWriterVisitor::SetupWriterFromAronTypePtr(writer, casted->acceptedType); - writer.writeEndDictType(); - break; - } - case eAronTupleType: - { - type::AronTupleTypePtr casted = type::AronTupleTypePtr::dynamicCast(aron); - writer.writeStartTupleType(); - for (const auto& value : casted->elementTypes) - { - AronTypeWriterVisitor::SetupWriterFromAronTypePtr(writer, value); - } - writer.writeEndTupleType(); - break; - } - case eAronListType: - { - type::AronListTypePtr casted = type::AronListTypePtr::dynamicCast(aron); - writer.writeStartListType(); - AronTypeWriterVisitor::SetupWriterFromAronTypePtr(writer, casted->acceptedType); - writer.writeEndListType(); - break; - } -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - type::Aron##upperType##TypePtr casted = type::Aron##upperType##TypePtr::dynamicCast(aron); \ - writer.write##upperType##Type(casted->dimensions, casted->typeName); \ - break; \ -} - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - type::Aron##upperType##TypePtr casted = type::Aron##upperType##TypePtr::dynamicCast(aron); \ - writer.write##upperType##Type(); \ - break; \ -} - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - default: - { - throw exception::AronTypeDescriptorNotValidException("LegacyAronTypeWriter", "SetupWriterFromAronTypePtr", "Type-Type could not be resolved. The ice_id of the input was: " + aron->ice_id(), desc); - } - } - } - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h deleted file mode 100644 index 234a546c678bba4bd80efcae19555dd1b5c112b7..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriterVisitor/AronTypeWriterVisitor.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeWriterVisitor; - typedef std::shared_ptr<AronTypeWriterVisitor> AronTypeWriterVisitorPtr; - - class AronTypeWriterVisitor : - virtual public AronTypeWriter - { - private: - AronTypeWriterVisitor() = delete; - - public: - static void SetupWriterFromAronTypePtr(AronTypeWriter&, const typenavigator::AronTypeNavigatorPtr&); - static void SetupWriterFromAronTypePtr(AronTypeWriter&, const type::AronTypePtr&); - - public: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReader.h deleted file mode 100644 index 2c011b1bbeb572ba4f3045e2d44a888405949cb5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReader.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReader.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - template <typename InputTypename, typename TokenPtrTypename> - class AronTypeClassReader; - - template <typename InputTypename, typename TokenPtrTypename> - using AronTypeClassReaderPtr = std::shared_ptr<AronTypeClassReader<InputTypename, TokenPtrTypename>> ; - - template <typename InputTypename, typename TokenPtrTypename> - class AronTypeClassReader : - public AronTypeReader - { - public: - AronTypeClassReader() = delete; - AronTypeClassReader(const InputTypename& input) : - input(input) - { - } - - // ReadKey - std::string readKey() override - { - TokenPtrTypename token = stack.top(); - std::string k = token->resolveCurrentKey(); - return k; - } - - bool readKey(const std::string& k) override - { - TokenPtrTypename token = stack.top(); - token->setCurrentKey(k); - return true; - } - - std::string readObjectName() override - { - TokenPtrTypename token = stack.top(); - return token->getObjectName(); - } - - virtual AronTypeDescriptor getTypeOfNextAron() const override - { - if (stack.empty()) - { - // completely unknown. We assume a object on the top level - return eAronObjectType; - } - - TokenPtrTypename lastToken = stack.top(); - return lastToken->getTypeOfNextElement(); - } - - protected: - InputTypename input; - bool readInitialStart = false; - std::stack<TokenPtrTypename> stack; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReaderToken.h deleted file mode 100644 index 4d4879c82cd6e7cbde4426be8fbedcdce2b4de43..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReaderToken.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - class AronTypeClassReaderToken; - - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - using AronTypeClassReaderTokenPtr = std::shared_ptr<AronTypeClassReaderToken<ElementReturnPtrTypename, ElementAddTypename>>; - - template<typename ElementReturnPtrTypename, typename ElementAddTypename> - class AronTypeClassReaderToken : - virtual public AronReaderToken<AronTypeDescriptor, ElementReturnPtrTypename, ElementAddTypename> - { - public: - using PointerType = AronTypeClassReaderTokenPtr<ElementReturnPtrTypename, ElementAddTypename>; - - public: - // constructors - AronTypeClassReaderToken() = delete; - AronTypeClassReaderToken(const AronTypeDescriptor desc, const ElementAddTypename& type) : - AronReaderToken<AronTypeDescriptor, ElementReturnPtrTypename, ElementAddTypename>(desc, type) - { } - - bool currentIsEligableForResolvingKey() const override - { - if (this->descriptor == AronTypeDescriptor::eAronObjectType) - { - return true; - } - return false; - } - - virtual std::string getObjectName() const = 0; - virtual AronTypeDescriptor getTypeOfNextElement() const = 0; - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.cpp deleted file mode 100644 index f548134ab93af6657a265310be8a7612c6781339..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronTypeNavigatorReader.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - AronTypeNavigatorReader::AronTypeNavigatorReader(const typenavigator::AronContainerTypeNavigatorPtr& n) : - AronTypeClassReader<typenavigator::AronContainerTypeNavigatorPtr, AronTypeNavigatorReaderTokenPtr>(n) - { - } - - AronTypeNavigatorReader::AronTypeNavigatorReader(const type::AronContainerTypePtr& n) : - AronTypeClassReader<typenavigator::AronContainerTypeNavigatorPtr, AronTypeNavigatorReaderTokenPtr>( - typenavigator::AronContainerTypeNavigator::DynamicCast(typenavigator::AronTypeNavigator::FromAronType(n)) - ) - { - } - - typenavigator::AronTypeNavigatorPtr AronTypeNavigatorReader::getCurrentAndGoToNext() - { - if (!readInitialStart) - { - readInitialStart = true; - return input; - } - AronTypeNavigatorReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElementAndIncreaseCnt(); - } - - typenavigator::AronTypeNavigatorPtr AronTypeNavigatorReader::getCurrent() - { - if (!readInitialStart) - { - readInitialStart = true; - return input; - } - AronTypeNavigatorReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElement(); - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - int AronTypeNavigatorReader::readStart##upperType##Type() \ - { \ - typenavigator::AronTypeNavigatorPtr current_nav = getCurrentAndGoToNext(); \ - auto desc = current_nav->getDescriptor(); \ - if (desc != AronTypeDescriptor::eAron##upperType##Type) \ - { \ - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReader", "readStart" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType), desc); \ - return false; \ - } \ - typenavigator::Aron##upperType##TypeNavigatorPtr current_nav_casted = typenavigator::Aron##upperType##TypeNavigator::DynamicCast(current_nav); \ - AronTypeNavigatorReaderTokenPtr newToken = AronTypeNavigatorReaderTokenPtr(new AronTypeNavigatorReaderToken(current_nav->getDescriptor(), current_nav_casted)); \ - stack.push(newToken); \ - return newToken->getChildrenSize(); \ - } \ - \ - bool AronTypeNavigatorReader::readEnd##upperType##Type() \ - { \ - AronTypeNavigatorReaderTokenPtr token = stack.top(); \ - auto desc = token->getDescriptor(); \ - if (desc != AronTypeDescriptor::eAron##upperType##Type) \ - { \ - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReader", "readEnd" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType), desc); \ - return false; \ - } \ - \ - if (token->checkedAllChildren()) \ - { \ - stack.pop(); \ - return true; \ - } \ - return false; \ - } - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - - // Complex Type -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - std::pair<std::vector<int>, std::string> AronTypeNavigatorReader::read##upperType##Type() \ - { \ - typenavigator::AronTypeNavigatorPtr nav = getCurrentAndGoToNext(); \ - typenavigator::Aron##upperType##TypeNavigatorPtr casted = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(nav); \ - return std::make_pair(casted->getDimensions(), casted->getUsedType()); \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - - // Read primitives -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - void AronTypeNavigatorReader::read##upperType##Type() \ - { \ - typenavigator::AronTypeNavigatorPtr nav = getCurrentAndGoToNext(); \ - typenavigator::Aron##upperType##TypeNavigatorPtr casted = typenavigator::Aron##upperType##TypeNavigator::DynamicCastAndCheck(nav); \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.h deleted file mode 100644 index 29788d39f0f4c73265bb86bdbe0abed33cf635a7..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReader.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReader.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReaderToken.h> - - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNavigatorReader; - typedef std::shared_ptr<AronTypeNavigatorReader> AronTypeNavigatorReaderPtr; - - class AronTypeNavigatorReader : - virtual public AronTypeClassReader<typenavigator::AronContainerTypeNavigatorPtr, AronTypeNavigatorReaderTokenPtr> - { - public: - using PointerType = AronTypeNavigatorReaderPtr; - - public: - // constructors - AronTypeNavigatorReader() = delete; - AronTypeNavigatorReader(const typenavigator::AronContainerTypeNavigatorPtr& n); - AronTypeNavigatorReader(const type::AronContainerTypePtr& n); - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType##Type() override; \ - virtual bool readEnd##upperType##Type() override; \ - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> read##upperType##Type() override; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void read##upperType##Type() override; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - typenavigator::AronTypeNavigatorPtr getCurrentAndGoToNext(); - typenavigator::AronTypeNavigatorPtr getCurrent(); - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReaderToken.h deleted file mode 100644 index 12cca75857b599f5338040e8cca6fe5770ed0076..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NavigatorReader/AronTypeNavigatorReaderToken.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - // BaseClass - class AronTypeNavigatorReaderToken; - typedef std::shared_ptr<AronTypeNavigatorReaderToken> AronTypeNavigatorReaderTokenPtr; - - class AronTypeNavigatorReaderToken : - virtual public AronTypeClassReaderToken<typenavigator::AronTypeNavigatorPtr, typenavigator::AronContainerTypeNavigatorPtr> - { - public: - using PointerType = AronTypeNavigatorReaderTokenPtr; - - public: - // constructors - AronTypeNavigatorReaderToken() = delete; - AronTypeNavigatorReaderToken(const AronTypeDescriptor desc, const typenavigator::AronContainerTypeNavigatorPtr& type) : - AronReaderToken<AronTypeDescriptor, typenavigator::AronTypeNavigatorPtr, typenavigator::AronContainerTypeNavigatorPtr>(desc, type), - AronTypeClassReaderToken<typenavigator::AronTypeNavigatorPtr, typenavigator::AronContainerTypeNavigatorPtr>(desc, type) - { - switch (descriptor) - { - case eAronObjectType: - { - allKeys = typenavigator::AronObjectTypeNavigator::DynamicCast(element)->getAllKeys(); - maxIndex = allKeys.size(); - break; - } - case eAronDictType: - { - maxIndex = 1; - break; - } - case eAronTupleType: - { - maxIndex = typenavigator::AronTupleTypeNavigator::DynamicCast(element)->childrenSize(); - break; - } - case eAronListType: - { - maxIndex = 1; - break; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReaderToken", "AronTypeNavigatorReaderToken", "Received an invalid instance for a reader token.", desc); - } - } - - std::string getObjectName() const override - { - if(descriptor == eAronObjectType) - { - const typenavigator::AronObjectTypeNavigatorPtr next = typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(getCurrentElement()); - return next->getObjectName(); - } - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReaderToken", "AronTypeNavigatorReaderToken", "Could not get object nme of a non-object token", descriptor); - } - - AronTypeDescriptor getTypeOfNextElement() const override - { - const typenavigator::AronTypeNavigatorPtr next = getCurrentElement(); - return next->getDescriptor(); - } - - typenavigator::AronTypeNavigatorPtr getCurrentElement() const override - { - switch (descriptor) - { - case eAronObjectType: - { - typenavigator::AronObjectTypeNavigatorPtr casted = typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(element); - typenavigator::AronTypeNavigatorPtr ret = casted->getAcceptedType(resolveCurrentKey()); - return ret; - } - case eAronDictType: - { - typenavigator::AronDictTypeNavigatorPtr casted = typenavigator::AronDictTypeNavigator::DynamicCastAndCheck(element); - typenavigator::AronTypeNavigatorPtr ret = casted->getAcceptedType(); - return ret; - } - case eAronTupleType: - { - typenavigator::AronTupleTypeNavigatorPtr casted = typenavigator::AronTupleTypeNavigator::DynamicCastAndCheck(element); - typenavigator::AronTypeNavigatorPtr ret = casted->getAcceptedType(currentIndex); - return ret; - } - case eAronListType: - { - typenavigator::AronListTypeNavigatorPtr casted = typenavigator::AronListTypeNavigator::DynamicCastAndCheck(element); - typenavigator::AronTypeNavigatorPtr ret = casted->getAcceptedType(); - return ret; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.cpp deleted file mode 100644 index 03b525e43be244ff98fa804b4d3955699eeadda7..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronTypeNlohmannJSONReader.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - AronTypeNlohmannJSONReader::AronTypeNlohmannJSONReader(const nlohmann::json& n) : - AronTypeClassReader<nlohmann::json, AronTypeNlohmannJSONReaderTokenPtr>(n) - { - } - - AronTypeNlohmannJSONReader::AronTypeNlohmannJSONReader(const std::string& n) : - AronTypeClassReader<nlohmann::json, AronTypeNlohmannJSONReaderTokenPtr>(nlohmann::json::parse(n)) - { - } - - nlohmann::json AronTypeNlohmannJSONReader::getCurrentAndGoToNext() - { - if (!readInitialStart) - { - readInitialStart = true; - return input; - } - AronTypeNlohmannJSONReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElementAndIncreaseCnt(); - } - - nlohmann::json AronTypeNlohmannJSONReader::getCurrent() - { - if (!readInitialStart) - { - readInitialStart = true; - return input; - } - AronTypeNlohmannJSONReaderTokenPtr lastToken = stack.top(); - return lastToken->getCurrentElement(); - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - int AronTypeNlohmannJSONReader::readStart##upperType##Type() \ - { \ - nlohmann::json current_json = getCurrentAndGoToNext(); \ - AronTypeNlohmannJSONReaderTokenPtr newToken = AronTypeNlohmannJSONReaderTokenPtr(new AronTypeNlohmannJSONReaderToken(eAron##upperType##Type, current_json)); \ - stack.push(newToken); \ - return newToken->getChildrenSize(); \ - } \ - \ - bool AronTypeNlohmannJSONReader::readEnd##upperType##Type() \ - { \ - AronTypeNlohmannJSONReaderTokenPtr token = stack.top(); \ - auto desc = token->getDescriptor(); \ - if (desc != AronTypeDescriptor::eAron##upperType##Type) \ - { \ - throw exception::AronTypeDescriptorNotValidException("AronTypeNlohmannJSONReader", "readEnd" + std::string(#upperType), "A token in the stack has the wrong type. Expected " + std::string(#upperType) + "Type", desc); \ - return false; \ - } \ - \ - if (token->checkedAllChildren()) \ - { \ - stack.pop(); \ - return true; \ - } \ - return false; \ - } - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - - // Complex Type -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - std::pair<std::vector<int>, std::string> AronTypeNlohmannJSONReader::read##upperType##Type() \ - { \ - nlohmann::json j = getCurrent(); \ - std::vector<int> dims = j[ARON_TYPE_READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; \ - std::string type = j[ARON_TYPE_READER_WRITER_NDARRAY_TYPE_SLUG]; \ - return std::make_pair(dims, type); \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - - // Read primitives -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - void AronTypeNlohmannJSONReader::read##upperType##Type() \ - { \ - nlohmann::json j = getCurrentAndGoToNext(); \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h deleted file mode 100644 index ee52d331d6377fa6014eb8d2d2d159d32407e52d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReader.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReaderToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNlohmannJSONReader; - typedef std::shared_ptr<AronTypeNlohmannJSONReader> AronTypeNlohmannJSONReaderPtr; - - class AronTypeNlohmannJSONReader : - virtual public AronTypeClassReader<nlohmann::json, AronTypeNlohmannJSONReaderTokenPtr> - { - public: - using PointerType = AronTypeNlohmannJSONReaderPtr; - - public: - // constructors - AronTypeNlohmannJSONReader() = delete; - AronTypeNlohmannJSONReader(const nlohmann::json& n); - AronTypeNlohmannJSONReader(const std::string& n); - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual int readStart##upperType##Type() override; \ - virtual bool readEnd##upperType##Type() override; \ - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual std::pair<std::vector<int>, std::string> read##upperType##Type() override; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual void read##upperType##Type() override; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - nlohmann::json getCurrent(); - nlohmann::json getCurrentAndGoToNext(); - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReaderToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReaderToken.h deleted file mode 100644 index 86111ca6c43b028d9a36e8e953f461e6cc19cd21..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReaderToken.h +++ /dev/null @@ -1,196 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/json.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/AronTypeClassReaderToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - // BaseClass - class AronTypeNlohmannJSONReaderToken; - typedef std::shared_ptr<AronTypeNlohmannJSONReaderToken> AronTypeNlohmannJSONReaderTokenPtr; - - class AronTypeNlohmannJSONReaderToken : - virtual public AronTypeClassReaderToken<nlohmann::json, nlohmann::json> - { - public: - using PointerType = AronTypeNlohmannJSONReaderTokenPtr; - - public: - // constructors - AronTypeNlohmannJSONReaderToken() = delete; - AronTypeNlohmannJSONReaderToken(const AronTypeDescriptor desc, const nlohmann::json& type) : - AronReaderToken<AronTypeDescriptor, nlohmann::json, nlohmann::json>(desc, type), - AronTypeClassReaderToken<nlohmann::json, nlohmann::json>(desc, type) - { - switch (descriptor) - { - case eAronObjectType: - { - for (auto it = type.begin(); it != type.end(); ++it) - { - if ( - it.key() == ARON_READER_WRITER_TOKEN_OBJECT_NAME_SLUG || -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -it.key() == ARON_READER_WRITER_TOKEN_##capsType##_TYPENAME_SLUG || - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - it.key() == ARON_READER_WRITER_TOKEN_DICT_ACCEPTED_TYPE_SLUG || - it.key() == ARON_READER_WRITER_TOKEN_LIST_ACCEPTED_TYPE_SLUG || - it.key() == ARON_READER_WRITER_TOKEN_NDARRAY_NAME_SLUG || - it.key() == ARON_READER_WRITER_TOKEN_NDARRAY_DIMENSIONS_SLUG || - it.key() == ARON_READER_WRITER_TOKEN_NDARRAY_TYPE_SLUG - ) - { - continue; - } - - allKeys.push_back(it.key()); - } - maxIndex = allKeys.size(); - break; - } - case eAronDictType: - { - maxIndex = 1; - break; - } - case eAronTupleType: - { - maxIndex = type.size(); - break; - } - case eAronListType: - { - maxIndex = 1; - break; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNlohmannJSONReaderToken", "AronTypeNlohmannJSONReaderToken", "Received an invalid instance for a reader token.", desc); - } - } - - std::string getObjectName() const override - { - if (descriptor == eAronObjectType) - { - return element[ARON_READER_WRITER_TOKEN_OBJECT_NAME_SLUG]; - } - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorReaderToken", "AronTypeNavigatorReaderToken", "Could not get object nme of a non-object token", descriptor); - } - - AronTypeDescriptor getTypeOfNextElement() const override - { - const nlohmann::json next = getCurrentElement(); - - if (next.is_object()) - { - if (next.find(ARON_READER_WRITER_TOKEN_DICT_ACCEPTED_TYPE_SLUG) != next.end()) - { - return eAronDictType; - } - if (next.find(ARON_READER_WRITER_TOKEN_LIST_ACCEPTED_TYPE_SLUG) != next.end()) - { - return eAronListType; - } - if (next.find(ARON_READER_WRITER_TOKEN_NDARRAY_NAME_SLUG) != next.end()) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - if (next[ARON_READER_WRITER_TOKEN_NDARRAY_NAME_SLUG] == std::string(#upperType)) \ - { \ - return eAron##upperType##Type; \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - throw exception::AronException("AronTypeNlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Found indicator of NDArray but could not resolve real type. Found JSON: " + next[ARON_READER_WRITER_TOKEN_NDARRAY_NAME_SLUG].dump(2)); - } - return eAronObjectType; - } - if (next.is_array()) - { - return eAronTupleType; - } - if (next.is_string()) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - if (next == ARON_READER_WRITER_TOKEN_##capsType##_TYPENAME_SLUG) \ - { \ - return eAron##upperType##Type; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - throw exception::AronException("AronTypeNlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Could not convert to AronTypeDescriptor enum. Found JSON: " + next.dump(2)); - } - - nlohmann::json getCurrentElement() const override - { - switch (descriptor) - { - case eAronObjectType: - { - nlohmann::json ret = element[resolveCurrentKey()]; - return ret; - } - case eAronDictType: - { - nlohmann::json ret = element[ARON_READER_WRITER_TOKEN_DICT_ACCEPTED_TYPE_SLUG]; - return ret; - } - case eAronTupleType: - { - nlohmann::json ret = element[currentIndex]; - return ret; - } - case eAronListType: - { - nlohmann::json ret = element[ARON_READER_WRITER_TOKEN_LIST_ACCEPTED_TYPE_SLUG]; - return ret; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNlohmannJSONReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); - } - } - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h deleted file mode 100644 index 972d0517384ad1a0a3a53903958570a2c409e87f..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <stack> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template <typename GeneratePtr, typename TokenPtr> - class AronTypeClassWriter; - - template <typename GeneratePtr, typename TokenPtr> - using AronTypeClassWriterPtr = std::shared_ptr<AronTypeClassWriter<GeneratePtr, TokenPtr>>; - - template <typename GeneratePtr, typename TokenPtr> - class AronTypeClassWriter : - virtual public AronTypeWriter - { - public: - AronTypeClassWriter() = default; - - virtual bool writeKey(const std::string& k) override - { - TokenPtr token = stack.top(); - token->setCurrentKey(k); - return true; - } - - bool writeObjectName(const std::string& n) - { - TokenPtr token = stack.top(); - token->setName(n); - return true; - } - - GeneratePtr getResult() const - { - assertLastRemovedTokenIsSet(); - assertStackIsEmpty(); - return lastRemovedToken->getElement(); - } - - protected: - void assertLastRemovedTokenIsSet() const - { - if (lastRemovedToken == nullptr) - { - throw exception::AronException("AronTypeClassWriter", "assertLastRemovedTokenIsSet", "lastRemovedToken is NULL. Perhaps you never called a writeEnd* method?"); - } - if (lastRemovedToken->getElement() == nullptr) - { - throw exception::AronException("AronTypeClassWriter", "assertLastRemovedTokenIsSet", "lastRemovedToken->getElement() is NULL."); - } - } - void assertStackIsEmpty() const - { - if (stack.size() != 0) - { - throw exception::AronException("AronTypeClassWriter", "assertStackIsEmpty", "The Size of the stack is not 0. Perhaps you never called a writeEnd* method?"); - } - } - - protected: - bool wroteInitialStartContainer = false; - TokenPtr lastRemovedToken; - std::stack<TokenPtr> stack; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h deleted file mode 100644 index 5b016ca9f3e6245200500feb6d3be97cd6aae53b..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename ElementPtrTypename, typename ElementAddTypename> - class AronTypeClassWriterToken; - - template<typename ElementPtrTypename, typename ElementAddTypename> - using AronTypeClassWriterTokenPtr = std::shared_ptr<AronTypeClassWriterToken<ElementPtrTypename, ElementAddTypename>>; - - template<typename ElementPtrTypename, typename ElementAddTypename> - class AronTypeClassWriterToken : - virtual public AronWriterToken<AronTypeDescriptor, ElementPtrTypename, ElementAddTypename> - { - public: - using PointerType = AronTypeClassWriterToken<ElementPtrTypename, ElementAddTypename>; - - public: - // constructor - AronTypeClassWriterToken() = delete; - AronTypeClassWriterToken(const AronTypeDescriptor desc, const ElementPtrTypename& n) : - AronWriterToken<AronTypeDescriptor, ElementPtrTypename, ElementAddTypename>(desc, n) - {} - - // public member functions - virtual void addElement(const ElementAddTypename&) = 0; - - virtual std::string toElementAccessor() const override - { - AronTypeDescriptor desc = this->getDescriptor(); - switch (desc) - { - case eAronDictType: - case eAronListType: - return "[ACCEPTED_TYPE]"; - case eAronObjectType: - return "\"" + this->currentKey + "\""; - case eAronTupleType: - return "<" + std::to_string(this->currentIndex) + ">"; - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorWriterToken", "toElementAccessor", "Could not resove a type of a navigator. Allowed are only containers.", desc); - } - } - - virtual void setName(const std::string& n) = 0; - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.cpp deleted file mode 100644 index 8e05757db32997bedcb40de946bdbdda3ac8431f..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* -* 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 -*/ - -// STD/STL -#include <memory> -#include <numeric> - -// Header -#include "AronTypeNavigatorWriter.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h> - -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - - AronPath AronTypeNavigatorWriter::generateAronPath() - { - AronPath path; - if (!wroteInitialStartContainer) - { - wroteInitialStartContainer = true; - } - else - { - AronTypeNavigatorWriterTokenPtr parent_token = stack.top(); - path = AronPath(parent_token->getElement()->getPath(), parent_token->toElementAccessor()); - } - return path; - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNavigatorWriter::writeStart##upperType##Type() \ - { \ - AronPath path = generateAronPath(); \ - typenavigator::Aron##upperType##TypeNavigatorPtr type = typenavigator::Aron##upperType##TypeNavigatorPtr(new typenavigator::Aron##upperType##TypeNavigator(path)); \ - AronTypeNavigatorWriterTokenPtr new_token = AronTypeNavigatorWriterTokenPtr(new AronTypeNavigatorWriterToken(type->getDescriptor(), type)); \ - stack.push(new_token); \ - return true; \ - } \ - bool AronTypeNavigatorWriter::writeEnd##upperType##Type() \ - { \ - lastRemovedToken = stack.top(); \ - stack.pop(); \ - \ - if (stack.size() > 0) \ - { \ - AronTypeNavigatorWriterTokenPtr prevToken = stack.top(); \ - prevToken->addElement(lastRemovedToken->getElement()); \ - } \ - return true; \ - } - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNavigatorWriter::write##upperType##Type(const std::vector<int>& dims, const std::string& t) \ - { \ - AronPath path = generateAronPath(); \ - AronTypeNavigatorWriterTokenPtr token = stack.top(); \ - typenavigator::Aron##upperType##TypeNavigatorPtr aron(new typenavigator::Aron##upperType##TypeNavigator(path)); \ - aron->setUsedType(t); \ - aron->setDimensions(dims); \ - token->addElement(aron); \ - return true; \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNavigatorWriter::write##upperType##Type() \ - { \ - AronPath path = generateAronPath(); \ - AronTypeNavigatorWriterTokenPtr token = stack.top(); \ - typenavigator::Aron##upperType##TypeNavigatorPtr aron(new typenavigator::Aron##upperType##TypeNavigator(path)); \ - token->addElement(aron); \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h deleted file mode 100644 index 1b1fa8dd24f43ae9bab52c97d4da59ebae2f1f36..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <stack> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNavigatorWriter; - typedef std::shared_ptr<AronTypeNavigatorWriter> AronTypeNavigatorWriterPtr; - - class AronTypeNavigatorWriter : - virtual public AronTypeClassWriter<typenavigator::AronTypeNavigatorPtr, AronTypeNavigatorWriterTokenPtr> - { - public: - AronTypeNavigatorWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType##Type() override; \ - virtual bool writeEnd##upperType##Type() override; \ - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type(const std::vector<int>&, const std::string&) override; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type() override; \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - AronPath generateAronPath(); - - private: - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriterToken.h deleted file mode 100644 index dd1fc3caff7d836ec136f46797539af9f4df14f8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriterToken.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNavigatorWriterToken; - typedef std::shared_ptr<AronTypeNavigatorWriterToken> AronTypeNavigatorWriterTokenPtr; - - class AronTypeNavigatorWriterToken : - virtual public AronTypeClassWriterToken<typenavigator::AronContainerTypeNavigatorPtr, typenavigator::AronTypeNavigatorPtr> - { - public: - using PointerType = AronTypeNavigatorWriterTokenPtr; - - public: - // constructor - AronTypeNavigatorWriterToken() = delete; - AronTypeNavigatorWriterToken(const AronTypeDescriptor desc, const typenavigator::AronContainerTypeNavigatorPtr& t) : - AronWriterToken<AronTypeDescriptor, typenavigator::AronContainerTypeNavigatorPtr, typenavigator::AronTypeNavigatorPtr>(desc, t), - AronTypeClassWriterToken<typenavigator::AronContainerTypeNavigatorPtr, typenavigator::AronTypeNavigatorPtr>(desc, t) - { - } - - // virtual member functions - virtual void addElement(const typenavigator::AronTypeNavigatorPtr& n) override - { - switch (descriptor) - { - case eAronDictType: - { - typenavigator::AronDictTypeNavigatorPtr casted = typenavigator::AronDictTypeNavigator::DynamicCastAndCheck(element); - casted->setAcceptedType(n); - break; - } - case eAronListType: - { - typenavigator::AronListTypeNavigatorPtr casted = typenavigator::AronListTypeNavigator::DynamicCastAndCheck(element); - casted->setAcceptedType(n); - break; - } - case eAronObjectType: - { - typenavigator::AronObjectTypeNavigatorPtr casted = typenavigator::AronObjectTypeNavigator::DynamicCastAndCheck(element); - casted->addAcceptedType(currentKey, n); - break; - } - case eAronTupleType: - { - typenavigator::AronTupleTypeNavigatorPtr casted = typenavigator::AronTupleTypeNavigator::DynamicCastAndCheck(element); - casted->addAcceptedType(n); - currentIndex++; - break; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers. The path was: " + getElement()->pathToString(), descriptor); - } - } - - virtual void setName(const std::string& n) override - { - if (descriptor != AronTypeDescriptor::eAronObjectType) - { - throw exception::AronTypeDescriptorNotValidException("AronTypeNavigatorWriterToken", "setName", "Cant set the name of a non-object token. The path was: " + getElement()->pathToString(), descriptor); - } - typenavigator::AronObjectTypeNavigatorPtr casted = typenavigator::AronObjectTypeNavigator::DynamicCast(element); - casted->setObjectName(n); - } - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.cpp deleted file mode 100644 index f40e1ee6da8ea092e04265373c300ddddb7d016e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller (fabian dot peller at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include "AronTypeNlohmannJSONWriter.h" - -namespace armarx -{ - namespace aron - { - namespace io - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNlohmannJSONWriter::writeStart##upperType##Type() \ - { \ - nlohmann::json data; \ - AronTypeNlohmannJSONWriterTokenPtr new_token = AronTypeNlohmannJSONWriterTokenPtr(new AronTypeNlohmannJSONWriterToken(AronTypeDescriptor::eAron##upperType##Type, data)); \ - stack.push(new_token); \ - return true; \ - } \ - bool AronTypeNlohmannJSONWriter::writeEnd##upperType##Type() \ - { \ - lastRemovedToken = stack.top(); \ - stack.pop(); \ - \ - if (stack.size() > 0) \ - { \ - AronTypeNlohmannJSONWriterTokenPtr prevToken = stack.top(); \ - prevToken->addElement(lastRemovedToken->getElement()); \ - } \ - return true; \ - } - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNlohmannJSONWriter::write##upperType##Type(const std::vector<int>& dims, const std::string& t) \ - { \ - AronTypeNlohmannJSONWriterTokenPtr token = stack.top(); \ - nlohmann::json j; \ - j[ARON_TYPE_READER_WRITER_NDARRAY_NAME_SLUG] = std::string(#upperType); \ - j[ARON_TYPE_READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = dims; \ - j[ARON_TYPE_READER_WRITER_NDARRAY_TYPE_SLUG] = t; \ - token->addElement(j); \ - return true; \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeNlohmannJSONWriter::write##upperType##Type() \ - { \ - AronTypeNlohmannJSONWriterTokenPtr token = stack.top(); \ - nlohmann::json j(ARON_TYPE_READER_WRITER_##capsType##_TYPENAME); \ - token->addElement(j); \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h deleted file mode 100644 index 8241d0c31ffc4145d7af67c7bd225fd294cef7d5..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD / STL -#include <memory> -#include <stack> -#include <sstream> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNlohmannJSONWriter : - virtual public AronTypeClassWriter<nlohmann::json, AronTypeNlohmannJSONWriterTokenPtr> - { - public: - AronTypeNlohmannJSONWriter() = default; - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType##Type() override; \ - virtual bool writeEnd##upperType##Type() override; - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type(const std::vector<int>&, const std::string&) override; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type() override; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriterToken.h deleted file mode 100644 index 0635697480291309988873a91fe8a3946719bd4a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriterToken.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/json.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeNlohmannJSONWriterToken; - typedef std::shared_ptr<AronTypeNlohmannJSONWriterToken> AronTypeNlohmannJSONWriterTokenPtr; - - class AronTypeNlohmannJSONWriterToken : - virtual public AronTypeClassWriterToken<nlohmann::json, nlohmann::json> - { - public: - using PointerType = AronTypeNlohmannJSONWriterTokenPtr; - - public: - // constructor - AronTypeNlohmannJSONWriterToken() = delete; - AronTypeNlohmannJSONWriterToken(const AronTypeDescriptor desc, const nlohmann::json& t) : - AronWriterToken<AronTypeDescriptor, nlohmann::json, nlohmann::json>(desc, t), - AronTypeClassWriterToken<nlohmann::json, nlohmann::json>(desc, t) - { - } - - // virtual member functions - virtual void addElement(const nlohmann::json& n) override - { - auto desc = getDescriptor(); - switch (desc) - { - case eAronDictType: - { - element[ARON_READER_WRITER_TOKEN_DICT_ACCEPTED_TYPE_SLUG] = n; - break; - } - case eAronListType: - { - element[ARON_READER_WRITER_TOKEN_LIST_ACCEPTED_TYPE_SLUG] = n; - break; - } - case eAronObjectType: - { - element[currentKey] = n; - break; - } - case eAronTupleType: - { - element.push_back(n); - break; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeNlohmannJSONWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers.", desc); - } - } - - - // name functions - void setName(const std::string& n) override - { - auto desc = getDescriptor(); - if (desc != AronTypeDescriptor::eAronObjectType) - { - throw exception::AronTypeDescriptorNotValidException("AronTypeNlohmannJSONWriterToken", "setName", "Cant set the name of a non-object token.", desc); - } - element[ARON_READER_WRITER_TOKEN_OBJECT_NAME_SLUG] = n; - } - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.cpp b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.cpp deleted file mode 100644 index 4dcf9562ff8cfbe2bc7778b452cc7e7259c08992..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller (fabian dot peller at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include "AronTypeRapidXMLWriter.h" - -namespace armarx -{ - namespace aron - { - namespace io - { - bool AronTypeXMLWriter::writeStartDictType() - { - return true; - } - - bool AronTypeXMLWriter::writeEndDictType() - { - return true; - } - - bool AronTypeXMLWriter::writeStartListType() - { - return true; - } - - bool AronTypeXMLWriter::writeEndListType() - { - return true; - } - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeXMLWriter::write##upperType##Type(const std::vector<int>& d, const std::string& t) \ - { \ - return true; \ - } - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - bool AronTypeXMLWriter::write##upperType##Type() \ - { \ - return true; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.h deleted file mode 100644 index f449391e69f453b22d906501145ecc49cdc53725..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriter.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD / STL -#include <memory> -#include <stack> -#include <sstream> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriterToken.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeXMLWriter : - virtual public AronTypeClassWriter<RapidXmlReaderNode, AronTypeRapidXMLWriterTokenPtr> - { - public: -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool writeStart##upperType##Type() override; \ - virtual bool writeEnd##upperType##Type() override; - - HANDLE_CONTAINER_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type(const std::vector<int>&, const std::string&) override; \ - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - virtual bool write##upperType##Type() override; - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - private: - - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriterToken.h deleted file mode 100644 index c33498ad83af9d074ea62235ab5a974c09be354e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/RapidXMLWriter/AronTypeRapidXMLWriterToken.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Simox -#include <SimoxUtility/xml.h> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriterToken.h> - -// ArmarX -#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx -{ - namespace aron - { - namespace io - { - class AronTypeRapidXMLWriterToken; - typedef std::shared_ptr<AronTypeRapidXMLWriterToken> AronTypeRapidXMLWriterTokenPtr; - - class AronTypeRapidXMLWriterToken : - virtual public AronTypeClassWriterToken<RapidXmlReaderNode, RapidXmlReaderNode> - { - public: - using PointerType = AronTypeRapidXMLWriterTokenPtr; - - public: - // constructor - AronTypeRapidXMLWriterToken() = delete; - AronTypeRapidXMLWriterToken(const AronTypeDescriptor desc, const RapidXmlReaderNode& t) : - AronWriterToken<AronTypeDescriptor, RapidXmlReaderNode, RapidXmlReaderNode>(desc, t), - AronTypeClassWriterToken<RapidXmlReaderNode, RapidXmlReaderNode>(desc, t) - { - } - - // virtual member functions - virtual void addElement(const RapidXmlReaderNode& n) override - { - auto desc = getDescriptor(); - switch (desc) - { - case eAronDictType: - { - break; - } - case eAronListType: - { - break; - } - case eAronObjectType: - { - break; - } - case eAronTupleType: - { - break; - } - default: - throw exception::AronTypeDescriptorNotValidException("AronTypeRapidXMLWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers.", desc); - } - } - - // name functions - void setName(const std::string& n) override - { - auto desc = getDescriptor(); - if (desc != AronTypeDescriptor::eAronObjectType) - { - throw exception::AronTypeDescriptorNotValidException("AronTypeRapidXMLWriterToken", "setName", "Cant set the name of a non-object token.", desc); - } - } - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronWriterToken.h b/source/RobotAPI/libraries/aron/aroncore/io/AronWriterToken.h deleted file mode 100644 index 271d18054bb6631078d9eec67b1b8955255bb085..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronWriterToken.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -* 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 -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <string> - -// Base class -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderWriterToken.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - - - -namespace armarx -{ - namespace aron - { - namespace io - { - template<typename AronDescriptorTypename, typename ElementTypename, typename ElementAddTypename> - class AronWriterToken; - - template<typename AronDescriptorTypename, typename ElementTypename, typename ElementAddTypename> - using AronWriterTokenPtr = std::shared_ptr<AronWriterToken<AronDescriptorTypename, ElementTypename, ElementAddTypename>> ; - - template<typename AronDescriptorTypename, typename ElementTypename, typename ElementAddTypename> - class AronWriterToken : - public AronReaderWriterToken - { - public: - AronWriterToken() = delete; - AronWriterToken(const AronDescriptorTypename& desc, const ElementTypename& e) : - descriptor(desc), element(e), currentIndex(0), currentKey("") - { - }; - - // virtual definitions - virtual void addElement(const ElementAddTypename&) = 0; - virtual std::string toElementAccessor() const = 0; - - void setCurrentKey(const std::string& s) - { - if (s.empty()) - { - throw exception::AronException("AronWriterToken", "setCurrentKey", "The passed key is empty."); - } - currentKey = s; - } - - virtual ElementTypename getElement() const - { - return element; - } - - virtual AronDescriptorTypename getDescriptor() const - { - return descriptor; - } - - protected: - // members - AronDescriptorTypename descriptor; - ElementTypename element; - - // current index - unsigned int currentIndex; - - // current key - std::string currentKey; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h deleted file mode 100644 index bac611dd5f685ebe36736be30f1732501aaa418e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <unordered_map> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> - -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> -#include <RobotAPI/libraries/aron/aroncore/AronResolver.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> - -namespace armarx -{ - namespace aron - { - namespace navigator - { - template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> - class AronNavigator; - - template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> - using AronNavigatorPtr = std::shared_ptr<AronNavigator<Descriptor, Aron>>; - - template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> - class AronNavigator - { - public: - // constructors - AronNavigator() = delete; - AronNavigator(const Descriptor& descriptor, const AronPath& path) : - descriptor(descriptor), - path(path) - { - } - - // public member functions - Descriptor getDescriptor() const - { - return descriptor; - } - - AronPath getPath() const - { - return path; - } - - std::string pathToString() const - { - return path.toString(); - } - - // virual definitions - virtual typename Aron::PointerType getResult() const = 0; - virtual std::string getName() const = 0; - - protected: - static void CheckAronPtrForNull(const std::string& c, const std::string& m, const AronPath& p, const typename Aron::PointerType& data) - { - if (data.get() == nullptr) - { - throw exception::AronExceptionWithPathInfo(c, m, "Could not cast an AronPtr. The Ptr was NULL.", p); - } - } - - private: - // members - const Descriptor descriptor; - const AronPath path; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h deleted file mode 100644 index 0f23c7137ae3f61f89e5266b0b36e06d4f6b57e8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <string> -#include <unordered_map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - class AronDataNavigatorFactory; - typedef std::shared_ptr<AronDataNavigatorFactory> AronDataNavigatorFactoryPtr; - - class AronDataNavigator; - typedef std::shared_ptr<AronDataNavigator> AronDataNavigatorPtr; - - class AronDataNavigator : - virtual public navigator::AronNavigator<AronDataDescriptor, data::AronData> - { - public: - using PointerType = AronDataNavigatorPtr; - - public: - // constructors - AronDataNavigator() = delete; - AronDataNavigator(const AronDataDescriptor&, const AronPath& p = AronPath()); - - // operators - virtual bool equalsDataNavigator(const AronDataNavigatorPtr&) const = 0; - - // static methods - static AronDataNavigatorPtr FromAronData(const data::AronDataPtr&, const AronPath& = AronPath()); - static std::vector<AronDataNavigatorPtr> FromAronData(const std::vector<data::AronDataPtr>&, const AronPath& = AronPath()); - static std::vector<data::AronDataPtr> ToAronData(const std::vector<AronDataNavigatorPtr>&); - - template<typename AronNavigatorType> - static typename AronNavigatorType::PointerType DynamicCast(const AronDataNavigatorPtr& n) - { - return AronNavigatorType::DynamicCast(n); - } - - template<typename AronNavigatorType> - static typename AronNavigatorType::PointerType DynamicCastAndCheck(const AronDataNavigatorPtr& n) - { - return AronNavigatorType::DynamicCastAndCheck(n); - } - - // virtual definitions of base class - virtual data::AronDataPtr getResult() const override = 0; - virtual std::string getName() const override = 0; - - // virtual definitions - virtual std::vector<AronDataNavigatorPtr> getChildren() const = 0; - virtual size_t childrenSize() const = 0; - - virtual typenavigator::AronTypeNavigatorPtr recalculateType() const = 0; - virtual bool fullfillsType(const typenavigator::AronTypeNavigatorPtr&) const = 0; - - protected: - static void CheckDataNavigatorPtrForNull(const std::string&, const std::string&, const AronDataNavigatorPtr&); - static void CheckDataNavigatorPtrForNull(const std::string&, const std::string&, const AronPath&, const AronDataNavigatorPtr&); - - private: - static const AronDataNavigatorFactoryPtr FACTORY; - }; - - class AronContainerDataNavigator; - typedef std::shared_ptr<AronContainerDataNavigator> AronContainerDataNavigatorPtr; - - class AronContainerDataNavigator : - virtual public AronDataNavigator - { - public: - using PointerType = AronContainerDataNavigatorPtr; - - // virtual definitions - virtual AronDataNavigatorPtr navigateAbsolute(const AronPath& path) const = 0; - - // member functions - AronDataNavigatorPtr navigateRelative(const AronPath& path) const; - - // static definitions - static AronContainerDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n); - static AronContainerDataNavigatorPtr DynamicCastAndCheck(const AronDataNavigatorPtr& n); - }; - - class AronComplexDataNavigator; - typedef std::shared_ptr<AronComplexDataNavigator> AronComplexDataNavigatorPtr; - - class AronComplexDataNavigator : - virtual public AronDataNavigator - { - public: - using PointerType = AronComplexDataNavigatorPtr; - - static AronComplexDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n) - { - AronComplexDataNavigatorPtr casted = std::dynamic_pointer_cast<AronComplexDataNavigator>(n); - return casted; - } - }; - - class AronPrimitiveDataNavigator; - typedef std::shared_ptr<AronPrimitiveDataNavigator> AronPrimitiveDataNavigatorPtr; - - class AronPrimitiveDataNavigator : - virtual public AronDataNavigator - { - public: - using PointerType = AronPrimitiveDataNavigatorPtr; - - static AronPrimitiveDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n) - { - AronPrimitiveDataNavigatorPtr casted = std::dynamic_pointer_cast<AronPrimitiveDataNavigator>(n); - return casted; - } - }; - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.cpp deleted file mode 100644 index a344953d9e79df70031fbeaef172f08e976b725a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Header -#include "AronDataNavigatorFactory.h" - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - - // Map types to factories - const std::map<AronDataDescriptor, AronDataNavigatorFactoryPtr> AronDataNavigatorFactory::FACTORIES = - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - {AronResolver::GetDescriptorForAronDataId(typeid(data::Aron##upperType)), AronDataNavigatorFactoryPtr(new Aron##upperType##DataNavigatorFactory())}, \ - - HANDLE_CONTAINER_DATA - HANDLE_COMPLEX_DATA - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - }; - - // Access method - AronDataNavigatorPtr AronDataNavigatorFactory::create(const data::AronDataPtr& aron, const AronPath& path) const - { - CheckIfInputIsNull("AronDataNavigatorFactory", "create", path, aron); - - auto typeDescriptor = AronResolver::GetDescriptorForAronData(aron); - auto factory_iterator = FACTORIES.find(typeDescriptor); - if (factory_iterator == FACTORIES.end()) - { - throw exception::AronExceptionWithPathInfo("AronDataNavigatorFactory", "create", "Cannot find the desired factory for input: " + AronDataDescriptorToString.at(typeDescriptor) + ". Cannot create navigator", path); - } - return factory_iterator->second->createSpecific(aron, path); - } - - AronDataNavigatorPtr AronDataNavigatorFactory::createSpecific(const data::AronDataPtr&, const AronPath& p) const - { - throw exception::AronExceptionWithPathInfo("AronDataNavigatorFactory", "createSpecific", "Called disallowed method of an AronDataNavigatorFactory. Use child class instead!", p); - } - - // Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - AronDataNavigatorPtr Aron##upperType##DataNavigatorFactory::createSpecific(const data::AronDataPtr& aron, const AronPath& path) const \ - { \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"DataNavigatorFactory", "create", path, aron); \ - data::Aron##upperType##Ptr aronCasted = data::Aron##upperType##Ptr::dynamicCast(aron); \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"DataNavigatorFactory", "create", path, aronCasted); \ - return AronDataNavigatorPtr(new Aron##upperType##DataNavigator(aronCasted, path)); \ - } - - HANDLE_CONTAINER_DATA - HANDLE_COMPLEX_DATA - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h deleted file mode 100644 index 28ec1e39285ed6a450782b84dedc10311f0c9b27..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <unordered_map> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/navigators/AronNavigatorFactory.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - class AronDataNavigatorFactory; - typedef std::shared_ptr<AronDataNavigatorFactory> AronDataNavigatorFactoryPtr; - - class AronDataNavigatorFactory : - virtual public navigator::AronNavigatorFactory<data::AronDataPtr, AronDataNavigatorPtr> - { - public: - AronDataNavigatorFactory() = default; - virtual AronDataNavigatorPtr create(const data::AronDataPtr&, const AronPath&) const override; - virtual AronDataNavigatorPtr createSpecific(const data::AronDataPtr&, const AronPath&) const override; - - private: - static const std::map<AronDataDescriptor, AronDataNavigatorFactoryPtr> FACTORIES; - }; - - // Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##DataNavigatorFactory : \ - virtual public AronDataNavigatorFactory \ - { \ - public: \ - Aron##upperType##DataNavigatorFactory() = default; \ - virtual AronDataNavigatorPtr createSpecific(const data::AronDataPtr&, const AronPath&) const override; \ - }; - - HANDLE_CONTAINER_DATA - HANDLE_COMPLEX_DATA - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp deleted file mode 100644 index c7cc7fcaae5fb57a3173374f077b9a9069dae54e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp +++ /dev/null @@ -1,297 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronDictDataNavigator.h" - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - - // constructors - AronDictDataNavigator::AronDictDataNavigator(const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronDict, path), - AronDataNavigator(AronDataDescriptor::eAronDict, path), - aron(new data::AronDict()) - { - } - - AronDictDataNavigator::AronDictDataNavigator(const data::AronDictPtr& o, const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronDict, path), - AronDataNavigator(AronDataDescriptor::eAronDict, path), - aron(o) - { - CheckAronPtrForNull("AronDictDataNavigator", "AronDictDataNavigator", getPath(), aron); - - for (const auto& [key, dataPtr] : aron->elements) - { - childrenNavigators[key] = AronDataNavigator::FromAronData(dataPtr, AronPath(path, key)); - } - } - - AronDictDataNavigator::AronDictDataNavigator(const data::AronDataDict& d, const AronPath& path) : - AronDictDataNavigator(data::AronDictPtr(new data::AronDict(d)), path) - { - } - - AronDictDataNavigator::AronDictDataNavigator(const std::map<std::string, AronDataNavigatorPtr>& m, const AronPath& path) : - AronDictDataNavigator(path) - { - for (const auto& [key, dataPtr] : m) - { - addElement(key, dataPtr); - } - } - - // operators - bool AronDictDataNavigator::operator==(const AronDictDataNavigator& other) const - { - for (const auto& [key, nav] : childrenNavigators) - { - if (not(other.hasElement(key))) - { - return false; - } - if (not(nav->equalsDataNavigator(other.getElement(key)))) - { - return false; - } - } - return true; - } - - bool AronDictDataNavigator::equalsDataNavigator(const AronDataNavigatorPtr& other) const - { - if (other == nullptr) - { - return false; - } - AronDictDataNavigatorPtr casted = DynamicCast(other); - return equalsDeep(casted); - } - - bool AronDictDataNavigator::equalsDeep(const AronDictDataNavigatorPtr& other) const - { - return *this == *other; - } - - // static methods - AronDictDataNavigatorPtr AronDictDataNavigator::DynamicCast(const AronDataNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronDictDataNavigator>(n); - } - - AronDictDataNavigator AronDictDataNavigator::DynamicCast(AronDataNavigator& n) - { - return dynamic_cast<AronDictDataNavigator&>(n); - } - - AronDictDataNavigatorPtr AronDictDataNavigator::DynamicCastAndCheck(const AronDataNavigatorPtr& n) - { - CheckDataNavigatorPtrForNull("AronDictDataNavigator", "DynamicCastAndCheck[Before]", n); - AronDictDataNavigatorPtr casted = AronDictDataNavigator::DynamicCast(n); - CheckDataNavigatorPtrForNull("AronDictDataNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); - return casted; - } - - AronDictDataNavigatorPtr AronDictDataNavigator::FromAronDictPtr(const data::AronDictPtr& aron) - { - return std::make_shared<AronDictDataNavigator>(aron); - } - - data::AronDictPtr AronDictDataNavigator::ToAronDictPtr(const AronDictDataNavigatorPtr& navigator) - { - return navigator ? navigator->toAronDictPtr() : nullptr; - } - - data::AronDictPtr AronDictDataNavigator::toAronDictPtr() const - { - return aron; - } - - // public member functions - std::vector<std::string> AronDictDataNavigator::getAllKeys() const - { - std::vector<std::string> ret; - for (const auto& [key, _] : childrenNavigators) - { - ret.push_back(key); - } - return ret; - } - - void AronDictDataNavigator::addElement(const std::string& key, const AronDataNavigatorPtr& data) - { - this->childrenNavigators[key] = data; - this->aron->elements[key] = data->getResult(); - } - - bool AronDictDataNavigator::hasElement(const std::string& key) const - { - return childrenNavigators.count(key) > 0; - } - - AronDataNavigatorPtr AronDictDataNavigator::getElement(const std::string& key) const - { - auto it = childrenNavigators.find(key); - if (it == childrenNavigators.end()) - { - std::string all_keys = ""; - for (const auto& child : this->getAllKeys()) - { - all_keys += child + ", "; - } - throw exception::AronExceptionWithPathInfo("AronDictDataNavigator", "getElement", "Could not find key '" + key + "'. But I found the following keys: [" + all_keys + "]", getPath()); - } - return it->second; - } - - std::map<std::string, AronDataNavigatorPtr> AronDictDataNavigator::getElements() const - { - return childrenNavigators; - } - - void AronDictDataNavigator::clear() - { - childrenNavigators.clear(); - aron->elements.clear(); - } - - // virtual implementations - data::AronDataPtr AronDictDataNavigator::getResult() const - { - return toAronDictPtr(); - } - - std::string AronDictDataNavigator::getName() const - { - return "AronDict"; - } - - typenavigator::AronTypeNavigatorPtr AronDictDataNavigator::recalculateType() const - { - typenavigator::AronDictTypeNavigatorPtr typenav = typenavigator::AronDictTypeNavigatorPtr(new typenavigator::AronDictTypeNavigator(getPath())); - for (const auto& [key, nav] : childrenNavigators) - { - if (typenav->getAcceptedType() == nullptr) - { - typenav->setAcceptedType(nav->recalculateType()); - continue; - } - - if (!nav->fullfillsType(typenav->getAcceptedType())) - { - throw exception::AronExceptionWithPathInfo("AronDictDataNavigator", "recalculateType", "Cannot recalculate the aronType. Inconsistency found for key: " + key, getPath()); - } - } - return typenav->getAcceptedType(); - } - - bool AronDictDataNavigator::fullfillsType(const typenavigator::AronTypeNavigatorPtr& type) const - { - if (!AronResolver::TypesAreCorresponding(type->getDescriptor(), getDescriptor())) - { - return false; - } - - { - typenavigator::AronSingleAcceptedTypeHavingTypeNavigatorPtr dictTypenav = typenavigator::AronSingleAcceptedTypeHavingTypeNavigator::DynamicCast(type); - if (dictTypenav) - { - for (const auto& [_, nav] : childrenNavigators) - { - if (!nav->fullfillsType(dictTypenav->getAcceptedType())) - { - return false; - } - } - return true; - } - } - - { - typenavigator::AronMultipleDictAcceptedTypeHavingTypeNavigatorPtr dictTypenav = typenavigator::AronMultipleDictAcceptedTypeHavingTypeNavigator::DynamicCast(type); - if (dictTypenav) - { - for (const auto& [key, nav] : childrenNavigators) - { - if (!nav->fullfillsType(dictTypenav->getAcceptedType(key))) - { - return false; - } - } - return true; - } - } - return false; - } - - std::vector<AronDataNavigatorPtr> AronDictDataNavigator::getChildren() const - { - std::vector<AronDataNavigatorPtr> ret(childrenNavigators.size()); - for (const auto& [key, nav] : childrenNavigators) - { - ret.push_back(nav); - } - return ret; - } - - size_t AronDictDataNavigator::childrenSize() const - { - return childrenNavigators.size(); - } - - AronDataNavigatorPtr AronDictDataNavigator::navigateAbsolute(const AronPath& path) const - { - if (!path.hasElement()) - { - throw exception::AronException("AronDictDataNavigator", "navigate", "Could not navigate without a valid path. The path was empty."); - } - std::string el = path.getFirstElement(); - if (!hasElement(el)) - { - throw exception::AronStringNotValidException("AronDictDataNavigator", "navigate", "Could not find an element of a path.", el); - } - - if (path.size() == 1) - { - return childrenNavigators.at(el); - } - else - { - AronPath next = path.withDetachedFirstElement(); - AronContainerDataNavigatorPtr c = AronContainerDataNavigator::DynamicCastAndCheck(childrenNavigators.at(el)); - return c->navigateAbsolute(next); - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h deleted file mode 100644 index c68bd3324423dc366eb89a883eb956c231476a90..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - class AronDictDataNavigator; - typedef std::shared_ptr<AronDictDataNavigator> AronDictDataNavigatorPtr; - - class AronDictDataNavigator : - virtual public AronContainerDataNavigator - { - public: - using PointerType = AronDictDataNavigatorPtr; - - public: - // constructors - AronDictDataNavigator(const AronPath& path = AronPath()); - AronDictDataNavigator(const data::AronDictPtr&, const AronPath& path = AronPath()); - AronDictDataNavigator(const data::AronDataDict&, const AronPath& path = AronPath()); - AronDictDataNavigator(const std::map<std::string, AronDataNavigatorPtr>&, const AronPath& path = AronPath()); - - // operators - bool operator==(const AronDictDataNavigator&) const; - virtual bool equalsDataNavigator(const AronDataNavigatorPtr&) const override; - bool equalsDeep(const AronDictDataNavigatorPtr&) const; - - // static methods - static AronDictDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n); - static AronDictDataNavigator DynamicCast(AronDataNavigator& n); - static AronDictDataNavigatorPtr DynamicCastAndCheck(const AronDataNavigatorPtr& n); - - static AronDictDataNavigatorPtr FromAronDictPtr(const data::AronDictPtr& aron); - static data::AronDictPtr ToAronDictPtr(const AronDictDataNavigatorPtr& navigator); - - // public member functions - data::AronDictPtr toAronDictPtr() const; - std::vector<std::string> getAllKeys() const; - - void addElement(const std::string& key, const AronDataNavigatorPtr&); - bool hasElement(const std::string&) const; - AronDataNavigatorPtr getElement(const std::string&) const; - std::map<std::string, AronDataNavigatorPtr> getElements() const; - - void clear(); - - // virtual implementations - virtual data::AronDataPtr getResult() const override; - virtual std::string getName() const override; - virtual std::vector<AronDataNavigatorPtr> getChildren() const override; - virtual size_t childrenSize() const override; - - virtual typenavigator::AronTypeNavigatorPtr recalculateType() const override; - virtual bool fullfillsType(const typenavigator::AronTypeNavigatorPtr&) const override; - - virtual AronDataNavigatorPtr navigateAbsolute(const AronPath& path) const override; - - private: - // members - std::map<std::string, AronDataNavigatorPtr> childrenNavigators; - data::AronDictPtr aron; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp deleted file mode 100644 index a393b26ac23023c789c61af94abb6d4fe10f72cd..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronListDataNavigator.h" - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - // constructors - AronListDataNavigator::AronListDataNavigator(const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronList, path), - AronDataNavigator(AronDataDescriptor::eAronList, path), - aron(new data::AronList()) - { - } - - AronListDataNavigator::AronListDataNavigator(const data::AronListPtr& l, const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronList, path), - AronDataNavigator(AronDataDescriptor::eAronList, path), - aron(l) - { - CheckAronPtrForNull("AronListDataNavigator", "AronListDataNavigator", getPath(), aron); - - unsigned int i = 0; - for (const auto& dataPtr : l->elements) - { - childrenNavigators.push_back(FromAronData(dataPtr, AronPath(path, std::to_string(i++)))); - } - } - - AronListDataNavigator::AronListDataNavigator(const data::AronDataList& d, const AronPath& path) : - AronListDataNavigator(data::AronListPtr(new data::AronList(d)), path) - { - } - - AronListDataNavigator::AronListDataNavigator(const std::vector<AronDataNavigatorPtr>& n, const AronPath& path) : - AronListDataNavigator(path) - { - for (const auto& dataPtr : n) - { - addElement(dataPtr); - } - } - - // operators - bool AronListDataNavigator::operator==(const AronListDataNavigator& other) const - { - unsigned int i = 0; - for (const auto& nav : childrenNavigators) - { - if (not(other.hasElement(i))) - { - return false; - } - if (not(nav->equalsDataNavigator(other.getElement(i)))) - { - return false; - } - i++; - } - return true; - } - - bool AronListDataNavigator::equalsDataNavigator(const AronDataNavigatorPtr& other) const - { - if (other == nullptr) - { - return false; - } - AronListDataNavigatorPtr casted = DynamicCast(other); - return equalsDeep(casted); - } - - bool AronListDataNavigator::equalsDeep(const AronListDataNavigatorPtr& other) const - { - return *this == *other; - } - - // static methods - AronListDataNavigatorPtr AronListDataNavigator::DynamicCast(const AronDataNavigatorPtr& n) - { - AronListDataNavigatorPtr casted = std::dynamic_pointer_cast<AronListDataNavigator>(n); - return casted; - } - - AronListDataNavigator AronListDataNavigator::DynamicCast(AronDataNavigator& n) - { - return dynamic_cast<AronListDataNavigator&>(n); - } - - AronListDataNavigatorPtr AronListDataNavigator::DynamicCastAndCheck(const AronDataNavigatorPtr& n) - { - CheckDataNavigatorPtrForNull("AronListDataNavigator", "DynamicCastAndCheck[Before]", n); - AronListDataNavigatorPtr casted = AronListDataNavigator::DynamicCast(n); - CheckDataNavigatorPtrForNull("AronListDataNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); - return casted; - } - - AronListDataNavigatorPtr AronListDataNavigator::FromAronListPtr(const data::AronListPtr& aron) - { - return std::make_shared<AronListDataNavigator>(aron); - } - - data::AronListPtr AronListDataNavigator::ToAronListPtr(const AronListDataNavigatorPtr& navigator) - { - return navigator ? navigator->toAronListPtr() : nullptr; - } - - // public member functions - void AronListDataNavigator::addElement(const AronDataNavigatorPtr& n) - { - childrenNavigators.push_back(n); - aron->elements.push_back(n->getResult()); - } - - bool AronListDataNavigator::hasElement(unsigned int i) const - { - return i < childrenNavigators.size(); - } - - AronDataNavigatorPtr AronListDataNavigator::getElement(unsigned int i) const - { - if (i >= childrenNavigators.size()) - { - throw exception::AronExceptionWithPathInfo("AronListDataNavigator", "getElement", "The index i = " + std::to_string(i) + " is out of bounds (size = " + std::to_string(childrenNavigators.size()) + ")", getPath()); - } - return childrenNavigators[i]; - } - - std::vector<AronDataNavigatorPtr> AronListDataNavigator::getElements() const - { - return childrenNavigators; - } - - void AronListDataNavigator::clear() - { - childrenNavigators.clear(); - aron->elements.clear(); - } - - data::AronListPtr AronListDataNavigator::toAronListPtr() const - { - return aron; - } - - // virtual implementations - data::AronDataPtr AronListDataNavigator::getResult() const - { - return toAronListPtr(); - } - - std::string AronListDataNavigator::getName() const - { - return "AronList"; - } - - typenavigator::AronTypeNavigatorPtr AronListDataNavigator::recalculateType() const - { - typenavigator::AronListTypeNavigatorPtr typenav = typenavigator::AronListTypeNavigatorPtr(new typenavigator::AronListTypeNavigator(getPath())); - unsigned int i = 0; - for (const auto& nav : childrenNavigators) - { - if (typenav->getAcceptedType() == nullptr) - { - typenav->setAcceptedType(nav->recalculateType()); - continue; - } - - if (!nav->fullfillsType(typenav->getAcceptedType())) - { - throw exception::AronExceptionWithPathInfo("AronListDataNavigator", "recalculateType", "Cannot recalculate the aronType. Inconsistency found for index: " + std::to_string(i), getPath()); - } - ++i; - } - return typenav->getAcceptedType(); - } - - bool AronListDataNavigator::fullfillsType(const typenavigator::AronTypeNavigatorPtr& type) const - { - if (!AronResolver::TypesAreCorresponding(type->getDescriptor(), getDescriptor())) - { - return false; - } - - { - typenavigator::AronSingleAcceptedTypeHavingTypeNavigatorPtr listTypenav = typenavigator::AronSingleAcceptedTypeHavingTypeNavigator::DynamicCast(type); - if (listTypenav) - { - for (const auto& nav : childrenNavigators) - { - if (!nav->fullfillsType(listTypenav->getAcceptedType())) - { - return false; - } - } - return true; - } - } - - { - typenavigator::AronMultipleListAcceptedTypeHavingTypeNavigatorPtr listTypenav = typenavigator::AronMultipleListAcceptedTypeHavingTypeNavigator::DynamicCast(type); - if (listTypenav) - { - unsigned int i = 0; - for (const auto& nav : childrenNavigators) - { - if (!nav->fullfillsType(listTypenav->getAcceptedType(i))) - { - return false; - } - } - return true; - } - } - - return false; - } - - std::vector<AronDataNavigatorPtr> AronListDataNavigator::getChildren() const - { - return childrenNavigators; - } - - size_t AronListDataNavigator::childrenSize() const - { - return childrenNavigators.size(); - } - - AronDataNavigatorPtr AronListDataNavigator::navigateAbsolute(const AronPath& path) const - { - if (!path.hasElement()) - { - throw exception::AronException("AronListDataNavigator", "navigate", "Could not navigate without a valid path. The path was empty."); - } - unsigned int i = std::stoi(path.getFirstElement()); - if (!hasElement(i)) - { - throw exception::AronIndexNotValidException("AronListDataNavigator", "navigate", "Could not find an element of a path.", i, childrenSize()); - } - - if (path.size() == 1) - { - return childrenNavigators.at(i); - } - else - { - AronPath next = path.withDetachedFirstElement(); - AronContainerDataNavigatorPtr c = AronContainerDataNavigator::DynamicCastAndCheck(childrenNavigators.at(i)); - return c->navigateAbsolute(next); - } - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h deleted file mode 100644 index fd7e9c0fb61f26d073a23cfe5b577cfdd4dcf2ae..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - class AronListDataNavigator; - typedef std::shared_ptr<AronListDataNavigator> AronListDataNavigatorPtr; - - class AronListDataNavigator : - virtual public AronContainerDataNavigator - { - public: - using PointerType = AronListDataNavigatorPtr; - - public: - // constructors - AronListDataNavigator(const AronPath& path = AronPath()); - AronListDataNavigator(const data::AronListPtr&, const AronPath& path = AronPath()); - AronListDataNavigator(const data::AronDataList&, const AronPath& path = AronPath()); - AronListDataNavigator(const std::vector<AronDataNavigatorPtr>&, const AronPath& path = AronPath()); - - // operators - bool operator==(const AronListDataNavigator&) const; - virtual bool equalsDataNavigator(const AronDataNavigatorPtr&) const override; - bool equalsDeep(const AronListDataNavigatorPtr&) const; - - // static methods - static AronListDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n); - static AronListDataNavigator DynamicCast(AronDataNavigator& n); - static AronListDataNavigatorPtr DynamicCastAndCheck(const AronDataNavigatorPtr& n); - - static AronListDataNavigatorPtr FromAronListPtr(const data::AronListPtr& aron); - static data::AronListPtr ToAronListPtr(const AronListDataNavigatorPtr& navigator); - - // public member functions - data::AronListPtr toAronListPtr() const; - - void addElement(const AronDataNavigatorPtr&); - AronDataNavigatorPtr getElement(unsigned int) const; - bool hasElement(unsigned int) const; - std::vector<AronDataNavigatorPtr> getElements() const; - - void clear(); - - // virtual implementations - virtual data::AronDataPtr getResult() const override; - virtual std::string getName() const override; - virtual std::vector<AronDataNavigatorPtr> getChildren() const override; - virtual size_t childrenSize() const override; - - virtual typenavigator::AronTypeNavigatorPtr recalculateType() const override; - virtual bool fullfillsType(const typenavigator::AronTypeNavigatorPtr&) const override; - - virtual AronDataNavigatorPtr navigateAbsolute(const AronPath& path) const override; - - private: - std::vector<AronDataNavigatorPtr> childrenNavigators; - data::AronListPtr aron; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp deleted file mode 100644 index 46cf0bbfc6650d260af669c8fd8671c4c87eace1..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronNDArrayDataNavigator.h" - -// Simox -#include <SimoxUtility/algorithm/string.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - // constructors - AronNDArrayDataNavigator::AronNDArrayDataNavigator(const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronNDArray, path), - AronDataNavigator(AronDataDescriptor::eAronNDArray, path), - aron(new data::AronNDArray()) - { - - } - - AronNDArrayDataNavigator::AronNDArrayDataNavigator(const data::AronNDArrayPtr& o, const AronPath& path) : - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronNDArray, path), - AronDataNavigator(AronDataDescriptor::eAronNDArray, path), - aron(o) - { - CheckAronPtrForNull("AronNDArrayDataNavigator", "AronNDArrayDataNavigator", getPath(), aron); - } - - AronNDArrayDataNavigator::AronNDArrayDataNavigator(const std::vector<int>& dim, const std::string& t, const std::vector<unsigned char>& data, const AronPath& path) : - AronNDArrayDataNavigator(data::AronNDArrayPtr(new data::AronNDArray(dim, t, data)), path) - { - } - - // operators - bool AronNDArrayDataNavigator::operator==(const AronNDArrayDataNavigator& other) const - { - const auto otherAron = other.toAronNDArrayPtr(); - if (aron->dimensions != otherAron->dimensions) - { - return false; - } - if (aron->type != otherAron->type) - { - return false; - } - // performs memcmp - if (aron->data != otherAron->data) - { - return false; - } - return true; - } - - bool AronNDArrayDataNavigator::equalsDataNavigator(const AronDataNavigatorPtr& other) const - { - if (other == nullptr) - { - return false; - } - AronNDArrayDataNavigatorPtr casted = DynamicCast(other); - return equalsDeep(casted); - } - - bool AronNDArrayDataNavigator::equalsDeep(const AronNDArrayDataNavigatorPtr& other) const - { - return *this == *other; - } - - - // static methods - AronNDArrayDataNavigatorPtr AronNDArrayDataNavigator::DynamicCast(const AronDataNavigatorPtr& n) - { - AronNDArrayDataNavigatorPtr casted = std::dynamic_pointer_cast<AronNDArrayDataNavigator>(n); - return casted; - } - - AronNDArrayDataNavigator AronNDArrayDataNavigator::DynamicCast(AronDataNavigator& n) - { - return dynamic_cast<AronNDArrayDataNavigator&>(n); - } - - AronNDArrayDataNavigatorPtr AronNDArrayDataNavigator::DynamicCastAndCheck(const AronDataNavigatorPtr& n) - { - CheckDataNavigatorPtrForNull("AronNDArrayDataNavigator", "DynamicCastAndCheck[Before]", n); - AronNDArrayDataNavigatorPtr casted = AronNDArrayDataNavigator::DynamicCast(n); - CheckDataNavigatorPtrForNull("AronNDArrayDataNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); - return casted; - } - - AronNDArrayDataNavigatorPtr AronNDArrayDataNavigator::FromAronNDArrayPtr(const data::AronNDArrayPtr& aron) - { - return std::make_shared<AronNDArrayDataNavigator>(aron); - } - - data::AronNDArrayPtr AronNDArrayDataNavigator::ToAronNDArrayPtr(const AronNDArrayDataNavigatorPtr& navigator) - { - return navigator ? navigator->toAronNDArrayPtr() : nullptr; - } - - // public member functions - unsigned char* AronNDArrayDataNavigator::getData() const - { - return aron->data.data(); - } - - void AronNDArrayDataNavigator::setData(unsigned int elements, const unsigned char* src) - { - aron->data = std::vector<unsigned char>(elements); - memcpy(aron->data.data(), src, elements); - } - - std::vector<int> AronNDArrayDataNavigator::getDimensions() const - { - return aron->dimensions; - } - - void AronNDArrayDataNavigator::setDimensions(const std::vector<int>& d) - { - aron->dimensions = d; - } - - void AronNDArrayDataNavigator::addDimension(int i) - { - aron->dimensions.push_back(i); - } - - std::string AronNDArrayDataNavigator::getType() const - { - return aron->type; - } - - void AronNDArrayDataNavigator::setType(const std::string& t) - { - if (t.empty()) - { - throw exception::AronExceptionWithPathInfo("AronNDArrayDataNavigator", "setType", "The type cannot be empty", getPath()); - } - - aron->type = t; - } - - data::AronNDArrayPtr AronNDArrayDataNavigator::toAronNDArrayPtr() const - { - return aron; - } - - // virtual implementations - data::AronDataPtr AronNDArrayDataNavigator::getResult() const - { - return toAronNDArrayPtr(); - } - - std::string AronNDArrayDataNavigator::getName() const - { - return "AronNDArray<" + simox::alg::to_string(aron->dimensions, ", ") + ", " + aron->type + ">"; - } - - typenavigator::AronTypeNavigatorPtr AronNDArrayDataNavigator::recalculateType() const - { - // We set all to openCVMat because it accepts n-dimensional types - typenavigator::AronOpenCVMatTypeNavigatorPtr typenav = typenavigator::AronOpenCVMatTypeNavigatorPtr(new typenavigator::AronOpenCVMatTypeNavigator(getPath())); - typenav->setDimensions(std::vector<int>(aron->dimensions.begin(), std::prev(aron->dimensions.end()))); - typenav->setUsedType(aron->type); - return typenav; - } - - bool AronNDArrayDataNavigator::fullfillsType(const typenavigator::AronTypeNavigatorPtr& type) const - { - if (!AronResolver::TypesAreCorresponding(type->getDescriptor(), getDescriptor())) - { - return false; - } - - switch (type->getDescriptor()) - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ -case eAron##upperType##Type: \ -{ \ - typenavigator::Aron##upperType##TypeNavigatorPtr casted = typenavigator::Aron##upperType##TypeNavigator::DynamicCast(type); \ - if (std::vector<int>(aron->dimensions.begin(), std::prev(aron->dimensions.end())) != casted->getDimensions() || aron->type != casted->getUsedType()) \ - { \ - return false; \ - } \ - break; \ -} - - HANDLE_COMPLEX_TYPES -#undef RUN_ARON_MACRO - default: - throw exception::AronExceptionWithPathInfo("AronNDArrayDataNavigator", "fullfillsType", "Could not cast a type to an NDArray-Type", getPath()); - } - return true; - } - - std::string AronNDArrayDataNavigator::DimensionsToString(const std::vector<int>& dimensions) - { - std::stringstream ss; - ss << "(" << simox::alg::join(simox::alg::multi_to_string(dimensions), ", ") << ")"; - return ss.str(); - } - - std::vector<AronDataNavigatorPtr> AronNDArrayDataNavigator::getChildren() const - { - return {}; - } - - size_t AronNDArrayDataNavigator::childrenSize() const - { - return 0; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h deleted file mode 100644 index df7fb6885aaba66339a339096d8b7c95ef3f983e..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { - class AronNDArrayDataNavigator; - typedef std::shared_ptr<AronNDArrayDataNavigator> AronNDArrayDataNavigatorPtr; - - class AronNDArrayDataNavigator : - virtual public AronComplexDataNavigator - { - public: - using PointerType = AronNDArrayDataNavigatorPtr; - - public: - // constructors - AronNDArrayDataNavigator(const AronPath& path = AronPath()); - AronNDArrayDataNavigator(const data::AronNDArrayPtr&, const AronPath& path = AronPath()); - AronNDArrayDataNavigator(const std::vector<int>&, const std::string&, const std::vector<unsigned char>&, const AronPath& path = AronPath()); - - // operators - bool operator==(const AronNDArrayDataNavigator&) const; - virtual bool equalsDataNavigator(const AronDataNavigatorPtr&) const override; - bool equalsDeep(const AronNDArrayDataNavigatorPtr&) const; - - // static methods - static AronNDArrayDataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n); - static AronNDArrayDataNavigator DynamicCast(AronDataNavigator& n); - static AronNDArrayDataNavigatorPtr DynamicCastAndCheck(const AronDataNavigatorPtr& n); - - static AronNDArrayDataNavigatorPtr FromAronNDArrayPtr(const data::AronNDArrayPtr& aron); - static data::AronNDArrayPtr ToAronNDArrayPtr(const AronNDArrayDataNavigatorPtr& navigator); - - /// Return dimensions in a readable string such as "(2, 3, 4)". - static std::string DimensionsToString(const std::vector<int>& dimensions); - - - // public member functions - unsigned char* getData() const; - void setData(unsigned int, const unsigned char*); - - std::vector<int> getDimensions() const; - void setDimensions(const std::vector<int>&); - void addDimension(int); - - std::string getType() const; - void setType(const std::string&); - - data::AronNDArrayPtr toAronNDArrayPtr() const; - - // virtual implementations - virtual data::AronDataPtr getResult() const override; - virtual std::string getName() const override; - virtual std::vector<AronDataNavigatorPtr> getChildren() const override; - virtual size_t childrenSize() const override; - - virtual typenavigator::AronTypeNavigatorPtr recalculateType() const override; - virtual bool fullfillsType(const typenavigator::AronTypeNavigatorPtr&) const override; - - private: - data::AronNDArrayPtr aron; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp deleted file mode 100644 index eb71b578dd1801a30f0c5e2817041bc7f1132ed4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#include "AronPrimitiveDataNavigator.h" - -#include <ArmarXCore/core/exceptions/Exception.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace datanavigator - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - /* constructors */ \ - Aron##upperType##DataNavigator::Aron##upperType##DataNavigator(const data::Aron##upperType##Ptr& o, const AronPath& path) : \ - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAron##upperType, path), \ - AronDataNavigator(AronDataDescriptor::eAron##upperType, path), \ - aron(o) \ - { \ - } \ - \ - Aron##upperType##DataNavigator::Aron##upperType##DataNavigator(const AronPath& path) : \ - AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAron##upperType, path), \ - AronDataNavigator(AronDataDescriptor::eAron##upperType, path), \ - aron(new data::Aron##upperType()) \ - { \ - } \ - \ - Aron##upperType##DataNavigator::Aron##upperType##DataNavigator(const lowerType& d, const AronPath& path) : \ - Aron##upperType##DataNavigator(data::Aron##upperType##Ptr(new data::Aron##upperType(d)), path) \ - { \ - } \ - \ - /* operators */ \ - bool Aron##upperType##DataNavigator::operator==(const Aron##upperType##DataNavigator& other) const \ - { \ - const auto& otherAron = other.toAron##upperType##Ptr(); \ - if(aron->value != otherAron->value) \ - return false; \ - return true; \ - } \ - \ - bool Aron##upperType##DataNavigator::equalsDataNavigator(const AronDataNavigatorPtr& other) const \ - { \ - if(other == nullptr) \ - { \ - return false; \ - } \ - Aron##upperType##DataNavigatorPtr casted = DynamicCast(other); \ - return equalsDeep(casted); \ - } \ - \ - bool Aron##upperType##DataNavigator::equalsDeep(const Aron##upperType##DataNavigatorPtr& other) const \ - { \ - /* only for consistency. There is no "deep" comparison. */ \ - return *this == *other; \ - } \ - \ - /* static methods */ \ - Aron##upperType##DataNavigatorPtr Aron##upperType##DataNavigator::DynamicCast(const AronDataNavigatorPtr& n) \ - { \ - Aron##upperType##DataNavigatorPtr casted = std::dynamic_pointer_cast<Aron##upperType##DataNavigator>(n); \ - return casted; \ - } \ - \ - Aron##upperType##DataNavigator Aron##upperType##DataNavigator::DynamicCast(AronDataNavigator& n) \ - { \ - return dynamic_cast<Aron##upperType##DataNavigator&>(n); \ - } \ - \ - Aron##upperType##DataNavigatorPtr Aron##upperType##DataNavigator::DynamicCastAndCheck(const AronDataNavigatorPtr& n) \ - { \ - CheckDataNavigatorPtrForNull("Aron"+std::string(#upperType)+"DataNavigator", "DynamicCastAndCheck[Before]", n); \ - Aron##upperType##DataNavigatorPtr casted = Aron##upperType##DataNavigator::DynamicCast(n); \ - CheckDataNavigatorPtrForNull("Aron"+std::string(#upperType)+"DataNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); \ - return casted; \ - } \ - \ - Aron##upperType##DataNavigatorPtr Aron##upperType##DataNavigator::FromAron##upperType##Ptr(const data::Aron##upperType##Ptr& aron) \ - { \ - return std::make_shared<Aron##upperType##DataNavigator>(aron); \ - } \ - \ - data::Aron##upperType##Ptr Aron##upperType##DataNavigator::ToAron##upperType##Ptr(const Aron##upperType##DataNavigatorPtr& navigator) \ - { \ - return navigator ? navigator->toAron##upperType##Ptr() : nullptr; \ - } \ - \ - /* public member functions */ \ - void Aron##upperType##DataNavigator::setValue(const lowerType& x) \ - { \ - aron->value = x; \ - } \ - \ - lowerType Aron##upperType##DataNavigator::getValue() const \ - { \ - return aron->value; \ - } \ - \ - data::Aron##upperType##Ptr Aron##upperType##DataNavigator::toAron##upperType##Ptr() const \ - { \ - return aron; \ - } \ - \ - /* virtual implementations */ \ - data::AronDataPtr Aron##upperType##DataNavigator::getResult() const \ - { \ - return aron; \ - } \ - \ - std::string Aron##upperType##DataNavigator::getName() const \ - { \ - return "Aron" + std::string(#upperType); \ - } \ - \ - bool Aron##upperType##DataNavigator::fullfillsType(const typenavigator::AronTypeNavigatorPtr& type) const \ - { \ - return AronResolver::TypesAreCorresponding(type->getDescriptor(), getDescriptor()); \ - } \ - \ - typenavigator::AronTypeNavigatorPtr Aron##upperType##DataNavigator::recalculateType() const \ - { \ - return typenavigator::Aron##upperType##TypeNavigatorPtr(new typenavigator::Aron##upperType##TypeNavigator(getPath())); \ - } \ - \ - std::vector<AronDataNavigatorPtr> Aron##upperType##DataNavigator::getChildren() const \ - { \ - return {}; \ - } \ - \ - size_t Aron##upperType##DataNavigator::childrenSize() const \ - { \ - return 0; \ - } \ - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h deleted file mode 100644 index a84afbd35bff491e9c381d3c77c79ee33f173e21..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.cpp deleted file mode 100644 index 6cb665fd736af4fb3b6aa6e28541d4f796ed11fe..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronDictTypeNavigator.h" - - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - // constructors - AronDictTypeNavigator::AronDictTypeNavigator(const AronPath& path) : - AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronDictType, path), - AronTypeNavigator(AronTypeDescriptor::eAronDictType, path), - type(new type::AronDictType()) - { - - } - - AronDictTypeNavigator::AronDictTypeNavigator(const type::AronDictTypePtr& o, const AronPath& path) : - AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronDictType, path), - AronTypeNavigator(AronTypeDescriptor::eAronDictType, path), - type(o) - { - CheckAronPtrForNull("AronDictTypeNavigator", "AronDictTypeNavigator", getPath(), o); - - acceptedTypeNavigator = FromAronType(o->acceptedType); - } - - void AronDictTypeNavigator::setAcceptedType(const AronTypeNavigatorPtr& a) - { - type->acceptedType = a->getResult(); - acceptedTypeNavigator = a; - } - - // static methods - AronDictTypeNavigatorPtr AronDictTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronDictTypeNavigator>(n); - } - - AronDictTypeNavigatorPtr AronDictTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronDictTypeNavigator", "DynamicCastAndCheck[Before]", n); - AronDictTypeNavigatorPtr casted = AronDictTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronDictTypeNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); - return casted; - } - - // virtual implementations - type::AronTypePtr AronDictTypeNavigator::getResult() const - { - CheckAronPtrForNull("AronDictTypeNavigator", "getResult", getPath(), type->acceptedType); - return type; - } - - std::string AronDictTypeNavigator::getName() const - { - return "AronDictType<" + acceptedTypeNavigator->getName() + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.cpp deleted file mode 100644 index 4d5923c044eab1d309be1c9a5b8ffd97c5d0af02..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronEigenMatrixTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - const std::map<std::string, std::vector<std::string>> AronEigenMatrixTypeNavigator::ACCEPTED_TYPES = - { - {"short", {}}, - {"int", {}}, - {"long", {}}, - {"float", {}}, - {"double", {}}, - //{"complex float", {"std::complex<float>"}}, - //{"complex double", {"std::complex<double>"}}, - }; - - // constructors - AronEigenMatrixTypeNavigator::AronEigenMatrixTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronEigenMatrixType, path), - AronTypeNavigator(AronTypeDescriptor::eAronEigenMatrixType, path), - type(new type::AronEigenMatrixType({1, 1}, "")) - { - } - - AronEigenMatrixTypeNavigator::AronEigenMatrixTypeNavigator(const type::AronEigenMatrixTypePtr& o, const AronPath& path) : - AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronDictType, path), - AronTypeNavigator(AronTypeDescriptor::eAronEigenMatrixType, path), - type(o) - { - CheckAronPtrForNull("AronEigenMatrixTypeNavigator", "AronEigenMatrixTypeNavigator", getPath(), o); - if (type->dimensions.size() != 2) - { - throw exception::AronSizeNotValidException("AronEigenMatrixTypeNavigator", "AronEigenMatrixTypeNavigator", "The size of the AronPtr is too small", type->dimensions.size(), 2); - } - } - - unsigned int AronEigenMatrixTypeNavigator::getRows() const - { - return type->dimensions[0]; - } - - unsigned int AronEigenMatrixTypeNavigator::getCols() const - { - return type->dimensions[1]; - } - - void AronEigenMatrixTypeNavigator::setRows(const unsigned int& w) - { - if (w == 0) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "setRows", "The rows of cannot be 0", getPath()); - } - type->dimensions[0] = w; - } - - void AronEigenMatrixTypeNavigator::setCols(const unsigned int& h) - { - if (h == 0) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "setCols", "The cols cannot be 0", getPath()); - } - type->dimensions[1] = h; - } - - type::AronEigenMatrixTypePtr AronEigenMatrixTypeNavigator::toAronEigenMatrixTypePtr() const - { - if (type->dimensions.empty()) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "getCastedResult", "The dimension eigen matrix is empty", getPath()); - } - if (std::any_of(type->dimensions.begin(), type->dimensions.end(), [](int i) - { - return i < -1; - })) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "getCastedResult", "The dimension size is wrong. At least one empty is <-1", getPath()); - } - if (type->typeName.empty()) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "getCastedResult", "The useType of eigen matrix is empty.", getPath()); - } - return type; - } - - std::string AronEigenMatrixTypeNavigator::getUsedType() const - { - return type->typeName; - } - - std::vector<int> AronEigenMatrixTypeNavigator::getDimensions() const - { - return type->dimensions; - } - - void AronEigenMatrixTypeNavigator::setUsedType(const std::string& u) - { - if (u.empty()) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "setUsedType", "The useType cannot be empty", getPath()); - } - - for (const auto& [key, vec] : ACCEPTED_TYPES) - { - if (u == key || std::find(vec.begin(), vec.end(), key) != vec.end()) - { - type->typeName = key; - return; - } - } - throw exception::AronStringNotValidException("AronEigenMatrixTypeNavigator", "setUsedType", "The type was not found in the ACCEPTED_TYPES", u); - } - - void AronEigenMatrixTypeNavigator::setDimensions(const std::vector<int>& d) - { - if (d.empty()) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "setDimensions", "The dimensions of an eigen matrix cannot be empty", getPath()); - } - if (std::any_of(d.begin(), d.end(), [](int i) - { - return i < -1; - })) - { - throw exception::AronExceptionWithPathInfo("AronEigenMatrixTypeNavigator", "setDimensions", "The dimension size is wrong. At least one empty is <-1", getPath()); - } - type->dimensions = d; - } - - // static methods - AronEigenMatrixTypeNavigatorPtr AronEigenMatrixTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronEigenMatrixTypeNavigator>(n); - } - - AronEigenMatrixTypeNavigatorPtr AronEigenMatrixTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronEigenMatrixTypeNavigator", "DynamicCast[Before]", n); - AronEigenMatrixTypeNavigatorPtr casted = AronEigenMatrixTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronEigenMatrixTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // virtual implementations - type::AronTypePtr AronEigenMatrixTypeNavigator::getResult() const - { - return toAronEigenMatrixTypePtr(); - } - - std::string AronEigenMatrixTypeNavigator::getName() const - { - return "AronEigenMatrixType<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h deleted file mode 100644 index 2409b97ae583ffcfa5bc0eadc25b07d33c58eb1d..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronEigenMatrixTypeNavigator.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - class AronEigenMatrixTypeNavigator; - typedef std::shared_ptr<AronEigenMatrixTypeNavigator> AronEigenMatrixTypeNavigatorPtr; - - class AronEigenMatrixTypeNavigator : - virtual public AronNDArraySerializerTypeNavigator - { - public: - using PointerType = AronEigenMatrixTypeNavigatorPtr; - - public: - // constructors - AronEigenMatrixTypeNavigator() = delete; - AronEigenMatrixTypeNavigator(const AronPath& path); - AronEigenMatrixTypeNavigator(const type::AronEigenMatrixTypePtr&, const AronPath& path); - - unsigned int getRows() const; - unsigned int getCols() const; - - void setRows(const unsigned int&); - void setCols(const unsigned int&); - - type::AronEigenMatrixTypePtr toAronEigenMatrixTypePtr() const; - - // static methods - static AronEigenMatrixTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronEigenMatrixTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); - - // virtual implementations - virtual void setDimensions(const std::vector<int>&) override; - virtual void setUsedType(const std::string&) override; - - std::string getUsedType() const; - std::vector<int> getDimensions() const; - - virtual type::AronTypePtr getResult() const override; - virtual std::string getName() const override; - - public: - static const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES; - - private: - // members - type::AronEigenMatrixTypePtr type; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.cpp deleted file mode 100644 index f513259d79cfb92c9b6a605b674f349d93706932..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronIVTCByteImageTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - const std::map<std::string, std::vector<std::string>> AronIVTCByteImageTypeNavigator::ACCEPTED_TYPES = - { - {"GrayScale", {"CByteImage::ImageType::eGrayScale"}}, - {"RGB24", {"CByteImage::ImageType::eRGB24"}}, - {"RGB24Split", {"CByteImage::ImageType::eRGB24Split"}} - }; - - // constructors - AronIVTCByteImageTypeNavigator::AronIVTCByteImageTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronIVTCByteImageType, path), - AronTypeNavigator(AronTypeDescriptor::eAronIVTCByteImageType, path), - type(new type::AronIVTCByteImageType({0, 0}, "")) - { - } - - AronIVTCByteImageTypeNavigator::AronIVTCByteImageTypeNavigator(const type::AronIVTCByteImageTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronIVTCByteImageType, path), - AronTypeNavigator(AronTypeDescriptor::eAronIVTCByteImageType, path), - type(o) - { - CheckAronPtrForNull("AronIVTCByteImageTypeNavigator", "AronIVTCByteImageTypeNavigator", getPath(), o); - if (type->dimensions.size() != 2) - { - throw exception::AronSizeNotValidException("AronIVTCByteImageTypeNavigator", "AronIVTCByteImageTypeNavigator", "The size of the AronPtr is too small", type->dimensions.size(), 2); - } - } - - type::AronIVTCByteImageTypePtr AronIVTCByteImageTypeNavigator::toAronIVTCByteImageTypePtr() const - { - if (type->dimensions.size() != 2) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "getCastedResult", "The dimension size is wrong. Got size: " + std::to_string(type->dimensions.size()), getPath()); - } - if (std::any_of(type->dimensions.begin(), type->dimensions.end(), [](int i) - { - return i <= 0; - })) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "getCastedResult", "The dimension size is wrong. At least one empty is <=0", getPath()); - } - if (type->typeName.empty()) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "getCastedResult", "The useType of image is empty.", getPath()); - } - return type; - } - - std::vector<int> AronIVTCByteImageTypeNavigator::getDimensions() const - { - return type->dimensions; - } - - void AronIVTCByteImageTypeNavigator::setDimensions(const std::vector<int>& d) - { - if (d.size() != 2) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "setDimensions", "Wrong number of elements in dimension array. The size must be equal to 2. The size was: " + std::to_string(d.size()), getPath()); - } - - type->dimensions = d; - } - - unsigned int AronIVTCByteImageTypeNavigator::getWidth() const - { - return type->dimensions[0]; - } - - unsigned int AronIVTCByteImageTypeNavigator::getHeight() const - { - return type->dimensions[1]; - } - - std::string AronIVTCByteImageTypeNavigator::getUsedType() const - { - return type->typeName; - } - - void AronIVTCByteImageTypeNavigator::setWidth(const unsigned int& w) - { - if (w == 0) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "setWidth", "The width of an cannot be 0", getPath()); - } - type->dimensions[0] = w; - } - - void AronIVTCByteImageTypeNavigator::setHeight(const unsigned int& h) - { - if (h == 0) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "setHeight", "The height of an image cannot be 0", getPath()); - } - type->dimensions[1] = h; - } - - void AronIVTCByteImageTypeNavigator::setUsedType(const std::string& u) - { - if (u.empty()) - { - throw exception::AronExceptionWithPathInfo("AronIVTCByteImageTypeNavigator", "setUsedType", "The useType cannot be empty", getPath()); - } - - for (const auto& [key, vec] : ACCEPTED_TYPES) - { - if (u == key || std::find(vec.begin(), vec.end(), key) != vec.end()) - { - type->typeName = key; - return; - } - } - throw exception::AronStringNotValidException("AronIVTCByteImageTypeNavigator", "setUsedType", "The type was not found in the ACCEPTED_TYPES", u); - } - - // static methods - AronIVTCByteImageTypeNavigatorPtr AronIVTCByteImageTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronIVTCByteImageTypeNavigator>(n); - } - - AronIVTCByteImageTypeNavigatorPtr AronIVTCByteImageTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronIVTCByteImageTypeNavigator", "DynamicCast[Before]", n); - AronIVTCByteImageTypeNavigatorPtr casted = AronIVTCByteImageTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronIVTCByteImageTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // virtual implementations - type::AronTypePtr AronIVTCByteImageTypeNavigator::getResult() const - { - return toAronIVTCByteImageTypePtr(); - } - - std::string AronIVTCByteImageTypeNavigator::getName() const - { - return "AronIVTCByteImageType<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h deleted file mode 100644 index b0ebf28bbed62632a41f757348de7687ee9d7abb..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronIVTCByteImageTypeNavigator.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - class AronIVTCByteImageTypeNavigator; - typedef std::shared_ptr<AronIVTCByteImageTypeNavigator> AronIVTCByteImageTypeNavigatorPtr; - - class AronIVTCByteImageTypeNavigator : - virtual public AronNDArraySerializerTypeNavigator - { - public: - using PointerType = AronIVTCByteImageTypeNavigatorPtr; - - public: - // constructors - AronIVTCByteImageTypeNavigator() = delete; - AronIVTCByteImageTypeNavigator(const AronPath& path); - AronIVTCByteImageTypeNavigator(const type::AronIVTCByteImageTypePtr&, const AronPath& path); - - unsigned int getWidth() const; - unsigned int getHeight() const; - - void setWidth(const unsigned int&); - void setHeight(const unsigned int&); - - type::AronIVTCByteImageTypePtr toAronIVTCByteImageTypePtr() const; - - // static methods - static AronIVTCByteImageTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronIVTCByteImageTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); - - // virtual implementations - virtual void setDimensions(const std::vector<int>&) override; - virtual void setUsedType(const std::string&) override; - - virtual std::vector<int> getDimensions() const override; - virtual std::string getUsedType() const override; - - virtual type::AronTypePtr getResult() const override; - virtual std::string getName() const override; - - public: - static const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES; - - private: - // members - type::AronIVTCByteImageTypePtr type; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.cpp deleted file mode 100644 index 98f6f7364a94546b21afebad5c3fc86c04189af0..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronListTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - // constructors - AronListTypeNavigator::AronListTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronListType, path), - AronTypeNavigator(AronTypeDescriptor::eAronListType, path), - type(new type::AronListType()) - { - } - - AronListTypeNavigator::AronListTypeNavigator(const type::AronListTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronListType, path), - AronTypeNavigator(AronTypeDescriptor::eAronListType, path), - type(o) - { - CheckAronPtrForNull("AronListTypeNavigator", "AronListTypeNavigator", getPath(), o); - - acceptedTypeNavigator = FromAronType(o->acceptedType); - } - - // static methods - AronListTypeNavigatorPtr AronListTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronListTypeNavigator>(n); - } - - AronListTypeNavigatorPtr AronListTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronListTypeNavigator", "DynamicCast[Before]", n); - AronListTypeNavigatorPtr casted = AronListTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronListTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - type::AronListTypePtr AronListTypeNavigator::toAronListTypePtr() const - { - CheckAronPtrForNull("AronListTypeNavigator", "getCastedResult", getPath(), type->acceptedType); - return type; - } - - // virtual implementations - type::AronTypePtr AronListTypeNavigator::getResult() const - { - return toAronListTypePtr(); - } - - std::string AronListTypeNavigator::getName() const - { - return "AronListType<" + acceptedTypeNavigator->getName() + ">"; - } - - void AronListTypeNavigator::setAcceptedType(const AronTypeNavigatorPtr& a) - { - CheckTypeNavigatorPtrForNull("AronListTypeNavigator", "setAcceptedType", a); - type->acceptedType = a->getResult(); - acceptedTypeNavigator = a; - } - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.cpp deleted file mode 100644 index 9d483dd69ab02a49a1a8ea95bfe93a6010ee6807..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronObjectTypeNavigator.h" - - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - // constructors - AronObjectTypeNavigator::AronObjectTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronObjectType, path), - AronTypeNavigator(AronTypeDescriptor::eAronObjectType, path), - type((new type::AronObjectType())) - { - } - - AronObjectTypeNavigator::AronObjectTypeNavigator(const type::AronObjectTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronObjectType, path), - AronTypeNavigator(AronTypeDescriptor::eAronObjectType, path), - type(o) - { - CheckAronPtrForNull("AronObjectTypeNavigator", "AronObjectTypeNavigator", getPath(), o); - - for(const auto& [key, t] : o->elementTypes) - { - acceptedTypeNavigators[key] = FromAronType(t); - } - } - - // static methods - AronObjectTypeNavigatorPtr AronObjectTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronObjectTypeNavigator>(n); - } - - AronObjectTypeNavigatorPtr AronObjectTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronObjectTypeNavigator", "DynamicCast[Before]", n); - AronObjectTypeNavigatorPtr casted = AronObjectTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronObjectTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // public member functions - void AronObjectTypeNavigator::addAcceptedType(const std::string& k, const AronTypeNavigatorPtr& v) - { - if (k.empty()) - { - throw exception::AronExceptionWithPathInfo("AronObjectTypeNavigator", "addAcceptedType", "Cannot set an element with an empty key.", getPath()); - } - CheckTypeNavigatorPtrForNull("AronObjectTypeNavigator", "addAcceptedType", v); - type->elementTypes[k] = v->getResult(); - acceptedTypeNavigators[k] = v; - } - - void AronObjectTypeNavigator::setObjectName(const std::string& n) - { - //path.setRootIdentifier(n); - type->objectName = n; - } - - void AronObjectTypeNavigator::setExtends(const AronObjectTypeNavigatorPtr& p) - { - CheckTypeNavigatorPtrForNull("AronObjectTypeNavigator", "setExtends", p); - type::AronObjectTypePtr ex = type::AronObjectTypePtr::dynamicCast(p->getResult()); - CheckAronPtrForNull("AronObjectTypeNavigator", "setExtends", getPath(), ex); - extends = p; - } - - std::string AronObjectTypeNavigator::getObjectName() const - { - return type->objectName; - } - - AronObjectTypeNavigatorPtr AronObjectTypeNavigator::getExtends() const - { - return extends; - } - - type::AronObjectTypePtr AronObjectTypeNavigator::toAronObjectTypePtr() const - { - if (type->objectName.empty()) - { - throw exception::AronExceptionWithPathInfo("AronObjectTypeNavigator", "getResult", "The object name is empty.", getPath()); - } - //if(acceptedTypeNavigators.empty()) - //{ - // throw exception::AronExceptionWithPathInfo("AronObjectTypeNavigator", "getResult", "No accepted types set", getPath()); - //} - return type; - } - - // virtual implementations - type::AronTypePtr AronObjectTypeNavigator::getResult() const - { - return toAronObjectTypePtr(); - } - - std::string AronObjectTypeNavigator::getName() const - { - return "AronObjectType<" + type->objectName + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h deleted file mode 100644 index 4ce10c46896a1b7c597cdbac8142a2fa875d9720..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeNavigator.h" - - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - class AronObjectTypeNavigator; - typedef std::shared_ptr<AronObjectTypeNavigator> AronObjectTypeNavigatorPtr; - - class AronObjectTypeNavigator : - virtual public AronMultipleDictAcceptedTypeHavingTypeNavigator, - virtual public AronDictSerializerTypeNavigator - { - public: - using PointerType = AronObjectTypeNavigatorPtr; - - public: - // constructors - AronObjectTypeNavigator(const AronPath& = AronPath()); - AronObjectTypeNavigator(const type::AronObjectTypePtr&, const AronPath& = AronPath()); - - // public member functions - std::string getObjectName() const; - AronObjectTypeNavigatorPtr getExtends() const; - - void setObjectName(const std::string&); - void setExtends(const AronObjectTypeNavigatorPtr&); - - type::AronObjectTypePtr toAronObjectTypePtr() const; - - // static methods - static AronObjectTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronObjectTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); - - // virtual implementations - virtual void addAcceptedType(const std::string&, const AronTypeNavigatorPtr&) override; - - virtual type::AronTypePtr getResult() const override; - virtual std::string getName() const override; - - private: - // members - AronObjectTypeNavigatorPtr extends; - type::AronObjectTypePtr type; - - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.cpp deleted file mode 100644 index cf58ee6f50b8503515744cd0308fca033f4c14f6..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronOpenCVMatTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - const std::map<std::string, std::vector<std::string>> AronOpenCVMatTypeNavigator::ACCEPTED_TYPES = - { - {"CV_8U", {"8U"}}, - {"CV_8S", {"8S"}}, - {"CV_16U", {"16U"}}, - {"CV_16S", {"16S"}}, - {"CV_32S", {"32S"}}, - {"CV_32F", {"32F"}}, - {"CV_64F", {"64F"}}, - }; - - // constructors - AronOpenCVMatTypeNavigator::AronOpenCVMatTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronOpenCVMatType, path), - AronTypeNavigator(AronTypeDescriptor::eAronOpenCVMatType, path), - type(new type::AronOpenCVMatType({}, "")) - { - } - - AronOpenCVMatTypeNavigator::AronOpenCVMatTypeNavigator(const type::AronOpenCVMatTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronOpenCVMatType, path), - AronTypeNavigator(AronTypeDescriptor::eAronOpenCVMatType, path), - type(o) - { - CheckAronPtrForNull("AronOpenCVMatTypeNavigator", "AronOpenCVMatTypeNavigator", getPath(), o); - } - - type::AronOpenCVMatTypePtr AronOpenCVMatTypeNavigator::toAronOpenCVMatTypePtr() const - { - if (type->dimensions.empty()) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "getCastedResult", "The dimension size is empty", getPath()); - } - if (std::any_of(type->dimensions.begin(), type->dimensions.end(), [](int i) - { - return i < -1; - })) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "getCastedResult", "The dimension size is wrong. At least one empty is <-1", getPath()); - } - if (type->typeName.empty()) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "getCastedResult", "The useType of image is empty.", getPath()); - } - return type; - } - - std::string AronOpenCVMatTypeNavigator::getUsedType() const - { - return type->typeName; - } - - std::vector<int> AronOpenCVMatTypeNavigator::getDimensions() const - { - return type->dimensions; - } - - void AronOpenCVMatTypeNavigator::setUsedType(const std::string& u) - { - if (u.empty()) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "setUsedType", "The useType cannot be empty", getPath()); - } - - for (const auto& [key, vec] : ACCEPTED_TYPES) - { - if (u == key || std::find(vec.begin(), vec.end(), key) != vec.end()) - { - type->typeName = key; - return; - } - } - throw exception::AronStringNotValidException("AronOpenCVMatTypeNavigator", "setUsedType", "The type was not found in the ACCEPTED_TYPES", u); - } - - void AronOpenCVMatTypeNavigator::setDimensions(const std::vector<int>& d) - { - if (d.empty()) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "setDimensions", "The dimensions of an opencv mat cannot be empty", getPath()); - } - if (std::any_of(d.begin(), d.end(), [](int i) - { - return i < -1; - })) - { - throw exception::AronExceptionWithPathInfo("AronOpenCVMatTypeNavigator", "setDimensions", "The dimension size is wrong. At least one empty is <-1", getPath()); - } - type->dimensions = d; - } - - - // static methods - AronOpenCVMatTypeNavigatorPtr AronOpenCVMatTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronOpenCVMatTypeNavigator>(n); - } - - AronOpenCVMatTypeNavigatorPtr AronOpenCVMatTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronOpenCVMatTypeNavigator", "DynamicCast[Before]", n); - AronOpenCVMatTypeNavigatorPtr casted = AronOpenCVMatTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronOpenCVMatTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // virtual implementations - type::AronTypePtr AronOpenCVMatTypeNavigator::getResult() const - { - return toAronOpenCVMatTypePtr(); - } - - std::string AronOpenCVMatTypeNavigator::getName() const - { - return "AronOpenCVMatType<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h deleted file mode 100644 index 5aca82d138a4fb445b4cfb1595824dba5aea7d8b..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronOpenCVMatTypeNavigator.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - class AronOpenCVMatTypeNavigator; - typedef std::shared_ptr<AronOpenCVMatTypeNavigator> AronOpenCVMatTypeNavigatorPtr; - - class AronOpenCVMatTypeNavigator : - virtual public AronNDArraySerializerTypeNavigator - { - public: - using PointerType = AronOpenCVMatTypeNavigatorPtr; - - public: - // constructors - AronOpenCVMatTypeNavigator() = delete; - AronOpenCVMatTypeNavigator(const AronPath& path); - AronOpenCVMatTypeNavigator(const type::AronOpenCVMatTypePtr&, const AronPath& path); - - type::AronOpenCVMatTypePtr toAronOpenCVMatTypePtr() const; - - // static methods - static AronOpenCVMatTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronOpenCVMatTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); - - // virtual implementations - virtual void setDimensions(const std::vector<int>&) override; - virtual void setUsedType(const std::string&) override; - - virtual std::vector<int> getDimensions() const override; - virtual std::string getUsedType() const override; - - virtual type::AronTypePtr getResult() const override; - virtual std::string getName() const override; - - public: - static const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES; - - private: - // members - type::AronOpenCVMatTypePtr type; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.cpp deleted file mode 100644 index 2cec3be614a8bf391fd1dd6089a9b742cac6565a..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronPCLPointCloudTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - const std::map<std::string, std::vector<std::string>> AronPCLPointCloudTypeNavigator::ACCEPTED_TYPES = - { - {"PointXYZ", {"pcl::PointXYZ"}}, - {"PointXYZI", {"pcl::PointXYZI"}}, - {"PointXYZL", {"pcl::PointXYZL"}}, - {"PointXYZRGB", {"pcl::PointXYZRGB"}}, - {"PointXYZRGBL", {"pcl::PointXYZRGBL"}}, - {"PointXYZRGBA", {"pcl::PointXYZRGBA"}}, - {"PointXYZHSV", {"pcl::PointXYZHSV"}}, - }; - - // constructors - AronPCLPointCloudTypeNavigator::AronPCLPointCloudTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronPCLPointCloudType, path), - AronTypeNavigator(AronTypeDescriptor::eAronPCLPointCloudType, path), - type(new type::AronPCLPointCloudType({0, 0}, "")) - { - } - - AronPCLPointCloudTypeNavigator::AronPCLPointCloudTypeNavigator(const type::AronPCLPointCloudTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronPCLPointCloudType, path), - AronTypeNavigator(AronTypeDescriptor::eAronPCLPointCloudType, path), - type(o) - { - CheckAronPtrForNull("AronPCLPointCloudTypeNavigator", "AronPCLPointCloudTypeNavigator", getPath(), o); - } - - type::AronPCLPointCloudTypePtr AronPCLPointCloudTypeNavigator::toAronPCLPointCloudTypePtr() const - { - if (type->dimensions.size() != 2) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "getCastedResult", "The dimension size is wrong. Got size: " + std::to_string(type->dimensions.size()), getPath()); - } - if (std::any_of(type->dimensions.begin(), type->dimensions.end(), [](int i) - { - return i <= 0; - })) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "getCastedResult", "The dimension size is wrong. At least one empty is <=0", getPath()); - } - if (type->typeName.empty()) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "getCastedResult", "The useType of image is empty.", getPath()); - } - return type; - } - - std::vector<int> AronPCLPointCloudTypeNavigator::getDimensions() const - { - return type->dimensions; - } - - void AronPCLPointCloudTypeNavigator::setDimensions(const std::vector<int>& d) - { - if (d.size() != 2) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "setDimensions", "Wrong number of elements in dimension array. The size must be equal to 2. The size was: " + std::to_string(d.size()), getPath()); - } - type->dimensions = d; - } - - unsigned int AronPCLPointCloudTypeNavigator::getWidth() const - { - return type->dimensions[0]; - } - - unsigned int AronPCLPointCloudTypeNavigator::getHeight() const - { - return type->dimensions[1]; - } - - std::string AronPCLPointCloudTypeNavigator::getUsedType() const - { - return type->typeName; - } - - void AronPCLPointCloudTypeNavigator::setWidth(const unsigned int& w) - { - if (w == 0) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "setWidth", "The width of aa pointcloud cannot be 0", getPath()); - } - type->dimensions[0] = w; - } - - void AronPCLPointCloudTypeNavigator::setHeight(const unsigned int& h) - { - if (h == 0) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "setHeight", "The height of aa pointcloud cannot be 0", getPath()); - } - type->dimensions[1] = h; - } - - void AronPCLPointCloudTypeNavigator::setUsedType(const std::string& u) - { - if (u.empty()) - { - throw exception::AronExceptionWithPathInfo("AronPCLPointCloudTypeNavigator", "setUsedType", "The useType cannot be empty", getPath()); - } - - for (const auto& [key, vec] : ACCEPTED_TYPES) - { - if (u == key || std::find(vec.begin(), vec.end(), key) != vec.end()) - { - type->typeName = key; - return; - } - } - throw exception::AronStringNotValidException("AronPCLPointCloudTypeNavigator", "setUsedType", "The type was not found in the ACCEPTED_TYPES", u); - } - - - // static methods - AronPCLPointCloudTypeNavigatorPtr AronPCLPointCloudTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronPCLPointCloudTypeNavigator>(n); - } - - AronPCLPointCloudTypeNavigatorPtr AronPCLPointCloudTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronPCLPointCloudTypeNavigator", "DynamicCast[Before]", n); - AronPCLPointCloudTypeNavigatorPtr casted = AronPCLPointCloudTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronPCLPointCloudTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // virtual implementations - type::AronTypePtr AronPCLPointCloudTypeNavigator::getResult() const - { - return toAronPCLPointCloudTypePtr(); - } - - std::string AronPCLPointCloudTypeNavigator::getName() const - { - return "AronPCLPointCloudType<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h deleted file mode 100644 index 0ed1bb7b19a79df7ac7896623cccb59f8797f426..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPCLPointCloudTypeNavigator.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <string> -#include <map> - -// Base Class -#include "AronTypeNavigator.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - class AronPCLPointCloudTypeNavigator; - typedef std::shared_ptr<AronPCLPointCloudTypeNavigator> AronPCLPointCloudTypeNavigatorPtr; - - class AronPCLPointCloudTypeNavigator : - virtual public AronNDArraySerializerTypeNavigator - { - public: - using PointerType = AronPCLPointCloudTypeNavigatorPtr; - - public: - // constructors - AronPCLPointCloudTypeNavigator() = delete; - AronPCLPointCloudTypeNavigator(const AronPath& path); - AronPCLPointCloudTypeNavigator(const type::AronPCLPointCloudTypePtr&, const AronPath& path); - - unsigned int getWidth() const; - unsigned int getHeight() const; - - void setWidth(const unsigned int&); - void setHeight(const unsigned int&); - - type::AronPCLPointCloudTypePtr toAronPCLPointCloudTypePtr() const; - - // static methods - static AronPCLPointCloudTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronPCLPointCloudTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); - - // virtual implementations - virtual void setDimensions(const std::vector<int>&) override; - virtual void setUsedType(const std::string&) override; - - virtual std::vector<int> getDimensions() const override; - virtual std::string getUsedType() const override; - - virtual type::AronTypePtr getResult() const override; - virtual std::string getName() const override; - - public: - static const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES; - - private: - // members - type::AronPCLPointCloudTypePtr type; - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.cpp deleted file mode 100644 index 559af3fcc77bcaf15a0dab1718d165f597b03198..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - - -// STD/STL -#include <string> -#include <map> - -// Header -#include "AronPrimitiveTypeNavigator.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - /* constructors */ \ - Aron##upperType##TypeNavigator::Aron##upperType##TypeNavigator(const AronPath& path) : \ - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAron##upperType##Type, path), \ - AronTypeNavigator(AronTypeDescriptor::eAron##upperType##Type, path), \ - type(new type::Aron##upperType##Type()) \ - { \ - } \ - \ - Aron##upperType##TypeNavigator::Aron##upperType##TypeNavigator(const type::Aron##upperType##TypePtr&o, const AronPath& path) : \ - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAron##upperType##Type, path), \ - AronTypeNavigator(AronTypeDescriptor::eAron##upperType##Type, path), \ - type(o) \ - { \ - CheckAronPtrForNull("Aron" + std::string(#upperType) + "TypeNavigator", "Aron" + std::string(#upperType) + "TypeNavigator", getPath(), o); \ - } \ - \ - type::Aron##upperType##TypePtr Aron##upperType##TypeNavigator::toAron##upperType##TypePtr() const \ - { \ - return type; \ - } \ - \ - /* static methods */ \ - Aron##upperType##TypeNavigatorPtr Aron##upperType##TypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) \ - {\ - CheckTypeNavigatorPtrForNull("Aron" + std::string(#upperType) + "TypeNavigator", "DynamicCast[Before]", n); \ - Aron##upperType##TypeNavigatorPtr casted = Aron##upperType##TypeNavigator::DynamicCast(n); \ - CheckTypeNavigatorPtrForNull("Aron" + std::string(#upperType) + "TypeNavigator", "DynamicCast[After]", n->getPath(), casted); \ - return casted; \ - }\ - \ - Aron##upperType##TypeNavigatorPtr Aron##upperType##TypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) \ - {\ - return std::dynamic_pointer_cast<Aron##upperType##TypeNavigator>(n); \ - }\ - \ - /* virtual implementations */\ - type::AronTypePtr Aron##upperType##TypeNavigator::getResult() const\ - {\ - return toAron##upperType##TypePtr(); \ - }\ - \ - std::string Aron##upperType##TypeNavigator::getName() const \ - {\ - return "Aron" + std::string(#upperType) + "Type"; \ - } - - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.cpp deleted file mode 100644 index 9f9d44403a7159ecc4746e027cee37ac1cd9cb6c..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// Header -#include "AronTupleTypeNavigator.h" - - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - // constructors - AronTupleTypeNavigator::AronTupleTypeNavigator(const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronTupleType, path), - AronTypeNavigator(AronTypeDescriptor::eAronTupleType, path), - type(new type::AronTupleType()) - { - } - - AronTupleTypeNavigator::AronTupleTypeNavigator(const type::AronTupleTypePtr& o, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(AronTypeDescriptor::eAronTupleType, path), - AronTypeNavigator(AronTypeDescriptor::eAronTupleType, path), - type(o) - { - CheckAronPtrForNull("AronTupleTypeNavigator", "AronTupleTypeNavigator", getPath(), o); - - for (const auto& t : type->elementTypes) - { - acceptedTypeNavigators.push_back(FromAronType(t)); - } - } - - type::AronTupleTypePtr AronTupleTypeNavigator::toAronTupleTypePtr() const - { - if (acceptedTypeNavigators.empty()) - { - throw exception::AronExceptionWithPathInfo("AronTupleTypeNavigator", "getCastedResult", "No accepted types set", getPath()); - } - return type; - } - - // static methods - AronTupleTypeNavigatorPtr AronTupleTypeNavigator::DynamicCast(const AronTypeNavigatorPtr& n) - { - return std::dynamic_pointer_cast<AronTupleTypeNavigator>(n); - } - - AronTupleTypeNavigatorPtr AronTupleTypeNavigator::DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - CheckTypeNavigatorPtrForNull("AronTupleTypeNavigator", "DynamicCast[Before]", n); - AronTupleTypeNavigatorPtr casted = AronTupleTypeNavigator::DynamicCast(n); - CheckTypeNavigatorPtrForNull("AronTupleTypeNavigator", "DynamicCast[After]", n->getPath(), casted); - return casted; - } - - // public member functions - void AronTupleTypeNavigator::addAcceptedType(const AronTypeNavigatorPtr& v) - { - CheckTypeNavigatorPtrForNull("AronTupleTypeNavigator", "addAcceptedType", getPath(), v); - type->elementTypes.push_back(v->getResult()); - acceptedTypeNavigators.push_back(v); - } - - // virtual implementations - type::AronTypePtr AronTupleTypeNavigator::getResult() const - { - return toAronTupleTypePtr(); - } - - std::string AronTupleTypeNavigator::getName() const - { - std::vector<std::string> names; - for (const auto n : acceptedTypeNavigators) - { - names.push_back(n->getName()); - } - return "AronTupleType<" + simox::alg::to_string(names, ", ") + ">"; - } - } - } -} - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.cpp deleted file mode 100644 index b4476ab539fefa604b2ab737bb97e0ac7bfc3516..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Header -#include "AronTypeNavigator.h" - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - /* AronTypeNavigator */ - // static data members - const AronTypeNavigatorFactoryPtr AronTypeNavigator::FACTORY = AronTypeNavigatorFactoryPtr(new AronTypeNavigatorFactory()); - - // constructors - AronTypeNavigator::AronTypeNavigator(const AronTypeDescriptor& d, const AronPath& path) : - navigator::AronNavigator<AronTypeDescriptor, type::AronType>::AronNavigator(d, path) - { - } - - AronTypeNavigatorPtr AronTypeNavigator::FromAronType(const type::AronTypePtr& a, const AronPath& path) - { - return FACTORY->create(a, path); - } - - void AronTypeNavigator::CheckTypeNavigatorPtrForNull(const std::string& c, const std::string& m, const AronTypeNavigatorPtr& data) - { - if (data.get() == nullptr) - { - throw exception::AronException(c, m, "Could not cast an AronTypeNavigatorPtr. The Ptr was NULL."); - } - } - - void AronTypeNavigator::CheckTypeNavigatorPtrForNull(const std::string& c, const std::string& m, const AronPath& p, const AronTypeNavigatorPtr& data) - { - if (data.get() == nullptr) - { - throw exception::AronExceptionWithPathInfo(c, m, "Could not cast an AronTypeNavigatorPtr. The Ptr was NULL.", p); - } - } - - /* AronSingleAcceptedTypeHavingTypeNavigator */ - AronTypeNavigatorPtr AronSingleAcceptedTypeHavingTypeNavigator::getAcceptedType() const - { - return acceptedTypeNavigator; - } - - size_t AronSingleAcceptedTypeHavingTypeNavigator::childrenSize() const - { - return 1; - } - - /* AronMultipleListAcceptedTypeHavingTypeNavigator */ - std::vector<AronTypeNavigatorPtr> AronMultipleListAcceptedTypeHavingTypeNavigator::getAcceptedTypes() const - { - return acceptedTypeNavigators; - } - - AronTypeNavigatorPtr AronMultipleListAcceptedTypeHavingTypeNavigator::getAcceptedType(unsigned int i) const - { - if (i >= acceptedTypeNavigators.size()) - { - return nullptr; - } - return acceptedTypeNavigators[i]; - } - - size_t AronMultipleListAcceptedTypeHavingTypeNavigator::childrenSize() const - { - return acceptedTypeNavigators.size(); - } - - /* AronMultipleDictAcceptedTypeHavingTypeNavigator */ - std::map<std::string, AronTypeNavigatorPtr> AronMultipleDictAcceptedTypeHavingTypeNavigator::getAcceptedTypes() const - { - return acceptedTypeNavigators; - } - - AronTypeNavigatorPtr AronMultipleDictAcceptedTypeHavingTypeNavigator::getAcceptedType(const std::string& s) const - { - if (acceptedTypeNavigators.find(s) == acceptedTypeNavigators.end()) - { - return nullptr; - } - return acceptedTypeNavigators.at(s); - } - - size_t AronMultipleDictAcceptedTypeHavingTypeNavigator::childrenSize() const - { - return acceptedTypeNavigators.size(); - } - - std::vector<std::string> AronMultipleDictAcceptedTypeHavingTypeNavigator::getAllKeys() const - { - std::vector<std::string> ret; - for (const auto& [key, _] : acceptedTypeNavigators) - { - ret.push_back(key); - } - return ret; - } - - /* AronComplexTypeNavigator */ - size_t AronComplexTypeNavigator::childrenSize() const - { - return 0; - } - - /* AronPrimitiveTypeNavigator */ - size_t AronPrimitiveTypeNavigator::childrenSize() const - { - return 0; - } - - } - } -} - - diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h deleted file mode 100644 index cd16a8f86387f67771366161140864af083aa6e4..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h +++ /dev/null @@ -1,310 +0,0 @@ -/* -* This file is part of ArmarX. -* -* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), -* Karlsruhe Institute of Technology (KIT), all rights reserved. -* -* ArmarX is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License version 2 as -* published by the Free Software Foundation. -* -* ArmarX is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) -* @copyright http://www.gnu.org/licenses/gpl-2.0.txt -* GNU General Public License -*/ - -#pragma once - -// STD/STL -#include <memory> -#include <vector> -#include <map> -#include <string> - -// Simox -#include <SimoxUtility/algorithm/string.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h> - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - class AronTypeNavigatorFactory; - typedef std::shared_ptr<AronTypeNavigatorFactory> AronTypeNavigatorFactoryPtr; - - class AronTypeNavigator; - typedef std::shared_ptr<AronTypeNavigator> AronTypeNavigatorPtr; - - class AronTypeNavigator : - virtual public navigator::AronNavigator<AronTypeDescriptor, type::AronType> - { - public: - using PointerType = AronTypeNavigatorPtr; - - public: - // constructors - AronTypeNavigator() = delete; - AronTypeNavigator(const AronTypeDescriptor&, const AronPath&); - - // virtual methods - virtual type::AronTypePtr getResult() const override = 0; - virtual std::string getName() const override = 0; - virtual size_t childrenSize() const = 0; - - // static methods - static AronTypeNavigatorPtr FromAronType(const type::AronTypePtr&, const AronPath& = AronPath()); - - template<typename AronNavigatorType> - static typename AronNavigatorType::PointerType DynamicCast(const AronTypeNavigatorPtr& n) - { - return AronNavigatorType::DynamicCast(n); - } - - template<typename AronNavigatorType> - static typename AronNavigatorType::PointerType DynamicCastAndCheck(const AronTypeNavigatorPtr& n) - { - return AronNavigatorType::DynamicCastAndCheck(n); - } - - protected: - static void CheckTypeNavigatorPtrForNull(const std::string&, const std::string&, const AronTypeNavigatorPtr& data); - static void CheckTypeNavigatorPtrForNull(const std::string&, const std::string&, const AronPath&, const AronTypeNavigatorPtr& data); - - private: - static const AronTypeNavigatorFactoryPtr FACTORY; - }; - - - /* More hierarchy */ - class AronContainerTypeNavigator; - typedef std::shared_ptr<AronContainerTypeNavigator> AronContainerTypeNavigatorPtr; - - class AronContainerTypeNavigator : - virtual public AronTypeNavigator - { - public: - using PointerType = AronContainerTypeNavigatorPtr; - - public: - // static methods - static AronContainerTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronContainerTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronContainerTypeNavigator>(n); - return casted; - } - }; - - - - class AronSingleAcceptedTypeHavingTypeNavigator; - typedef std::shared_ptr<AronSingleAcceptedTypeHavingTypeNavigator> AronSingleAcceptedTypeHavingTypeNavigatorPtr; - - class AronSingleAcceptedTypeHavingTypeNavigator : - virtual public AronContainerTypeNavigator - { - public: - using PointerType = AronSingleAcceptedTypeHavingTypeNavigatorPtr; - - public: - // virtual methods - virtual void setAcceptedType(const AronTypeNavigatorPtr&) = 0; - virtual AronTypeNavigatorPtr getAcceptedType() const; - - virtual size_t childrenSize() const override; - - - // static methods - static AronSingleAcceptedTypeHavingTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronSingleAcceptedTypeHavingTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronSingleAcceptedTypeHavingTypeNavigator>(n); - return casted; - } - protected: - AronTypeNavigatorPtr acceptedTypeNavigator; - }; - - - - class AronMultipleListAcceptedTypeHavingTypeNavigator; - typedef std::shared_ptr<AronMultipleListAcceptedTypeHavingTypeNavigator> AronMultipleListAcceptedTypeHavingTypeNavigatorPtr; - - class AronMultipleListAcceptedTypeHavingTypeNavigator : - virtual public AronContainerTypeNavigator - { - public: - using PointerType = AronMultipleListAcceptedTypeHavingTypeNavigatorPtr; - - public: - virtual void addAcceptedType(const AronTypeNavigatorPtr&) = 0; - virtual std::vector<AronTypeNavigatorPtr> getAcceptedTypes() const; - virtual AronTypeNavigatorPtr getAcceptedType(unsigned int) const; - - virtual size_t childrenSize() const override; - - // static methods - static AronMultipleListAcceptedTypeHavingTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronMultipleListAcceptedTypeHavingTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronMultipleListAcceptedTypeHavingTypeNavigator>(n); - return casted; - } - protected: - // members - std::vector<AronTypeNavigatorPtr> acceptedTypeNavigators; - }; - - - - class AronMultipleDictAcceptedTypeHavingTypeNavigator; - typedef std::shared_ptr<AronMultipleDictAcceptedTypeHavingTypeNavigator> AronMultipleDictAcceptedTypeHavingTypeNavigatorPtr; - - class AronMultipleDictAcceptedTypeHavingTypeNavigator : - virtual public AronContainerTypeNavigator - { - public: - using PointerType = AronMultipleDictAcceptedTypeHavingTypeNavigatorPtr; - - public: - virtual void addAcceptedType(const std::string&, const AronTypeNavigatorPtr&) = 0; - virtual std::map<std::string, AronTypeNavigatorPtr> getAcceptedTypes() const; - virtual AronTypeNavigatorPtr getAcceptedType(const std::string&) const; - - virtual size_t childrenSize() const override; - - std::vector<std::string> getAllKeys() const; - - // static methods - static AronMultipleDictAcceptedTypeHavingTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronMultipleDictAcceptedTypeHavingTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronMultipleDictAcceptedTypeHavingTypeNavigator>(n); - return casted; - } - protected: - // members - std::map<std::string, AronTypeNavigatorPtr> acceptedTypeNavigators; - }; - - - - class AronDictSerializerTypeNavigator; - typedef std::shared_ptr<AronDictSerializerTypeNavigator> AronDictSerializerTypeNavigatorPtr; - - class AronDictSerializerTypeNavigator : - virtual public AronContainerTypeNavigator - { - public: - using PointerType = AronDictSerializerTypeNavigatorPtr; - - public: - // static methods - static AronDictSerializerTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronDictSerializerTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronDictSerializerTypeNavigator>(n); - return casted; - } - }; - - - - class AronListSerializerTypeNavigator; - typedef std::shared_ptr<AronListSerializerTypeNavigator> AronListSerializerTypeNavigatorPtr; - - class AronListSerializerTypeNavigator : - virtual public AronContainerTypeNavigator - { - public: - using PointerType = AronListSerializerTypeNavigatorPtr; - - public: - // static methods - static AronListSerializerTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronListSerializerTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronListSerializerTypeNavigator>(n); - return casted; - } - }; - - - - class AronComplexTypeNavigator; - typedef std::shared_ptr<AronComplexTypeNavigator> AronComplexTypeNavigatorPtr; - - class AronComplexTypeNavigator : - virtual public AronTypeNavigator - { - public: - using PointerType = AronComplexTypeNavigatorPtr; - - virtual size_t childrenSize() const override; - - // static methods - static AronComplexTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronComplexTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronComplexTypeNavigator>(n); - return casted; - } - }; - - - - class AronNDArraySerializerTypeNavigator; - typedef std::shared_ptr<AronNDArraySerializerTypeNavigator> AronNDArraySerializerTypeNavigatorPtr; - - class AronNDArraySerializerTypeNavigator : - virtual public AronComplexTypeNavigator - { - public: - using PointerType = AronNDArraySerializerTypeNavigatorPtr; - - public: - // virtual methods - virtual void setDimensions(const std::vector<int>&) = 0; - virtual void setUsedType(const std::string&) = 0; - - virtual std::string getUsedType() const = 0; - virtual std::vector<int> getDimensions() const = 0; - - // static methods - static AronNDArraySerializerTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronNDArraySerializerTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronNDArraySerializerTypeNavigator>(n); - return casted; - } - }; - - - - class AronPrimitiveTypeNavigator; - typedef std::shared_ptr<AronPrimitiveTypeNavigator> AronPrimitiveTypeNavigatorPtr; - - class AronPrimitiveTypeNavigator : - virtual public AronTypeNavigator - { - public: - using PointerType = AronPrimitiveTypeNavigatorPtr; - - virtual size_t childrenSize() const override; - - // static methods - static AronPrimitiveTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n) - { - AronPrimitiveTypeNavigatorPtr casted = std::dynamic_pointer_cast<AronPrimitiveTypeNavigator>(n); - return casted; - } - }; - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.cpp deleted file mode 100644 index 139a9e146429c4c1362371d65c2e3cabf8385172..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -// STD/STL - -// Header -#include "AronTypeNavigatorFactory.h" - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - - // Map types to factories - const std::map<AronTypeDescriptor, AronTypeNavigatorFactoryPtr> AronTypeNavigatorFactory::FACTORIES = - { -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - {AronResolver::GetDescriptorForAronTypeId(typeid(type::Aron##upperType##Type)), AronTypeNavigatorFactoryPtr(new Aron##upperType##TypeNavigatorFactory())}, \ - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - }; - - // Access method - AronTypeNavigatorPtr AronTypeNavigatorFactory::create(const type::AronTypePtr& aron, const AronPath& path) const - { - CheckIfInputIsNull("AronTypeNavigatorFactory", "create", path, aron); - - auto typeDescriptor = AronResolver::GetDescriptorForAronType(aron); - auto factory_iterator = FACTORIES.find(typeDescriptor); - if (factory_iterator == FACTORIES.end()) - { - throw exception::AronExceptionWithPathInfo("AronTypeNavigatorFactory", "create", "Cannot find the desired factory for input: " + AronTypeDescriptorToString.at(typeDescriptor) + ". Cannot create navigator", path); - } - return factory_iterator->second->createSpecific(aron, path); - } - - AronTypeNavigatorPtr AronTypeNavigatorFactory::createSpecific(const type::AronTypePtr&, const AronPath& p) const - { - throw exception::AronExceptionWithPathInfo("AronTypeNavigatorFactory", "createSpecific", "Called disallowed method of an AronTypeNavigatorFactory. Use child class instead!", p); - } - - // Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - AronTypeNavigatorPtr Aron##upperType##TypeNavigatorFactory::createSpecific(const type::AronTypePtr& aron, const AronPath& path) const \ - { \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeNavigatorFactory", "create", path, aron); \ - type::Aron##upperType##TypePtr aronCasted = type::Aron##upperType##TypePtr::dynamicCast(aron); \ - CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeNavigatorFactory", "create", path, aronCasted); \ - return AronTypeNavigatorPtr(new Aron##upperType##TypeNavigator(aronCasted, path)); \ - } - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.h b/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.h deleted file mode 100644 index dfda634e4dd750f00e9cfaed669c16451a099b87..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of ArmarX. - * - * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), - * Karlsruhe Institute of Technology (KIT), all rights reserved. - * - * ArmarX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * ArmarX is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) - * @copyright http://www.gnu.org/licenses/gpl-2.0.txt - * GNU General Public License - */ - -#pragma once - -// STD/STL -#include <memory> -#include <unordered_map> - -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/navigators/AronNavigatorFactory.h> - -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/AronDescriptor.h> - -namespace armarx -{ - namespace aron - { - namespace typenavigator - { - class AronTypeNavigatorFactory; - typedef std::shared_ptr<AronTypeNavigatorFactory> AronTypeNavigatorFactoryPtr; - - class AronTypeNavigatorFactory : - virtual public navigator::AronNavigatorFactory<type::AronTypePtr, AronTypeNavigatorPtr> - { - public: - AronTypeNavigatorFactory() = default; - virtual AronTypeNavigatorPtr create(const type::AronTypePtr&, const AronPath&) const override; - virtual AronTypeNavigatorPtr createSpecific(const type::AronTypePtr&, const AronPath&) const override; - - private: - static const std::map<AronTypeDescriptor, AronTypeNavigatorFactoryPtr> FACTORIES; - }; - - // Factories -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeNavigatorFactory : \ - virtual public AronTypeNavigatorFactory \ - { \ - public: \ - Aron##upperType##TypeNavigatorFactory() = default; \ - virtual AronTypeNavigatorPtr createSpecific(const type::AronTypePtr&, const AronPath&) const override; \ - }; - - HANDLE_CONTAINER_TYPES - HANDLE_COMPLEX_TYPES - HANDLE_PRIMITIVE_TYPES -#undef RUN_ARON_MACRO - } - } -} diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/EigenMatrixTest.xml b/source/RobotAPI/libraries/aron/aroncore/test/xmls/EigenMatrixTest.xml deleted file mode 100644 index 0656e2f56972af2f0fc0e0adc49d2e40a11df986..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/EigenMatrixTest.xml +++ /dev/null @@ -1,16 +0,0 @@ -<!--Some fancy comment --> -<?xml version="1.0" encoding="UTF-8" ?> -<AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - </CodeIncludes> - <AronIncludes> - </AronIncludes> - <GenerateTypes> - <GenerateType name='armarx::EigenMatrixTest'> - <ObjectChild key='the_eigen_matrix'> - <EigenMatrix rows="25" cols="25" type="int" /> - </ObjectChild> - </GenerateType> - </GenerateTypes> -</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/OpenCVMatTest.xml b/source/RobotAPI/libraries/aron/aroncore/test/xmls/OpenCVMatTest.xml deleted file mode 100644 index f47a174059ccf876b1e1a9cae0b220c3212906a8..0000000000000000000000000000000000000000 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/OpenCVMatTest.xml +++ /dev/null @@ -1,16 +0,0 @@ -<!--Some fancy comment --> -<?xml version="1.0" encoding="UTF-8" ?> -<AronTypeDefinition> - <CodeIncludes> - <Include include="<opencv2/core/core.hpp>" /> - </CodeIncludes> - <AronIncludes> - </AronIncludes> - <GenerateTypes> - <GenerateType name='armarx::OpenCVMatTest'> - <ObjectChild key='the_opencv_matrix'> - <OpenCVMat dimensions="25, 25" type="CV_32S" /> - </ObjectChild> - </GenerateType> - </GenerateTypes> -</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.cpp b/source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.cpp similarity index 96% rename from source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.cpp rename to source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.cpp index 0fee550d6fb6f8342bc64d0290fdb5e26beafc1d..32a2572b24693176cee05121b89fcba025d66077 100644 --- a/source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.cpp +++ b/source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.cpp @@ -31,7 +31,7 @@ namespace armarx { namespace aron { - namespace codegeneration + namespace codegenerator { } diff --git a/source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.h b/source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.h similarity index 97% rename from source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.h rename to source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.h index 3b6e95cf91675d53b04bcc4aa9670a47df8c05a2..f04a757684fc6e6d602d74f4f84f18413667e2fa 100644 --- a/source/RobotAPI/libraries/aron/aroncodegeneration/AronCodeGenerator.h +++ b/source/RobotAPI/libraries/aron/codegenerationhelper/AronCodeGenerator.h @@ -32,7 +32,7 @@ namespace armarx { namespace aron { - namespace codegeneration + namespace codegenerator { /* This is just a dummy class to create a target which depends on the aron code generator executable. */ class AronCodeGenerator; diff --git a/source/RobotAPI/libraries/aron/aroncodegeneration/CMakeLists.txt b/source/RobotAPI/libraries/aron/codegenerationhelper/CMakeLists.txt similarity index 100% rename from source/RobotAPI/libraries/aron/aroncodegeneration/CMakeLists.txt rename to source/RobotAPI/libraries/aron/codegenerationhelper/CMakeLists.txt diff --git a/source/RobotAPI/libraries/aron/converter/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..637345f2b3a4792f269dfd1cee0aed7861db323c --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(ivt) +add_subdirectory(pcl) +add_subdirectory(eigen) +add_subdirectory(opencv) diff --git a/source/RobotAPI/libraries/aron/converter/eigen/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/eigen/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..44b70e2e88ffe15465aa558cb153d491f8ce62c4 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/eigen/CMakeLists.txt @@ -0,0 +1,25 @@ +set(LIB_NAME aroneigenconverter) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") + +set(LIBS + aron +) + +set(LIB_FILES + EigenConverter.cpp +) + +set(LIB_HEADERS + EigenConverter.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +if(Eigen3_FOUND) + include_directories(${Eigen3_INCLUDE_DIR}) +endif() diff --git a/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.cpp b/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e266d962d5b1b2d6bc691354f5a80b1b4c38761d --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.cpp @@ -0,0 +1,56 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + + +// Header +#include "EigenConverter.h" + +namespace armarx::aron::converter +{ + Eigen::Quaternion<float> AronEigenConverter::ConvertToQuaternionf(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToQuaternion<float>(n); + } + Eigen::Quaternion<double> AronEigenConverter::ConvertToQuaterniond(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToQuaternion<double>(n); + } + Eigen::Vector3f AronEigenConverter::ConvertToVector3f(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToVector<float, 3>(n); + } + Eigen::Vector3d AronEigenConverter::ConvertToVector3d(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToVector<double, 3>(n); + } + Eigen::Matrix4f AronEigenConverter::ConvertToMatrix4f(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToMatrix<float, 4, 4>(n); + } + Eigen::Matrix4d AronEigenConverter::ConvertToMatrix4d(const datanavigator::NDArrayNavigatorPtr& n) + { + return ConvertToMatrix<double, 4, 4>(n); + } +} diff --git a/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.h b/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..90562a6db2b8d18a4c40714598b6046984d2a433 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/eigen/EigenConverter.h @@ -0,0 +1,104 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <numeric> + +// Eigen +#include <Eigen/Geometry> +#include <Eigen/Core> + +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h> + + +namespace armarx::aron::converter +{ + class AronEigenConverter + { + AronEigenConverter() = delete; + + public: + // TODO: Add inplace methods + // TODO: Remove Ptrs for references + + static Eigen::Quaternion<float> ConvertToQuaternionf(const datanavigator::NDArrayNavigatorPtr&); + static Eigen::Quaternion<double> ConvertToQuaterniond(const datanavigator::NDArrayNavigatorPtr&); + static Eigen::Vector3f ConvertToVector3f(const datanavigator::NDArrayNavigatorPtr&); + static Eigen::Vector3d ConvertToVector3d(const datanavigator::NDArrayNavigatorPtr&); + static Eigen::Matrix4f ConvertToMatrix4f(const datanavigator::NDArrayNavigatorPtr&); + static Eigen::Matrix4d ConvertToMatrix4d(const datanavigator::NDArrayNavigatorPtr&); + + template<typename T> + static Eigen::Quaternion<T> ConvertToQuaternion(const datanavigator::NDArrayNavigatorPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if(nav->getDimensions() != std::vector<int>({1, 4, sizeof(T)})) + { + throw error::AronException("AronEigenConverter", "ConvertToQuaternion", "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getDimensions(); + + Eigen::Quaternion<T> ret; + memcpy(reinterpret_cast<unsigned char*>(ret.coeffs().data()), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } + + template<typename T, int Size> + static Eigen::Matrix<T, Size, 1> ConvertToVector(const datanavigator::NDArrayNavigatorPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if(nav->getDimensions() != std::vector<int>({Size, 1, sizeof(T)})) + { + throw error::AronException("AronEigenConverter", "ConvertToVector", "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getDimensions(); + + Eigen::Matrix<T, Size, 1> ret; + memcpy(reinterpret_cast<unsigned char*>(ret.data()), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } + + template<typename T, int Rows, int Cols> + static Eigen::Matrix<T, Rows, Cols> ConvertToMatrix(const datanavigator::NDArrayNavigatorPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if(nav->getDimensions() != std::vector<int>({Rows, Cols, sizeof(T)})) + { + throw error::AronException("AronEigenConverter", "ConvertToMatrix", "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getDimensions(); + + Eigen::Matrix<T, Rows, Cols> ret; + memcpy(reinterpret_cast<unsigned char*>(ret.data()), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } + }; + +} diff --git a/source/RobotAPI/libraries/aron/converter/ivt/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/ivt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a7651058d79736edb0797659365ddfc4b62782c6 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/ivt/CMakeLists.txt @@ -0,0 +1,25 @@ +set(LIB_NAME aronivtconverter) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(IVT COMPONENTS ivt ivtopencv QUIET) +armarx_build_if(IVT_FOUND "IVT not available") + +set(LIBS + aron ivt ivtopencv +) + +set(LIB_FILES + IVTConverter.cpp +) + +set(LIB_HEADERS + IVTConverter.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +if(IVT_FOUND) + include_directories(${IVT_INCLUDE_DIRS}) +endif() diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigatorFactory.h b/source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.cpp similarity index 52% rename from source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigatorFactory.h rename to source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.cpp index e893a001bf33bd97a091328f7ba874a8ef075124..13b85f22684e0cc847b01147aebca4bbfdbdf84b 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/AronNavigatorFactory.h +++ b/source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.cpp @@ -21,39 +21,27 @@ * GNU General Public License */ -#pragma once - // STD/STL -#include <memory> -#include <string> -#include <unordered_map> - -// Base Class -#include <RobotAPI/libraries/aron/aroncore/AronFactory.h> - -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> +#include <numeric> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/AronPath.h> +// Header +#include "IVTConverter.h" -namespace armarx +namespace armarx::aron::converter { - namespace aron + std::shared_ptr<CByteImage> AronIVTConverter::ConvertToCByteImage(const datanavigator::NDArrayNavigatorPtr& nav) { - namespace navigator - { - template <typename Input, typename Output> // requires ... - class AronNavigatorFactory : - virtual public AronPtrInputPtrOutputFactory<Input, Output> - { - public: - AronNavigatorFactory() = default; + ARMARX_CHECK_NOT_NULL(nav); - virtual Output create(const Input&, const AronPath&) const = 0; - virtual Output createSpecific(const Input&, const AronPath&) const = 0; - }; + if (nav->getDimensions().size() != 3) // +1 for bytes per pixel + { + throw error::AronException("AronIVTConverter", "ConvertToCByteImage", "The size of an NDArray does not match.", nav->getPath()); } + auto dims = nav->getDimensions(); + + auto ret = std::make_shared<CByteImage>(); + ret->Set(dims[0], dims[1], static_cast<CByteImage::ImageType>(std::stoi(nav->getType()))); + memcpy(reinterpret_cast<unsigned char*>(ret->pixels), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; } } diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReaderWriter.h b/source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.h similarity index 51% rename from source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReaderWriter.h rename to source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.h index e2d92fb3082a416c6867ce98870935cc94a3a4bf..65752d37413a6cd916e01e75b69a92c7ab66ad4d 100644 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataReaderWriter.h +++ b/source/RobotAPI/libraries/aron/converter/ivt/IVTConverter.h @@ -24,33 +24,21 @@ #include <memory> #include <string> -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> +// IVT +#include <Image/ByteImage.h> +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronReaderWriter.h> +#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h> -namespace armarx +namespace armarx::aron::converter { - namespace aron + class AronIVTConverter { - namespace io - { - class AronDataReaderWriter; - typedef std::shared_ptr<AronDataReaderWriter> AronDataReaderWriterPtr; - - class AronDataReaderWriter : - public AronReaderWriter - { - public: - AronDataReaderWriter() = default; - - protected: - const std::string ARON_DATA_READER_WRITER_NDARRAY_DIMENSIONS_SLUG = "ARON_NDARRAY_DIMESIONS"; - const std::string ARON_DATA_READER_WRITER_NDARRAY_TYPE_SLUG = "ARON_NDARRAY_TYPE"; - const std::string ARON_DATA_READER_WRITER_NDARRAY_DATA_SLUG = "ARON_NDARRAY_DATA"; - }; - } - } + AronIVTConverter() = delete; + public: + static std::shared_ptr<CByteImage> ConvertToCByteImage(const datanavigator::NDArrayNavigatorPtr&); + }; } diff --git a/source/RobotAPI/libraries/aron/converter/opencv/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/opencv/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b54988b28c2e024b6035a8f722e2fe184ec78bf --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/opencv/CMakeLists.txt @@ -0,0 +1,25 @@ +set(LIB_NAME aronopencvconverter) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(OpenCV QUIET) +armarx_build_if(OpenCV_FOUND "OpenCV not available") + +set(LIBS + aron ${OpenCV_LIBRARIES} +) + +set(LIB_FILES + OpenCVConverter.cpp +) + +set(LIB_HEADERS + OpenCVConverter.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +if(OpenCV_FOUND) + include_directories(${OpenCV_INCLUDE_DIRS}) +endif() diff --git a/source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.cpp b/source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..160a0287137066ec9688dd5a372727a4d543c234 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.cpp @@ -0,0 +1,47 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL +#include <numeric> + +// Header +#include "OpenCVConverter.h" + +namespace armarx::aron::converter +{ + cv::Mat AronOpenCVConverter::ConvertToMat(const datanavigator::NDArrayNavigatorPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if(nav->getDimensions().size() < 3) + { + throw error::AronException("AronIVTConverter", "ConvertToCByteImage", "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getDimensions(); + + cv::Mat ret(std::vector<int>({dims.begin(), std::prev(dims.end())}), std::stoi(nav->getType())); + memcpy(reinterpret_cast<unsigned char*>(ret.data), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } +} + diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriter.h b/source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.h similarity index 68% rename from source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriter.h rename to source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.h index 90007e2496354ad87b24ce558841b6b2291a44a4..7b26277d8c6c61f2e4ef277bcb367c81931745f0 100644 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronReaderWriter.h +++ b/source/RobotAPI/libraries/aron/converter/opencv/OpenCVConverter.h @@ -24,30 +24,23 @@ #include <memory> #include <string> -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> +// Eigen +#include <opencv2/core/core.hpp> +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h> - -namespace armarx +namespace armarx::aron::converter { - namespace aron + class AronOpenCVConverter { - namespace io - { - class AronReaderWriter; - typedef std::shared_ptr<AronReaderWriter> AronReaderWriterPtr; - - class AronReaderWriter - { - public: - AronReaderWriter() = default; + AronOpenCVConverter() = delete; - protected: + public: + static cv::Mat ConvertToMat(const datanavigator::NDArrayNavigatorPtr&); + }; - }; - } - } } diff --git a/source/RobotAPI/libraries/aron/converter/pcl/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/pcl/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a1c4532df8ad750b94056911c3cfd157ff937f4 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/pcl/CMakeLists.txt @@ -0,0 +1,25 @@ +set(LIB_NAME aronpclconverter) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(PCL QUIET) +armarx_build_if(PCL_FOUND "PCL not available") + +set(LIBS + aron ${PCL_COMMON_LIBRARIES} +) + +set(LIB_FILES + PCLConverter.cpp +) + +set(LIB_HEADERS + PCLConverter.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +if(PCL_FOUND) + include_directories(${PCL_INCLUDE_DIRS}) +endif() diff --git a/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.cpp b/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23dd2e4d38142a7cb03a9dbad16f0c7b5f728d07 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.cpp @@ -0,0 +1,33 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + + +// Header +#include "PCLConverter.h" + +namespace armarx::aron::converter +{ + +} diff --git a/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.h b/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..a58bb7c989b7adb3f5b0b4bbc9f1e1f6cf12fa86 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/pcl/PCLConverter.h @@ -0,0 +1,62 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <numeric> + +// Eigen +#include <pcl/point_cloud.h> +#include <pcl/point_types.h> + +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h> + + +namespace armarx::aron::converter +{ + class AronPCLConverter + { + AronPCLConverter() = delete; + + public: + template<typename T> + static pcl::PointCloud<T> ConvertToPointClout(const datanavigator::NDArrayNavigatorPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if(nav->getDimensions().size() != 3) // +1 for bytes per pixel + { + throw error::AronException("AronIVTConverter", "ConvertToCByteImage", "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getDimensions(); + + pcl::PointCloud<T> ret(dims[0], dims[1]); + memcpy(reinterpret_cast<unsigned char*>(ret.points.data()), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } + }; + +} diff --git a/source/RobotAPI/libraries/aron/core/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bdb8203c8083108012fb02e10eac9b7b7a2779e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/CMakeLists.txt @@ -0,0 +1,223 @@ +set(LIB_NAME aron) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +find_package(Eigen3 QUIET) +armarx_build_if(Eigen3_FOUND "Eigen3 not available") +if(Eigen3_FOUND) + include_directories(${Eigen3_INCLUDE_DIR}) +endif() + +find_package(Simox QUIET) +armarx_build_if(Simox_FOUND "Simox not available") +if(Simox_FOUND) + include_directories(${Simox_INCLUDE_DIR}) +endif() + + +set(LIBS + ArmarXCoreInterfaces + ArmarXCore + RobotAPIInterfaces + cppgen + ${Simox_LIBS} +) + +set(LIB_FILES + Resolver.cpp + Path.cpp + + navigator/data/Navigator.cpp + navigator/data/container/List.cpp + navigator/data/container/Dict.cpp + navigator/data/complex/NDArray.cpp + navigator/data/primitive/Primitive.cpp + navigator/data/NavigatorFactory.cpp + + navigator/type/Navigator.cpp + navigator/type/container/Object.cpp + navigator/type/container/List.cpp + navigator/type/container/Dict.cpp + navigator/type/container/Tuple.cpp + navigator/type/container/Pair.cpp + navigator/type/ndarray/EigenMatrix.cpp + navigator/type/ndarray/EigenQuaternion.cpp + navigator/type/ndarray/IVTCByteImage.cpp + navigator/type/ndarray/OpenCVMat.cpp + navigator/type/ndarray/PCLPointCloud.cpp + navigator/type/ndarray/Position.cpp + navigator/type/ndarray/Pose.cpp + navigator/type/ndarray/Orientation.cpp + navigator/type/enum/IntEnum.cpp + navigator/type/primitive/Primitive.cpp + navigator/type/NavigatorFactory.cpp + + navigator/visitors/DataVisitor.cpp + navigator/visitors/TypedDataVisitor.cpp + + io/dataIO/writer/navigator/NavigatorWriter.cpp + io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp + + io/dataIO/reader/navigator/NavigatorReader.cpp + io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp + + io/dataIO/visitor/Visitor.cpp + io/dataIO/converter/Converter.cpp + + io/typeIO/writer/navigator/NavigatorWriter.cpp + io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp + + io/typeIO/reader/navigator/NavigatorReader.cpp + io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.cpp + + io/typeIO/visitor/Visitor.cpp + io/typeIO/converter/Converter.cpp + + codegenerator/codeWriter/cpp/Writer.cpp + codegenerator/codeWriter/cpp/serializer/Serializer.cpp + codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.cpp + codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp + codegenerator/codeWriter/cpp/serializer/container/Dict.cpp + codegenerator/codeWriter/cpp/serializer/container/List.cpp + codegenerator/codeWriter/cpp/serializer/container/Object.cpp + codegenerator/codeWriter/cpp/serializer/container/Tuple.cpp + codegenerator/codeWriter/cpp/serializer/container/Pair.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/Position.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.cpp + codegenerator/codeWriter/cpp/serializer/ndarray/Pose.cpp + codegenerator/codeWriter/cpp/serializer/enum/IntEnum.cpp + codegenerator/codeWriter/cpp/serializer/primitive/Primitive.cpp + codegenerator/codeWriter/cpp/serializer/SerializerFactory.cpp + + codegenerator/typeReader/xml/Data.cpp + codegenerator/typeReader/xml/ReaderFactory.cpp + codegenerator/typeReader/xml/Reader.cpp +) + +set(LIB_HEADERS + Debug.h + Config.h + Concepts.h + Descriptor.h + Resolver.h + Randomizer.h + Exception.h + Factory.h + Path.h + + navigator/Navigator.h + navigator/NavigatorFactory.h + + navigator/data/Navigator.h + navigator/data/container/List.h + navigator/data/container/Dict.h + navigator/data/complex/NDArray.h + navigator/data/primitive/Primitive.h + navigator/data/AllNavigators.h + navigator/data/NavigatorFactory.h + + navigator/type/Navigator.h + navigator/type/container/Object.h + navigator/type/container/List.h + navigator/type/container/Dict.h + navigator/type/container/Tuple.h + navigator/type/container/Pair.h + navigator/type/ndarray/EigenMatrix.h + navigator/type/ndarray/EigenQuaternion.h + navigator/type/ndarray/IVTCByteImage.h + navigator/type/ndarray/OpenCVMat.h + navigator/type/ndarray/PCLPointCloud.h + navigator/type/ndarray/Position.h + navigator/type/ndarray/Pose.h + navigator/type/ndarray/Orientation.h + navigator/type/enum/IntEnum.h + navigator/type/primitive/Primitive.h + navigator/type/AllNavigators.h + navigator/type/NavigatorFactory.h + + navigator/visitors/DataVisitor.h + navigator/visitors/TypedDataVisitor.h + + io/Data.h + + io/dataIO/Writer.h + io/dataIO/writer/WriterToken.h + io/dataIO/writer/navigator/NavigatorWriterToken.h + io/dataIO/writer/navigator/NavigatorWriter.h + io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h + io/dataIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h + + io/dataIO/Reader.h + io/dataIO/reader/ReaderToken.h + io/dataIO/reader/navigator/NavigatorReaderToken.h + io/dataIO/reader/navigator/NavigatorReader.h + io/dataIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h + io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h + + io/dataIO/visitor/Visitor.h + io/dataIO/converter/Converter.h + + io/typeIO/Writer.h + io/typeIO/writer/WriterToken.h + io/typeIO/writer/navigator/NavigatorWriterToken.h + io/typeIO/writer/navigator/NavigatorWriter.h + io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h + io/typeIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h + + io/typeIO/Reader.h + io/typeIO/reader/ReaderToken.h + io/typeIO/reader/navigator/NavigatorReader.h + io/typeIO/reader/navigator/NavigatorReaderToken.h + io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h + io/typeIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h + + io/typeIO/visitor/Visitor.h + io/typeIO/converter/Converter.h + + codegenerator/WriterInfo.h + codegenerator/ReaderInfo.h + codegenerator/GenerateTypeInfo.h + codegenerator/GenerateIntEnumInfo.h + + codegenerator/codeWriter/CodeWriter.h + codegenerator/codeWriter/SerializerFactory.h + + codegenerator/codeWriter/cpp/AronCppClass.h + codegenerator/codeWriter/cpp/Writer.h + codegenerator/codeWriter/cpp/serializer/Serializer.h + codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.h + codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.h + codegenerator/codeWriter/cpp/serializer/container/Dict.h + codegenerator/codeWriter/cpp/serializer/container/List.h + codegenerator/codeWriter/cpp/serializer/container/Object.h + codegenerator/codeWriter/cpp/serializer/container/Tuple.h + codegenerator/codeWriter/cpp/serializer/container/Pair.h + codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.h + codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.h + codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.h + codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.h + codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.h + codegenerator/codeWriter/cpp/serializer/ndarray/Position.h + codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.h + codegenerator/codeWriter/cpp/serializer/ndarray/Pose.h + codegenerator/codeWriter/cpp/serializer/enum/IntEnum.h + codegenerator/codeWriter/cpp/serializer/primitive/Primitive.h + codegenerator/codeWriter/cpp/serializer/AllSerializers.h + codegenerator/codeWriter/cpp/serializer/SerializerFactory.h + + codegenerator/typeReader/Reader.h + codegenerator/typeReader/xml/Data.h + codegenerator/typeReader/xml/ReaderFactory.h + codegenerator/typeReader/xml/Reader.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +# add unit tests +add_subdirectory(test) diff --git a/source/RobotAPI/libraries/aron/core/Concepts.h b/source/RobotAPI/libraries/aron/core/Concepts.h new file mode 100644 index 0000000000000000000000000000000000000000..91c9d0931152d15491adf6e7efb8462cc5bcfe57 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Concepts.h @@ -0,0 +1,166 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Config.h> + + +namespace armarx::aron +{ + template<class T> + static constexpr bool isPrimitive = + std::is_same_v<T, int > || + std::is_same_v<T, long > || + std::is_same_v<T, float > || + std::is_same_v<T, double > || + std::is_same_v<T, bool > || + std::is_same_v<T, std::string>; + + + // TODO: make nice + /* // General Concepts + template <typename CppType> + concept IsAronPrimitiveCppType = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<CppType, lowerType>::value) + + HANDLE_PRIMITIVE_TYPES + #undef RUN_ARON_MACRO + ; + + template <typename AronData, typename CppType> + concept AreAronPrimitiveDependent = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronData, Aron##upperType>::value && std::is_same<CppType, lowerType>::value) + + HANDLE_PRIMITIVE_TYPES + #undef RUN_ARON_MACRO + ; + + template <typename AronData> + concept IsAronData = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronData, Aron##upperType>::value) + + HANDLE_ALL_ARON_DATA + #undef RUN_ARON_MACRO + ; + + template <typename AronAbstractTypeType> + concept IsAronAbstractType = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronAbstractTypeType, Aron##upperType##Type>::value) + + HANDLE_ALL_ARON_TYPES + #undef RUN_ARON_MACRO + ; + + template <typename AronAbstractTypeType, typename AronData, typename CppType> + concept AreAronAbstractTypeAndPrimitiveDependent = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronAbstractTypeType, Aron##upperType##Type>::value && std::is_same<AronData, Aron##upperType>::value && std::is_same<CppType, lowerType>::value) + + HANDLE_PRIMITIVE_TYPES + #undef RUN_ARON_MACRO + ; + + + + // Compound + template <typename Aron> + concept isAron = IsAronData<Aron> || IsAronAbstractType<Aron>; + + + + + + // Navigator Concepts + namespace data + { + class Navigator; + + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##Navigator; + + HANDLE_CONTAINER_DATA + #undef RUN_ARON_MACRO + + template<typename AronDataType, typename CppType> requires AreAronPrimitiveDependent<AronDataType, CppType> + class AronPrimitiveDataNavigator; + + template <typename Navigator> + concept IsNavigator = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<Navigator, upperType##Navigator>::value) + + HANDLE_CONTAINER_DATA + #undef RUN_ARON_MACRO + + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<Navigator, AronPrimitiveDataNavigator<Aron##upperType, lowerType>>::value) + + HANDLE_PRIMITIVE_TYPES + #undef RUN_ARON_MACRO + ; + } + + + + + + // AronAbstractTypeNavigator Concepts + namespace types + { + class AronAbstractTypeNavigator; + + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##Navigator; + + HANDLE_CONTAINER_TYPES + #undef RUN_ARON_MACRO + + template<typename AronAbstractTypeType, typename AronDataType, typename CppType> requires AreAronAbstractTypeAndPrimitiveDependent<AronAbstractTypeType, AronDataType, CppType> + class AronPrimitiveTypeNavigator; + + template <typename AronAbstractTypeNavigator> + concept IsAronAbstractTypeNavigator = false + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronAbstractTypeNavigator, upperType##Navigator>::value) + + HANDLE_CONTAINER_TYPES + #undef RUN_ARON_MACRO + + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + || (std::is_same<AronAbstractTypeNavigator, AronPrimitiveTypeNavigator<Aron##upperType##Type, Aron##upperType, lowerType>>::value) + + HANDLE_PRIMITIVE_TYPES + #undef RUN_ARON_MACRO + ; + }*/ +} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronConfig.h b/source/RobotAPI/libraries/aron/core/Config.h similarity index 58% rename from source/RobotAPI/libraries/aron/aroncore/AronConfig.h rename to source/RobotAPI/libraries/aron/core/Config.h index aad8d12956613c317c9d1dcf2b8c382a33db96f1..fc05237a22dab5dc57cb4f44b6d4b9616cc379d2 100644 --- a/source/RobotAPI/libraries/aron/aroncore/AronConfig.h +++ b/source/RobotAPI/libraries/aron/core/Config.h @@ -46,20 +46,10 @@ * | | * | |->AronList: * This container represents a std::vector<T> where T can be any datatype convertable to Aron. - * TODO: + * TODO: complete doc */ -/** - * Should I use macros in C++? - * As a rule, you should only use macros, when a better alternative does not exist. - * They should not be used to generate code; you should simply write the code instead - * (if the code is type-agnostic, write a template instead and use concepts). - * - * However I it is easier right now, so I will use it. - */ - - #include <string> namespace armarx @@ -82,77 +72,51 @@ namespace armarx RUN_ARON_MACRO(Object, object, OBJECT) \ RUN_ARON_MACRO(List, list, LIST) \ RUN_ARON_MACRO(Dict, dict, DICT) \ - RUN_ARON_MACRO(Tuple, tuple, TUPLE) \ + RUN_ARON_MACRO(Pair, pair, PAIR) \ + RUN_ARON_MACRO(Tuple, tuple, TUPLE) #define HANDLE_DICT_SERIALIZER_TYPES \ RUN_ARON_MACRO(Object, object, OBJECT) \ - RUN_ARON_MACRO(Dict, dict, DICT) \ + RUN_ARON_MACRO(Dict, dict, DICT) #define HANDLE_LIST_SERIALIZER_TYPES \ RUN_ARON_MACRO(List, list, LIST) \ RUN_ARON_MACRO(Tuple, tuple, TUPLE) \ - -#define HANDLE_CONTAINER_TYPES_EXCEPT_OBJECT \ - RUN_ARON_MACRO(List, list, LIST) \ - RUN_ARON_MACRO(Dict, dict, DICT) \ - RUN_ARON_MACRO(Tuple, tuple, TUPLE) \ + RUN_ARON_MACRO(Pair, pair, PAIR) // All complex types go here -#define HANDLE_COMPLEX_TYPES \ +#define HANDLE_NDARRAY_TYPES \ RUN_ARON_MACRO(EigenMatrix, eigenmatrix, EIGEN_MATRIX) \ + RUN_ARON_MACRO(EigenQuaternion, eigenquaternion, EIGEN_QUATERNION) \ RUN_ARON_MACRO(IVTCByteImage, ivtcbyteimage, IVT_CBYTE_IMAGE) \ RUN_ARON_MACRO(OpenCVMat, opencvmat, OPENCV_MAT) \ - RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD) + RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD) \ + RUN_ARON_MACRO(Position, position, POSITION) \ + RUN_ARON_MACRO(Orientation, orientation, ORIENTATION) \ + RUN_ARON_MACRO(Pose, pose, POSE) -// All primitive types without cpp type. -// The target language type must be similar to the lowercase type +// All enum types (they differ from primitive types since they have a list of accepted values and names) +// TODO: Think about extending enums to StringEnums, FloatEnumns etc. +#define HANDLE_ENUM_TYPES \ + RUN_ARON_MACRO(IntEnum, intenum, INT_ENUM) + +// All primitive types #define HANDLE_PRIMITIVE_TYPES \ RUN_ARON_MACRO(Int, int, INT) \ RUN_ARON_MACRO(Long, long, LONG) \ RUN_ARON_MACRO(Float, float, FLOAT) \ RUN_ARON_MACRO(Double, double, DOUBLE) \ RUN_ARON_MACRO(String, string, STRING) \ - RUN_ARON_MACRO(Bool, bool, BOOL) - -#define HANDLE_PRIMITIVE_TYPES_EXCEPT_STRING \ - RUN_ARON_MACRO(Int, int, INT) \ - RUN_ARON_MACRO(Long, long, LONG) \ - RUN_ARON_MACRO(Float, float, FLOAT) \ - RUN_ARON_MACRO(Double, double, DOUBLE) \ - RUN_ARON_MACRO(Bool, bool, BOOL) - -namespace armarx::aron -{ - template<class T> - static constexpr bool is_aron_primitive_type_v = - std::is_same_v<T, int > || - std::is_same_v<T, long > || - std::is_same_v<T, float > || - std::is_same_v<T, double > || - std::is_same_v<T, bool > || - std::is_same_v<T, std::string>; -} + RUN_ARON_MACRO(Bool, bool, BOOL) \ + RUN_ARON_MACRO(Time, time, TIME) // All combined #define HANDLE_ALL_ARON_TYPES \ HANDLE_CONTAINER_TYPES \ - HANDLE_COMPLEX_TYPES \ + HANDLE_NDARRAY_TYPES \ + HANDLE_ENUM_TYPES \ HANDLE_PRIMITIVE_TYPES -/************************************ - * ABSTRACT TYPES ******************* - ***********************************/ -#define HANDLE_CONTAINER_ARON_ABSTRACT_TYPES \ - RUN_ARON_MACRO(AronDictSerializerType, arondictserializertype, ARON_DICT_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(AronListSerializerType, aronlistserializertype, ARON_LIST_SERIALIZER_TYPE) - -#define HANDLE_COMPLEX_ARON_ABSTRACT_TYPES \ - RUN_ARON_MACRO(AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) - -#define HANDLE_ALL_ARON_ABSTRACT_TYPES \ - HANDLE_CONTAINER_ARON_ABSTRACT_TYPES \ - HANDLE_COMPLEX_ARON_ABSTRACT_TYPES - /************************************ * DATA ***************************** ***********************************/ @@ -165,26 +129,52 @@ namespace armarx::aron #define HANDLE_COMPLEX_DATA \ RUN_ARON_MACRO(NDArray, ndarray, NDARRAY) +// the lowercase name must be euqal to the cpp name +#define HANDLE_PRIMITIVE_DATA \ + RUN_ARON_MACRO(Int, int, INT) \ + RUN_ARON_MACRO(Long, long, LONG) \ + RUN_ARON_MACRO(Float, float, FLOAT) \ + RUN_ARON_MACRO(Double, double, DOUBLE) \ + RUN_ARON_MACRO(String, string, STRING) \ + RUN_ARON_MACRO(Bool, bool, BOOL) + +// if you only need the "real" primitives +#define HANDLE_PRIMITIVE_DATA_EXCEPT_STRING \ + RUN_ARON_MACRO(Int, int, INT) \ + RUN_ARON_MACRO(Long, long, LONG) \ + RUN_ARON_MACRO(Float, float, FLOAT) \ + RUN_ARON_MACRO(Double, double, DOUBLE) \ + RUN_ARON_MACRO(Bool, bool, BOOL) + // All three combined #define HANDLE_ALL_ARON_DATA \ HANDLE_CONTAINER_DATA \ HANDLE_COMPLEX_DATA \ - HANDLE_PRIMITIVE_TYPES + HANDLE_PRIMITIVE_DATA /************************************ - * MIXED **************************** + * What type corresponds to which data + * (t,t,T,d,d,D) => t in Type, d in Data ***********************************/ #define HANDLE_CONTAINER_CORRESPONDING \ RUN_ARON_MACRO(List, list, LIST, List, list, LIST) \ + RUN_ARON_MACRO(Pair, pair, PAIR, List, list, LIST) \ RUN_ARON_MACRO(Tuple, tuple, TUPLE, List, list, LIST) \ RUN_ARON_MACRO(Object, object, OBJECT, Dict, dict, DICT) \ RUN_ARON_MACRO(Dict, dict, DICT, Dict, dict, DICT) #define HANDLE_COMPLEX_CORRESPONDING \ RUN_ARON_MACRO(EigenMatrix, eigenmatrix, EIGEN_MATRIX, NDArray, ndarray, NDARRAY) \ + RUN_ARON_MACRO(EigenQuaternion, eigenmatrix, EIGEN_MATRIX, NDArray, ndarray, NDARRAY) \ RUN_ARON_MACRO(IVTCByteImage, ivtcbyteimage, IVT_CBYTE_IMAGE, NDArray, ndarray, NDARRAY) \ RUN_ARON_MACRO(OpenCVMat, opencvmat, OPENCV_MAT, NDArray, ndarray, NDARRAY) \ - RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD, NDArray, ndarray, NDARRAY) + RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD, NDArray, ndarray, NDARRAY) \ + RUN_ARON_MACRO(Position, position, POSITION, NDArray, ndarray, NDARRAY) \ + RUN_ARON_MACRO(Orientation, orientation, ORIENTATION, NDArray, ndarray, NDARRAY) \ + RUN_ARON_MACRO(Pose, pose, POSE, NDArray, ndarray, NDARRAY) + +#define HANDLE_ENUM_CORRESPONDING \ + RUN_ARON_MACRO(IntEnum, intenum, INT_ENUM, Int, int, INT) #define HANDLE_PRIMITIVE_CORRESPONDING \ RUN_ARON_MACRO(Int, int, INT, Int, int, INT) \ @@ -192,47 +182,24 @@ namespace armarx::aron RUN_ARON_MACRO(Float, float, FLOAT, Float, float, FLOAT) \ RUN_ARON_MACRO(Double, double, DOUBLE, Double, double, DOUBLE) \ RUN_ARON_MACRO(String, string, STRING, String, string, STRING) \ - RUN_ARON_MACRO(Bool, bool, BOOL, Bool, bool, BOOL) + RUN_ARON_MACRO(Bool, bool, BOOL, Bool, bool, BOOL) \ + RUN_ARON_MACRO(Time, time, TIME, Long, long, LONG) #define HANDLE_ALL_CORRESPONDING \ HANDLE_CONTAINER_CORRESPONDING \ HANDLE_COMPLEX_CORRESPONDING \ + HANDLE_ENUM_CORRESPONDING \ HANDLE_PRIMITIVE_CORRESPONDING -#define HANDLE_CONTAINER_ARON_TYPE_ARON_ABSTRACT_TYPE_CORRESPONDING \ - RUN_ARON_MACRO(List, list, LIST, AronListSerializerType, aronlistserializertype, ARON_LIST_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(Tuple, tuple, TUPLE, AronListSerializerType, aronlistserializertype, ARON_LIST_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(Object, object, OBJECT, AronDictSerializerType, arondictserializertype, ARON_DICT_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(Dict, dict, DICT, AronDictSerializerType, arondictserializertype, ARON_DICT_SERIALIZER_TYPE) - -#define HANDLE_COMPLEX_ARON_TYPE_ARON_ABSTRACT_TYPE_CORRESPONDING \ - RUN_ARON_MACRO(EigenMatrix, eigenmatrix, EIGEN_MATRIX, AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(IVTCByteImage, ivtcbyteimage, IVT_CBYTE_IMAGE, AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(OpenCVMat, opencvmat, OPENCV_MAT, AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(PCLPointCloud, pclpointcloud, PCL_POINTCLOUD, AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) - -#define HANDLE_ALL_ARON_TYPE_ARON_ABSTRACT_TYPE_CORRESPONDING \ - HANDLE_CONTAINER_ARON_TYPE_ARON_ABSTRACT_TYPE_CORRESPONDING \ - HANDLE_COMPLEX_ARON_TYPE_ARON_ABSTRACT_TYPE_CORRESPONDING - -#define HANDLE_CONTAINER_ARON_DATA_ARON_ABSTRACT_TYPE_CORRESPONDING \ - RUN_ARON_MACRO(List, list, LIST, AronListSerializerType, aronlistserializertype, ARON_LIST_SERIALIZER_TYPE) \ - RUN_ARON_MACRO(Dict, dict, DICT, AronDictSerializerType, arondictserializertype, ARON_DICT_SERIALIZER_TYPE) - -#define HANDLE_COMPLEX_ARON_DATA_ARON_ABSTRACT_TYPE_CORRESPONDING \ - RUN_ARON_MACRO(NDArray, ndarray, NDARRAY, AronNDArraySerializerType, aronndarrayserializertype, ARON_NDARRAY_SERIALIZER_TYPE) - -#define HANDLE_ALL_ARON_DATA_ARON_ABSTRACT_TYPE_CORRESPONDING \ - HANDLE_CONTAINER_ARON_DATA_ARON_ABSTRACT_TYPE_CORRESPONDING \ - HANDLE_COMPLEX_ARON_DATA_ARON_ABSTRACT_TYPE_CORRESPONDING - /************************************ - * Related ************************** + * Related data types *************** + * (which on can be converted into what) + * automatically symmetric but not transitive ***********************************/ #define HANDLE_ARON_PRIMITIVE_DATA_RELATED \ RUN_ARON_MACRO(Int, int, INT, Long, long, LONG) \ RUN_ARON_MACRO(Int, int, INT, Float, float, FLOAT) \ RUN_ARON_MACRO(Int, int, INT, Double, double, DOUBLE) \ - RUN_ARON_MACRO(Long, long, LONG, Double, double, DOUBLE) \ RUN_ARON_MACRO(Long, long, LONG, Float, float, FLOAT) \ + RUN_ARON_MACRO(Long, long, LONG, Double, double, DOUBLE) \ RUN_ARON_MACRO(Float, float, FLOAT, Double, double, DOUBLE) diff --git a/source/RobotAPI/libraries/aron/core/Debug.h b/source/RobotAPI/libraries/aron/core/Debug.h new file mode 100644 index 0000000000000000000000000000000000000000..6687e8909ffb6d33918cde779f3e9d7f8a342007 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Debug.h @@ -0,0 +1,83 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Config.h> + +#include <RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> + +#include <RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h> + +namespace armarx::aron +{ + class Debug + { + public: + Debug() = delete; + + static std::string AronDataPtrToString(const data::AronDataPtr& data) + { + dataIO::writer::NlohmannJSONWriter w; + dataIO::Visitor::SetupWriterFromAronDataPtr(w, data); + return w.getResult().dump(2); + } + + static std::string NavigatorPtrToString(const datanavigator::NavigatorPtr& data) + { + if (data == nullptr) + { + return ""; + } + dataIO::writer::NlohmannJSONWriter w; + dataIO::Visitor::SetupWriterFromAronDataPtr(w, data); + return w.getResult().dump(2); + } + + static std::string AronTypePtrToString(const type::AronTypePtr& data) + { + typeIO::writer::NlohmannJSONWriter w; + typeIO::Visitor::SetupWriterFromAronTypePtr(w, data); + return w.getResult().dump(2); + } + + static std::string NavigatorPtrToString(const typenavigator::NavigatorPtr& data) + { + if (data == nullptr) + { + return ""; + } + typeIO::writer::NlohmannJSONWriter w; + typeIO::Visitor::SetupWriterFromAronTypePtr(w, data); + return w.getResult().dump(2); + } + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/AronDescriptor.h b/source/RobotAPI/libraries/aron/core/Descriptor.h similarity index 56% rename from source/RobotAPI/libraries/aron/aroncore/AronDescriptor.h rename to source/RobotAPI/libraries/aron/core/Descriptor.h index 04b547c2516e12f398376a02c1370f8bbe91cd0e..8beadd6fe75e32997382623f96e68f7a5ee70f47 100644 --- a/source/RobotAPI/libraries/aron/aroncore/AronDescriptor.h +++ b/source/RobotAPI/libraries/aron/core/Descriptor.h @@ -31,53 +31,60 @@ #include <string> // ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> +#include <RobotAPI/libraries/aron/core/Config.h> -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/AronConfig.h> - -namespace armarx +namespace armarx::aron::type { - namespace aron + enum Descriptor { - enum AronTypeDescriptor - { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - eAron##upperType##Type, + e##upperType, - HANDLE_ALL_ARON_TYPES + HANDLE_ALL_ARON_TYPES #undef RUN_ARON_MACRO - eAronUnknownType = -1 - }; + eUnknown = -1 + }; - enum AronDataDescriptor - { + const std::map<type::Descriptor, std::string> _descriptorstring = + { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - eAron##upperType, + { e##upperType, "armarx::aron::type::Descriptor::e" + std::string(#upperType) }, - HANDLE_ALL_ARON_DATA + HANDLE_ALL_ARON_TYPES #undef RUN_ARON_MACRO - eAronUnknown = -1 - }; + {eUnknown, "armarx::aron::type::Descriptor::eUnknown"} + }; + + inline std::string DESCRIPTOR_TO_STRING(const type::Descriptor d) + { + return type::_descriptorstring.at(d); + } +} - const std::map<AronTypeDescriptor, std::string> AronTypeDescriptorToString = - { +namespace armarx::aron::data +{ + enum Descriptor + { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { eAron##upperType##Type, "eAron" + std::string(#upperType) + "Type" }, + e##upperType, - HANDLE_ALL_ARON_TYPES + HANDLE_ALL_ARON_DATA #undef RUN_ARON_MACRO - {eAronUnknownType, "eAronUnknownType"} - }; + eUnknown = -1 + }; - const std::map<AronDataDescriptor, std::string> AronDataDescriptorToString = - { + const std::map<data::Descriptor, std::string> _descriptorstring = + { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - { eAron##upperType, "eAron" + std::string(#upperType) }, + { e##upperType, "armarx::aron::data::Descriptor::e" + std::string(#upperType) }, - HANDLE_ALL_ARON_DATA + HANDLE_ALL_ARON_DATA #undef RUN_ARON_MACRO - {eAronUnknown, "eAronUnknown"} - }; + {eUnknown, "armarx::aron::data::Descriptor::eUnknown"} + }; + + inline std::string DESCRIPTOR_TO_STRING(const data::Descriptor d) + { + return data::_descriptorstring.at(d); } } diff --git a/source/RobotAPI/libraries/aron/core/Exception.h b/source/RobotAPI/libraries/aron/core/Exception.h new file mode 100644 index 0000000000000000000000000000000000000000..13044c9f973b43478e9e753ddc9554f1e8509139 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Exception.h @@ -0,0 +1,179 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <ArmarXCore/core/exceptions/Exception.h> +#include <RobotAPI/libraries/aron/core/Path.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::error +{ + class AronException : + public armarx::LocalException + { + public: + AronException() = delete; + AronException(const std::string& caller, const std::string& method, const std::string& reason) : + LocalException(caller + "::" + method + ": " + reason + ".") + { + + } + + AronException(const std::string& caller, const std::string& method, const std::string& reason, const Path& path) : + LocalException(caller + "::" + method + ": " + reason + ". The path was: " + path.toString()) + { + + } + }; + + class NotImplementedYetException : + public AronException + { + public: + NotImplementedYetException() = delete; + NotImplementedYetException(const std::string& caller, const std::string& method) : + AronException(caller, method, "This method is not yet implemented!") + { + + } + }; + + class AronNotValidException : + public AronException + { + public: + AronNotValidException() = delete; + AronNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const data::AronDataPtr& data) : + AronException(caller, method, reason + ". The ice_id of the data was: " + data->ice_id()) + { + + } + + AronNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const data::AronDataPtr& data, const Path& path) : + AronException(caller, method, reason + ". The ice_id of the data was: " + data->ice_id(), path) + { + + } + + AronNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const type::AronTypePtr& type) : + AronException(caller, method, reason + ". The ice_id of the type was: " + type->ice_id()) + { + + } + + AronNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const type::AronTypePtr& type, const Path& path) : + AronException(caller, method, reason + ". The ice_id of the type was: " + type->ice_id(), path) + { + + } + }; + + class DescriptorNotValidException : + public AronException + { + public: + DescriptorNotValidException() = delete; + DescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const type::Descriptor& type) : + AronException(caller, method, reason + ". The name of the type-enum was: " + type::DESCRIPTOR_TO_STRING(type)) + { + + } + + DescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const type::Descriptor& type, const Path& path) : + AronException(caller, method, reason + ". The name of the type-enum was: " + type::DESCRIPTOR_TO_STRING(type), path) + { + + } + + DescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const data::Descriptor& data) : + AronException(caller, method, reason + ". The name of the data-enum was: " + data::DESCRIPTOR_TO_STRING(data)) + { + + } + + DescriptorNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const data::Descriptor& data, const Path& path) : + AronException(caller, method, reason + ". The name of the data-enum was: " + data::DESCRIPTOR_TO_STRING(data), path) + { + + } + }; + + class StringNotValidException : + public AronException + { + public: + StringNotValidException() = delete; + StringNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const std::string& input) : + AronException(caller, method, reason + ". Got: " + input) + { + + } + + StringNotValidException(const std::string& caller, const std::string& method, const std::string& reason, const std::string& input, const Path& path) : + AronException(caller, method, reason + ". Got: " + input, path) + { + + } + }; + + class IndexNotValidException : + public AronException + { + public: + IndexNotValidException() = delete; + IndexNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected) : + AronException(caller, method, reason + ". The requested index is: " + std::to_string(real) + ". The maximum index was: " + std::to_string(expected)) + { + + } + + IndexNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected, const Path& path) : + AronException(caller, method, reason + ". The requested index is: " + std::to_string(real) + ". The maximum index was: " + std::to_string(expected), path) + { + + } + }; + + class SizeNotValidException : + public AronException + { + public: + SizeNotValidException() = delete; + SizeNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected) : + AronException(caller, method, reason + ". The measured size is: " + std::to_string(real) + ". The expected size was: " + std::to_string(expected)) + { + + } + + SizeNotValidException(const std::string& caller, const std::string& method, const std::string& reason, int real, int expected, const Path& path) : + AronException(caller, method, reason + ". The measured size is: " + std::to_string(real) + ". The expected size was: " + std::to_string(expected), path) + { + + } + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h b/source/RobotAPI/libraries/aron/core/Factory.h similarity index 67% rename from source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h rename to source/RobotAPI/libraries/aron/core/Factory.h index 0dc901f719822a1191fc3203f00285c490be1946..fe34cd471eba26d6886a3b7ec853c9f52ea76063 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h +++ b/source/RobotAPI/libraries/aron/core/Factory.h @@ -25,12 +25,24 @@ // STD/STL #include <memory> +#include <string> +#include <unordered_map> // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/Path.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +namespace armarx::aron +{ + template <typename Input, typename Output> + class Factory + { + public: + Factory() = default; + + virtual Output create(const Input&, const Path&) const = 0; + virtual Output createSpecific(const Input&, const Path&) const = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/Path.cpp b/source/RobotAPI/libraries/aron/core/Path.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9fbd9c8bf979414766d310d0ae35b9b98fc9055 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Path.cpp @@ -0,0 +1,190 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Path.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> + +namespace armarx::aron +{ + Path::Path() : + rootIdentifier("\\"), + delimeter("->") + { + + } + + Path::Path(const std::vector<std::string>& p) : + path(p) + { + + } + + Path::Path(const std::string& s, const std::string& d): + rootIdentifier(s), + delimeter(d) + { + + } + + Path::Path(const std::string& s, const std::string& d, const std::vector<std::string>& p) : + rootIdentifier(s), + delimeter(d), + path(p) + { + + } + + Path::Path(const Path& p) : + rootIdentifier(p.getRootIdentifier()), + delimeter(p.getDelimeter()), + path(p.getPath()) + { + + } + + Path::Path(const Path& p, const std::string& s) : + Path(p) + { + append(s); + } + + Path::Path(const Path& p, const std::string& s, const std::string& s2) : + Path(p) + { + append(s); + append(s2); + } + + Path::Path(const Path& pa, const std::vector<std::string>& p) : + Path(pa) + { + for (const std::string& s : p) + { + append(s); + } + } + + void Path::setRootIdentifier(const std::string& s) + { + rootIdentifier = s; + } + + std::string Path::getRootIdentifier() const + { + return rootIdentifier; + } + + void Path::setDelimeter(const std::string& d) + { + delimeter = d; + } + + std::string Path::getDelimeter() const + { + return delimeter; + } + + void Path::append(const std::string& str) + { + path.push_back(str); + } + + std::vector<std::string> Path::getPath() const + { + return path; + } + + std::string Path::getLastElement() const + { + if (!hasElement()) + { + throw error::AronException("NavigatorPath", "getLastElement", "Try to access last element of empty vector."); + } + return path.back(); + } + + std::string Path::getFirstElement() const + { + if (!hasElement()) + { + throw error::AronException("NavigatorPath", "getFirstElement", "Try to access last element of empty vector."); + } + return path[0]; + } + + bool Path::hasElement() const + { + return path.size() > 0; + } + + size_t Path::size() const + { + return path.size(); + } + + std::string Path::toString() const + { + std::stringstream ss; + ss << rootIdentifier; + for (const std::string& s : path) + { + ss << delimeter << s; + } + return ss.str(); + } + + Path Path::withDetachedLastElement() const + { + std::vector<std::string> p = path; + p.pop_back(); + return Path(rootIdentifier, delimeter, p); + } + + Path Path::withDetachedFirstElement() const + { + std::vector<std::string> p = path; + p.erase(p.begin()); + return Path(rootIdentifier, delimeter, p); + } + + Path Path::getWithoutPrefix(const Path& pref) const + { + unsigned int firstWithoutMatch = 0; + for (const std::string& el : pref.getPath()) + { + if (path.size() <= firstWithoutMatch || el != path[firstWithoutMatch]) + { + break; + } + else + { + firstWithoutMatch++; + } + } + std::vector<std::string> elementsWithoutPrefix(path.begin() + firstWithoutMatch, path.end()); + return Path(rootIdentifier, delimeter, elementsWithoutPrefix); + } +} diff --git a/source/RobotAPI/libraries/aron/core/Path.h b/source/RobotAPI/libraries/aron/core/Path.h new file mode 100644 index 0000000000000000000000000000000000000000..b9eb3f6108852b2eb6d2e22e935f2b634385a1cc --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Path.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include<vector> +#include<string> + +namespace armarx::aron +{ + class Path + { + public: + Path(); + Path(const std::vector<std::string>&); + Path(const std::string&, const std::string&); + Path(const std::string&, const std::string&, const std::vector<std::string>&); + Path(const Path&); + Path(const Path&, const std::string&); + Path(const Path&, const std::string&, const std::string&); + Path(const Path&, const std::vector<std::string>&); + Path& operator=(const armarx::aron::Path&) = default; + + std::vector<std::string> getPath() const; + std::string getFirstElement() const; + std::string getLastElement() const; + bool hasElement() const; + size_t size() const; + + void setRootIdentifier(const std::string&); + std::string getRootIdentifier() const; + + void setDelimeter(const std::string&); + std::string getDelimeter() const; + + std::string toString() const; + + Path withDetachedFirstElement() const; + Path withDetachedLastElement() const; + Path getWithoutPrefix(const Path&) const; + + private: + void append(const std::string&); + + private: + std::string rootIdentifier; + std::string delimeter; + std::vector<std::string> path; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/Randomizer.h b/source/RobotAPI/libraries/aron/core/Randomizer.h new file mode 100644 index 0000000000000000000000000000000000000000..aeefb6913607dde05b926bfc237262a490fa93a4 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Randomizer.h @@ -0,0 +1,394 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <numeric> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + +namespace armarx::aron +{ + class Randomizer + { + public: + Randomizer() + { + initialize_random(); + }; + + typenavigator::NavigatorPtr generateRandomType(bool mustBeObject = false) const + { + type::Descriptor nextType = type::eObject; + if (!mustBeObject) + { + std::vector<type::Descriptor> descriptors = + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + type::e##upperType, + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + }; + + int randomType = generateRandom(descriptors.size(), 0); + nextType = descriptors[randomType]; + } + + switch (nextType) + { + case type::eObject: + { + typenavigator::ObjectNavigatorPtr t = typenavigator::ObjectNavigatorPtr(new typenavigator::ObjectNavigator(Path())); + std::string objectName = generateRandomWord(); + t->setObjectName(objectName); + + std::vector<std::string> usedNames({objectName}); + int members = generateRandom(4, 2); + std::set<std::string> usedKeys; + for (int i = 0; i < members; ++i) + { + std::string key = generateRandomWord(usedKeys); + usedKeys.insert(key); + + typenavigator::NavigatorPtr m = generateRandomType(false); + t->addMemberType(key, m); + } + return t; + } + case type::eDict: + { + typenavigator::DictNavigatorPtr t = typenavigator::DictNavigatorPtr(new typenavigator::DictNavigator()); + typenavigator::NavigatorPtr a = generateRandomType(false); + + t->setAcceptedType(a); + return t; + } + case type::eTuple: + { + typenavigator::TupleNavigatorPtr t = typenavigator::TupleNavigatorPtr(new typenavigator::TupleNavigator()); + + int members = generateRandom(4, 2); + for (int i = 0; i < members; ++i) + { + typenavigator::NavigatorPtr m = generateRandomType(false); + t->addAcceptedType(m); + } + return t; + } + case type::eList: + { + typenavigator::ListNavigatorPtr t = typenavigator::ListNavigatorPtr(new typenavigator::ListNavigator()); + typenavigator::NavigatorPtr a = generateRandomType(false); + + t->setAcceptedType(a); + return t; + } + case type::ePair: + { + typenavigator::PairNavigatorPtr t = typenavigator::PairNavigatorPtr(new typenavigator::PairNavigator()); + typenavigator::NavigatorPtr a = generateRandomType(false); + typenavigator::NavigatorPtr b = generateRandomType(false); + + t->setFirstAcceptedType(a); + t->setSecondAcceptedType(b); + return t; + } + case type::eEigenMatrix: + case type::eEigenQuaternion: + case type::eIVTCByteImage: + case type::eOpenCVMat: + case type::ePCLPointCloud: + case type::ePosition: + case type::eOrientation: + case type::ePose: + + case type::eInt: + { + auto t = std::make_shared<typenavigator::IntNavigator>(); + return t; + } + case type::eLong: + { + auto t = std::make_shared<typenavigator::LongNavigator>(); + return t; + } + case type::eFloat: + { + auto t = std::make_shared<typenavigator::FloatNavigator>(); + return t; + } + case type::eDouble: + { + auto t = std::make_shared<typenavigator::DoubleNavigator>(); + return t; + } + case type::eString: + { + auto t = std::make_shared<typenavigator::StringNavigator>(); + return t; + } + case type::eBool: + { + auto t = std::make_shared<typenavigator::BoolNavigator>(); + return t; + } + case type::eTime: + { + auto t = std::make_shared<typenavigator::TimeNavigator>(); + return t; + } + default: + { + throw error::DescriptorNotValidException("Randomizer", "generateRandomType", "No valid type found!", nextType); + } + } + } + + datanavigator::NavigatorPtr generateAronDataFromType(const typenavigator::NavigatorPtr& type) const + { + const type::Descriptor desc = type->getDescriptor(); + switch (desc) + { + // In an object, we do not want to edit the keys. + case type::eObject: + { + typenavigator::ObjectNavigatorPtr t = typenavigator::ObjectNavigator::DynamicCastAndCheck(type); + datanavigator::DictNavigatorPtr d = datanavigator::DictNavigatorPtr(new datanavigator::DictNavigator()); + for (const auto& [k, tt] : t->getMemberTypes()) + { + d->addElement(k, generateAronDataFromType(tt)); + } + return d; + } + + // here all totally random + case type::eDict: + { + typenavigator::DictNavigatorPtr t = typenavigator::DictNavigator::DynamicCastAndCheck(type); + return datanavigator::NavigatorPtr(new datanavigator::DictNavigator()); + } + +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +case type::e##upperType: \ +{ \ + typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + return datanavigator::NavigatorPtr(new datanavigator::ListNavigator()); \ +} + + HANDLE_LIST_SERIALIZER_TYPES +#undef RUN_ARON_MACRO + +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +case type::e##upperType: \ +{ \ + typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + datanavigator::NDArrayNavigatorPtr ndarray = datanavigator::NDArrayNavigatorPtr(new datanavigator::NDArrayNavigator()); \ + return ndarray; \ +} + + HANDLE_NDARRAY_TYPES +#undef RUN_ARON_MACRO + +#define RUN_ARON_MACRO(upperType, lowerType, capsType, upperData, lowerData, capsData) \ +case type::e##upperType: \ +{ \ + typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + return datanavigator::NavigatorPtr(new datanavigator::upperData##Navigator()); \ +} + + HANDLE_PRIMITIVE_CORRESPONDING +#undef RUN_ARON_MACRO + default: + { + throw error::DescriptorNotValidException("Randomizer", "generateAronDataFromType", "No valid type found!", desc); + } + } + } + + void initializeRandomly(datanavigator::NavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + // Containers + type::Descriptor desc = type->getDescriptor(); + switch (desc) + { + +#define RUN_ARON_MACRO(upperType, lowerType, capsType, upperData, lowerData, capsData) \ +case type::e##upperType: \ +{ \ + typenavigator::upperType##NavigatorPtr t = typenavigator::upperType##Navigator::DynamicCastAndCheck(type); \ + datanavigator::upperData##NavigatorPtr d = datanavigator::upperData##Navigator::DynamicCastAndCheck(data); \ + initializeRandomly(d, t); \ + break; \ +} + + HANDLE_ALL_CORRESPONDING +#undef RUN_ARON_MACRO + + default: + { + throw error::DescriptorNotValidException("Randomizer", "initializeRandomly", "No valid type found!", desc); + } + } + } + + int generateRandom(int max, int min) const + { + max += 1; + int random = (std::rand() % (max - min)) + min; + return random; + } + + std::string generateRandomWord(const std::set<std::string>& usedKeys = {}) const + { + std::vector<string> words = + { + "Lorem", "ipsum", "dolor", "sit", "amet", "consetetur", "sadipscing", "elitr" + "sed", "diam", "nonumy", "eirmod", "tempor", "invidunt", "ut", "labore", "et" + "dolore", "magna", "aliquyam", "eratsed" + }; + + int i = generateRandom(words.size() - 1, 0); + std::string key = words[i]; + + while (usedKeys.count(key) > 0) + { + key = generateRandomWord(usedKeys); + } + + return key; + } + + std::vector<unsigned char> generateRandomBlob(unsigned int size) const + { + std::vector<unsigned char> new_blob(size, 0); + for (unsigned int i = 0; i < size; ++i) + { + new_blob[i] = (generateRandom(127, 0)); + } + return new_blob; + } + + private: + void initialize_random() const + { + std::srand(std::time(nullptr)); + } + + public: + void initializeRandomly(datanavigator::DictNavigatorPtr& data, const typenavigator::ObjectNavigatorPtr& type) const + { + for (auto& [key, nextData] : data->getElements()) + { + initializeRandomly(nextData, type->getMemberTypes()[key]); + } + } + + void initializeRandomly(datanavigator::DictNavigatorPtr& data, const typenavigator::DictNavigatorPtr& type) const + { + data->clear(); + int numElements = generateRandom(5, 1); + std::set<std::string> usedKeys; + for (int i = 0; i < numElements; ++i) + { + std::string key = generateRandomWord(usedKeys); + usedKeys.insert(key); + datanavigator::NavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); + initializeRandomly(newData, type->getAcceptedType()); + data->addElement(key, newData); + } + } + + void initializeRandomly(datanavigator::ListNavigatorPtr& data, const typenavigator::TupleNavigatorPtr& type) const + { + unsigned int i = 0; + for (auto& nextData : data->getElements()) + { + initializeRandomly(nextData, type->getAcceptedType(i++)); + } + } + + void initializeRandomly(datanavigator::ListNavigatorPtr& data, const typenavigator::PairNavigatorPtr& type) const + { + datanavigator::NavigatorPtr first = data->getElement(0); + datanavigator::NavigatorPtr second = data->getElement(1); + initializeRandomly(first, type->getFirstAcceptedType()); + initializeRandomly(second, type->getSecondAcceptedType()); + } + + void initializeRandomly(datanavigator::ListNavigatorPtr& data, const typenavigator::ListNavigatorPtr& type) const + { + data->clear(); + int numElements = generateRandom(5, 1); + for (int i = 0; i < numElements; ++i) + { + datanavigator::NavigatorPtr newData = generateAronDataFromType(type->getAcceptedType()); + initializeRandomly(newData, type->getAcceptedType()); + data->addElement(newData); + } + } + + void initializeRandomly(datanavigator::NDArrayNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + std::vector<int> dims = data->getDimensions(); + int bytes = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); + std::vector<unsigned char> blob = generateRandomBlob(bytes); + data->setData(bytes, blob.data()); + } + + void initializeRandomly(datanavigator::IntNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandom(1000, -1000)); + } + + void initializeRandomly(datanavigator::LongNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandom(1000, -1000)); + } + + void initializeRandomly(datanavigator::FloatNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandom(1000, -1000)); + } + + void initializeRandomly(datanavigator::DoubleNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandom(1000, -1000)); + } + + void initializeRandomly(datanavigator::BoolNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandom(1, 0)); + } + + void initializeRandomly(datanavigator::StringNavigatorPtr& data, const typenavigator::NavigatorPtr& type) const + { + data->setValue(generateRandomWord()); + } + }; +} diff --git a/source/RobotAPI/libraries/aron/core/Resolver.cpp b/source/RobotAPI/libraries/aron/core/Resolver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c3080eebbb6b053343adaf01a1f4a04f1a7c4e7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Resolver.cpp @@ -0,0 +1,169 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Simox +#include <SimoxUtility/meta/type_name.h> + +// Header +#include "Resolver.h" + +namespace armarx::aron +{ + type::Descriptor Resolver::GetDescriptor(const type::AronTypePtr& a) + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + { \ + type::Aron##upperType##Ptr aron = type::Aron##upperType##Ptr::dynamicCast(a); \ + if(aron) \ + { \ + return type::Descriptor::e##upperType; \ + } \ + } + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + throw error::AronNotValidException("Resolver", "GetTypeForAronAbstractType", "Could not cast AronType to a valid type", a); + } + + data::Descriptor Resolver::GetDescriptor(const data::AronDataPtr& a) + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + { \ + data::Aron##upperType##Ptr aron = data::Aron##upperType##Ptr::dynamicCast(a); \ + if(aron) \ + { \ + return data::Descriptor::e##upperType; \ + } \ + } + HANDLE_ALL_ARON_DATA +#undef RUN_ARON_MACRO + throw error::AronNotValidException("Resolver", "GetTypeForAronData", "Could not cast AronData to a valid type", a); + } + + bool Resolver::Correspond(const type::Descriptor& t, const data::Descriptor& d) + { +#define RUN_ARON_MACRO(typeUpperType, typeLowerType, typeCapsType, dataUpperType, dataLowerType, dataCapsType) \ + if(t == type::Descriptor::e##typeUpperType && d == data::Descriptor::e##dataUpperType) \ + { \ + return true; \ + } + + HANDLE_ALL_CORRESPONDING +#undef RUN_ARON_MACRO + return false; + } + + type::Descriptor Resolver::GetFirstIfCorrespond(const type::Descriptor& t, const data::Descriptor& d) + { + if (Correspond(t, d)) + { + return t; + } + return GetCorresponding(d); + } + + data::Descriptor Resolver::GetCorresponding(const type::Descriptor& d) + { +#define RUN_ARON_MACRO(typeUpperType, typeLowerType, typeCapsType, dataUpperType, dataLowerType, dataCapsType) \ + { \ + if(d == type::Descriptor::e##typeUpperType) \ + { \ + return data::Descriptor::e##dataUpperType; \ + } \ + } + HANDLE_ALL_CORRESPONDING +#undef RUN_ARON_MACRO + return data::Descriptor::eUnknown; + } + + type::Descriptor Resolver::GetCorresponding(const data::Descriptor& d) + { +#define RUN_ARON_MACRO(typeUpperType, typeLowerType, typeCapsType, dataUpperType, dataLowerType, dataCapsType) \ + { \ + if(d == data::Descriptor::e##dataUpperType) \ + { \ + return type::Descriptor::e##typeUpperType; \ + } \ + } + HANDLE_ALL_CORRESPONDING +#undef RUN_ARON_MACRO + return type::Descriptor::eUnknown; + } + + bool Resolver::AreRelated(const data::Descriptor& d, const data::Descriptor& d2) + { + if (d == d2) + { + return true; + } +#define RUN_ARON_MACRO(data1UpperType, data1LowerType, data1CapsType, data2UpperType, data2LowerType, data2CapsType) \ + if( \ + (d == data::Descriptor::e##data1UpperType && d2 == data::Descriptor::e##data2UpperType) || \ + (d2 == data::Descriptor::e##data1UpperType && d == data::Descriptor::e##data2UpperType) \ + ) \ + { \ + return true; \ + } + + HANDLE_ARON_PRIMITIVE_DATA_RELATED +#undef RUN_ARON_MACRO + return false; + } + + bool Resolver::AreRelated(const type::Descriptor& t, const type::Descriptor& t2) + { + if (t == t2) + { + return true; + } +#define RUN_ARON_MACRO(type1UpperType, type1LowerType, type1CapsType, type2UpperType, type2LowerType, type2CapsType) \ + if( \ + (t == type::Descriptor::e##type1UpperType && t2 == type::Descriptor::e##type2UpperType) || \ + (t2 == type::Descriptor::e##type1UpperType && t == type::Descriptor::e##type2UpperType) \ + ) \ + { \ + return true; \ + } + + HANDLE_ARON_PRIMITIVE_DATA_RELATED +#undef RUN_ARON_MACRO + return false; + } + + data::Descriptor Resolver::GetFirstIfRelated(const data::Descriptor& d, const data::Descriptor& d2) + { + if (AreRelated(d, d2)) + { + return d; + } + return d2; + } + + type::Descriptor Resolver::GetFirstIfRelated(const type::Descriptor& t, const type::Descriptor& t2) + { + if (AreRelated(t, t2)) + { + return t; + } + return t2; + } +} diff --git a/source/RobotAPI/libraries/aron/core/Resolver.h b/source/RobotAPI/libraries/aron/core/Resolver.h new file mode 100644 index 0000000000000000000000000000000000000000..8c04597ef1fa5ab5866a1d56d0713ae53aa3e8fb --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/Resolver.h @@ -0,0 +1,61 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <typeindex> +#include <typeinfo> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron +{ + class Resolver + { + private: // disallow creating this object. static use only + Resolver() = delete; + + public: + static type::Descriptor GetDescriptor(const type::AronTypePtr&); + + static data::Descriptor GetDescriptor(const data::AronDataPtr&); + + static bool Correspond(const type::Descriptor&, const data::Descriptor&); + + static type::Descriptor GetFirstIfCorrespond(const type::Descriptor&, const data::Descriptor&); + + static data::Descriptor GetCorresponding(const type::Descriptor&); + static type::Descriptor GetCorresponding(const data::Descriptor&); + + static bool AreRelated(const data::Descriptor&, const data::Descriptor&); + static bool AreRelated(const type::Descriptor&, const type::Descriptor&); + + static data::Descriptor GetFirstIfRelated(const data::Descriptor&, const data::Descriptor&); + static type::Descriptor GetFirstIfRelated(const type::Descriptor&, const type::Descriptor&); + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h b/source/RobotAPI/libraries/aron/core/codegenerator/GenerateIntEnumInfo.h similarity index 61% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h rename to source/RobotAPI/libraries/aron/core/codegenerator/GenerateIntEnumInfo.h index 43d30adb2c0d48644739a89a7e419267ad954bfe..832c3e47d08766a565ddb4dc297239da472d1d9a 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronGenerateTypeInfo.h +++ b/source/RobotAPI/libraries/aron/core/codegenerator/GenerateIntEnumInfo.h @@ -28,25 +28,18 @@ #include <string> // ArmarX -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h> -namespace armarx +namespace armarx::aron::codegeneratorhelper { - namespace aron - { - namespace codegeneration - { - class AronGenerateTypeInfo; - typedef std::shared_ptr<AronGenerateTypeInfo> AronGenerateTypeInfoPtr; + class GenerateIntEnumInfo; + typedef std::shared_ptr<GenerateIntEnumInfo> GenerateIntEnumInfoPtr; - class AronGenerateTypeInfo - { - public: - std::string typeName; - std::string definedIn; - typenavigator::AronObjectTypeNavigatorPtr correspondingObjectType; - std::map<std::string, AronGenerateTypeInfoPtr> nestedObjects; - }; - } - } + class GenerateIntEnumInfo + { + public: + std::string typeName; + std::string definedIn; + typenavigator::IntEnumNavigatorPtr correspondingType; + }; } diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h b/source/RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h new file mode 100644 index 0000000000000000000000000000000000000000..a029bca09d634f3565e89e7ef7d39eaee3af1201 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h @@ -0,0 +1,48 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/libraries/aron/core/codegenerator/GenerateIntEnumInfo.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::aron::codegeneratorhelper +{ + class GenerateObjectInfo; + typedef std::shared_ptr<GenerateObjectInfo> GenerateObjectInfoPtr; + + class GenerateObjectInfo + { + public: + std::string typeName; + std::string definedIn; + typenavigator::ObjectNavigatorPtr correspondingType; + std::map<std::string, GenerateObjectInfoPtr> nestedObjects; + std::map<std::string, GenerateIntEnumInfoPtr> nestedIntEnums; + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronIncludeInfo.h b/source/RobotAPI/libraries/aron/core/codegenerator/IncludeInfo.h similarity index 100% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/AronIncludeInfo.h rename to source/RobotAPI/libraries/aron/core/codegenerator/IncludeInfo.h diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronReaderInfo.h b/source/RobotAPI/libraries/aron/core/codegenerator/ReaderInfo.h similarity index 83% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/AronReaderInfo.h rename to source/RobotAPI/libraries/aron/core/codegenerator/ReaderInfo.h index 3139023f8c95ccb3eb72b553f07dcedb64b1af68..855a00cf276c29c8e2aa512e597d22e1d674570d 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronReaderInfo.h +++ b/source/RobotAPI/libraries/aron/core/codegenerator/ReaderInfo.h @@ -27,16 +27,12 @@ #include <memory> #include <string> -namespace armarx +namespace armarx::aron::codegeneratorhelper { - namespace aron - { - namespace codegeneration - { - class AronReaderInfo; - typedef std::shared_ptr<AronReaderInfo> AronReaderInfoPtr; + class ReaderInfo; + typedef std::shared_ptr<ReaderInfo> ReaderInfoPtr; - class AronReaderInfo + class ReaderInfo { public: std::string methodName; @@ -44,6 +40,4 @@ namespace armarx std::string readerClassType; std::string include; }; - } - } } diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronWriterInfo.h b/source/RobotAPI/libraries/aron/core/codegenerator/WriterInfo.h similarity index 83% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/AronWriterInfo.h rename to source/RobotAPI/libraries/aron/core/codegenerator/WriterInfo.h index 651f2be5b7708d4b12035b07612f693bf8690eb5..e6c85f594ec6088454dbdec6555761b345d9dea4 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/AronWriterInfo.h +++ b/source/RobotAPI/libraries/aron/core/codegenerator/WriterInfo.h @@ -27,16 +27,12 @@ #include <memory> #include <string> -namespace armarx +namespace armarx::aron::codegeneratorhelper { - namespace aron - { - namespace codegeneration - { - class AronWriterInfo; - typedef std::shared_ptr<AronWriterInfo> AronWriterInfoPtr; + class WriterInfo; + typedef std::shared_ptr<WriterInfo> WriterInfoPtr; - class AronWriterInfo + class WriterInfo { public: std::string methodName; @@ -44,6 +40,4 @@ namespace armarx std::string writerClassType; std::string include; }; - } - } } diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/CodeWriter.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/CodeWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..f2f9b12c22c9a8bcf3ca88ddc4ba19f6f8168b14 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/CodeWriter.h @@ -0,0 +1,80 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <map> +#include <vector> +#include <typeinfo> +#include <typeindex> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/MetaClass.h> + +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + +#include <RobotAPI/libraries/aron/core/codegenerator/WriterInfo.h> +#include <RobotAPI/libraries/aron/core/codegenerator/ReaderInfo.h> +#include <RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h> + +namespace armarx::aron::codegenerator +{ + class CodeWriter + { + public: + CodeWriter() = delete; + CodeWriter(const std::string& producerName, const std::vector<std::string>& additionalIncludesFromXMLFile): + producerName(producerName), + additionalIncludes(additionalIncludesFromXMLFile) + {} + + virtual void generateTypeObjects(const std::vector<codegeneratorhelper::GenerateObjectInfoPtr>&) = 0; + virtual void generateTypeIntEnums(const std::vector<codegeneratorhelper::GenerateIntEnumInfoPtr>&) = 0; + + std::vector<MetaClassPtr> getTypeClasses() const + { + return typeClasses; + } + + protected: + virtual void addFromAronMethod() = 0; + virtual void addToAronMethod() = 0; + virtual void addToAronTypeMethod() = 0; + + protected: + std::vector<MetaClassPtr> typeClasses; + + std::string producerName; + std::vector<codegeneratorhelper::WriterInfoPtr> dataWriters; + std::vector<codegeneratorhelper::ReaderInfoPtr> dataReaders; + std::vector<codegeneratorhelper::WriterInfoPtr> initialTypeWriters; + std::vector<codegeneratorhelper::WriterInfoPtr> currentTypeWriters; + std::vector<codegeneratorhelper::ReaderInfoPtr> typeReaders; + std::vector<std::string> additionalIncludes; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/SerializerFactory.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/SerializerFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..09656fc3861e0f92e95f87d3f19e825de45631a7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/SerializerFactory.h @@ -0,0 +1,51 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <unordered_map> + +// Base Class +#include <RobotAPI/libraries/aron/core/Factory.h> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/Path.h> + +namespace armarx::aron::codegenerator +{ + template <typename Input, typename Output> + class SerializerFactory : + virtual public aron::Factory<Input, Output> + { + public: + SerializerFactory() = default; + + virtual Output create(const Input&, const Path&) const = 0; + virtual Output createSpecific(const Input&, const Path&) const = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h new file mode 100644 index 0000000000000000000000000000000000000000..7098b08c6630be31bbb44c0fe098d09071e68b45 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h @@ -0,0 +1,60 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> + +#include <RobotAPI/libraries/aron/core/io/dataIO/Reader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> + + +namespace armarx::aron::cppcodegenerator +{ + class AronCppClass; + typedef std::shared_ptr<AronCppClass> AronCppClassPtr; + + class AronCppClass + { + public: + using PointerType = AronCppClassPtr; + + public: + AronCppClass() = default; + virtual void reset() = 0; + virtual void initialize() = 0; + virtual void read(armarx::aron::dataIO::ReaderInterface& r) = 0; + virtual void write(armarx::aron::dataIO::WriterInterface& w) const = 0; + virtual void writeCurrentType(armarx::aron::typeIO::WriterInterface& w) const = 0; + static void writeType(armarx::aron::typeIO::WriterInterface& w) + { + throw error::AronException("AronCppClass", "writeType", "You are not allowed to call this method directly. Each class must inheriting from AronCppClass must implement this static method!"); + }; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0d2067811d86fd394dd29be507a9af7fcb96ba5 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.cpp @@ -0,0 +1,410 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + + +// Simox +#include <SimoxUtility/algorithm/string.h> + +// Header +#include "Writer.h" + +// ArmarX + +namespace armarx::aron::cppcodegenerator +{ + Writer::Writer(const std::string& producerName, const std::vector<std::string>& additionalIncludesFromXMLFile) : + CodeWriter(producerName, additionalIncludesFromXMLFile) + { + addToAronMethod(); + addFromAronMethod(); + addToAronTypeMethod(); + } + + void Writer::addToAronMethod() + { + // The toAron Serializer is visible by default + { + codegeneratorhelper::WriterInfoPtr toAron = codegeneratorhelper::WriterInfoPtr(new codegeneratorhelper::WriterInfo()); + toAron->methodName = "toAron"; + toAron->returnType = "armarx::aron::datanavigator::DictNavigatorPtr"; + toAron->writerClassType = "armarx::aron::dataIO::writer::NavigatorWriter"; + toAron->include = "<RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h>"; + dataWriters.push_back(toAron); + } + } + + void Writer::addFromAronMethod() + { + // The toAron Serializer is visible by default + { + codegeneratorhelper::ReaderInfoPtr fromAron = codegeneratorhelper::ReaderInfoPtr(new codegeneratorhelper::ReaderInfo()); + fromAron->methodName = "fromAron"; + fromAron->argumentType = "armarx::aron::datanavigator::DictNavigatorPtr"; + fromAron->readerClassType = "armarx::aron::dataIO::reader::NavigatorReader"; + fromAron->include = "<RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h>"; + dataReaders.push_back(fromAron); + } + { + codegeneratorhelper::ReaderInfoPtr fromAron = codegeneratorhelper::ReaderInfoPtr(new codegeneratorhelper::ReaderInfo()); + fromAron->methodName = "fromAron"; + fromAron->argumentType = "armarx::aron::data::AronDictPtr"; + fromAron->readerClassType = "armarx::aron::dataIO::reader::NavigatorReader"; + dataReaders.push_back(fromAron); + } + } + + void Writer::addToAronTypeMethod() + { + // The toAron Serializer is visible by default + codegeneratorhelper::WriterInfoPtr toAronType = codegeneratorhelper::WriterInfoPtr(new codegeneratorhelper::WriterInfo()); + toAronType->methodName = "toInitialAronType"; + toAronType->returnType = "armarx::aron::typenavigator::ObjectNavigatorPtr"; + toAronType->writerClassType = "armarx::aron::typeIO::writer::NavigatorWriter"; + toAronType->include = "<RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h>"; + initialTypeWriters.push_back(toAronType); + + // The toAron Serializer is visible by default + codegeneratorhelper::WriterInfoPtr toAronType2 = codegeneratorhelper::WriterInfoPtr(new codegeneratorhelper::WriterInfo()); + toAronType2->methodName = "toCurrentAronType"; + toAronType2->returnType = "armarx::aron::typenavigator::ObjectNavigatorPtr"; + toAronType2->writerClassType = "armarx::aron::typeIO::writer::NavigatorWriter"; + currentTypeWriters.push_back(toAronType2); + } + + void Writer::generateTypeObjects(const std::vector<codegeneratorhelper::GenerateObjectInfoPtr>& generateObjects) + { + for (const auto& publicGenerateObjectType : generateObjects) + { + const auto& nav = publicGenerateObjectType->correspondingType; + + //std::cout << "Generating: " << publicGenerateObjectType->correspondingObjectType->getName() << std::endl; + + // Convert to Object type and create class object + if (nav == nullptr) + { + throw error::AronException("ClassCppWriter", "generateTypeClasses", "An received public type is null. Abort due to error!"); + } + + auto serializer = std::make_shared<serializer::ObjectClassSerializer>(nav); + + CppClassPtr c = setupBasicCppClass(serializer->getFullCppTypename()); + setupMemberFields(c, serializer); + + if (nav->getExtends() != nullptr) + { + auto extendsSerializer = std::make_shared<serializer::ObjectClassSerializer>(nav->getExtends()); + c->addInherit(extendsSerializer->getFullCppTypename()); + } + else + { + c->addInherit("virtual public armarx::aron::cppcodegenerator::AronCppClass"); + c->addInclude("<RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h>"); + } + + // Add includes and guard + c->addClassDoc("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!!!!!AUTOGENERATED CLASS. Please do NOT edit. Instead, edit the corresponding .xml file!!!!!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + c->setPragmaOnceIncludeGuard(true); + c->addInclude("<memory>"); + c->addInclude("<string>"); + c->addInclude("<vector>"); + c->addInclude("<map>"); + c->addInclude("<RobotAPI/interface/aron.h>"); + for (const std::string& s : additionalIncludes) + { + if (!s.empty()) + { + c->addInclude(s); + } + } + + //std::cout << "Generate Type classes" << std::endl; + generateInnerTypeObjects(c, publicGenerateObjectType->nestedObjects); + + // ctor + c->addCtor(serializer->toCtor(c->getName())); + + // Generic methods + //std::cout << "Generate equals method" << std::endl; + CppMethodPtr equals = serializer->toEqualsMethod(); + c->addMethod(equals); + + //std::cout << "Generate reset method" << std::endl; + CppMethodPtr reset = serializer->toResetMethod(); + c->addMethod(reset); + + //std::cout << "Generate init method" << std::endl; + CppMethodPtr setup = serializer->toInitializeMethod(); + c->addMethod(setup); + + //std::cout << "Generate writeInit method" << std::endl; + CppMethodPtr writeInitialType = serializer->toWriteInitialTypeMethod(); + c->addMethod(writeInitialType); + + //std::cout << "Generate writeCurrent method" << std::endl; + CppMethodPtr writeCurrentType = serializer->toWriteCurrentTypeMethod(); + c->addMethod(writeCurrentType); + + //std::cout << "Generate write method" << std::endl; + CppMethodPtr write = serializer->toWriteMethod(); + c->addMethod(write); + + //std::cout << "Generate read method" << std::endl; + CppMethodPtr read = serializer->toReadMethod(); + c->addMethod(read); + + // Writermethods + for (const codegeneratorhelper::WriterInfoPtr& info : dataWriters) + { + if (!info->include.empty()) + { + c->addInclude(info->include); + } + CppMethodPtr convert = serializer->toSpecializedDataWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::datanavigator::DictNavigator::DynamicCast"); + c->addMethod(convert); + } + + // Add methods to set the member variables + for (const codegeneratorhelper::ReaderInfoPtr& info : dataReaders) + { + if (!info->include.empty()) + { + c->addInclude(info->include); + } + CppMethodPtr convert = serializer->toSpecializedDataReaderMethod(info->argumentType, info->methodName, info->readerClassType); + c->addMethod(convert); + } + + // Typewritermethods + for (const codegeneratorhelper::WriterInfoPtr& info : initialTypeWriters) + { + if (!info->include.empty()) + { + c->addInclude(info->include); + } + CppMethodPtr convert = serializer->toSpecializedInitialTypeWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::typenavigator::ObjectNavigator::DynamicCast"); + c->addMethod(convert); + } + + // Typewritermethods + for (const codegeneratorhelper::WriterInfoPtr& info : currentTypeWriters) + { + if (!info->include.empty()) + { + c->addInclude(info->include); + } + CppMethodPtr convert = serializer->toSpecializedCurrentTypeWriterMethod(info->returnType, info->methodName, info->writerClassType, "armarx::aron::typenavigator::ObjectNavigator::DynamicCast"); + c->addMethod(convert); + } + + // Add methods to set the member variables + for (const codegeneratorhelper::ReaderInfoPtr& info : typeReaders) + { + if (!info->include.empty()) + { + c->addInclude(info->include); + } + CppMethodPtr convert = serializer->toSpecializedCurrentTypeReaderMethod(info->argumentType, info->methodName, info->readerClassType); + c->addMethod(convert); + } + + typeClasses.push_back(c); + } + } + + void Writer::generateTypeIntEnums(const std::vector<codegeneratorhelper::GenerateIntEnumInfoPtr>& generateIntEnums) + { + for (const auto& publicGenerateIntEnumType : generateIntEnums) + { + const auto& nav = publicGenerateIntEnumType->correspondingType; + if (nav == nullptr) + { + throw error::AronException("ClassCppWriter", "generateTypeIntEnums", "An received public type is null. Abort due to error!"); + } + + auto serializer = std::make_shared<serializer::IntEnumClassSerializer>(nav); + + CppClassPtr c = setupBasicCppClass(serializer->getFullCppTypename()); + setupMemberFields(c, serializer); + + // Add includes and guard + c->addClassDoc("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!!!!!AUTOGENERATED CLASS. Please do NOT edit. Instead, edit the corresponding .xml file!!!!!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + c->setPragmaOnceIncludeGuard(true); + c->addInclude("<memory>"); + c->addInclude("<string>"); + c->addInclude("<vector>"); + c->addInclude("<map>"); + c->addInclude("<RobotAPI/interface/aron.h>"); + + c->addInherit("virtual public armarx::aron::cppcodegenerator::AronCppClass"); + c->addInclude("<RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/AronCppClass.h>"); + + // ctor + c->addCtor(serializer->toCtor(c->getName())); + c->addCtor(serializer->toCopyCtor(c->getName())); + c->addCtor(serializer->toInnerEnumCtor(c->getName())); + + // Specific methods + CppEnumPtr enumrepresentation = serializer->toInnerEnumDefinition(); + c->addInnerEnum(enumrepresentation); + + CppMethodPtr toString = serializer->toToStringMethod(); + c->addMethod(toString); + + CppMethodPtr fromString = serializer->toFromStringMethod(); + c->addMethod(fromString); + + CppMethodPtr intConversion = serializer->toIntMethod(); + c->addMethod(intConversion); + + CppMethodPtr enumAssignment = serializer->toEnumAssignmentMethod(); + c->addMethod(enumAssignment); + + CppMethodPtr enumAssignment2 = serializer->toCopyAssignmentMethod(); + c->addMethod(enumAssignment2); + + CppMethodPtr enumAssignment3 = serializer->toIntAssignmentMethod(); + c->addMethod(enumAssignment3); + + // Generic methods + //std::cout << "Generate equals method" << std::endl; + CppMethodPtr equals = serializer->toEqualsMethod(); + c->addMethod(equals); + + //std::cout << "Generate reset method" << std::endl; + CppMethodPtr reset = serializer->toResetMethod(); + c->addMethod(reset); + + //std::cout << "Generate init method" << std::endl; + CppMethodPtr setup = serializer->toInitializeMethod(); + c->addMethod(setup); + + //std::cout << "Generate writeInit method" << std::endl; + CppMethodPtr writeInitialType = serializer->toWriteInitialTypeMethod(); + c->addMethod(writeInitialType); + + //std::cout << "Generate writeCurrent method" << std::endl; + CppMethodPtr writeCurrentType = serializer->toWriteCurrentTypeMethod(); + c->addMethod(writeCurrentType); + + //std::cout << "Generate write method" << std::endl; + CppMethodPtr write = serializer->toWriteMethod(); + c->addMethod(write); + + //std::cout << "Generate read method" << std::endl; + CppMethodPtr read = serializer->toReadMethod(); + c->addMethod(read); + + typeClasses.push_back(c); + } + } + + void Writer::generateInnerTypeObjects(CppClassPtr& classToAdd, const std::map<std::string, codegeneratorhelper::GenerateObjectInfoPtr>& localGenerateTypes) + { + // setup inner classes + for (const auto& [_, localGenerateObjectType] : localGenerateTypes) + { + const auto& nav = localGenerateObjectType->correspondingType; + + auto serializer = std::make_shared<serializer::ObjectClassSerializer>(nav); + + CppClassPtr c = setupBasicCppClass(serializer->getFullCppTypename()); + setupMemberFields(c, serializer); + + if (nav->getExtends() != nullptr) + { + auto extendsSerializer = std::make_shared<serializer::ObjectClassSerializer>(nav->getExtends()); + c->addInherit(extendsSerializer->getFullCppTypename()); + } + else + { + c->addInherit("virtual public armarx::aron::cppcodegenerator::AronCppClass"); + } + + CppMethodPtr equals = serializer->toEqualsMethod(); + c->addMethod(equals); + + CppMethodPtr reset = serializer->toResetMethod(); + c->addMethod(reset); + + CppMethodPtr setup = serializer->toInitializeMethod(); + c->addMethod(setup); + + CppMethodPtr writeInitialType = serializer->toWriteInitialTypeMethod(); + c->addMethod(writeInitialType); + + CppMethodPtr writeCurrentType = serializer->toWriteCurrentTypeMethod(); + c->addMethod(writeCurrentType); + + CppMethodPtr write = serializer->toWriteMethod(); + c->addMethod(write); + + CppMethodPtr read = serializer->toReadMethod(); + c->addMethod(read); + + generateInnerTypeObjects(c, localGenerateObjectType->nestedObjects); + classToAdd->addInnerClass(c); + } + } + + CppClassPtr Writer::setupBasicCppClass(const std::string& cppTypename) const + { + std::vector<std::string> split = simox::alg::split(cppTypename, "::"); + if (split.size() < 1) + { + throw error::AronException("ClassCppWriter", "setupCppClassFromObjectType", "The cpp name of an inner type was empty. Please check the type definition file if all object names are set correctly."); + } + + std::vector<std::string> namespaces(split); + namespaces.pop_back(); + + CppClassPtr c = std::make_shared<CppClass>(namespaces, split[split.size() - 1]); + return c; + } + + void Writer::setupMemberFields(CppClassPtr& c, const serializer::ObjectClassSerializerPtr& o) const + { + auto publicFields = o->getPublicVariableDeclarations(""); + for (const auto& f : publicFields) + { + c->addPublicField(f); + } + } + + void Writer::setupMemberFields(CppClassPtr& c, const serializer::IntEnumClassSerializerPtr& o) const + { + auto publicFields = o->getPublicVariableDeclarations(""); + for (const auto& f : publicFields) + { + c->addPublicField(f); + } + } +} + + + + + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.h new file mode 100644 index 0000000000000000000000000000000000000000..91dd59689dfb678b45ac6b5190ea1b8a04f05cd4 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/Writer.h @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <set> +#include <map> +#include <vector> + +// Parent class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/CodeWriter.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> + +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.h> +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.h> + +namespace armarx::aron::cppcodegenerator +{ + class Writer; + typedef std::shared_ptr<Writer> WriterPtr; + + class Writer : + virtual public codegenerator::CodeWriter + { + public: + Writer() = delete; + Writer(const std::string&, const std::vector<std::string>&); + + virtual void generateTypeObjects(const std::vector<codegeneratorhelper::GenerateObjectInfoPtr>&) override; + virtual void generateTypeIntEnums(const std::vector<codegeneratorhelper::GenerateIntEnumInfoPtr>&) override; + + protected: + virtual void addToAronMethod() override; + virtual void addFromAronMethod() override; + virtual void addToAronTypeMethod() override; + + private: + void generateInnerTypeObjects(CppClassPtr& classToAdd, const std::map<std::string, codegeneratorhelper::GenerateObjectInfoPtr>& localGenerateTypes); + + CppClassPtr setupBasicCppClass(const std::string&) const; + void setupMemberFields(CppClassPtr&, const serializer::ObjectClassSerializerPtr&) const; + void setupMemberFields(CppClassPtr&, const serializer::IntEnumClassSerializerPtr&) const; + + private: + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/AllSerializers.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/AllSerializers.h new file mode 100644 index 0000000000000000000000000000000000000000..d4c7f75c8d1498eec120718bde8c0194e9153277 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/AllSerializers.h @@ -0,0 +1,17 @@ +#pragma once + +#include "container/Object.h" +#include "container/List.h" +#include "container/Dict.h" +#include "container/Tuple.h" +#include "container/Pair.h" +#include "ndarray/EigenMatrix.h" +#include "ndarray/EigenQuaternion.h" +#include "ndarray/IVTCByteImage.h" +#include "ndarray/OpenCVMat.h" +#include "ndarray/PCLPointCloud.h" +#include "ndarray/Position.h" +#include "ndarray/Orientation.h" +#include "ndarray/Pose.h" +#include "enum/IntEnum.h" +#include "primitive/Primitive.h" diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3b18a9f8c7c220e125fe828ce52868fdabab4d83 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.cpp @@ -0,0 +1,325 @@ +/* +* This file is part of ArmarX. +* +* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), +* Karlsruhe Institute of Technology (KIT), all rights reserved. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +// STD/STL + +// Header +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.h> + +namespace armarx::aron::cppcodegenerator +{ + // constantes + const std::string Serializer::ARON_DATA_NAME = simox::meta::get_type_name(typeid(armarx::aron::data::AronData)); + const std::string Serializer::ARON_DATA_PTR_NAME = Serializer::ARON_DATA_NAME + "::PointerType"; + + const std::string Serializer::ARON_TYPE_NAME = simox::meta::get_type_name(typeid(armarx::aron::type::AronType)); + const std::string Serializer::ARON_TYPE_PTR_NAME = Serializer::ARON_TYPE_NAME + "::PointerType"; + + const std::map<std::string, std::string> Serializer::RESOLVE_TYPENAMES = + { + {"string", "std::string"}, + }; + + const std::map<std::string, std::string> Serializer::ESCAPE_ACCESSORS = + { + {"->", "_ptr_"}, + {".", "_dot_"}, + {"[", "_lbr_"}, + {"]", "_rbr_"}, + }; + + const SerializerFactoryPtr Serializer::FACTORY = SerializerFactoryPtr(new SerializerFactory()); + + + // static methods + std::string Serializer::ResolveCppTypename(const std::string& enteredTypeName) + { + auto i = Serializer::RESOLVE_TYPENAMES.find(enteredTypeName); + if (i != Serializer::RESOLVE_TYPENAMES.end()) + { + return i->second; + } + return enteredTypeName; + } + + std::vector<std::string> Serializer::ResolveCppTypenames(const std::vector<std::string>& enteredTypeNames) + { + std::vector<std::string> ret; + for (const auto& t : enteredTypeNames) + { + ret.push_back(Serializer::ResolveCppTypename(t)); + } + return ret; + } + + std::string Serializer::EscapeAccessor(const std::string& accessor) + { + std::string escaped_accessor = accessor; + for (const auto& [key, value] : ESCAPE_ACCESSORS) + { + escaped_accessor = simox::alg::replace_all(escaped_accessor, key, value); + } + return escaped_accessor; + } + + std::string Serializer::UnescapeAccessor(const std::string& accessor) + { + std::string unescaped_accessor = accessor; + for (const auto& [key, value] : ESCAPE_ACCESSORS) + { + unescaped_accessor = simox::alg::replace_all(unescaped_accessor, value, key); + } + return unescaped_accessor; + } + + std::string Serializer::ExtractCppTypename(const typenavigator::NavigatorPtr& n) + { + SerializerPtr cpp = Serializer::FromAronTypeNaviagtorPtr(n); + return cpp->getFullCppTypename(); + } + + std::vector<std::string> Serializer::ExtractCppTypenames(const std::vector<typenavigator::NavigatorPtr>& n) + { + std::vector<std::string> ret; + for (const auto& typenav : n) + { + ret.push_back(Serializer::ExtractCppTypename(typenav)); + } + return ret; + } + + SerializerPtr Serializer::FromAronTypeNaviagtorPtr(const typenavigator::NavigatorPtr& n) + { + return FACTORY->create(n, n->getPath()); + } + + // constructors + Serializer::Serializer(const std::string& cppName, const std::string& aronDataTypename, const std::string& aronTypeTypename, bool is_ptr) : + is_ptr(is_ptr), + cppTypename(cppName), + aronDataTypename(aronDataTypename), + aronTypeTypename(aronTypeTypename) + { + + } + + std::string Serializer::getCoreCppTypename() const + { + return cppTypename; + } + + std::string Serializer::getFullCppTypename() const + { + return is_ptr ? "std::shared_ptr<" + cppTypename + ">" : cppTypename; + } + + std::string Serializer::getAronDataTypename() const + { + return aronDataTypename; + } + + std::string Serializer::getAronDataPtrTypename() const + { + return getAronDataTypename() + "::PointerType"; + } + + std::string Serializer::getAronTypeTypename() const + { + return aronTypeTypename; + } + + std::string Serializer::getAronTypePtrTypename() const + { + return getAronTypeTypename() + "::PointerType"; + } + + CppCtorPtr Serializer::toCtor(const std::string& name) const + { + CppCtorPtr c = CppCtorPtr(new CppCtor(name + "()")); + std::vector<std::pair<std::string, std::string>> initList = this->getCtorInitializers(""); + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("initialize();"); + b->appendBlock(this->getCtorBlock("")); + c->addInitListEntries(initList); + c->setBlock(b); + + return c; + } + + CppMethodPtr Serializer::toResetMethod() const + { + std::stringstream doc; + doc << "@brief reset() - This method resets all member variables to default. \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void reset() override", doc.str())); + CppBlockPtr b = this->getResetBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::toInitializeMethod() const + { + std::stringstream doc; + doc << "@brief initialize() - This method initializes member variables according to the XML type description. \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void initialize() override", doc.str())); + CppBlockPtr b = this->getInitializeBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::toWriteInitialTypeMethod() 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 << "@return - the result of the writer implementation"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("static void writeInitialType(armarx::aron::typeIO::WriterInterface& w)", doc.str())); + CppBlockPtr b = this->getWriteInitialTypeBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::toWriteCurrentTypeMethod() const + { + std::stringstream doc; + doc << "@brief writeType() - This method returns a new type from the current class structure using a type writer implementation. \n"; + doc << "@return - the result of the writer implementation"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void writeCurrentType(armarx::aron::typeIO::WriterInterface& w) const override", doc.str())); + CppBlockPtr b = this->getWriteCurrentTypeBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::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 << "@param w - The writer implementation\n"; + doc << "@return - the result of the writer implementation"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void write(armarx::aron::dataIO::WriterInterface& w) const override", doc.str())); + CppBlockPtr b = this->getWriteBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::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 << "@param r - The reader implementation\n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("virtual void read(armarx::aron::dataIO::ReaderInterface& r) override", doc.str())); + CppBlockPtr b = this->getReadBlock(""); + m->setBlock(b); + return m; + } + + CppMethodPtr Serializer::toSpecializedDataWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const + { + std::stringstream doc; + doc << "@brief specializedDataWrite() - 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(returnname + " " + methodname + "() const", doc.str())); + m->addLine(writerName + " writer;"); + m->addLine("this->write(writer);"); + m->addLine("return " + enforceConversion + "(writer.getResult());"); + return m; + } + + CppMethodPtr Serializer::toSpecializedDataReaderMethod(const std::string& argumentname, const std::string& methodname, const std::string& readerName, const std::string& enforceConversion) const + { + std::stringstream doc; + doc << "@brief specializedDataRead() - This method sets the struct members to new values given in a reader implementation. \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void " + methodname + "(const " + argumentname + "& input)", doc.str())); + m->addLine(readerName + " reader(" + enforceConversion + "(input));"); + m->addLine("this->read(reader);"); + return m; + } + + CppMethodPtr Serializer::toSpecializedInitialTypeWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const + { + std::stringstream doc; + doc << "@brief specializedTypeWrite() - 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 " + returnname + " " + methodname + "()", doc.str())); + m->addLine(writerName + " writer;"); + m->addLine("writeInitialType(writer);"); + m->addLine("return " + enforceConversion + "(writer.getResult());"); + return m; + } + + CppMethodPtr Serializer::toSpecializedCurrentTypeWriterMethod(const std::string& returnname, const std::string& methodname, const std::string& writerName, const std::string& enforceConversion) const + { + std::stringstream doc; + doc << "@brief specializedTypeWrite() - This method returns a new type from the current member data types using a writer implementation. \n"; + doc << "@return - the result of the writer implementation"; + + CppMethodPtr m = CppMethodPtr(new CppMethod(returnname + " " + methodname + "()", doc.str())); + m->addLine(writerName + " writer;"); + m->addLine("this->writeCurrentType(writer);"); + m->addLine("return " + enforceConversion + "(writer.getResult());"); + return m; + } + + CppMethodPtr Serializer::toSpecializedCurrentTypeReaderMethod(const std::string& argumentname, const std::string& methodname, const std::string& readerName, const std::string& enforceConversion) const + { + std::stringstream doc; + doc << "@brief specializedTypeRead() - This method sets the structure of the members to new values given in a reader implementation. \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void " + methodname + "(const " + argumentname + "& input)", doc.str())); + m->addLine(readerName + " reader(" + enforceConversion + "(input));"); + m->addLine("this->readType(reader);"); + return m; + } + + CppMethodPtr Serializer::toEqualsMethod() const + { + std::stringstream doc; + 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->getFullCppTypename() + "& i) const", doc.str())); + CppBlockPtr b = this->getEqualsBlock("", "i"); + b->addLine("return true;"); + m->setBlock(b); + return m; + } + +} + + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h new file mode 100644 index 0000000000000000000000000000000000000000..9d115fb427be210f023a79d54f713bfe07501bc1 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h @@ -0,0 +1,138 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <vector> +#include <map> +#include <string> + +// Simox +#include <SimoxUtility/meta/type_name.h> +#include <SimoxUtility/algorithm/string.h> + +// ArmarX +#include <ArmarXCore/libraries/cppgen/CppBlock.h> +#include <ArmarXCore/libraries/cppgen/CppField.h> +#include <ArmarXCore/libraries/cppgen/CppCtor.h> +#include <ArmarXCore/libraries/cppgen/CppMethod.h> +#include <ArmarXCore/libraries/cppgen/CppClass.h> + +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::cppcodegenerator +{ + class SerializerFactory; + typedef std::shared_ptr<SerializerFactory> SerializerFactoryPtr; + + class Serializer; + typedef std::shared_ptr<Serializer> SerializerPtr; + + class Serializer + { + public: + using PointerType = SerializerPtr; + + public: + // constructors + Serializer(const std::string& cppName, const std::string& aronDataTypename, const std::string& aronTypeTypename, bool is_ptr = false); + + // public member methods + std::string getCoreCppTypename() const; + std::string getFullCppTypename() const; + + std::string getAronDataTypename() const; + std::string getAronDataPtrTypename() const; + + std::string getAronTypeTypename() const; + std::string getAronTypePtrTypename() const; + + CppMethodPtr toSpecializedDataWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; + CppMethodPtr toSpecializedDataReaderMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; + + CppMethodPtr toSpecializedInitialTypeWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; + CppMethodPtr toSpecializedCurrentTypeWriterMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; + CppMethodPtr toSpecializedCurrentTypeReaderMethod(const std::string&, const std::string&, const std::string&, const std::string& enforceType = "") const; + + // virtual override definitions + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const = 0; + + CppCtorPtr toCtor(const std::string&) const; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const = 0; + virtual CppBlockPtr getCtorBlock(const std::string&) const = 0; + + CppMethodPtr toResetMethod() const; + virtual CppBlockPtr getResetBlock(const std::string&) const = 0; + + CppMethodPtr toWriteInitialTypeMethod() const; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const = 0; + + CppMethodPtr toWriteCurrentTypeMethod() const; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const = 0; + + CppMethodPtr toInitializeMethod() const; + virtual CppBlockPtr getInitializeBlock(const std::string&) const = 0; + + CppMethodPtr toWriteMethod() const; + virtual CppBlockPtr getWriteBlock(const std::string&) const = 0; + + CppMethodPtr toReadMethod() const; + virtual CppBlockPtr getReadBlock(const std::string&) const = 0; + + CppMethodPtr toEqualsMethod() const; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const = 0; + + // static methods + static std::string ResolveCppTypename(const std::string&); + static std::vector<std::string> ResolveCppTypenames(const std::vector<std::string>&); + static std::string EscapeAccessor(const std::string&); + static std::string UnescapeAccessor(const std::string&); + + static std::string ExtractCppTypename(const typenavigator::NavigatorPtr&); + static std::vector<std::string> ExtractCppTypenames(const std::vector<typenavigator::NavigatorPtr>&); + + static SerializerPtr FromAronTypeNaviagtorPtr(const typenavigator::NavigatorPtr&); + + private: + // members + const static std::string ARON_DATA_NAME; + const static std::string ARON_DATA_PTR_NAME; + + const static std::string ARON_TYPE_NAME; + const static std::string ARON_TYPE_PTR_NAME; + + static const std::map<std::string, std::string> RESOLVE_TYPENAMES; + static const std::map<std::string, std::string> ESCAPE_ACCESSORS; + + static const SerializerFactoryPtr FACTORY; + + bool is_ptr; + std::string cppTypename; + std::string aronDataTypename; + std::string aronTypeTypename; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b777b8201d2ddfa302135a1b7795afd134a8c9d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.cpp @@ -0,0 +1,89 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + +// Header +#include "SerializerFactory.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/AllSerializers.h> + +namespace armarx::aron::cppcodegenerator +{ + // Access method + SerializerPtr SerializerFactory::create(const typenavigator::NavigatorPtr& n, const Path& path) const + { + static const std::map<type::Descriptor, SerializerFactoryPtr> Factories = + { + {type::eObject, SerializerFactoryPtr(new ObjectSerializerFactory())}, + {type::eDict, SerializerFactoryPtr(new DictSerializerFactory())}, + {type::eList, SerializerFactoryPtr(new ListSerializerFactory())}, + {type::eTuple, SerializerFactoryPtr(new TupleSerializerFactory())}, + {type::ePair, SerializerFactoryPtr(new PairSerializerFactory())}, + {type::eEigenMatrix, SerializerFactoryPtr(new EigenMatrixSerializerFactory())}, + {type::eEigenQuaternion, SerializerFactoryPtr(new EigenQuaternionSerializerFactory())}, + {type::eIVTCByteImage, SerializerFactoryPtr(new IVTCByteImageSerializerFactory())}, + {type::eOpenCVMat, SerializerFactoryPtr(new OpenCVMatSerializerFactory())}, + {type::ePCLPointCloud, SerializerFactoryPtr(new PCLPointCloudSerializerFactory())}, + {type::ePosition, SerializerFactoryPtr(new PositionSerializerFactory())}, + {type::eOrientation, SerializerFactoryPtr(new OrientationSerializerFactory())}, + {type::ePose, SerializerFactoryPtr(new PoseSerializerFactory())}, + {type::eIntEnum, SerializerFactoryPtr(new IntEnumSerializerFactory())}, + {type::eInt, SerializerFactoryPtr(new IntSerializerFactory())}, + {type::eLong, SerializerFactoryPtr(new LongSerializerFactory())}, + {type::eFloat, SerializerFactoryPtr(new FloatSerializerFactory())}, + {type::eDouble, SerializerFactoryPtr(new DoubleSerializerFactory())}, + {type::eString, SerializerFactoryPtr(new StringSerializerFactory())}, + {type::eBool, SerializerFactoryPtr(new BoolSerializerFactory())}, + {type::eTime, SerializerFactoryPtr(new TimeSerializerFactory())} + }; + + //CheckIfPtrIsNull("NavigatorFactory", "create", path, n); + auto res = n->getResult(); + auto factory_iterator = Factories.find(Resolver::GetDescriptor(res)); + if (factory_iterator == Factories.end()) + { + throw error::AronException("NavigatorFactory", "create", "Cannot find the desired factory for input (ice_id): " + res->ice_id() + ". Cannot create navigator", path); + } + return factory_iterator->second->createSpecific(n, path); + } + + SerializerPtr SerializerFactory::createSpecific(const typenavigator::NavigatorPtr&, const Path&) const + { + throw error::AronException("NavigatorFactory", "createSpecific", "Called disallowed method. Use child class instead!"); + } + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + SerializerPtr upperType##SerializerFactory::createSpecific(const typenavigator::NavigatorPtr& n, const Path& path) const \ + { \ + /*CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeCppSerializerFactory", "createSpecific[BeforeCast]", path, n); */\ + typenavigator::upperType##NavigatorPtr casted = typenavigator::upperType##Navigator::DynamicCast(n); \ + /*CheckIfInputIsNull("Aron"+std::string(#upperType)+"TypeCppSerializerFactory", "createSpecific[AfterCast]", path, casted); */\ + return SerializerPtr(new serializer::upperType##Serializer(casted)); \ + } + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..fc1bca391e4d79e19b03be4cefa0dd053613d42d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/SerializerFactory.h @@ -0,0 +1,65 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <unordered_map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/SerializerFactory.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/AllSerializers.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::cppcodegenerator +{ + class SerializerFactory; + typedef std::shared_ptr<SerializerFactory> SerializerFactoryPtr; + + class SerializerFactory : + virtual public codegenerator::SerializerFactory<typenavigator::NavigatorPtr, SerializerPtr> + { + public: + SerializerFactory() = default; + virtual SerializerPtr create(const typenavigator::NavigatorPtr&, const Path&) const override; + virtual SerializerPtr createSpecific(const typenavigator::NavigatorPtr&, const Path&) const override; + + }; + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##SerializerFactory : \ + virtual public SerializerFactory \ + { \ + public: \ + upperType##SerializerFactory() = default; \ + virtual SerializerPtr createSpecific(const typenavigator::NavigatorPtr&, const Path&) const override; \ + }; + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7431b8ee225433eccd286322310c4feb47082ebe --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.cpp @@ -0,0 +1,152 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Dict.h" + + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + DictSerializer::DictSerializer(const typenavigator::DictNavigatorPtr& n) : + Serializer("std::map<std::string, " + FromAronTypeNaviagtorPtr(n->getAcceptedType())->getFullCppTypename() + ">", simox::meta::get_type_name(typeid(data::AronDict)), simox::meta::get_type_name(typeid(type::AronDict))), + navigator(n) + { + + } + + // virtual implementations + std::vector<CppFieldPtr> DictSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> DictSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr DictSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr DictSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".clear();"); + return b; + } + + CppBlockPtr DictSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = {};"); + return b; + } + + CppBlockPtr DictSerializer::getWriteInitialTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartDict();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; + + auto type_s = FromAronTypeNaviagtorPtr(navigator->getAcceptedType()); + CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(type_s->getFullCppTypename()); + b->appendBlock(b2); + b->addLine("w.writeEndDict();"); + return b; + } + + CppBlockPtr DictSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartDict();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; + + auto type_s = FromAronTypeNaviagtorPtr(navigator->getAcceptedType()); + CppBlockPtr b2 = type_s->getWriteCurrentTypeBlock(type_s->getFullCppTypename()); + b->appendBlock(b2); + b->addLine("w.writeEndDict();"); + return b; + } + + CppBlockPtr DictSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartDict();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator_key = escaped_accessor + DICT_KEY_ACCESSOR; + std::string accessor_iterator_val = escaped_accessor + DICT_VALUE_ACCESSOR; + + b->addLine("for (const auto& [" + accessor_iterator_key + ", " + accessor_iterator_val + "] : " + accessor + ") "); + + auto type_s = FromAronTypeNaviagtorPtr(navigator->getAcceptedType()); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + b2->addLine("w.writeKey(" + accessor_iterator_key + ");"); + b2 = CppBlock::MergeBlocks(b2, type_s->getWriteBlock(accessor_iterator_val)); + b->addBlock(b2); + + b->addLine("w.writeEndDict();"); + return b; + } + + CppBlockPtr DictSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".clear();"); + b->addLine("r.readStartDict();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator = escaped_accessor + DICT_ITERATOR_ACCESSOR; + std::string accessor_iterator_key = escaped_accessor + DICT_KEY_ACCESSOR; + + auto type_s = FromAronTypeNaviagtorPtr(navigator->getAcceptedType()); + + b->addLine("while(!r.readEndDict())"); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + b2->addLine("std::string " + accessor_iterator_key + " = r.readKey();"); + b2->addLine(type_s->getFullCppTypename() + " " + accessor_iterator + ";"); + b2 = CppBlock::MergeBlocks(b2, type_s->getReadBlock(accessor_iterator)); + b2->addLine(accessor + "[" + accessor_iterator_key + "] = " + accessor_iterator + ";"); + + b->addBlock(b2); + return b; + } + + CppBlockPtr DictSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.h new file mode 100644 index 0000000000000000000000000000000000000000..9e2e459761cb8589877893609a04da40b5579030 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Dict.h @@ -0,0 +1,73 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Dict.h> + + +namespace armarx::aron::cppcodegenerator::serializer +{ + class DictSerializer; + typedef std::shared_ptr<DictSerializer> DictSerializerPtr; + + class DictSerializer : + virtual public Serializer + { + public: + using PointerType = DictSerializerPtr; + + public: + // constructors + DictSerializer() = delete; + DictSerializer(const typenavigator::DictNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // Members + static constexpr const char* DICT_ITERATOR_ACCESSOR = "_iterator"; + static constexpr const char* DICT_KEY_ACCESSOR = "_key"; + static constexpr const char* DICT_VALUE_ACCESSOR = "_value"; + + typenavigator::DictNavigatorPtr navigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e4f924eb68608d9662231d94cae4e3cb89aa2ef --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.cpp @@ -0,0 +1,138 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "List.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + ListSerializer::ListSerializer(const typenavigator::ListNavigatorPtr& e) : + Serializer("std::vector<" + FromAronTypeNaviagtorPtr(e->getAcceptedType())->getFullCppTypename() + ">", simox::meta::get_type_name(typeid(data::AronList)), simox::meta::get_type_name(typeid(type::AronList))), + typenavigator(e) + { + + } + + std::vector<CppFieldPtr> ListSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> ListSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr ListSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr ListSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".clear();"); + return b; + } + + CppBlockPtr ListSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = {};"); + return b; + } + + CppBlockPtr ListSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartList();"); + auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); + + CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(type_s->getFullCppTypename()); + b->appendBlock(b2); + + b->addLine("w.writeEndList();"); + return b; + } + + CppBlockPtr ListSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartList();"); + auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); + + CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(type_s->getFullCppTypename()); // TODO: think about having a better solution not ignoting the current type + b->appendBlock(b2); + + b->addLine("w.writeEndList();"); + return b; + } + + CppBlockPtr ListSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartList();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR; + + auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); + b->addLine("for(unsigned int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + ".size(); ++" + accessor_iterator + ")"); + CppBlockPtr b2 = type_s->getWriteBlock(accessor + "[" + accessor_iterator + "]"); + b->addBlock(b2); + b->addLine("w.writeEndList();"); + return b; + } + + CppBlockPtr ListSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".clear();"); + b->addLine("r.readStartList();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_iterator = escaped_accessor + LIST_ITERATOR_ACCESSOR; + + b->addLine("while(!r.readEndList())"); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + + auto type_s = FromAronTypeNaviagtorPtr(typenavigator->getAcceptedType()); + b2->addLine(type_s->getFullCppTypename() + " " + accessor_iterator + ";"); + b2 = CppBlock::MergeBlocks(b2, type_s->getReadBlock(accessor_iterator)); + b2->addLine(accessor + ".push_back(" + accessor_iterator + ");"); + + b->addBlock(b2); + return b; + } + + CppBlockPtr ListSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.h new file mode 100644 index 0000000000000000000000000000000000000000..e35aaa2d8addcac9d6025e024c18c6f54b135589 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/List.h @@ -0,0 +1,69 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <vector> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + class ListSerializer; + typedef std::shared_ptr<ListSerializer> ListSerializerPtr; + + class ListSerializer : + public Serializer + { + public: + using PointerType = ListSerializerPtr; + + public: + // constructors + ListSerializer(const typenavigator::ListNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static constexpr const char* LIST_ITERATOR_ACCESSOR = "_iterator"; + + typenavigator::ListNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7dbfa3665199b9798232af977d5d53a63777716c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.cpp @@ -0,0 +1,105 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Object.h" + + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + ObjectSerializer::ObjectSerializer(const typenavigator::ObjectNavigatorPtr& e) : + Serializer(e->getObjectName(), simox::meta::get_type_name(typeid(data::AronDict)), simox::meta::get_type_name(typeid(type::AronObject))), + navigator(e) + { + //AddObjectTypeToAllObjectTypesList(ObjectNavigatorPtr(this)); + } + + std::vector<CppFieldPtr> ObjectSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> ObjectSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr ObjectSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr ObjectSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".reset();"); + return b; + } + + CppBlockPtr ObjectSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".initialize();"); + return b; + } + + CppBlockPtr ObjectSerializer::getWriteInitialTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + "::writeInitialType(w);"); + return b; + } + + CppBlockPtr ObjectSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".writeCurrentType(w);"); + return b; + } + + CppBlockPtr ObjectSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".write(w);"); + return b; + } + + CppBlockPtr ObjectSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".read(r);"); + return b; + } + + CppBlockPtr ObjectSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.h new file mode 100644 index 0000000000000000000000000000000000000000..b879a8794e7b1f25d8d409581bcfb477d21344dd --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Object.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class ObjectSerializer; + typedef std::shared_ptr<ObjectSerializer> ObjectSerializerPtr; + + class ObjectSerializer : + virtual public Serializer + { + public: + using PointerType = ObjectSerializerPtr; + + public: + // constructors + ObjectSerializer(const typenavigator::ObjectNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static constexpr const char* EXTENDS_ITERATOR_ACCESSOR = "_extends"; + + typenavigator::ObjectNavigatorPtr navigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6981f8625b4d748d97b51188e96f54129cfd2033 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.cpp @@ -0,0 +1,173 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Pair.h" + + +namespace armarx::aron::cppcodegenerator::serializer +{ + PairSerializer::PairSerializer(const typenavigator::PairNavigatorPtr& e) : + Serializer("std::pair<" + ExtractCppTypename(e->getFirstAcceptedType()) + ", " + ExtractCppTypename(e->getSecondAcceptedType()) + ">", simox::meta::get_type_name(typeid(data::AronList)), simox::meta::get_type_name(typeid(type::AronPair))), + typenavigator(e) + { + + } + + std::vector<CppFieldPtr> PairSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> PairSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr PairSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr PairSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + CppBlockPtr b21 = child_s1->getInitializeBlock(accessor + ".first"); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + CppBlockPtr b22 = child_s2->getInitializeBlock(accessor + ".second"); + b->appendBlock(b22); + + return b; + } + + CppBlockPtr PairSerializer::getWriteInitialTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartPair();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + std::string accessor_iterator1 = escaped_accessor + PAIR_FIRST_ACCESSOR; + b->addLine("w.writeKey(\"0\");"); + CppBlockPtr b21 = child_s1->getWriteInitialTypeBlock(accessor_iterator1); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + std::string accessor_iterator2 = escaped_accessor + PAIR_SECOND_ACCESSOR; + b->addLine("w.writeKey(\"1\");"); + CppBlockPtr b22 = child_s2->getWriteInitialTypeBlock(accessor_iterator2); + b->appendBlock(b22); + + b->addLine("w.writeEndPair();"); + return b; + } + + CppBlockPtr PairSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartPair();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + std::string accessor_iterator1 = escaped_accessor + PAIR_FIRST_ACCESSOR; + b->addLine("w.writeKey(\"0\");"); + CppBlockPtr b21 = child_s1->getWriteCurrentTypeBlock(accessor_iterator1); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + std::string accessor_iterator2 = escaped_accessor + PAIR_SECOND_ACCESSOR; + b->addLine("w.writeKey(\"1\");"); + CppBlockPtr b22 = child_s2->getWriteCurrentTypeBlock(accessor_iterator2); + b->appendBlock(b22); + + b->addLine("w.writeEndPair();"); + return b; + } + + CppBlockPtr PairSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + CppBlockPtr b21 = child_s1->getResetBlock(accessor + ".first"); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + CppBlockPtr b22 = child_s2->getResetBlock(accessor + ".second"); + b->appendBlock(b22); + + return b; + } + + CppBlockPtr PairSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartList();"); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + CppBlockPtr b21 = child_s1->getWriteBlock(accessor + ".first"); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + CppBlockPtr b22 = child_s2->getWriteBlock(accessor + ".second"); + b->appendBlock(b22); + + b->addLine("w.writeEndList();"); + return b; + } + + CppBlockPtr PairSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = {};"); + b->addLine("r.readStartList();"); + + auto child_s1 = FromAronTypeNaviagtorPtr(typenavigator->getFirstAcceptedType()); + CppBlockPtr b21 = child_s1->getReadBlock(accessor + ".first"); + b->appendBlock(b21); + + auto child_s2 = FromAronTypeNaviagtorPtr(typenavigator->getSecondAcceptedType()); + CppBlockPtr b22 = child_s2->getReadBlock(accessor + ".second"); + b->appendBlock(b22); + + b->addLine("r.readEndList();"); + return b; + } + + CppBlockPtr PairSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.h new file mode 100644 index 0000000000000000000000000000000000000000..f9441c02b5d4d82a866a32380c32794dc2df298e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Pair.h @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Pair.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class PairSerializer; + typedef std::shared_ptr<PairSerializer> PairSerializerPtr; + + class PairSerializer : + virtual public Serializer + { + public: + using PointerType = PairSerializerPtr; + + public: + // constructors + PairSerializer(const typenavigator::PairNavigatorPtr& e); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static constexpr const char* PAIR_FIRST_ACCESSOR = "_first"; + static constexpr const char* PAIR_SECOND_ACCESSOR = "_second"; + + + typenavigator::PairNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b83f2cd9e17c1e669749452fac0d827080b34a67 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.cpp @@ -0,0 +1,161 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Tuple.h" + + +namespace armarx::aron::cppcodegenerator::serializer +{ + TupleSerializer::TupleSerializer(const typenavigator::TupleNavigatorPtr& e) : + Serializer("std::tuple<" + simox::alg::join(ExtractCppTypenames(e->getAcceptedTypes()), ", ") + ">", simox::meta::get_type_name(typeid(data::AronList)), simox::meta::get_type_name(typeid(type::AronTuple))), + typenavigator(e) + { + + } + + std::vector<CppFieldPtr> TupleSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> TupleSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr TupleSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr TupleSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + unsigned int i = 0; + for (const auto& child : typenavigator->getAcceptedTypes()) + { + auto child_s = FromAronTypeNaviagtorPtr(child); + CppBlockPtr b2 = child_s->getInitializeBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); + b->appendBlock(b2); + } + return b; + } + + CppBlockPtr TupleSerializer::getWriteInitialTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartTuple();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + unsigned int i = 0; + for (const auto& type : typenavigator->getAcceptedTypes()) + { + std::string accessor_iterator = escaped_accessor + TUPLE_ITERATOR_ACCESSOR + std::to_string(i++); + auto type_s = FromAronTypeNaviagtorPtr(type); + b->addLine("w.writeKey(\"" + std::to_string(i) + "\");"); + CppBlockPtr b2 = type_s->getWriteInitialTypeBlock(accessor_iterator); + b->appendBlock(b2); + } + b->addLine("w.writeEndTuple();"); + return b; + } + + CppBlockPtr TupleSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartTuple();"); + + std::string escaped_accessor = EscapeAccessor(accessor); + unsigned int i = 0; + for (const auto& type : typenavigator->getAcceptedTypes()) + { + std::string accessor_iterator = escaped_accessor + TUPLE_ITERATOR_ACCESSOR + std::to_string(i++); + auto type_s = FromAronTypeNaviagtorPtr(type); + b->addLine("w.writeKey(\"" + std::to_string(i) + "\");"); + CppBlockPtr b2 = type_s->getWriteCurrentTypeBlock(accessor_iterator); + b->appendBlock(b2); + } + b->addLine("w.writeEndTuple();"); + return b; + } + + CppBlockPtr TupleSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + unsigned int i = 0; + for (const auto& type : typenavigator->getAcceptedTypes()) + { + auto type_s = FromAronTypeNaviagtorPtr(type); + CppBlockPtr b2 = type_s->getResetBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); + b->appendBlock(b2); + } + return b; + } + + CppBlockPtr TupleSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeStartList();"); + + unsigned int i = 0; + for (const auto& type : typenavigator->getAcceptedTypes()) + { + auto type_s = FromAronTypeNaviagtorPtr(type); + CppBlockPtr b2 = type_s->getWriteBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); + b->appendBlock(b2); + } + b->addLine("w.writeEndList();"); + return b; + } + + CppBlockPtr TupleSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = {};"); + b->addLine("r.readStartList();"); + + unsigned int i = 0; + for (const auto& type : typenavigator->getAcceptedTypes()) + { + auto type_s = FromAronTypeNaviagtorPtr(type); + CppBlockPtr b2 = type_s->getReadBlock("std::get<" + std::to_string(i++) + ">(" + accessor + ")"); + b->appendBlock(b2); + } + b->addLine("r.readEndList();"); + return b; + } + + CppBlockPtr TupleSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..52bd376ec1e2485800500e486313f408eadaa7a9 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/container/Tuple.h @@ -0,0 +1,70 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class TupleSerializer; + typedef std::shared_ptr<TupleSerializer> TupleSerializerPtr; + + class TupleSerializer : + virtual public Serializer + { + public: + using PointerType = TupleSerializerPtr; + + public: + // constructors + TupleSerializer(const typenavigator::TupleNavigatorPtr& e); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static constexpr const char* TUPLE_ITERATOR_ACCESSOR = "_iterator"; + + typenavigator::TupleNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a7ed2ec3339fcbd368b81b7afa3d7f0a873a8735 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.cpp @@ -0,0 +1,102 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "IntEnum.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + IntEnumSerializer::IntEnumSerializer(const typenavigator::IntEnumNavigatorPtr& n) : + Serializer(n->getEnumName(), simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronIntEnum))), + navigator(n) + { + } + + std::vector<CppFieldPtr> IntEnumSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> IntEnumSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr IntEnumSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr IntEnumSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".reset();"); + return b; + } + + CppBlockPtr IntEnumSerializer::getWriteInitialTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + "::writeInitialType(w);"); + return b; + } + + CppBlockPtr IntEnumSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".writeCurrentType(w);"); + return b; + } + + CppBlockPtr IntEnumSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".initialize();"); + return b; + } + + CppBlockPtr IntEnumSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".write(w);"); + return b; + } + + CppBlockPtr IntEnumSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + ".read(r);"); + return b; + } + + CppBlockPtr IntEnumSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); + b->addLine("\t return false;"); + return b; + } +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.h new file mode 100644 index 0000000000000000000000000000000000000000..abb82b441cb59b139ec531110523a7844216273d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/enum/IntEnum.h @@ -0,0 +1,70 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class IntEnumSerializer; + typedef std::shared_ptr<IntEnumSerializer> IntEnumSerializerPtr; + + class IntEnumSerializer : + virtual public Serializer + { + public: + using PointerType = IntEnumSerializerPtr; + + public: + // constructors + IntEnumSerializer(const typenavigator::IntEnumNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // Members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + + typenavigator::IntEnumNavigatorPtr navigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bb5203eb76777c0c09a08667689c108ddb25c85 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "EigenMatrix.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + + const std::map<std::string, std::pair<std::string, int>> EigenMatrixSerializer::ACCEPTED_TYPES = + { + {"short", {"short", 2}}, + {"int", {"int", 4}}, + {"long", {"long", 8}}, + {"float", {"float", 4}}, + {"double", {"double", 8}}, + //{"complex float", {"std::complex<float>", ???}}, + //{"complex double", {"std::complex<double>", ???}} + }; + + // constructors + EigenMatrixSerializer::EigenMatrixSerializer(const typenavigator::EigenMatrixNavigatorPtr& n) : + Serializer("Eigen::Matrix<" + ACCEPTED_TYPES.at(n->getTypename()).first + ", " + std::to_string(n->getRows()) + ", " + std::to_string(n->getCols()) + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronEigenMatrix))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> EigenMatrixSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> EigenMatrixSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr EigenMatrixSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeEigenMatrix({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeEigenMatrix({" + accessor + ".rows(), " + accessor + ".cols()}, \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + accessor + ".rows(), " + accessor + ".cols(), " + std::to_string(ACCEPTED_TYPES.at(typenavigator->getTypename()).second) + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("r.readStartNDArray(); // We do not need the dims and type since a EigenMat can not change (templated)"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr EigenMatrixSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + ".isApprox(" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + return b; + } +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..bbdb75fdf7bb55b287b6853457053da6aa32f476 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenMatrix.h @@ -0,0 +1,70 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class EigenMatrixSerializer; + typedef std::shared_ptr<EigenMatrixSerializer> EigenMatrixSerializerPtr; + + class EigenMatrixSerializer : + virtual public Serializer + { + public: + using PointerType = EigenMatrixSerializerPtr; + + public: + // constructors + EigenMatrixSerializer(const typenavigator::EigenMatrixNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // Members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + + typenavigator::EigenMatrixNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..825765164e23e2358dc465171d667f6dbe117020 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.cpp @@ -0,0 +1,110 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "EigenQuaternion.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + + const std::map<std::string, std::pair<std::string, int>> EigenQuaternionSerializer::ACCEPTED_TYPES = + { + {"float", {"float", 4}}, + {"double", {"double", 8}} + }; + + // constructors + EigenQuaternionSerializer::EigenQuaternionSerializer(const typenavigator::EigenQuaternionNavigatorPtr& n) : + Serializer("Eigen::Quaternion<" + ACCEPTED_TYPES.at(n->getTypename()).first + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronEigenQuaternion))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> EigenQuaternionSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> EigenQuaternionSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr EigenQuaternionSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeEigenQuaternion(\"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeEigenQuaternion(\"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + simox::alg::to_string(typenavigator->getDimensions(), ", ") + ", " + std::to_string(ACCEPTED_TYPES.at(typenavigator->getTypename()).second) + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".coeffs().data()));"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("r.readStartNDArray(); // We do not need the dims and type since a EigenMat can not change (templated)"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".coeffs().data()));"); + return b; + } + + CppBlockPtr EigenQuaternionSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + ".isApprox(" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + return b; + } +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.h new file mode 100644 index 0000000000000000000000000000000000000000..9f306d7dd6604e43ba4e86b4e112c225c911e504 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/EigenQuaternion.h @@ -0,0 +1,70 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class EigenQuaternionSerializer; + typedef std::shared_ptr<EigenQuaternionSerializer> EigenQuaternionSerializerPtr; + + class EigenQuaternionSerializer : + virtual public Serializer + { + public: + using PointerType = EigenQuaternionSerializerPtr; + + public: + // constructors + EigenQuaternionSerializer(const typenavigator::EigenQuaternionNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // Members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + + typenavigator::EigenQuaternionNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cdb9e79036d16756fb4e2f6f05c97bcf1d7d6b2e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.cpp @@ -0,0 +1,121 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "IVTCByteImage.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + + const std::map<std::string, std::pair<std::string, int>> IVTCByteImageSerializer::ACCEPTED_TYPES = + { + {"GrayScale", {"CByteImage::ImageType::eGrayScale", 1}}, + {"RGB24", {"CByteImage::ImageType::eRGB24", 3}}, + {"RGB24Split", {"CByteImage::ImageType::eRGB24Split", 3}} + }; + + // constructors + IVTCByteImageSerializer::IVTCByteImageSerializer(const typenavigator::IVTCByteImageNavigatorPtr& e) : + Serializer("CByteImage", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronIVTCByteImage)), true), + typenavigator(e) + { + // check if type exists + ACCEPTED_TYPES.at(typenavigator->getTypename()); + } + + std::vector<CppFieldPtr> IVTCByteImageSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> IVTCByteImageSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr IVTCByteImageSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + "->Set(" + accessor + "->width, " + accessor + "->height, " + accessor + "->type);"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = std::make_shared<" + getCoreCppTypename() + ">(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + ", " + ACCEPTED_TYPES.at(typenavigator->getTypename()).first + ");"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeIVTCByteImage(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + ", \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeIVTCByteImage(" + accessor + "->width, " + accessor + "->height, \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + accessor + "->width, " + accessor + "->height, " + accessor + "->bytesPerPixel}, std::to_string(" + accessor + "->type), reinterpret_cast<const unsigned char*>(" + accessor + "->pixels));"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string dims_accessor = escaped_accessor + DIMENSION_ACCESSOR; + std::string type_accessor = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + dims_accessor + ", " + type_accessor + "] = r.readStartNDArray();"); + b->addLine(accessor + "->Set(" + dims_accessor + "[0], " + dims_accessor + "[1], static_cast<CByteImage::ImageType>(std::stoi(" + type_accessor + ")));"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + "->pixels));"); + return b; + } + + CppBlockPtr IVTCByteImageSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + "->IsCompatible(" + otherInstanceAccessor + ".get())))"); + b->addLine("\t return false;"); + b->addLine("if (not (memcmp(" + accessor + "->pixels, " + otherInstanceAccessor + "->pixels, " + accessor + "->width * " + accessor + "->height * " + accessor + "->bytesPerPixel) == 0))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.h new file mode 100644 index 0000000000000000000000000000000000000000..ac91df514b87f3377f5f9738a613cd1dc6c29ca6 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/IVTCByteImage.h @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class IVTCByteImageSerializer; + typedef std::shared_ptr<IVTCByteImageSerializer> AronIVTCByteImageTypeCppSerializerPtr; + + class IVTCByteImageSerializer : + virtual public Serializer + { + public: + using PointerType = AronIVTCByteImageTypeCppSerializerPtr; + + public: + // constructors + IVTCByteImageSerializer(const typenavigator::IVTCByteImageNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::IVTCByteImageNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3961a3884b7867599997cc2c1b695d8abeffec7b --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.cpp @@ -0,0 +1,157 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "OpenCVMat.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + + const std::map<std::string, std::pair<std::string, int>> OpenCVMatSerializer::ACCEPTED_TYPES = + { + {"CV_8U", {"CV_8U", 1}}, + {"CV_8S", {"CV_8S", 1}}, + {"CV_16U", {"CV_16U", 2}}, + {"CV_16S", {"CV_16S", 2}}, + {"CV_32S", {"CV_32S", 4}}, + {"CV_32F", {"CV_32F", 4}}, + {"CV_64F", {"CV_64F", 8}}, + }; + + // constructors + OpenCVMatSerializer::OpenCVMatSerializer(const typenavigator::OpenCVMatNavigatorPtr& e) : + Serializer("cv::Mat", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronOpenCVMat))), + typenavigator(e) + { + // check if type exists + if (ACCEPTED_TYPES.find(e->getTypename()) == ACCEPTED_TYPES.end()) + { + throw error::StringNotValidException("OpenCVMatSerializer", "OpenCVMatSerializer", "Could not find a matching typename.", e->getTypename(), e->getPath()); + } + } + + std::vector<CppFieldPtr> OpenCVMatSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> OpenCVMatSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr OpenCVMatSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_iterator = escaped_accessor + ITERATOR_ACCESSOR; + + b->addLine("std::vector<int> " + accessor_dimensions + ";"); + b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + ".dims; ++" + accessor_iterator + ")"); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + b2->addLine(accessor_dimensions + ".push_back(" + accessor + ".size[" + accessor_iterator + "]);"); + b->appendBlock(b2); + b->addLine(accessor + " = " + getFullCppTypename() + "(" + accessor_dimensions + ", " + accessor + ".type());"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "(std::vector<int>({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}), " + ACCEPTED_TYPES.at(typenavigator->getTypename()).first + ");"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeOpenCVMat({" + simox::alg::to_string<int>(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_iterator = escaped_accessor + ITERATOR_ACCESSOR; + + b->addLine("std::vector<int> " + accessor_dimensions + ";"); + b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + ".dims; ++" + accessor_iterator + ")"); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + b2->addLine(accessor_dimensions + ".push_back(" + accessor + ".size[" + accessor_iterator + "]);"); + b->appendBlock(b2); + b->addLine("w.writeOpenCVMat(" + accessor_dimensions + ", std::to_string(" + accessor + ".type()));"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_iterator = escaped_accessor + ITERATOR_ACCESSOR; + + b->addLine("std::vector<int> " + accessor_dimensions + ";"); + b->addLine("for (int " + accessor_iterator + " = 0; " + accessor_iterator + " < " + accessor + ".dims; ++" + accessor_iterator + ")"); + CppBlockPtr b2 = CppBlockPtr(new CppBlock()); + b2->addLine(accessor_dimensions + ".push_back(" + accessor + ".size[" + accessor_iterator + "]);"); + b->appendBlock(b2); + b->addLine(accessor_dimensions + ".push_back(" + accessor + ".elemSize());"); + b->addLine("w.writeNDArray(" + accessor_dimensions + ", std::to_string(" + accessor + ".type()), reinterpret_cast<const unsigned char*>(" + accessor + ".data));"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_type = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + accessor_dimensions + ", " + accessor_type + "] = r.readStartNDArray();"); + b->addLine(accessor + " = " + getFullCppTypename() + "(std::vector<int>({" + accessor_dimensions + ".begin(), std::prev(" + accessor_dimensions + ".end())}), std::stoi(" + accessor_type + "));"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".data));"); + return b; + } + + CppBlockPtr OpenCVMatSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (cv::countNonZero(" + accessor + " != " + otherInstanceAccessor + ") != 0)"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.h new file mode 100644 index 0000000000000000000000000000000000000000..dff7118e2e4dad0cdc46267e4a927f7d53435eac --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/OpenCVMat.h @@ -0,0 +1,73 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class OpenCVMatSerializer; + typedef std::shared_ptr<OpenCVMatSerializer> AronOpenCVMatTypeCppSerializerPtr; + + class OpenCVMatSerializer : + virtual public Serializer + { + public: + using PointerType = AronOpenCVMatTypeCppSerializerPtr; + + public: + // constructors + OpenCVMatSerializer(const typenavigator::OpenCVMatNavigatorPtr& n); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + static constexpr const char* ITERATOR_ACCESSOR = "_iterator"; + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::OpenCVMatNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a431295f0583429740b3c43f0b64dfccf24b5499 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.cpp @@ -0,0 +1,109 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Orientation.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + OrientationSerializer::OrientationSerializer(const typenavigator::OrientationNavigatorPtr& n) : + Serializer("Eigen::Quaternion<" + n->getTypename() + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronOrientation))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> OrientationSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> OrientationSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr OrientationSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr OrientationSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr OrientationSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr OrientationSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeOrientation();"); + return b; + } + + CppBlockPtr OrientationSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeOrientation();"); + return b; + } + + CppBlockPtr OrientationSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + simox::alg::to_string(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".coeffs().data()));"); + return b; + } + + CppBlockPtr OrientationSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_type = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + accessor_dimensions + ", " + accessor_type + "] = r.readStartNDArray();"); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".coeffs().data()));"); + return b; + } + + CppBlockPtr OrientationSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + ".isApprox(" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.h new file mode 100644 index 0000000000000000000000000000000000000000..248a1a6da3f4a93da04e362640bdb0fa5feedd8e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Orientation.h @@ -0,0 +1,69 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + class OrientationSerializer; + typedef std::shared_ptr<OrientationSerializer> AronOrientationTypeCppSerializerPtr; + + class OrientationSerializer : + virtual public Serializer + { + public: + using PointerType = AronOrientationTypeCppSerializerPtr; + + public: + // constructors + OrientationSerializer(const typenavigator::OrientationNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::OrientationNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1ba373de5aaaf56fb7062da4134792991b80ac47 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.cpp @@ -0,0 +1,124 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "PCLPointCloud.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + + const std::map<std::string, std::pair<std::string, int>> PCLPointCloudSerializer::ACCEPTED_TYPES = + { + // see http://docs.ros.org/en/groovy/api/pcl/html/point__types_8hpp_source.html + {"PointXYZ", {"pcl::PointXYZ", 16}}, + {"PointXYZI", {"pcl::PointXYZI", 32}}, + {"PointXYZL", {"pcl::PointXYZL", 32}}, + {"PointXYZRGB", {"pcl::PointXYZRGB", 32}}, + {"PointXYZRGBL", {"pcl::PointXYZRGBL", 32}}, + {"PointXYZRGBA", {"pcl::PointXYZRGBA", 32}}, + {"PointXYZHSV", {"pcl::PointXYZHSV", 32}}, + }; + + // constructors + PCLPointCloudSerializer::PCLPointCloudSerializer(const typenavigator::PCLPointCloudNavigatorPtr& n) : + Serializer("pcl::PointCloud<" + ACCEPTED_TYPES.at(n->getTypename()).first + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronPCLPointCloud))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> PCLPointCloudSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> PCLPointCloudSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr PCLPointCloudSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "(" + accessor + ".width, " + accessor + ".height);"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + ");"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePCLPointCloud(" + std::to_string(typenavigator->getWidth()) + ", " + std::to_string(typenavigator->getHeight()) + ", \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getWriteCurrentTypeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePCLPointCloud(" + accessor + ".width, " + accessor + ".height, \"" + typenavigator->getTypename() + "\");"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + accessor + ".width, " + accessor + ".height, " + std::to_string(ACCEPTED_TYPES.at(typenavigator->getTypename()).second) + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".points.data()));"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string dims_accessor = escaped_accessor + DIMENSION_ACCESSOR; + std::string type_accessor = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + dims_accessor + ", " + type_accessor + "] = r.readStartNDArray();"); + b->addLine(accessor + " = " + getFullCppTypename() + "(" + dims_accessor + "[0], " + dims_accessor + "[1]);"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".points.data()));"); + return b; + } + + CppBlockPtr PCLPointCloudSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (" + accessor + ".width != " + otherInstanceAccessor + ".width || " + accessor + ".height != " + otherInstanceAccessor + ".height)"); + b->addLine("\t return false;"); + //b->addLine("if (" + accessor + "->points != " + otherInstanceAccessor + "->points)"); + //b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.h new file mode 100644 index 0000000000000000000000000000000000000000..101ee2ee61047673fed94964f2d41da297d0c263 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/PCLPointCloud.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + class PCLPointCloudSerializer; + typedef std::shared_ptr<PCLPointCloudSerializer> AronPCLPointCloudTypeCppSerializerPtr; + + class PCLPointCloudSerializer : + virtual public Serializer + { + public: + using PointerType = AronPCLPointCloudTypeCppSerializerPtr; + + public: + // constructors + PCLPointCloudSerializer(const typenavigator::PCLPointCloudNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::PCLPointCloudNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7039894e985935fb8fb38e0d97fc10af7f7bd85 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.cpp @@ -0,0 +1,109 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Pose.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + PoseSerializer::PoseSerializer(const typenavigator::PoseNavigatorPtr& n) : + Serializer("Eigen::Matrix<" + n->getTypename() + ", " + simox::alg::to_string(n->getDimensions(), ", ") + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronPose))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> PoseSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> PoseSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr PoseSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr PoseSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr PoseSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr PoseSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePose();"); + return b; + } + + CppBlockPtr PoseSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePose();"); + return b; + } + + CppBlockPtr PoseSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + simox::alg::to_string(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr PoseSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_type = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + accessor_dimensions + ", " + accessor_type + "] = r.readStartNDArray();"); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr PoseSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + ".isApprox(" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.h new file mode 100644 index 0000000000000000000000000000000000000000..567b4f1ef970f2084c7b032074808438d3d27e5d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Pose.h @@ -0,0 +1,69 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + class PoseSerializer; + typedef std::shared_ptr<PoseSerializer> AronPoseTypeCppSerializerPtr; + + class PoseSerializer : + virtual public Serializer + { + public: + using PointerType = AronPoseTypeCppSerializerPtr; + + public: + // constructors + PoseSerializer(const typenavigator::PoseNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::PoseNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4bb664d2ece7171047ca837e1642a45250de19cf --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.cpp @@ -0,0 +1,109 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Position.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + PositionSerializer::PositionSerializer(const typenavigator::PositionNavigatorPtr& n) : + Serializer("Eigen::Matrix<" + n->getTypename() + ", " + simox::alg::to_string(n->getDimensions(), ", ") + ">", simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronPosition))), + typenavigator(n) + { + } + + std::vector<CppFieldPtr> PositionSerializer::getPublicVariableDeclarations(const std::string& name) const + { + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); + return {field}; + } + + std::vector<std::pair<std::string, std::string>> PositionSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr PositionSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr PositionSerializer::getResetBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr PositionSerializer::getInitializeBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + return b; + } + + CppBlockPtr PositionSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePosition();"); + return b; + } + + CppBlockPtr PositionSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePosition();"); + return b; + } + + CppBlockPtr PositionSerializer::getWriteBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeNDArray({" + simox::alg::to_string(typenavigator->getDimensions(), ", ") + "}, \"" + typenavigator->getTypename() + "\", reinterpret_cast<const unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr PositionSerializer::getReadBlock(const std::string& accessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + std::string escaped_accessor = EscapeAccessor(accessor); + std::string accessor_dimensions = escaped_accessor + DIMENSION_ACCESSOR; + std::string accessor_type = escaped_accessor + TYPE_ACCESSOR; + + b->addLine("const auto [" + accessor_dimensions + ", " + accessor_type + "] = r.readStartNDArray();"); + b->addLine(accessor + " = " + getFullCppTypename() + "();"); + b->addLine("r.readEndNDArray(reinterpret_cast<unsigned char*>(" + accessor + ".data()));"); + return b; + } + + CppBlockPtr PositionSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (" + accessor + ".isApprox(" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.h new file mode 100644 index 0000000000000000000000000000000000000000..94b9317e0921c8d1e9c1985eb0060d6427ddfeaa --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/ndarray/Position.h @@ -0,0 +1,69 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + class PositionSerializer; + typedef std::shared_ptr<PositionSerializer> AronPositionTypeCppSerializerPtr; + + class PositionSerializer : + virtual public Serializer + { + public: + using PointerType = AronPositionTypeCppSerializerPtr; + + public: + // constructors + PositionSerializer(const typenavigator::PositionNavigatorPtr&); + + // virtual implementations + virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const override; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + static constexpr const char* DIMENSION_ACCESSOR = "_dimensions"; + static constexpr const char* TYPE_ACCESSOR = "_type"; + + typenavigator::PositionNavigatorPtr typenavigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.cpp similarity index 54% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.cpp rename to source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.cpp index 8e96c5e6cd4edbb4497189e1b1723709467aec49..28c002f1ccb06aa6e9484df1c15c40c2c9e55615 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.cpp +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.cpp @@ -27,89 +27,92 @@ #include <map> // Header -#include "AronPrimitiveTypeCppSerializer.h" +#include "Primitive.h" -namespace armarx +namespace armarx::aron::cppcodegenerator::serializer { - namespace aron + + namespace { - namespace codegeneration + std::string convertStdString(const std::string& s) { - namespace classwriter + if (s == "string") { - namespace cppSerializer - { - -#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + return "std::string"; + } + return s; + } + } +#define RUN_ARON_MACRO(upperType, lowerType, capsType, upperData, lowerData, capsData) \ /* constructors */ \ - Aron##upperType##TypeCppSerializer::Aron##upperType##TypeCppSerializer(const typenavigator::Aron##upperType##TypeNavigatorPtr& e) : \ - AronTypeCppSerializer(simox::meta::get_type_name(typeid(lowerType)), simox::meta::get_type_name(typeid(data::Aron##upperType)), simox::meta::get_type_name(typeid(type::Aron##upperType##Type))), \ + upperType##Serializer::upperType##Serializer(const typenavigator::upperType##NavigatorPtr& e) : \ + Serializer(convertStdString(#lowerData), simox::meta::get_type_name(typeid(data::Aron##upperData)), simox::meta::get_type_name(typeid(type::Aron##upperType))), \ typenavigator(e) \ { \ \ } \ \ /* virtual implementations */ \ - std::vector<CppFieldPtr> Aron##upperType##TypeCppSerializer::getPublicVariableDeclarations(const std::string& name) const \ + std::vector<CppFieldPtr> upperType##Serializer::getPublicVariableDeclarations(const std::string& name) const \ { \ - CppFieldPtr field = CppFieldPtr(new CppField(getCppTypename(), name)); \ + CppFieldPtr field = CppFieldPtr(new CppField(getFullCppTypename(), name)); \ return {field}; \ } \ \ - std::vector<std::pair<std::string, std::string>> Aron##upperType##TypeCppSerializer::getCtorInitializers(const std::string&) const \ + std::vector<std::pair<std::string, std::string>> upperType##Serializer::getCtorInitializers(const std::string&) const \ { \ return {}; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getCtorBlock(const std::string&) const \ + CppBlockPtr upperType##Serializer::getCtorBlock(const std::string&) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getResetBlock(const std::string& accessor) const \ + CppBlockPtr upperType##Serializer::getResetBlock(const std::string& accessor) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ b->addLine(accessor + " = {};"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getInitializeBlock(const std::string& accessor) const \ + CppBlockPtr upperType##Serializer::getInitializeBlock(const std::string& accessor) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ b->addLine(accessor + " = {};"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getWriteInitialTypeBlock(const std::string&) const \ + CppBlockPtr upperType##Serializer::getWriteInitialTypeBlock(const std::string&) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ - b->addLine("w.write" + std::string(#upperType) + "Type();"); \ + b->addLine("w.write" + std::string(#upperType) + "();"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getWriteCurrentTypeBlock(const std::string&) const \ + CppBlockPtr upperType##Serializer::getWriteCurrentTypeBlock(const std::string&) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ - b->addLine("w.write" + std::string(#upperType) + "Type();"); \ + b->addLine("w.write" + std::string(#upperType) + "();"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getWriteBlock(const std::string& accessor) const \ + CppBlockPtr upperType##Serializer::getWriteBlock(const std::string& accessor) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ b->addLine("w.writePrimitive(" + accessor + ");"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getReadBlock(const std::string& accessor) const \ + CppBlockPtr upperType##Serializer::getReadBlock(const std::string& accessor) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ b->addLine("r.readPrimitive("+accessor+");"); \ return b; \ } \ \ - CppBlockPtr Aron##upperType##TypeCppSerializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const \ + CppBlockPtr upperType##Serializer::getEqualsBlock(const std::string& accessor, const std::string& otherInstanceAccessor) const \ { \ CppBlockPtr b = CppBlockPtr(new CppBlock()); \ b->addLine("if (not (" + accessor + " == " + otherInstanceAccessor + "))"); \ @@ -117,10 +120,6 @@ namespace armarx return b; \ } - HANDLE_PRIMITIVE_TYPES + HANDLE_PRIMITIVE_CORRESPONDING #undef RUN_ARON_MACRO - } - } - } - } } diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.h similarity index 71% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.h rename to source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.h index 5abc26edd72cdf103238fa35d088f150a9710468..c1ff77cebfe61356f501c48a6bfbad1e601e981b 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/codeWriters/cppWriter/typeSerializers/AronPrimitiveTypeCppSerializer.h +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/primitive/Primitive.h @@ -27,36 +27,28 @@ #include <string> // Base Class -#include "AronTypeCppSerializer.h" +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> // ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> -namespace armarx +namespace armarx::aron::cppcodegenerator::serializer { - namespace aron - { - namespace codegeneration - { - namespace classwriter - { - namespace cppSerializer - { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeCppSerializer; \ - typedef std::shared_ptr<Aron##upperType##TypeCppSerializer> Aron##upperType##TypeCppSerializerPtr; \ + class upperType##Serializer; \ + typedef std::shared_ptr<upperType##Serializer> upperType##SerializerPtr; \ \ - class Aron##upperType##TypeCppSerializer : \ - virtual public AronTypeCppSerializer \ + class upperType##Serializer : \ + virtual public Serializer \ { \ public: \ - using PointerType = Aron##upperType##TypeCppSerializerPtr; \ + using PointerType = upperType##SerializerPtr; \ \ public: \ /* constructors */ \ - Aron##upperType##TypeCppSerializer(const typenavigator::Aron##upperType##TypeNavigatorPtr& e); \ + upperType##Serializer(const typenavigator::upperType##NavigatorPtr& e); \ \ /* virtual implementations */ \ virtual std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string& name) const override; \ @@ -72,13 +64,9 @@ namespace armarx \ private: \ /* members */ \ - typenavigator::Aron##upperType##TypeNavigatorPtr typenavigator; \ + typenavigator::upperType##NavigatorPtr typenavigator; \ }; HANDLE_PRIMITIVE_TYPES #undef RUN_ARON_MACRO - } - } - } - } } diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9d22766cf2f51e163758c27c962661a3cb6758f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.cpp @@ -0,0 +1,258 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "IntEnumClass.h" + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + IntEnumClassSerializer::IntEnumClassSerializer(const typenavigator::IntEnumNavigatorPtr& n) : + Serializer(n->getEnumName(), simox::meta::get_type_name(typeid(data::AronNDArray)), simox::meta::get_type_name(typeid(type::AronIntEnum))), + navigator(n), + enumName("__ImplEnum") + { + } + + std::vector<CppFieldPtr> IntEnumClassSerializer::getPublicVariableDeclarations(const std::string&) const + { + std::vector<CppFieldPtr> fields; + std::stringstream enum_to_name; + std::stringstream name_to_enum; + std::stringstream enum_to_value; + std::stringstream value_to_enum; + + enum_to_name << "{" << std::endl; + name_to_enum << "{" << std::endl; + enum_to_value << "{" << std::endl; + value_to_enum << "{" << std::endl; + for (const auto& [key, value] : navigator->getAcceptedValues()) + { + std::string enumKeyWithNamespace = enumName + "::" + key; + fields.push_back(std::make_shared<CppField>("const static " + enumName, key + " = " + enumKeyWithNamespace)); + + enum_to_name << "\t\t{" << enumKeyWithNamespace << ", \"" << key << "\"}," << std::endl; + name_to_enum << "\t\t{\"" << key << "\", " << enumKeyWithNamespace << "}," << std::endl; + + enum_to_value << "\t\t{" << enumKeyWithNamespace << ", " << value << "}," << std::endl; + value_to_enum << "\t\t{" << value << ", " << enumKeyWithNamespace << "}," << std::endl; + } + + enum_to_name << "\t}"; + name_to_enum << "\t}"; + enum_to_value << "\t}"; + value_to_enum << "\t}"; + + fields.push_back(std::make_shared<CppField>("const std::map<" + enumName + ", std::string>", "EnumToStringMap", enum_to_name.str())); + fields.push_back(std::make_shared<CppField>("const std::map<std::string, " + enumName + ">", "StringToEnumMap", name_to_enum.str())); + fields.push_back(std::make_shared<CppField>("const std::map<" + enumName + ", int>", "EnumToValueMap", enum_to_value.str())); + fields.push_back(std::make_shared<CppField>("const std::map<int, " + enumName + ">", "ValueToEnumMap", value_to_enum.str())); + + fields.push_back(std::make_shared<CppField>(enumName, "value")); + + return fields; + } + + std::vector<std::pair<std::string, std::string>> IntEnumClassSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr IntEnumClassSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getResetBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("value = {};"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeInt();"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writeInt();"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getInitializeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("value = {};"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getWriteBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("w.writePrimitive(EnumToValueMap.at(value));"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getReadBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("int temporary;"); + b->addLine("r.readPrimitive(temporary);"); + b->addLine("value = ValueToEnumMap.at(temporary);"); + return b; + } + + CppBlockPtr IntEnumClassSerializer::getEqualsBlock(const std::string&, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + b->addLine("if (not (value == " + otherInstanceAccessor + ".value))"); + b->addLine("\t return false;"); + return b; + } + + + CppCtorPtr IntEnumClassSerializer::toCopyCtor(const std::string& name) const + { + CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + getFullCppTypename() + "& i)"); + std::vector<std::pair<std::string, std::string>> initList = {{"value", "i.value"}}; + c->addInitListEntries(initList); + return c; + } + + CppCtorPtr IntEnumClassSerializer::toInnerEnumCtor(const std::string& name) const + { + CppCtorPtr c = std::make_shared<CppCtor>(name + "(const " + enumName + " e)"); + std::vector<std::pair<std::string, std::string>> initList = {{"value", "e"}}; + c->addInitListEntries(initList); + return c; + } + + CppEnumPtr IntEnumClassSerializer::toInnerEnumDefinition() const + { + CppEnumPtr e = std::make_shared<CppEnum>(enumName, "The internal enum definition of the enum of this autogenerated class."); + for (const auto& [key, value] : navigator->getAcceptedValues()) + { + e->addField(std::make_shared<CppEnumField>(key)); + } + return e; + } + + CppMethodPtr IntEnumClassSerializer::toIntMethod() const + { + std::stringstream doc; + doc << "@brief int() - Converts the internally stored value to int representation \n"; + doc << "@return - the int representation"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("operator int() const", doc.str())); + CppBlockPtr b = std::make_shared<CppBlock>(); + b->addLine("return EnumToValueMap.at(value);"); + m->setBlock(b); + return m; + } + + CppMethodPtr IntEnumClassSerializer::toCopyAssignmentMethod() const + { + std::stringstream doc; + doc << "@brief operator=() - Assignment operator for copy \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void operator=(" + getFullCppTypename() + "& c)", doc.str())); + CppBlockPtr b = std::make_shared<CppBlock>(); + b->addLine("value = c.value;"); + m->setBlock(b); + return m; + } + + CppMethodPtr IntEnumClassSerializer::toEnumAssignmentMethod() const + { + std::stringstream doc; + doc << "@brief operator=() - Assignment operator for the internally defined enum \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void operator=(" + enumName + " v)", doc.str())); + CppBlockPtr b = std::make_shared<CppBlock>(); + b->addLine("value = v;"); + m->setBlock(b); + return m; + } + + CppMethodPtr IntEnumClassSerializer::toIntAssignmentMethod() const + { + std::stringstream doc; + doc << "@brief operator=() - Assignment operator for the internally defined enum \n"; + doc << "@return - nothing"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("void 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) + \"'\");"); + b->addBlock(b2); + b->addLine("else"); + CppBlockPtr b3 = std::make_shared<CppBlock>(); + b3->addLine("value = it->second;"); + b->addBlock(b3); + m->setBlock(b); + return m; + } + + CppMethodPtr IntEnumClassSerializer::toToStringMethod() const + { + std::stringstream doc; + doc << "@brief toString() - Converts the internally stored value to string \n"; + doc << "@return - the name of the enum"; + + CppMethodPtr m = CppMethodPtr(new CppMethod("std::string toString() const", doc.str())); + CppBlockPtr b = std::make_shared<CppBlock>(); + b->addLine("return EnumToStringMap.at(value);"); + m->setBlock(b); + return m; + } + + CppMethodPtr IntEnumClassSerializer::toFromStringMethod() const + { + std::stringstream doc; + 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())); + 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 + \"'\");"); + b->addBlock(b2); + b->addLine("else"); + CppBlockPtr b3 = std::make_shared<CppBlock>(); + b3->addLine("value = it->second;"); + b->addBlock(b3); + + m->setBlock(b); + return m; + } +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.h new file mode 100644 index 0000000000000000000000000000000000000000..5e7d3875fe29a4f10e15fb7123fecf33276e19d1 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/IntEnumClass.h @@ -0,0 +1,81 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h> + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class IntEnumClassSerializer; + typedef std::shared_ptr<IntEnumClassSerializer> IntEnumClassSerializerPtr; + + class IntEnumClassSerializer : + virtual public Serializer + { + public: + using PointerType = IntEnumClassSerializerPtr; + + public: + // constructors + IntEnumClassSerializer(const typenavigator::IntEnumNavigatorPtr&); + + // virtual implementations + std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + CppCtorPtr toCopyCtor(const std::string&) const; + CppCtorPtr toInnerEnumCtor(const std::string&) const; + CppEnumPtr toInnerEnumDefinition() const; + CppMethodPtr toIntMethod() const; + CppMethodPtr toCopyAssignmentMethod() const; + CppMethodPtr toEnumAssignmentMethod() const; + CppMethodPtr toIntAssignmentMethod() const; + CppMethodPtr toToStringMethod() const; + CppMethodPtr toFromStringMethod() const; + + private: + // Members + static const std::map<std::string, std::pair<std::string, int>> ACCEPTED_TYPES; + + typenavigator::IntEnumNavigatorPtr navigator; + std::string enumName; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..25abfc6f9c848d3e78dbcb67e738ac80d2f8672b --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.cpp @@ -0,0 +1,199 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "ObjectClass.h" + + +namespace armarx::aron::cppcodegenerator::serializer +{ + // constructors + ObjectClassSerializer::ObjectClassSerializer(const typenavigator::ObjectNavigatorPtr& e) : + Serializer(e->getObjectName(), simox::meta::get_type_name(typeid(data::AronDict)), simox::meta::get_type_name(typeid(type::AronObject))), + navigator(e) + { + //AddObjectTypeToAllObjectTypesList(ObjectNavigatorPtr(this)); + } + + std::vector<CppFieldPtr> ObjectClassSerializer::getPublicVariableDeclarations(const std::string&) const + { + std::vector<CppFieldPtr> fields; + for (const auto& [key, member] : navigator->getMemberTypes()) + { + auto member_s = FromAronTypeNaviagtorPtr(member); + std::vector<CppFieldPtr> member_fields = member_s->getPublicVariableDeclarations(key); + fields.insert(fields.end(), member_fields.begin(), member_fields.end()); + } + return fields; + } + + std::vector<std::pair<std::string, std::string>> ObjectClassSerializer::getCtorInitializers(const std::string&) const + { + return {}; + } + + CppBlockPtr ObjectClassSerializer::getCtorBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + return b; + } + + CppBlockPtr ObjectClassSerializer::getResetBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::reset();"); + } + + for (const auto& [key, child] : navigator->getMemberTypes()) + { + auto child_s = FromAronTypeNaviagtorPtr(child); + CppBlockPtr b2 = child_s->getResetBlock(key); + b->appendBlock(b2); + } + return b; + } + + CppBlockPtr ObjectClassSerializer::getInitializeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::initialize();"); + } + + for (const auto& [key, child] : navigator->getMemberTypes()) + { + const auto child_s = FromAronTypeNaviagtorPtr(child); + CppBlockPtr b2 = child_s->getInitializeBlock(key); + b->appendBlock(b2); + } + return b; + } + + CppBlockPtr ObjectClassSerializer::getWriteInitialTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::writeInitialType(w);"); + } + + b->addLine("w.writeStartObject(\"" + navigator->getObjectName() + "\");"); + for (const auto& [key, child] : navigator->getMemberTypes()) + { + const auto child_s = FromAronTypeNaviagtorPtr(child); + b->addLine("w.writeKey(\"" + key + "\");"); + CppBlockPtr b2 = child_s->getWriteInitialTypeBlock(child_s->getFullCppTypename()); + b->appendBlock(b2); + } + b->addLine("w.writeEndObject();"); + return b; + } + + CppBlockPtr ObjectClassSerializer::getWriteCurrentTypeBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::writeCurrentType(w);"); + } + + b->addLine("w.writeStartObject(\"" + navigator->getObjectName() + "\");"); + for (const auto& [key, child] : navigator->getMemberTypes()) + { + const auto child_s = FromAronTypeNaviagtorPtr(child); + b->addLine("w.writeKey(\"" + key + "\");"); + CppBlockPtr b2 = child_s->getWriteCurrentTypeBlock(key); + b->appendBlock(b2); + } + b->addLine("w.writeEndObject();"); + return b; + } + + CppBlockPtr ObjectClassSerializer::getWriteBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::write(w, aron_type);"); + } + + b->addLine("w.writeStartDict();"); + for (const auto& [key, child] : navigator->getMemberTypes()) + { + const auto child_s = FromAronTypeNaviagtorPtr(child); + b->addLine("w.writeKey(\"" + key + "\");"); + CppBlockPtr b2 = child_s->getWriteBlock(key); + b->appendBlock(b2); + } + b->addLine("w.writeEndDict();"); + return b; + } + + CppBlockPtr ObjectClassSerializer::getReadBlock(const std::string&) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine(extends_s->getFullCppTypename() + "::read(r);"); + } + + b->addLine("r.readStartDict();"); + for (const auto& [key, child] : navigator->getMemberTypes()) + { + const auto child_s = FromAronTypeNaviagtorPtr(child); + b->addLine("r.loadMember(\"" + key + "\");"); + CppBlockPtr b2 = child_s->getReadBlock(key); + b->appendBlock(b2); + } + b->addLine("r.readEndDict();"); + return b; + } + + CppBlockPtr ObjectClassSerializer::getEqualsBlock(const std::string&, const std::string& otherInstanceAccessor) const + { + CppBlockPtr b = CppBlockPtr(new CppBlock()); + if (navigator->getExtends() != nullptr) + { + const auto extends_s = FromAronTypeNaviagtorPtr(navigator->getExtends()); + b->addLine("if (not (" + extends_s->getFullCppTypename() + "::operator== (" + otherInstanceAccessor + ")))"); + b->addLine("\t return false;"); + } + for (const auto& [key, child] : navigator->getMemberTypes()) + { + auto child_s = FromAronTypeNaviagtorPtr(child); + CppBlockPtr b2 = child_s->getEqualsBlock(key, otherInstanceAccessor + "." + key); + b->appendBlock(b2); + } + return b; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.h b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.h new file mode 100644 index 0000000000000000000000000000000000000000..7b996cb7625ab2968d515cb0db05060a85e0ce60 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/toplevel/ObjectClass.h @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/codeWriter/cpp/serializer/Serializer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + + +namespace armarx::aron::cppcodegenerator::serializer +{ + + class ObjectClassSerializer; + typedef std::shared_ptr<ObjectClassSerializer> ObjectClassSerializerPtr; + + class ObjectClassSerializer : + virtual public Serializer + { + public: + using PointerType = ObjectClassSerializerPtr; + + public: + // constructors + ObjectClassSerializer(const typenavigator::ObjectNavigatorPtr&); + + // virtual implementations + std::vector<CppFieldPtr> getPublicVariableDeclarations(const std::string&) const; + virtual std::vector<std::pair<std::string, std::string>> getCtorInitializers(const std::string&) const override; + virtual CppBlockPtr getCtorBlock(const std::string&) const override; + virtual CppBlockPtr getWriteInitialTypeBlock(const std::string&) const override; + virtual CppBlockPtr getWriteCurrentTypeBlock(const std::string&) const override; + virtual CppBlockPtr getInitializeBlock(const std::string&) const override; + virtual CppBlockPtr getResetBlock(const std::string&) const override; + virtual CppBlockPtr getWriteBlock(const std::string&) const override; + virtual CppBlockPtr getReadBlock(const std::string&) const override; + virtual CppBlockPtr getEqualsBlock(const std::string&, const std::string&) const override; + + private: + // members + static constexpr const char* EXTENDS_ITERATOR_ACCESSOR = "_extends"; + + typenavigator::ObjectNavigatorPtr navigator; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/Reader.h b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/Reader.h new file mode 100644 index 0000000000000000000000000000000000000000..c65d64893b4ecc86f2c5b97a7bc7be5cdbb18ff0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/Reader.h @@ -0,0 +1,88 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <filesystem> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/codegenerator/ReaderInfo.h> +#include <RobotAPI/libraries/aron/core/codegenerator/WriterInfo.h> +#include <RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h> + +namespace armarx::aron::typereader +{ + template <typename Input> + class Reader; + + template <typename Input> + using ReaderPtr = std::shared_ptr<Reader<Input>>; + + template <typename Input> + class Reader + { + public: + Reader() = default; + + virtual void parseFile(const std::string& filename) = 0; + virtual void parseFile(const std::filesystem::path& file) = 0; + + std::vector<std::string> getCodeIncludes() const + { + return codeIncludes; + } + std::vector<std::string> getAronIncludes() const + { + return aronIncludes; + } + std::vector<codegeneratorhelper::WriterInfoPtr> getWriters() const + { + return writers; + } + std::vector<codegeneratorhelper::ReaderInfoPtr> getReaders() const + { + return readers; + } + std::vector<codegeneratorhelper::GenerateObjectInfoPtr> getGenerateObjects() const + { + return generateObjects; + } + std::vector<codegeneratorhelper::GenerateIntEnumInfoPtr> getGenerateIntEnums() const + { + return generateIntEnums; + } + + protected: + std::vector<std::string> alreadyParsedXMLFiles; + + std::vector<std::string> codeIncludes; + std::vector<std::string> aronIncludes; + std::vector<codegeneratorhelper::ReaderInfoPtr> readers; + std::vector<codegeneratorhelper::WriterInfoPtr> writers; + std::vector<codegeneratorhelper::GenerateIntEnumInfoPtr> generateIntEnums; + std::vector<codegeneratorhelper::GenerateObjectInfoPtr> generateObjects; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.cpp @@ -0,0 +1 @@ + diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h new file mode 100644 index 0000000000000000000000000000000000000000..2f152c9e4d1d2925d8a0c5848f9529458b666604 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h @@ -0,0 +1,161 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <map> + +// ArmarX +#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> + +#include <RobotAPI/libraries/aron/core/Concepts.h> + +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + + +namespace armarx::aron::xmltypereader +{ + class Data + { + private: + Data() = delete; + + public: + // Definition tags + static constexpr const char* TYPE_DEFINITION_TAG = "arontypedefinition"; + + static constexpr const char* CODE_INCLUDES_TAG = "codeincludes"; + static constexpr const char* INCLUDES_TAG = "aronincludes"; + static constexpr const char* GENERATE_TYPES_TAG = "generatetypes"; + + static constexpr const char* INCLUDE_TAG = "include"; + static constexpr const char* GENERATE_OBJECT_TAG = "object"; + static constexpr const char* GENERATE_INT_ENUM_TAG = "intenum"; + + // Attribute names + static constexpr const char* METHOD_ATTRIBUTE_NAME = "method"; + static constexpr const char* RETURN_ATTRIBUTE_NAME = "return"; + static constexpr const char* ARGUMENT_TYPE_ATTRIBUTE_NAME = "argumenttype"; + static constexpr const char* INCLUDE_ATTRIBUTE_NAME = "include"; + static constexpr const char* READER_ATTRIBUTE_NAME = "reader"; + static constexpr const char* WRITER_ATTRIBUTE_NAME = "writer"; + static constexpr const char* EXTENDS_ATTRIBUTE_NAME = "extends"; + static constexpr const char* NAME_ATTRIBUTE_NAME = "name"; + static constexpr const char* VALUE_ATTRIBUTE_NAME = "value"; + static constexpr const char* KEY_ATTRIBUTE_NAME = "key"; + static constexpr const char* TYPE_ATTRIBUTE_NAME = "type"; + static constexpr const char* WIDTH_ATTRIBUTE_NAME = "width"; + static constexpr const char* HEIGHT_ATTRIBUTE_NAME = "height"; + static constexpr const char* ROWS_ATTRIBUTE_NAME = "rows"; + static constexpr const char* COLS_ATTRIBUTE_NAME = "cols"; + static constexpr const char* DIMENSIONS_ATTRIBUTE_NAME = "dimensions"; + + // Second level tags. Only important if in specific top level tag + static constexpr const char* OBJECT_CHILD_TAG = "objectchild"; + static constexpr const char* ENUM_VALUE_TAG = "enumvalue"; + + // Top Level type tags +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + static constexpr const char* GENERATE_##capsType##_MEMBER_TAG = #lowerType; + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + + static void EnforceAttribute(const RapidXmlReaderNode& node, const std::string& att) + { + if (!HasAttribute(node, att)) + { + throw error::StringNotValidException("XMLReaderData", "EnforceAttribute", "A <" + node.name() + ">-tag does not have the correct attribute", att); + } + } + + static bool HasAttribute(const RapidXmlReaderNode& node, const std::string& att) + { + return node.has_attribute(att.c_str()); + } + + static std::string GetAttribute(const RapidXmlReaderNode& node, const std::string& att) + { + EnforceAttribute(node, att); + return node.attribute_value(att.c_str()); + } + + static std::string GetAttributeWithDefault(const RapidXmlReaderNode& node, const std::string& att, const std::string def) + { + if (!(HasAttribute(node, att))) + { + return def; + } + return node.attribute_value(att.c_str()); + } + + static bool HasTagName(const RapidXmlReaderNode& node, const std::string& name) + { + return (simox::alg::to_lower(name) == simox::alg::to_lower(node.name())); + } + + static void EnforceTagName(const RapidXmlReaderNode& node, const std::string& name) + { + if (!(HasTagName(node, name))) + { + throw error::StringNotValidException("XMLReaderData", "EnforceTagName", "The node <" + node.name() + "> has the wrong tag", name); + } + } + + static std::string GetTagName(const RapidXmlReaderNode& node) + { + return simox::alg::to_lower(node.name()); + } + + static bool CheckMinChildSize(const RapidXmlReaderNode& node, const size_t size) + { + std::vector<RapidXmlReaderNode> children = node.nodes(); + return children.size() >= size; + } + + static bool CheckMaxChildSize(const RapidXmlReaderNode& node, const size_t size) + { + std::vector<RapidXmlReaderNode> children = node.nodes(); + return children.size() <= size; + } + + static bool CheckExactChildSize(const RapidXmlReaderNode& node, const size_t size) + { + std::vector<RapidXmlReaderNode> children = node.nodes(); + return children.size() == size; + } + + static void EnforceChildSize(const RapidXmlReaderNode& node, const size_t size) + { + if (!Data::CheckExactChildSize(node, size)) + { + throw error::SizeNotValidException("XMLReaderData", "EnforceChildSize", "The node <" + node.name() + "> has the wrong number of children", node.nodes().size(), size); + } + } + }; +} diff --git a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp similarity index 55% rename from source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.cpp rename to source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp index ae4efcea13c7552bd6735f3ee4c134aa3a5b87a4..6bf00c8db81a9bd61b579d760b6b250f47544537 100644 --- a/source/RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLReader.cpp +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp @@ -25,43 +25,37 @@ // Header -#include "AronTypeXMLReader.h" +#include "Reader.h" // ArmarX #include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> -#include <RobotAPI/libraries/aron/aroncore/codegenerator/typeReaders/xmlReader/AronTypeXMLData.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h> +#include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> -namespace armarx -{ - namespace aron - { - namespace codegeneration - { - namespace typereader +namespace armarx::aron::xmltypereader { - void AronTypeXMLReader::parseFile(const std::string& filename) + void Reader::parseFile(const std::string& filename) { RapidXmlReaderPtr reader = RapidXmlReader::FromFile(filename); parse(reader); } - void AronTypeXMLReader::parseFile(const std::filesystem::path& file) + void Reader::parseFile(const std::filesystem::path& file) { RapidXmlReaderPtr reader = RapidXmlReader::FromFile(file.string()); parse(reader); } // private method reading nodes - void AronTypeXMLReader::parse(const RapidXmlReaderPtr& reader) + void Reader::parse(const RapidXmlReaderPtr& reader) { RapidXmlReaderNode root = reader->getRoot(); // Check Header - AronTypeXMLReaderData::EnforceTagName(root, AronTypeXMLReaderData::ARON_TYPE_DEFINITION_TAG); + Data::EnforceTagName(root, Data::TYPE_DEFINITION_TAG); - AronTypeXMLReaderData::CheckMaxChildSize(root, 4); + Data::CheckMaxChildSize(root, 4); std::vector<RapidXmlReaderNode> children = root.nodes(); int cpp_includes_index = -1; @@ -71,33 +65,33 @@ namespace armarx int index = 0; for (const auto& child : children) { - if (AronTypeXMLReaderData::HasTagName(child, AronTypeXMLReaderData::ARON_CODE_INCLUDES_TAG)) + if (Data::HasTagName(child, Data::CODE_INCLUDES_TAG)) { if (cpp_includes_index != -1) { - throw exception::AronException("AronTypeXMLReader", "parse", "Already found an include tag. Please check the xml file."); + throw error::AronException("XMLReader", "parse", "Already found an include tag. Please check the xml file."); } else { cpp_includes_index = index; } } - else if (AronTypeXMLReaderData::HasTagName(child, AronTypeXMLReaderData::ARON_ARON_INCLUDES_TAG)) + else if (Data::HasTagName(child, Data::INCLUDES_TAG)) { if (include_aron_file_index != -1) { - throw exception::AronException("AronTypeXMLReader", "parse", "Already found an use type tag. Please check the xml file."); + throw error::AronException("XMLReader", "parse", "Already found an use type tag. Please check the xml file."); } else { include_aron_file_index = index; } } - else if (AronTypeXMLReaderData::HasTagName(child, AronTypeXMLReaderData::ARON_GENERATE_TYPES_TAG)) + else if (Data::HasTagName(child, Data::GENERATE_TYPES_TAG)) { if (generate_types_index != -1) { - throw exception::AronException("AronTypeXMLReader", "parse", "Already found an generate type tag. Please check the xml file."); + throw error::AronException("XMLReader", "parse", "Already found an generate type tag. Please check the xml file."); } else { @@ -106,7 +100,7 @@ namespace armarx } else { - throw exception::AronStringNotValidException("AronTypeXMLReader", "parse", "Found an unexpected xml tag", child.name()); + throw error::StringNotValidException("XMLReader", "parse", "Found an unexpected xml tag", child.name()); } index++; } @@ -137,41 +131,58 @@ namespace armarx for (const auto& generateType : children[generate_types_index].nodes()) { // ugly workaround - const typenavigator::AronObjectTypeNavigatorPtr aronObj = readGenerateType(generateType); - const std::map<std::string, AronGenerateTypeInfoPtr> generatedObjects = factory.GetAllKnownGeneratedPublicObjects(); - generateTypes.push_back(generatedObjects.at(aronObj->getObjectName())); + if(Data::HasTagName(generateType, Data::GENERATE_OBJECT_TAG)) + { + const auto nav = readGenerateObject(generateType); + const auto infos = factory.AllPublicObjects; + generateObjects.push_back(infos.at(simox::alg::to_lower(nav->getObjectName()))); + continue; + } + if(Data::HasTagName(generateType, Data::GENERATE_INT_ENUM_TAG)) + { + const auto nav = readGenerateIntEnum(generateType); + const auto infos = factory.AllPublicIntEnums; + generateIntEnums.push_back(infos.at(simox::alg::to_lower(nav->getEnumName()))); + continue; + } + throw error::StringNotValidException("XMLReader", "parse", "Could not find a valid tag inside generatetypes", generateType.name()); + } } } - std::string AronTypeXMLReader::readCppInclude(const RapidXmlReaderNode& node) const + std::string Reader::readCppInclude(const RapidXmlReaderNode& node) const { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_INCLUDE_TAG); - AronTypeXMLReaderData::EnforceAttribute(node, AronTypeXMLReaderData::ARON_INCLUDE_ATTRIBUTE_NAME); - const std::string include = node.attribute_value(AronTypeXMLReaderData::ARON_INCLUDE_ATTRIBUTE_NAME.c_str()); + Data::EnforceTagName(node, Data::INCLUDE_TAG); + Data::EnforceAttribute(node, Data::INCLUDE_ATTRIBUTE_NAME); + const std::string include = node.attribute_value(Data::INCLUDE_ATTRIBUTE_NAME); return include; } - std::string AronTypeXMLReader::readAronInclude(const RapidXmlReaderNode& node) const + std::string Reader::readAronInclude(const RapidXmlReaderNode& node) const { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_INCLUDE_TAG); + Data::EnforceTagName(node, Data::INCLUDE_TAG); - const std::string xmlinclude = AronTypeXMLReaderData::GetAttribute(node, AronTypeXMLReaderData::ARON_INCLUDE_ATTRIBUTE_NAME); + const std::string xmlinclude = Data::GetAttribute(node, Data::INCLUDE_ATTRIBUTE_NAME); // parse parent xml file and add objects to alreday known - AronTypeXMLReader anotherReader; + Reader anotherReader; anotherReader.parseFile(xmlinclude); return xmlinclude; } - typenavigator::AronObjectTypeNavigatorPtr AronTypeXMLReader::readGenerateType(const RapidXmlReaderNode& node) const + typenavigator::ObjectNavigatorPtr Reader::readGenerateObject(const RapidXmlReaderNode& node) const + { + Data::EnforceTagName(node, Data::GENERATE_OBJECT_TAG); + return typenavigator::ObjectNavigator::DynamicCastAndCheck(factory.create(node, Path())); + + } + + typenavigator::IntEnumNavigatorPtr Reader::readGenerateIntEnum(const RapidXmlReaderNode& node) const { - AronTypeXMLReaderData::EnforceTagName(node, AronTypeXMLReaderData::ARON_GENERATE_TYPE_TAG); - return typenavigator::AronObjectTypeNavigator::DynamicCast(factory.createSpecific(node, AronPath())); + Data::EnforceTagName(node, Data::GENERATE_INT_ENUM_TAG); + return typenavigator::IntEnumNavigator::DynamicCastAndCheck(factory.create(node, Path())); } - } - } - } } diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h new file mode 100644 index 0000000000000000000000000000000000000000..0801465160e06ddbd0ebfc78b57d8b8bb97eafcd --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.h @@ -0,0 +1,66 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <filesystem> + +// Base Class +#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/Reader.h> + +// ArmarX +#include <SimoxUtility/xml.h> +#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> + +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.h> + +namespace armarx::aron::xmltypereader +{ + class Reader; + typedef std::shared_ptr<Reader> ReaderPtr; + + class Reader : + virtual public typereader::Reader<std::string> + { + public: + Reader() = default; + + virtual void parseFile(const std::string&) override; + virtual void parseFile(const std::filesystem::path&) override; + + private: + void parse(const RapidXmlReaderPtr& node); + + std::string readCppInclude(const RapidXmlReaderNode& node) const; + std::string readAronInclude(const RapidXmlReaderNode& node) const; + + typenavigator::ObjectNavigatorPtr readGenerateObject(const RapidXmlReaderNode& node) const; + typenavigator::IntEnumNavigatorPtr readGenerateIntEnum(const RapidXmlReaderNode& node) const; + + private: + ReaderFactory factory; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da9eff9f25c9ee9478d7c183ae4fde981e21a16f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.cpp @@ -0,0 +1,414 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + +// Simox +#include <SimoxUtility/algorithm/string.h> + +// Header +#include "ReaderFactory.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Data.h> + +namespace armarx::aron::xmltypereader +{ + std::stack<codegeneratorhelper::GenerateObjectInfoPtr> ReaderFactory::ObjectGenerationStack = {}; + std::map<std::string, codegeneratorhelper::GenerateObjectInfoPtr> ReaderFactory::AllPublicObjects = {}; + std::map<std::string, codegeneratorhelper::GenerateIntEnumInfoPtr> ReaderFactory::AllPublicIntEnums = {}; + + + typenavigator::NavigatorPtr ReaderFactory::create(const RapidXmlReaderNode& node, const Path& path) const + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + {Data::GENERATE_##capsType##_MEMBER_TAG, ReaderFactoryPtr(new upperType##ReaderFactory())}, + static const std::map<std::string, ReaderFactoryPtr> Factories = + { + {Data::GENERATE_OBJECT_TAG, ReaderFactoryPtr(new ObjectReaderFactory())}, + {Data::GENERATE_INT_ENUM_TAG, ReaderFactoryPtr(new IntEnumReaderFactory())}, + HANDLE_ALL_ARON_TYPES + }; +#undef RUN_ARON_MACRO + + const std::string tag = simox::alg::to_lower(node.name()); + if (tag == "") + { + throw error::AronException("XMLReaderFactory", "create", "An node is empty. Cannot find facory for empty nodes."); + } + auto factory_iterator = Factories.find(tag); + if (factory_iterator != Factories.end()) + { + return factory_iterator->second->createSpecific(node, path); + } + + // Search for known objects + return ResolveTypename(tag); + } + + typenavigator::NavigatorPtr ReaderFactory::createSpecific(const RapidXmlReaderNode&, const Path& p) const + { + throw error::AronException("ReaderFactory", "createSpecific", "Called disallowed method of an NavigatorFactory. Use child class instead!", p); + } + + typenavigator::NavigatorPtr ReaderFactory::ResolveTypename(const std::string& name) + { + const auto public_intenum_it = AllPublicIntEnums.find(name); + if (public_intenum_it != AllPublicIntEnums.end()) + { + return public_intenum_it->second->correspondingType; + } + + const auto public_obj_it = AllPublicObjects.find(name); + if (public_obj_it != AllPublicObjects.end()) + { + return public_obj_it->second->correspondingType; + } + + throw error::StringNotValidException("XMLReaderFactory", "ResolveTypename", "Could not find a tag. You can only access already finished public objects.", name); + } + + // Object type + typenavigator::NavigatorPtr ObjectReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceAttribute(node, Data::NAME_ATTRIBUTE_NAME); + const std::string extends = Data::GetAttributeWithDefault(node, Data::EXTENDS_ATTRIBUTE_NAME, ""); + const std::string name = Data::GetAttribute(node, Data::NAME_ATTRIBUTE_NAME); + + bool object_is_nested = ObjectGenerationStack.size() > 0; + if (object_is_nested) + { + if (name.rfind("::") != std::string::npos) + { + throw error::StringNotValidException("AronObjectTypeXMLReaderFactory", "createSpecific", "Namespaces are not allowed in nested classes", name, path); + } + } + + // set the new object + auto aronObjectType = std::make_shared<typenavigator::ObjectNavigator>(path); + aronObjectType->setObjectName(name); + + auto newObject = std::make_shared<codegeneratorhelper::GenerateObjectInfo>(); + newObject->typeName = name; + newObject->correspondingType = aronObjectType; + + if (extends != "") + { + auto it = AllPublicObjects.find(extends); + if (it == AllPublicObjects.end()) + { + throw error::StringNotValidException("AronObjectTypeXMLReaderFactory", "createSpecific", "An extends name could not be found. Perhaps you need to change the order of your types or you have to add another UseType", extends, path); + } + codegeneratorhelper::GenerateObjectInfoPtr parentObj = it->second; + aronObjectType->setExtends(parentObj->correspondingType); + } + + ObjectGenerationStack.push(newObject); + for (const RapidXmlReaderNode& objectChild : node.nodes()) + { + Data::EnforceTagName(objectChild, Data::OBJECT_CHILD_TAG); + Data::EnforceChildSize(objectChild, 1); + + Data::EnforceAttribute(objectChild, Data::KEY_ATTRIBUTE_NAME); + const std::string key = objectChild.attribute_value(Data::KEY_ATTRIBUTE_NAME); + + std::vector<RapidXmlReaderNode> children = objectChild.nodes(); + typenavigator::NavigatorPtr childNavigator = create(children[0], Path(path, key)); + aronObjectType->addMemberType(key, childNavigator); + } + ObjectGenerationStack.pop(); + + if (object_is_nested) + { + // We are in a local nested class since there is a parent class in stack + codegeneratorhelper::GenerateObjectInfoPtr parent = ObjectGenerationStack.top(); + parent->nestedObjects.insert(std::make_pair(simox::alg::to_lower(newObject->typeName), newObject)); + } + else + { + // We are a public top level class. Add to AllPublicObjects + AllPublicObjects.insert(std::make_pair(simox::alg::to_lower(newObject->typeName), newObject)); + } + + return aronObjectType; + } + + // List type (List) + typenavigator::NavigatorPtr ListReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_LIST_MEMBER_TAG); + + typenavigator::ListNavigatorPtr list(new typenavigator::ListNavigator(path)); + Data::EnforceChildSize(node, 1); + std::vector<RapidXmlReaderNode> listTypeNodeChildren = node.nodes(); + const RapidXmlReaderNode typeNode = listTypeNodeChildren[0]; + typenavigator::NavigatorPtr type = create(typeNode, Path(path, "type")); + + list->setAcceptedType(type); + return list; + } + + // List type (Dict) + typenavigator::NavigatorPtr DictReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_DICT_MEMBER_TAG); + + typenavigator::DictNavigatorPtr dict(new typenavigator::DictNavigator(path)); + Data::EnforceChildSize(node, 1); + std::vector<RapidXmlReaderNode> dictTypeNodeChildren = node.nodes(); + const RapidXmlReaderNode typeNode = dictTypeNodeChildren[0]; + typenavigator::NavigatorPtr type = create(typeNode, Path(path, "type")); + dict->setAcceptedType(type); + + return dict; + } + + // List type (Tuple) + typenavigator::NavigatorPtr TupleReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_TUPLE_MEMBER_TAG); + std::vector<RapidXmlReaderNode> nodeChildren = node.nodes(); + + if (nodeChildren.size() < 1) + { + throw error::AronException("AronTupleTypeXMLReaderFactory", "createSpecific", "A tuple must have at least one type. Found child nodes size: " + std::to_string(nodeChildren.size())); + } + + typenavigator::TupleNavigatorPtr tuple(new typenavigator::TupleNavigator(path)); + unsigned int i = 0; + for (const RapidXmlReaderNode& tupleTypeDeclarationNode : nodeChildren) + { + Data::EnforceChildSize(tupleTypeDeclarationNode, 1); + + std::vector<RapidXmlReaderNode> typeNodeChildren = tupleTypeDeclarationNode.nodes(); + const RapidXmlReaderNode typeNode = typeNodeChildren[0]; + + typenavigator::NavigatorPtr type = create(typeNode, Path(path, "<" + std::to_string(i++) + ">")); + tuple->addAcceptedType(type); + } + return tuple; + } + + // List type (Pair) + typenavigator::NavigatorPtr PairReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_PAIR_MEMBER_TAG); + std::vector<RapidXmlReaderNode> nodeChildren = node.nodes(); + + if (nodeChildren.size() != 2) + { + throw error::AronException("AronPairTypeXMLReaderFactory", "createSpecific", "A pair must have two types. Found child nodes size: " + std::to_string(nodeChildren.size())); + } + + typenavigator::PairNavigatorPtr pair(new typenavigator::PairNavigator(path)); + + Data::EnforceChildSize(nodeChildren[0], 1); + std::vector<RapidXmlReaderNode> type1NodeChildren = nodeChildren[0].nodes(); + const RapidXmlReaderNode type1Node = type1NodeChildren[0]; + + typenavigator::NavigatorPtr type1 = create(type1Node, Path(path, std::to_string(0))); + pair->setFirstAcceptedType(type1); + + Data::EnforceChildSize(nodeChildren[1], 1); + std::vector<RapidXmlReaderNode> type2NodeChildren = nodeChildren[1].nodes(); + const RapidXmlReaderNode type2Node = type2NodeChildren[0]; + + typenavigator::NavigatorPtr type2 = create(type2Node, Path(path, std::to_string(1))); + pair->setSecondAcceptedType(type2); + + return pair; + } + + // Complex type (IVTCByteImage) + typenavigator::NavigatorPtr IVTCByteImageReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_IVT_CBYTE_IMAGE_MEMBER_TAG); + Data::EnforceAttribute(node, Data::TYPE_ATTRIBUTE_NAME); + + int width = std::stoi(Data::GetAttributeWithDefault(node, Data::WIDTH_ATTRIBUTE_NAME, "1")); + int height = std::stoi(Data::GetAttributeWithDefault(node, Data::HEIGHT_ATTRIBUTE_NAME, "1")); + std::string type = node.attribute_value(Data::TYPE_ATTRIBUTE_NAME);; + + typenavigator::IVTCByteImageNavigatorPtr complex(new typenavigator::IVTCByteImageNavigator(path)); + complex->setWidth(width); + complex->setHeight(height); + complex->setTypename(type); + return complex; + } + + // Complex type (EigenMatrix) + typenavigator::NavigatorPtr EigenMatrixReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_EIGEN_MATRIX_MEMBER_TAG); + Data::EnforceAttribute(node, Data::TYPE_ATTRIBUTE_NAME); + + int rows = std::stoi(Data::GetAttributeWithDefault(node, Data::ROWS_ATTRIBUTE_NAME, "1")); + int cols = std::stoi(Data::GetAttributeWithDefault(node, Data::COLS_ATTRIBUTE_NAME, "1")); + std::string type = node.attribute_value(Data::TYPE_ATTRIBUTE_NAME); + + typenavigator::EigenMatrixNavigatorPtr complex(new typenavigator::EigenMatrixNavigator(path)); + complex->setRows(rows); + complex->setCols(cols); + complex->setTypename(type); + return complex; + } + + // Complex type (EigenQuaternion) + typenavigator::NavigatorPtr EigenQuaternionReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_EIGEN_QUATERNION_MEMBER_TAG); + Data::EnforceAttribute(node, Data::TYPE_ATTRIBUTE_NAME); + + std::string type = node.attribute_value(Data::TYPE_ATTRIBUTE_NAME); + + typenavigator::EigenQuaternionNavigatorPtr complex(new typenavigator::EigenQuaternionNavigator(path)); + complex->setTypename(type); + return complex; + } + + // Complex type (OpenCVMat) + typenavigator::NavigatorPtr OpenCVMatReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_OPENCV_MAT_MEMBER_TAG); + Data::EnforceAttribute(node, Data::TYPE_ATTRIBUTE_NAME); + + std::vector<std::string> dimensions_as_strings = simox::alg::split(Data::GetAttributeWithDefault(node, Data::DIMENSIONS_ATTRIBUTE_NAME, "1"), ","); + std::vector<int> dimensions = simox::alg::to_vec<int>(dimensions_as_strings); + std::string type = node.attribute_value(Data::TYPE_ATTRIBUTE_NAME); + + typenavigator::OpenCVMatNavigatorPtr complex(new typenavigator::OpenCVMatNavigator(path)); + complex->setDimensions(dimensions); + complex->setTypename(type); + return complex; + } + + // Complex type (PCLPointCloud) + typenavigator::NavigatorPtr PCLPointCloudReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_PCL_POINTCLOUD_MEMBER_TAG); + Data::EnforceAttribute(node, Data::TYPE_ATTRIBUTE_NAME); + + int width = std::stoi(Data::GetAttributeWithDefault(node, Data::WIDTH_ATTRIBUTE_NAME, "1")); + int height = std::stoi(Data::GetAttributeWithDefault(node, Data::HEIGHT_ATTRIBUTE_NAME, "1")); + std::string type = node.attribute_value(Data::TYPE_ATTRIBUTE_NAME);; + + typenavigator::PCLPointCloudNavigatorPtr complex(new typenavigator::PCLPointCloudNavigator(path)); + complex->setWidth(width); + complex->setHeight(height); + complex->setTypename(type); + return complex; + } + + // Complex type (Position) + typenavigator::NavigatorPtr PositionReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_POSITION_MEMBER_TAG); + + typenavigator::PositionNavigatorPtr complex(new typenavigator::PositionNavigator(path)); + return complex; + } + + // Complex type (Orientation) + typenavigator::NavigatorPtr OrientationReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_ORIENTATION_MEMBER_TAG); + + typenavigator::OrientationNavigatorPtr complex(new typenavigator::OrientationNavigator(path)); + return complex; + } + + // Complex type (Pose) + typenavigator::NavigatorPtr PoseReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceTagName(node, Data::GENERATE_POSE_MEMBER_TAG); + + typenavigator::PoseNavigatorPtr complex(new typenavigator::PoseNavigator(path)); + return complex; + } + + + + // Enum (IntEnum) + typenavigator::NavigatorPtr IntEnumReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const + { + Data::EnforceAttribute(node, Data::NAME_ATTRIBUTE_NAME); + const std::string name = Data::GetAttribute(node, Data::NAME_ATTRIBUTE_NAME); + + bool enum_is_nested = ObjectGenerationStack.size() > 0; + if (enum_is_nested) + { + if (name.rfind("::") != std::string::npos) + { + throw error::StringNotValidException("IntEnumReaderFactory", "createSpecific", "Namespaces are not allowed in nested enums", name, path); + } + } + + // set the new object + auto aronIntEnumType = std::make_shared<typenavigator::IntEnumNavigator>(path); + aronIntEnumType->setEnumName(name); + + auto newEnumInfo = std::make_shared<codegeneratorhelper::GenerateIntEnumInfo>(); + newEnumInfo->typeName = name; + newEnumInfo->correspondingType = aronIntEnumType; + + for (const RapidXmlReaderNode& objectChild : node.nodes()) + { + Data::EnforceTagName(objectChild, Data::ENUM_VALUE_TAG); + Data::EnforceChildSize(objectChild, 0); + + Data::EnforceAttribute(objectChild, Data::KEY_ATTRIBUTE_NAME); + const std::string key = objectChild.attribute_value(Data::KEY_ATTRIBUTE_NAME); + + Data::EnforceAttribute(objectChild, Data::VALUE_ATTRIBUTE_NAME); + const std::string value = objectChild.attribute_value(Data::VALUE_ATTRIBUTE_NAME); + + aronIntEnumType->addAcceptedValue(key, std::stoi(value)); + } + + if (enum_is_nested) + { + // We are in a local nested class since there is a parent class in stack + codegeneratorhelper::GenerateObjectInfoPtr parent = ObjectGenerationStack.top(); + parent->nestedIntEnums.insert(std::make_pair(simox::alg::to_lower(newEnumInfo->typeName), newEnumInfo)); + } + else + { + // We are a public top level class. Add to AllPublicObjects + AllPublicIntEnums.insert(std::make_pair(simox::alg::to_lower(newEnumInfo->typeName), newEnumInfo)); + } + + return aronIntEnumType; + } + + // Primitve Types +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + typenavigator::NavigatorPtr upperType##ReaderFactory::createSpecific(const RapidXmlReaderNode& node, const Path& path) const \ + { \ + Data::EnforceTagName(node, Data::GENERATE_##capsType##_MEMBER_TAG); \ + return typenavigator::NavigatorPtr(new typenavigator::upperType##Navigator(path)); \ + } + + HANDLE_PRIMITIVE_TYPES +#undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.h b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..dbed99c551c990aedc4ab7546894ad8049387485 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/ReaderFactory.h @@ -0,0 +1,79 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <map> +#include <vector> +#include <stack> + +// Base Class +#include <RobotAPI/libraries/aron/core/Factory.h> + +// ArmarX +#include <ArmarXCore/core/rapidxml/wrapper/RapidXmlReader.h> +#include <RobotAPI/libraries/aron/core/codegenerator/GenerateTypeInfo.h> +#include <RobotAPI/libraries/aron/core/codegenerator/GenerateIntEnumInfo.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + + +namespace armarx::aron::xmltypereader +{ + class ReaderFactory; + typedef std::shared_ptr<ReaderFactory> ReaderFactoryPtr; + + class ReaderFactory : + virtual public aron::Factory<RapidXmlReaderNode, typenavigator::NavigatorPtr> + { + public: + ReaderFactory() = default; + + virtual typenavigator::NavigatorPtr create(const RapidXmlReaderNode&, const Path&) const override; + virtual typenavigator::NavigatorPtr createSpecific(const RapidXmlReaderNode&, const Path&) const override; + + protected: + static typenavigator::NavigatorPtr ResolveTypename(const std::string&); + + public: + static std::map<std::string, codegeneratorhelper::GenerateObjectInfoPtr> AllPublicObjects; + static std::map<std::string, codegeneratorhelper::GenerateIntEnumInfoPtr> AllPublicIntEnums; + + protected: + static std::stack<codegeneratorhelper::GenerateObjectInfoPtr> ObjectGenerationStack; + + }; + + #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##ReaderFactory : \ + virtual public ReaderFactory \ + { \ + public: \ + upperType##ReaderFactory() = default; \ + virtual typenavigator::NavigatorPtr createSpecific(const RapidXmlReaderNode&, const Path&) const override; \ + }; + + HANDLE_ALL_ARON_TYPES + #undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/core/io/Data.h b/source/RobotAPI/libraries/aron/core/io/Data.h new file mode 100644 index 0000000000000000000000000000000000000000..6d29388942067854205998b2c0aaef4e4b74a402 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/Data.h @@ -0,0 +1,62 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <ArmarXCore/core/exceptions/Exception.h> + +#include <RobotAPI/libraries/aron/core/Config.h> + + + +namespace armarx::aron::io +{ + class Data + { + private: + Data() = delete; + + public: + // TODO: Remove copy from ReaderWriter + static constexpr const char* READER_WRITER_NAME_SLUG = "ARON_NAME"; + static constexpr const char* READER_WRITER_DICT_ACCEPTED_TYPE_SLUG = "ARON_DICT_ACCEPTED_TYPE"; + static constexpr const char* READER_WRITER_LIST_ACCEPTED_TYPE_SLUG = "ARON_LIST_ACCEPTED_TYPE"; + + static constexpr const char* READER_WRITER_NDARRAY_NAME_SLUG = "ARON_NDARRAY_NAME"; + static constexpr const char* READER_WRITER_NDARRAY_DIMENSIONS_SLUG = "ARON_NDARRAY_DIMESIONS"; + static constexpr const char* READER_WRITER_NDARRAY_TYPE_SLUG = "ARON_NDARRAY_TYPE"; + static constexpr const char* READER_WRITER_NDARRAY_DATA_SLUG = "ARON_NDARRAY_DATA"; + + static constexpr const char* READER_WRITER_INT_ENUM_NAME_SLUG = "ARON_INT_ENUM_NAME"; + static constexpr const char* READER_WRITER_INT_ENUM_VALUE_SLUG = "ARON_INT_ENUM_VALUE"; + static constexpr const char* READER_WRITER_ENUM_KEY_SLUG = "ARON_ENUM_KEY"; + +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + static constexpr const char* READER_WRITER_##capsType##_TYPENAME_SLUG = #capsType; + + HANDLE_PRIMITIVE_TYPES +#undef RUN_ARON_MACRO + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/Reader.h b/source/RobotAPI/libraries/aron/core/io/dataIO/Reader.h new file mode 100644 index 0000000000000000000000000000000000000000..7df44a015c8f93f531e1e54c8dd2524ae98308d6 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/Reader.h @@ -0,0 +1,69 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <vector> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::dataIO +{ + class ReaderInterface; + typedef std::shared_ptr<ReaderInterface> ReaderInterfacePtr; + + class ReaderInterface + { + public: + virtual int readStartDict() = 0; + virtual bool readEndDict() = 0; + virtual int readStartList() = 0; + virtual bool readEndList() = 0; + + virtual std::tuple<std::vector<int>, std::string> readStartNDArray() = 0; + virtual bool readEndNDArray(unsigned char*) = 0; + + virtual void readPrimitive(int&) = 0; + virtual void readPrimitive(long&) = 0; + virtual void readPrimitive(float&) = 0; + virtual void readPrimitive(double&) = 0; + virtual void readPrimitive(std::string&) = 0; + virtual void readPrimitive(bool&) = 0; + + template<class T> + T readPrimitive() + { + T p; + readPrimitive(p); + return p; + } + + virtual std::string readKey() = 0; + virtual void loadMember(const std::string&) = 0; + + // Helper functions + virtual data::Descriptor getTypeOfNext(const type::Descriptor hint = type::eUnknown) const = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/Writer.h b/source/RobotAPI/libraries/aron/core/io/dataIO/Writer.h new file mode 100644 index 0000000000000000000000000000000000000000..89aca64073cc652b2a72d3da62b7ce0a7c3e76d9 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/Writer.h @@ -0,0 +1,57 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Config.h> + + + +namespace armarx::aron::dataIO +{ + class WriterInterface; + typedef std::shared_ptr<WriterInterface> WriterInterfacePtr; + + class WriterInterface + { + public: + virtual void writeStartDict() = 0; + virtual void writeEndDict() = 0; + virtual void writeStartList() = 0; + virtual void writeEndList() = 0; + + virtual void writeNDArray(const std::vector<int>&, const std::string&, const unsigned char*) = 0; + + virtual void writePrimitive(int) = 0; + virtual void writePrimitive(long) = 0; + virtual void writePrimitive(float) = 0; + virtual void writePrimitive(double) = 0; + virtual void writePrimitive(const std::string&) = 0; + virtual void writePrimitive(bool) = 0; + + virtual void writeKey(const std::string&) = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13b6703cd69bffe9e6c8f89cf4164ada98649bc0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.cpp @@ -0,0 +1,130 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "Converter.h" + +#include <RobotAPI/libraries/aron/core/Debug.h> + + + +namespace armarx::aron::dataIO +{ + void Converter::ConvertFromReader(ReaderInterface& reader, WriterInterface& writer, const aron::typenavigator::NavigatorPtr& expectedStructure) + { + type::Descriptor t_desc = expectedStructure != nullptr ? expectedStructure->getDescriptor() : type::eUnknown; + data::Descriptor desc = reader.getTypeOfNext(t_desc); + switch (desc) + { + case data::eDict: + { + int elements = reader.readStartDict(); + writer.writeStartDict(); + + typenavigator::NavigatorPtr childType = nullptr; + if (t_desc == type::eDict) + { + auto t = typenavigator::DictNavigator::DynamicCast(expectedStructure); + childType = t->getAcceptedType(); + } + + for (int i = 0; i < elements; ++i) + { + std::string key = reader.readKey(); + writer.writeKey(key); + + if (t_desc == type::eObject) + { + auto t = typenavigator::ObjectNavigator::DynamicCast(expectedStructure); + childType = t->getMemberType(key); + } + + Converter::ConvertFromReader(reader, writer, childType); + } + + writer.writeEndDict(); + reader.readEndDict(); + + break; + } + case data::eList: + { + int elements = reader.readStartList(); + writer.writeStartList(); + + typenavigator::NavigatorPtr childType = nullptr; + if (t_desc == type::eList) + { + auto t = typenavigator::ListNavigator::DynamicCast(expectedStructure); + childType = t->getAcceptedType(); + } + + for (int i = 0; i < elements; ++i) + { + if (t_desc == type::eObject) + { + auto t = typenavigator::TupleNavigator::DynamicCast(expectedStructure); + childType = t->getAcceptedType(i); + } + + Converter::ConvertFromReader(reader, writer, childType); + } + + writer.writeEndList(); + reader.readEndList(); + break; + } +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +case data::e##upperType: \ +{ \ + auto [dims, type] = reader.readStart##upperType(); \ + int elements = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); \ + std::vector<unsigned char> data(elements); \ + reader.readEnd##upperType(data.data()); \ + \ + writer.write##upperType(dims, type, data.data()); \ + break; \ +} + + HANDLE_COMPLEX_DATA +#undef RUN_ARON_MACRO + +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +case data::e##upperType: \ +{ \ + lowerType val = reader.readPrimitive<lowerType>(); \ + writer.writePrimitive(val); \ + break; \ +} + + HANDLE_PRIMITIVE_DATA +#undef RUN_ARON_MACRO + + default: + { + throw error::DescriptorNotValidException("LegacyAronDataReader", "SetupReaderAndGetResult", "Data-Type could not be resolved", desc); + } + } + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h b/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h new file mode 100644 index 0000000000000000000000000000000000000000..d51d81761b764d5616bb70e5cefd67dd105987bd --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/converter/Converter.h @@ -0,0 +1,48 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/Reader.h> + + +namespace armarx::aron::dataIO +{ + class Converter; + typedef std::shared_ptr<Converter> ConverterPtr; + + class Converter + { + private: + Converter() = delete; + + public: + static void ConvertFromReader(ReaderInterface&, WriterInterface&, const aron::typenavigator::NavigatorPtr& expectedStructure = nullptr); + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/ReaderToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/ReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..a757d2778ca04857fb436977bcec6e4eb9de3710 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/ReaderToken.h @@ -0,0 +1,127 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/io/Data.h> + +namespace armarx::aron::dataIO +{ + template<typename ElementTypename> + class ReaderTokenInterface; + + template<typename ElementTypename> + using ReaderTokenInterfacePtr = std::shared_ptr<ReaderTokenInterface<ElementTypename>>; + + template<typename ElementTypename> + class ReaderTokenInterface + { + public: + using PointerType = ReaderTokenInterfacePtr<ElementTypename>; + + + // Interface + virtual data::Descriptor getTypeOfNext(const type::Descriptor hint = type::eUnknown) const = 0; + virtual ElementTypename getNextElement() const = 0; + + // General implementation + ElementTypename getElement() const + { + return element; + } + + data::Descriptor getDescriptor() const + { + return descriptor; + } + + unsigned int getElementChildrenSize() const + { + return childrenSize; + } + + bool finishedElement() const + { + return currentIndex >= getElementChildrenSize(); + } + + std::string getCurrentKey() const + { + assertIndexInBounds(); + + // ugly workaround + if (this->currentKey == "") // probably in a dict where the caller does not know which keys are there + { + if (this->allMemberNames.size() == 0) + { + throw error::AronException("dataIO::ReaderTokenInterface", "getCurrentKey", "The currentKey is not set and the list of all keys is empty!"); + } + return this->allMemberNames[this->currentIndex]; + } + return this->currentKey; + } + + void setCurrentKey(const std::string& s) + { + currentKey = s; + } + + void assertType(data::Descriptor t) const + { + if (getDescriptor() != t) + { + throw error::DescriptorNotValidException("dataIO::ReaderTokenInterface", "assertType", "The type was not equal.", t); + } + } + + void assertIndexInBounds() const + { + if (this->currentIndex >= getElementChildrenSize()) + { + throw error::SizeNotValidException("dataIO::ReaderTokenInterface", "assertIndexInBounds", "Index out of bounds.", this->currentIndex, getElementChildrenSize()); + } + } + + ElementTypename getNextElementAndIncreaseCnt() + { + ElementTypename next = getNextElement(); + this->currentIndex++; + return next; + } + + protected: + // members + data::Descriptor descriptor = data::eUnknown; + ElementTypename element; + + unsigned int childrenSize = 0; + unsigned int currentIndex = 0; + + std::string currentKey = ""; + std::vector<std::string> allMemberNames = {}; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa5d3d14864aff4fd5d86b8cfc47b06a81cc0200 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.cpp @@ -0,0 +1,198 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NavigatorReader.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h> + + + +namespace armarx::aron::dataIO::reader +{ + NavigatorReader::NavigatorReader(const datanavigator::NavigatorPtr& n) : + input(n) + { + } + + NavigatorReader::NavigatorReader(const data::AronDataPtr& n) : + input(datanavigator::Navigator::FromAronData(n)) + { + } + + datanavigator::NavigatorPtr NavigatorReader::getNextAndIncrease() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + auto lastToken = stack.top(); + return lastToken->getNextElementAndIncreaseCnt(); + } + + datanavigator::NavigatorPtr NavigatorReader::getNext() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + auto lastToken = stack.top(); + return lastToken->getNextElement(); + } + + // Containers + int NavigatorReader::readStartDict() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = datanavigator::DictNavigator::DynamicCastAndCheck(current_nav); + int c = current_nav->childrenSize(); + auto newToken = std::make_shared<NavigatorReaderToken>(data::eDict, current_nav_casted); + stack.push(newToken); + return c; + } + + bool NavigatorReader::readEndDict() + { + auto token = stack.top(); + datanavigator::DictNavigator::DynamicCastAndCheck(token->getElement()); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NavigatorReader::readStartList() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = datanavigator::ListNavigator::DynamicCastAndCheck(current_nav); + int c = current_nav->childrenSize(); + auto newToken = std::make_shared<NavigatorReaderToken>(data::eList, current_nav_casted); + stack.push(newToken); + return c; + } + + bool NavigatorReader::readEndList() + { + auto token = stack.top(); + datanavigator::ListNavigator::DynamicCastAndCheck(token->getElement()); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + // Complex Data + std::tuple<std::vector<int>, std::string> NavigatorReader::readStartNDArray() + { + datanavigator::NavigatorPtr nav = getNext(); + datanavigator::NDArrayNavigatorPtr casted = datanavigator::NDArrayNavigator::DynamicCastAndCheck(nav); + return {casted->getDimensions(), casted->getType()}; + } + + bool NavigatorReader::readEndNDArray(unsigned char* data) + { + if (data == NULL) + { + throw error::AronException("NavigatorReader", "readEndNDArray", "The corresponding data pointer of an complex aron ptr is NULL."); + } + auto nav = getNextAndIncrease(); + auto casted = datanavigator::NDArrayNavigator::DynamicCastAndCheck(nav); + std::vector<int> dims = casted->getDimensions(); + memcpy(data, casted->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return true; + } + + // Read primitives + void NavigatorReader::readPrimitive(int& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::IntNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + void NavigatorReader::readPrimitive(long& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::LongNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + void NavigatorReader::readPrimitive(float& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::FloatNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + void NavigatorReader::readPrimitive(double& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::DoubleNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + void NavigatorReader::readPrimitive(std::string& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::StringNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + void NavigatorReader::readPrimitive(bool& t) + { + auto nav = getNextAndIncrease(); + auto casted = datanavigator::BoolNavigator::DynamicCastAndCheck(nav); + t = casted->getValue(); + } + + std::string NavigatorReader::readKey() + { + auto token = stack.top(); + return token->getCurrentKey(); + } + + void NavigatorReader::loadMember(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } + + // Helper functions + data::Descriptor NavigatorReader::getTypeOfNext(const type::Descriptor hint) const + { + auto token = stack.top(); + return token->getTypeOfNext(hint); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h new file mode 100644 index 0000000000000000000000000000000000000000..0bcc56b7bdc6e22775fc2d4345e1f9715e942d1f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h @@ -0,0 +1,80 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/dataIO/Reader.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReaderToken.h> + + +namespace armarx::aron::dataIO::reader +{ + class NavigatorReader; + typedef std::shared_ptr<NavigatorReader> NavigatorReaderPtr; + + class NavigatorReader : + virtual public ReaderInterface + { + public: + using PointerType = NavigatorReaderPtr; + + // constructors + NavigatorReader() = delete; + NavigatorReader(const datanavigator::NavigatorPtr& n); + NavigatorReader(const data::AronDataPtr& n); + + virtual int readStartDict() override; + virtual bool readEndDict() override; + virtual int readStartList() override; + virtual bool readEndList() override; + + virtual std::tuple<std::vector<int>, std::string> readStartNDArray() override; + virtual bool readEndNDArray(unsigned char*) override; + + virtual void readPrimitive(int&) override; + virtual void readPrimitive(long&) override; + virtual void readPrimitive(float&) override; + virtual void readPrimitive(double&) override; + virtual void readPrimitive(std::string&) override; + virtual void readPrimitive(bool&) override; + + virtual std::string readKey() override; + virtual void loadMember(const std::string&) override; + + virtual data::Descriptor getTypeOfNext(const type::Descriptor hint = type::eUnknown) const override; + + private: + datanavigator::NavigatorPtr getNext(); + datanavigator::NavigatorPtr getNextAndIncrease(); + + private: + datanavigator::NavigatorPtr input; + bool readInitialStart = false; + std::stack<NavigatorReaderTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReaderToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..2efb3352f203d93fa0b647ea318affea7d41b4fd --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReaderToken.h @@ -0,0 +1,102 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/ReaderToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> + +namespace armarx::aron::dataIO::reader +{ + // BaseClass + class NavigatorReaderToken; + typedef std::shared_ptr<NavigatorReaderToken> NavigatorReaderTokenPtr; + + class NavigatorReaderToken : + virtual public ReaderTokenInterface<datanavigator::NavigatorPtr> + { + public: + using PointerType = NavigatorReaderTokenPtr; + + public: + // constructors + NavigatorReaderToken() = delete; + NavigatorReaderToken(const data::Descriptor desc, const datanavigator::NavigatorPtr& data) + { + descriptor = desc; + element = data; + + switch (descriptor) + { + case data::Descriptor::eDict: + { + allMemberNames = datanavigator::DictNavigator::DynamicCastAndCheck(data)->getAllKeys(); + childrenSize = data->childrenSize(); + break; + } + case data::Descriptor::eList: + { + childrenSize = data->childrenSize(); + break; + } + default: + throw error::DescriptorNotValidException("NavigatorReaderToken", "NavigatorReaderToken", "Received an invalid instance for a reader token.", desc); + } + } + + data::Descriptor getTypeOfNext(const type::Descriptor hint = type::eUnknown) const override + { + const datanavigator::NavigatorPtr next = getNextElement(); + return next->getDescriptor(); + } + + datanavigator::NavigatorPtr getNextElement() const override + { + switch (descriptor) + { + case data::Descriptor::eDict: + { + datanavigator::DictNavigatorPtr casted = datanavigator::DictNavigator::DynamicCast(element); + datanavigator::NavigatorPtr ret = casted->getElement(getCurrentKey()); + return ret; + } + case data::Descriptor::eList: + { + datanavigator::ListNavigatorPtr casted = datanavigator::ListNavigator::DynamicCast(element); + datanavigator::NavigatorPtr ret = casted->getElement(currentIndex); + return ret; + } + default: + throw error::DescriptorNotValidException("NavigatorReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); + } + } + + private: + + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b15c88280210b4e9b2e583ba7439d87e68909d9 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp @@ -0,0 +1,190 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NlohmannJSONReader.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/data/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h> + + + +namespace armarx::aron::dataIO::reader +{ + NlohmannJSONReader::NlohmannJSONReader(const nlohmann::json& n) : + input(n) + { + } + + NlohmannJSONReader::NlohmannJSONReader(const std::string& n) : + input(nlohmann::json::parse(n)) + { + } + + nlohmann::json NlohmannJSONReader::getNextAndIncrease() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + NlohmannJSONReaderTokenPtr lastToken = stack.top(); + return lastToken->getNextElementAndIncreaseCnt(); + } + + nlohmann::json NlohmannJSONReader::getNext() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + NlohmannJSONReaderTokenPtr lastToken = stack.top(); + return lastToken->getNextElement(); + } + + int NlohmannJSONReader::readStartDict() + { + nlohmann::json current_json = getNextAndIncrease(); + int c = current_json.size(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(data::eDict, current_json); + stack.push(newToken); + return c; + } + + bool NlohmannJSONReader::readEndDict() + { + auto token = stack.top(); + token->assertType(data::eDict); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NlohmannJSONReader::readStartList() + { + nlohmann::json current_json = getNextAndIncrease(); + int c = current_json.size(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(data::eList, current_json); + stack.push(newToken); + return c; + } + + bool NlohmannJSONReader::readEndList() + { + auto token = stack.top(); + token->assertType(data::eList); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + // Complex Data + std::tuple<std::vector<int>, std::string> NlohmannJSONReader::readStartNDArray() + { + nlohmann::json j = getNext(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return {dims, type}; + } + + bool NlohmannJSONReader::readEndNDArray(unsigned char* data) + { + if (data == NULL) + { + throw error::AronException("NlohmannJSONReader", "readEndNDArray", "The corresponding data pointer of an complex aron ptr is NULL."); + } + nlohmann::json j = getNextAndIncrease(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::vector<unsigned char> d = j[io::Data::READER_WRITER_NDARRAY_DATA_SLUG]; + memcpy(data, d.data(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return true; + } + + // Read primitives + void NlohmannJSONReader::readPrimitive(int& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + void NlohmannJSONReader::readPrimitive(long& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + void NlohmannJSONReader::readPrimitive(float& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + void NlohmannJSONReader::readPrimitive(double& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + void NlohmannJSONReader::readPrimitive(std::string& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + void NlohmannJSONReader::readPrimitive(bool& t) + { + nlohmann::json j = getNextAndIncrease(); + t = j; + } + + std::string NlohmannJSONReader::readKey() + { + auto token = stack.top(); + return token->getCurrentKey(); + } + + void NlohmannJSONReader::loadMember(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } + + // Helper functions + data::Descriptor NlohmannJSONReader::getTypeOfNext(const type::Descriptor hint) const + { + auto token = stack.top(); + return token->getTypeOfNext(hint); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h new file mode 100644 index 0000000000000000000000000000000000000000..1ca1810a0c3085e4d53b7a79c934dc1eaa7e1e25 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h @@ -0,0 +1,78 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/dataIO/Reader.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h> + +namespace armarx::aron::dataIO::reader +{ + class NlohmannJSONReader; + typedef std::shared_ptr<NlohmannJSONReader> NlohmannJSONReaderPtr; + + class NlohmannJSONReader : + virtual public ReaderInterface + { + public: + using PointerType = NlohmannJSONReaderPtr; + + // constructors + NlohmannJSONReader() = delete; + NlohmannJSONReader(const nlohmann::json& n); + NlohmannJSONReader(const std::string& n); + + virtual int readStartDict() override; + virtual bool readEndDict() override; + virtual int readStartList() override; + virtual bool readEndList() override; + + virtual std::tuple<std::vector<int>, std::string> readStartNDArray() override; + virtual bool readEndNDArray(unsigned char*) override; + + virtual void readPrimitive(int&) override; + virtual void readPrimitive(long&) override; + virtual void readPrimitive(float&) override; + virtual void readPrimitive(double&) override; + virtual void readPrimitive(std::string&) override; + virtual void readPrimitive(bool&) override; + + virtual std::string readKey() override; + virtual void loadMember(const std::string&) override; + + virtual data::Descriptor getTypeOfNext(const type::Descriptor hint = type::eUnknown) const override; + + private: + nlohmann::json getNext(); + nlohmann::json getNextAndIncrease(); + + private: + nlohmann::json input; + bool readInitialStart = false; + std::stack<NlohmannJSONReaderTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..d155a2d155027ad03f16a359a903da88dae6776c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h @@ -0,0 +1,142 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Simox +#include <SimoxUtility/json.h> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/ReaderToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Resolver.h> + + + +namespace armarx::aron::dataIO::reader +{ + // BaseClass + class NlohmannJSONReaderToken; + typedef std::shared_ptr<NlohmannJSONReaderToken> NlohmannJSONReaderTokenPtr; + + class NlohmannJSONReaderToken : + virtual public ReaderTokenInterface<nlohmann::json> + { + public: + using PointerType = NlohmannJSONReaderTokenPtr; + + // constructors + NlohmannJSONReaderToken() = delete; + NlohmannJSONReaderToken(const data::Descriptor desc, const nlohmann::json& data) + { + descriptor = desc; + element = data; + + switch (descriptor) + { + case data::eDict: + { + for (auto it = data.begin(); it != data.end(); ++it) + { + allMemberNames.push_back(it.key()); + } + childrenSize = data.size(); + break; + } + case data::eList: + { + childrenSize = data.size(); + break; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONReaderToken", "NlohmannJSONReaderToken", "Received an invalid instance for a reader token.", desc); + } + } + + data::Descriptor getTypeOfNext(const type::Descriptor hint) const override + { + const nlohmann::json next = getNextElement(); + if (next.is_object()) + { + // Check if specific NDArray key exists + if (next.find(io::Data::READER_WRITER_NDARRAY_DATA_SLUG) != next.end()) + { + return data::eNDArray; + } + return data::eDict; + } + if (next.is_array()) + { + return data::eList; + } + if (next.is_number_integer()) + { + + data::Descriptor d = Resolver::GetFirstIfRelated( + Resolver::GetCorresponding(hint), + data::eLong); + return d; + } + if (next.is_number_float()) + { + data::Descriptor d = Resolver::GetFirstIfRelated( + Resolver::GetCorresponding(hint), + data::eDouble); + return d; + } + if (next.is_boolean()) + { + return data::eBool; + } + if (next.is_string()) + { + return data::eString; + } + throw error::AronException("NlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Could not convert to data::Descriptor enum."); + } + + nlohmann::json getNextElement() const override + { + switch (descriptor) + { + case data::eDict: + { + nlohmann::json ret = element[getCurrentKey()]; + return ret; + } + case data::eList: + { + nlohmann::json ret = element[currentIndex]; + return ret; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); + } + } + + private: + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f2dd3cd6e470c72698aae1c5c0bdcd948194e53 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.cpp @@ -0,0 +1,117 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "Visitor.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Resolver.h> + + + +namespace armarx::aron::dataIO +{ + + void Visitor::SetupWriterFromAronDataPtr(WriterInterface& writer, const datanavigator::NavigatorPtr& aron) + { + SetupWriterFromAronDataPtr(writer, aron->getResult()); + } + + void Visitor::SetupWriterFromAronDataPtr(WriterInterface& writer, const data::AronDataPtr& aron) + { + data::Descriptor desc = Resolver::GetDescriptor(aron); + switch (desc) + { + case data::eDict: + { + data::AronDictPtr casted = data::AronDictPtr::dynamicCast(aron); + writer.writeStartDict(); + for (const auto& [key, value] : casted->elements) + { + writer.writeKey(key); + Visitor::SetupWriterFromAronDataPtr(writer, value); + } + writer.writeEndDict(); + break; + } + case data::eList: + { + data::AronListPtr casted = data::AronListPtr::dynamicCast(aron); + writer.writeStartList(); + for (const auto& value : casted->elements) + { + Visitor::SetupWriterFromAronDataPtr(writer, value); + } + writer.writeEndList(); + break; + } + case data::eNDArray: + { + data::AronNDArrayPtr casted = data::AronNDArrayPtr::dynamicCast(aron); + writer.writeNDArray(casted->dimensions, casted->type, casted->data.data()); + break; + } + case data::eInt: + { + data::AronIntPtr casted = data::AronIntPtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + case data::eLong: + { + data::AronLongPtr casted = data::AronLongPtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + case data::eFloat: + { + data::AronFloatPtr casted = data::AronFloatPtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + case data::eDouble: + { + data::AronDoublePtr casted = data::AronDoublePtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + case data::eString: + { + data::AronStringPtr casted = data::AronStringPtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + case data::eBool: + { + data::AronBoolPtr casted = data::AronBoolPtr::dynamicCast(aron); + writer.writePrimitive(casted->value); + break; + } + default: + { + throw error::DescriptorNotValidException("LegacyAronDataWriter", "SetupWriterFromAronDataPtr", "Data-Type could not be resolved. The ice_id of the input was: " + aron->ice_id(), desc); + } + } + } +} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h b/source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h similarity index 51% rename from source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h rename to source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h index 902e9c59e7ba6ada4d18325fb1c527b2348cdf6d..b45ef50c60207e97e6e29e170df39cf0be237a90 100644 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriterVisitor/AronDataWriterVisitor.h +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/visitor/Visitor.h @@ -24,36 +24,26 @@ #include <memory> #include <string> -// BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> - // ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> - #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> -namespace armarx +namespace armarx::aron::dataIO { - namespace aron + class Visitor; + typedef std::shared_ptr<Visitor> VisitorPtr; + + class Visitor { - namespace io - { - class AronDataWriterVisitor; - typedef std::shared_ptr<AronDataWriterVisitor> AronDataWriterVisitorPtr; - - class AronDataWriterVisitor - { - private: - AronDataWriterVisitor() = delete; - - public: - static void SetupWriterFromAronDataPtr(AronDataWriter&, const datanavigator::AronDataNavigatorPtr&); - static void SetupWriterFromAronDataPtr(AronDataWriter&, const data::AronDataPtr&); - - public: - }; - } - } + private: + Visitor() = delete; + + public: + static void SetupWriterFromAronDataPtr(WriterInterface&, const datanavigator::NavigatorPtr&); + static void SetupWriterFromAronDataPtr(WriterInterface&, const data::AronDataPtr&); + + public: + }; } diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/WriterToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/WriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..950baf3f13359a2ff38db78a16af0c73e24d303e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/WriterToken.h @@ -0,0 +1,94 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/io/Data.h> + +namespace armarx::aron::dataIO +{ + template<typename ElementTypename> + class WriterTokenInterface; + + template<typename ElementTypename> + using WriterTokenPtr = std::shared_ptr<WriterTokenInterface<ElementTypename>>; + + template<typename ElementTypename> + class WriterTokenInterface + { + public: + using PointerType = WriterTokenInterface<ElementTypename>; + + // Interface + virtual void addElement(const ElementTypename&) = 0; + + // General implementation + void setCurrentKey(const std::string& s) + { + if (s.empty()) + { + throw error::AronException("AronWriterToken", "setCurrentKey", "The passed key is empty."); + } + currentKey = s; + } + + ElementTypename getElement() const + { + return element; + } + + data::Descriptor getDescriptor() const + { + return descriptor; + } + + std::string toAccessor() const + { + data::Descriptor desc = this->getDescriptor(); + switch (desc) + { + case data::eDict: + return currentKey; + case data::eList: + return std::to_string(currentIndex); + default: + throw error::DescriptorNotValidException("NavigatorWriterToken", "toElementAccessor", "Could not resove a type of a navigator. Allowed are only containers.", desc); + } + } + + protected: + // members + data::Descriptor descriptor = data::eUnknown; + ElementTypename element; + + // current index + unsigned int currentIndex = 0; + + // current key + std::string currentKey = ""; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..adebb69a3a86875ac18e9854c96256c01458a9a3 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.cpp @@ -0,0 +1,165 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NavigatorWriter.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> + + + +namespace armarx::aron::dataIO::writer +{ + + Path NavigatorWriter::generatePath() + { + Path path; + if (!wroteInitialStartContainer) + { + wroteInitialStartContainer = true; + } + else + { + auto parent_token = stack.top(); + path = Path(parent_token->getElement()->getPath(), parent_token->toAccessor()); + } + return path; + } + + // Containers + void NavigatorWriter::writeStartDict() + { + Path path = generatePath(); + auto data = std::make_shared<datanavigator::DictNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(data::eDict, data); + stack.push(new_token); + } + + void NavigatorWriter::writeEndDict() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NavigatorWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeStartList() + { + Path path = generatePath(); + auto data = std::make_shared<datanavigator::ListNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(data::eList, data); + stack.push(new_token); + } + + void NavigatorWriter::writeEndList() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NavigatorWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + // Complex Types + void NavigatorWriter::writeNDArray(const std::vector<int>& dims, const std::string& t, const unsigned char* data) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + datanavigator::NDArrayNavigatorPtr aron(new datanavigator::NDArrayNavigator(path)); + aron->setDimensions(dims); + aron->setType(t); + aron->setData(std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()), data); + token->addElement(aron); + } + + + // Primitive Types + void NavigatorWriter::writePrimitive(const int x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::IntNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writePrimitive(const long x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::LongNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writePrimitive(const float x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::FloatNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writePrimitive(const double x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::DoubleNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writePrimitive(const std::string& x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::StringNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writePrimitive(const bool x) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + auto aron = std::make_shared<datanavigator::BoolNavigator>(path); + aron->setValue(x); + token->addElement(aron); + } + + void NavigatorWriter::writeKey(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..3467d630a3301e4ed962f4529057d4be4089a4b5 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h @@ -0,0 +1,75 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriterToken.h> + +namespace armarx::aron::dataIO::writer +{ + class NavigatorWriter; + typedef std::shared_ptr<NavigatorWriter> NavigatorWriterPtr; + + class NavigatorWriter : + virtual public WriterInterface + { + public: + NavigatorWriter() = default; + + virtual void writeStartDict() override; + virtual void writeEndDict() override; + virtual void writeStartList() override; + virtual void writeEndList() override; + + virtual void writeNDArray(const std::vector<int>&, const std::string&, const unsigned char*) override; + + virtual void writePrimitive(const int) override; + virtual void writePrimitive(const long) override; + virtual void writePrimitive(const float) override; + virtual void writePrimitive(const double) override; + virtual void writePrimitive(const std::string&) override; + virtual void writePrimitive(const bool) override; + + virtual void writeKey(const std::string&) override; + + datanavigator::NavigatorPtr getResult() const + { + return lastRemovedToken->getElement(); + } + + private: + Path generatePath(); + + private: + bool wroteInitialStartContainer = false; + NavigatorWriterTokenPtr lastRemovedToken = nullptr; + std::stack<NavigatorWriterTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriterToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..8f10dd89e20a4ad0d606a6b2054d152679a76bee --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriterToken.h @@ -0,0 +1,78 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/WriterToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> + +namespace armarx::aron::dataIO::writer +{ + class NavigatorWriterToken; + typedef std::shared_ptr<NavigatorWriterToken> NavigatorWriterTokenPtr; + + class NavigatorWriterToken : + virtual public WriterTokenInterface<datanavigator::NavigatorPtr> + { + public: + using PointerType = NavigatorWriterTokenPtr; + + public: + // constructor + NavigatorWriterToken() = delete; + NavigatorWriterToken(const data::Descriptor desc, const datanavigator::NavigatorPtr& d) + { + descriptor = desc; + element = d; + } + + // public member functions + virtual void addElement(const datanavigator::NavigatorPtr& n) override + { + auto desc = this->getDescriptor(); + switch (desc) + { + case data::Descriptor::eDict: + { + datanavigator::DictNavigatorPtr casted = datanavigator::DictNavigator::DynamicCastAndCheck(element); + casted->addElement(currentKey, n); + break; + } + case data::Descriptor::eList: + { + datanavigator::ListNavigatorPtr casted = datanavigator::ListNavigator::DynamicCastAndCheck(element); + casted->addElement(n); + currentIndex++; + break; + } + default: + throw error::DescriptorNotValidException("NavigatorWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers. The path was: " + element->pathToString(), desc); + } + } + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e57ee04fd96febf4aeeb128385ac14dce87d9217 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp @@ -0,0 +1,133 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller (fabian dot peller at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include <numeric> + +#include "NlohmannJSONWriter.h" + +namespace armarx::aron::dataIO::writer +{ + + // Containers + void NlohmannJSONWriter::writeStartDict() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(data::eDict, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndDict() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeStartList() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(data::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndList() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + // Complex Types + void NlohmannJSONWriter::writeNDArray(const std::vector<int>& dims, const std::string& t, const unsigned char* data) \ + { + NlohmannJSONWriterTokenPtr token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = dims; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + int elements = std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>()); + std::vector<unsigned char> d = std::vector<unsigned char>(elements); + memcpy(d.data(), data, elements); + j[io::Data::READER_WRITER_NDARRAY_DATA_SLUG] = d; + token->addElement(j); + } + + // Primitive + void NlohmannJSONWriter::writePrimitive(const int x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writePrimitive(const long x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writePrimitive(const float x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writePrimitive(const double x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writePrimitive(const std::string& x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writePrimitive(const bool x) + { + auto token = stack.top(); + nlohmann::json j(x); + token->addElement(j); + } + + void NlohmannJSONWriter::writeKey(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } + +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..f36fa55d53127a2c79a6d0b9629718a24cb2070c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h @@ -0,0 +1,72 @@ +/* +* 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 +*/ + +#pragma once + +// STD / STL +#include <memory> +#include <stack> +#include <sstream> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/dataIO/Writer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h> + +namespace armarx::aron::dataIO::writer +{ + class NlohmannJSONWriter; + typedef std::shared_ptr<NlohmannJSONWriter> NlohmannJSONWriterPtr; + + class NlohmannJSONWriter : + virtual public WriterInterface + { + public: + NlohmannJSONWriter() = default; + + virtual void writeStartDict() override; + virtual void writeEndDict() override; + virtual void writeStartList() override; + virtual void writeEndList() override; + + virtual void writeNDArray(const std::vector<int>&, const std::string&, const unsigned char*) override; + + virtual void writePrimitive(const int) override; + virtual void writePrimitive(const long) override; + virtual void writePrimitive(const float) override; + virtual void writePrimitive(const double) override; + virtual void writePrimitive(const std::string&) override; + virtual void writePrimitive(const bool) override; + + virtual void writeKey(const std::string&) override; + + nlohmann::json getResult() const + { + return lastRemovedToken->getElement(); + } + + private: + bool wroteInitialStartContainer = false; + NlohmannJSONWriterTokenPtr lastRemovedToken = nullptr; + std::stack<NlohmannJSONWriterTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..9f37b4993a86c7006cfe8ad98b40ea006c09ff53 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h @@ -0,0 +1,78 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Simox +#include <SimoxUtility/json.h> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/WriterToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> + +namespace armarx::aron::dataIO::writer +{ + class NlohmannJSONWriterToken; + typedef std::shared_ptr<NlohmannJSONWriterToken> NlohmannJSONWriterTokenPtr; + + class NlohmannJSONWriterToken : + virtual public WriterTokenInterface<nlohmann::json> + { + public: + using PointerType = NlohmannJSONWriterTokenPtr; + + public: + // constructor + NlohmannJSONWriterToken() = delete; + NlohmannJSONWriterToken(const data::Descriptor desc, const nlohmann::json& d) + { + descriptor = desc; + element = d; + } + + // public member functions + virtual void addElement(const nlohmann::json& n) override + { + auto desc = this->getDescriptor(); + switch (desc) + { + case data::Descriptor::eDict: + { + element[currentKey] = n; + break; + } + case data::Descriptor::eList: + { + element.push_back(n); + currentIndex++; + break; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONWriterToken", "addElement", "Could not resove a type of a token. Allowed are only containers.", desc); + } + } + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/Reader.h b/source/RobotAPI/libraries/aron/core/io/typeIO/Reader.h new file mode 100644 index 0000000000000000000000000000000000000000..738b4c351b068bbfc54b363cf68901dbb6035837 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/Reader.h @@ -0,0 +1,75 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Config.h> + + +namespace armarx::aron::typeIO +{ + class ReaderInterface; + typedef std::shared_ptr<ReaderInterface> ReaderInterfacePtr; + + class ReaderInterface + { + public: + virtual std::tuple<std::string, int> readStartObject() = 0; + virtual bool readEndObject() = 0; + virtual int readStartList() = 0; + virtual bool readEndList() = 0; + virtual int readStartDict() = 0; + virtual bool readEndDict() = 0; + virtual int readStartTuple() = 0; + virtual bool readEndTuple() = 0; + virtual int readStartPair() = 0; + virtual bool readEndPair() = 0; + + virtual std::tuple<std::vector<int>, std::string> readEigenMatrix() = 0; + virtual std::string readEigenQuaternion() = 0; + virtual std::tuple<unsigned int, unsigned int, std::string> readIVTCByteImage() = 0; + virtual std::tuple<std::vector<int>, std::string> readOpenCVMat() = 0; + virtual std::tuple<unsigned int, unsigned int, std::string> readPCLPointCloud() = 0; + virtual void readPosition() = 0; + virtual void readOrientation() = 0; + virtual void readPose() = 0; + + virtual void readInt() = 0; + virtual void readLong() = 0; + virtual void readFloat() = 0; + virtual void readDouble() = 0; + virtual void readString() = 0; + virtual void readBool() = 0; + virtual void readTime() = 0; + + virtual std::string readKey() = 0; + virtual void loadMember(const std::string&) = 0; + + // Helper functions + virtual type::Descriptor getTypeOfNext() const = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/Writer.h b/source/RobotAPI/libraries/aron/core/io/typeIO/Writer.h new file mode 100644 index 0000000000000000000000000000000000000000..552b5fc1a9427357ee9b971115fc49dda89d3745 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/Writer.h @@ -0,0 +1,72 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Config.h> + + + +namespace armarx::aron::typeIO +{ + class WriterInterface; + typedef std::shared_ptr<WriterInterface> WriterInterfacePtr; + + class WriterInterface + { + public: + virtual void writeStartObject(const std::string&) = 0; + virtual void writeEndObject() = 0; + virtual void writeStartList() = 0; + virtual void writeEndList() = 0; + virtual void writeStartDict() = 0; + virtual void writeEndDict() = 0; + virtual void writeStartTuple() = 0; + virtual void writeEndTuple() = 0; + virtual void writeStartPair() = 0; + virtual void writeEndPair() = 0; + + virtual void writeEigenMatrix(const std::vector<int>&, const std::string&) = 0; + virtual void writeEigenQuaternion(const std::string&) = 0; + virtual void writeIVTCByteImage(unsigned int w, unsigned int h, const std::string&) = 0; + virtual void writeOpenCVMat(const std::vector<int>&, const std::string&) = 0; + virtual void writePCLPointCloud(unsigned int w, unsigned int h, const std::string&) = 0; + virtual void writePosition() = 0; + virtual void writeOrientation() = 0; + virtual void writePose() = 0; + + virtual void writeInt() = 0; + virtual void writeLong() = 0; + virtual void writeFloat() = 0; + virtual void writeDouble() = 0; + virtual void writeString() = 0; + virtual void writeBool() = 0; + virtual void writeTime() = 0; + + virtual void writeKey(const std::string&) = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9aca9ffceea3bbae3fbd76794112bdca58379d8 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.cpp @@ -0,0 +1,183 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "Converter.h" + +namespace armarx::aron::typeIO +{ + void Converter::ConvertFromReader(ReaderInterface& reader, WriterInterface& writer) + { + type::Descriptor desc = reader.getTypeOfNext(); + switch (desc) + { + case type::eObject: + { + const auto [name, elements] = reader.readStartObject(); + writer.writeStartObject(name); + + for (int i = 0; i < elements; ++i) + { + std::string key = reader.readKey(); + writer.writeKey(key); + Converter::ConvertFromReader(reader, writer); + } + + writer.writeEndObject(); + reader.readEndObject(); + break; + } + case type::eDict: + { + reader.readStartDict(); + writer.writeStartDict(); + + Converter::ConvertFromReader(reader, writer); + + writer.writeEndDict(); + reader.readEndDict(); + break; + } + case type::eTuple: + { + int elements = reader.readStartTuple(); + writer.writeStartTuple(); + + for (int i = 0; i < elements; ++i) + { + Converter::ConvertFromReader(reader, writer); + } + + writer.writeEndTuple(); + reader.readEndTuple(); + break; + } + case type::eList: + { + reader.readStartList(); + writer.writeStartList(); + + Converter::ConvertFromReader(reader, writer); + + writer.writeEndList(); + reader.readEndList(); + break; + } + case type::eEigenMatrix: + { + auto x = reader.readEigenMatrix(); + writer.writeEigenMatrix(std::get<0>(x), std::get<1>(x)); + break; + } + case type::eEigenQuaternion: + { + auto x = reader.readEigenQuaternion(); + writer.writeEigenQuaternion(x); + break; + } + case type::eIVTCByteImage: + { + auto x = reader.readIVTCByteImage(); + writer.writeIVTCByteImage(std::get<0>(x), std::get<1>(x), std::get<2>(x)); + break; + } + case type::eOpenCVMat: + { + auto x = reader.readOpenCVMat(); + writer.writeOpenCVMat(std::get<0>(x), std::get<1>(x)); + break; + } + case type::ePCLPointCloud: + { + auto x = reader.readPCLPointCloud(); + writer.writePCLPointCloud(std::get<0>(x), std::get<1>(x), std::get<2>(x)); + break; + } + case type::ePosition: + { + reader.readPosition(); + writer.writePosition(); + break; + } + case type::eOrientation: + { + reader.readOrientation(); + writer.writeOrientation(); + break; + } + case type::ePose: + { + reader.readPose(); + writer.writePose(); + break; + } + case type::eInt: + { + reader.readInt(); + writer.writeInt(); + break; + } + case type::eLong: + { + reader.readLong(); + writer.writeLong(); + break; + } + case type::eFloat: + { + reader.readFloat(); + writer.writeFloat(); + break; + } + case type::eDouble: + { + reader.readDouble(); + writer.writeDouble(); + break; + } + case type::eString: + { + reader.readString(); + writer.writeString(); + break; + } + case type::eBool: + { + reader.readBool(); + writer.writeBool(); + break; + } + case type::eTime: + { + reader.readTime(); + writer.writeTime(); + break; + } + default: + { + throw error::DescriptorNotValidException("LegacyAronTypeReader", "ConvertFromReader", "Type could not be resolved", desc); + } + } + } +} diff --git a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.h b/source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h similarity index 53% rename from source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.h rename to source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h index 133d605cb4417910933fbd4983247ddc420cebee..f1c59c61894ff07dfdea24d1f5682620392ebf35 100644 --- a/source/RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeConverter/AronTypeConverter.h +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/converter/Converter.h @@ -25,35 +25,28 @@ #include <string> // BaseClass -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeReader.h> -// ArmarX -#include <ArmarXCore/core/exceptions/Exception.h> +// ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/Reader.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> -namespace armarx +namespace armarx::aron::typeIO { - namespace aron + class Converter; + typedef std::shared_ptr<Converter> AronTypeConverterPtr; + + class Converter { - namespace io - { - class AronTypeConverter; - typedef std::shared_ptr<AronTypeConverter> AronTypeConverterPtr; - - class AronTypeConverter - { - private: - AronTypeConverter() = delete; - - public: - static void ConvertFromReader(AronTypeReader&, AronTypeWriter&); - - public: - }; - } - } + private: + Converter() = delete; + + public: + static void ConvertFromReader(ReaderInterface&, WriterInterface&); + + public: + }; } diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/ReaderToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/ReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..c4487c6baee1fd033932c276dc114891f274d575 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/ReaderToken.h @@ -0,0 +1,138 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <vector> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/io/Data.h> + +namespace armarx::aron::typeIO +{ + template<typename ElementTypename> + class ReaderTokenInterface; + + template<typename ElementTypename> + using ReaderTokenInterfacePtr = std::shared_ptr<ReaderTokenInterface<ElementTypename>>; + + template<typename ElementTypename> + class ReaderTokenInterface + { + public: + using PointerType = ReaderTokenInterfacePtr<ElementTypename>; + + public: + // Interface + virtual type::Descriptor getTypeOfNext() const = 0; + virtual ElementTypename getNextElement() const = 0; + + // General implementation + std::string getElementName() const + { + switch (descriptor) + { + case type::eObject: + case type::eIntEnum: + { + return elementName; + } + default: + throw error::DescriptorNotValidException("ReaderTokenInterface", "getElementName", "Could not get object nme of a non-object or non-enum token", descriptor); + } + } + + type::Descriptor getDescriptor() const + { + return descriptor; + } + + unsigned int getElementChildrenSize() const + { + return childrenSize; + } + + bool finishedElement() const + { + return currentIndex >= getElementChildrenSize(); + } + + std::string getCurrentKey() const + { + assertIndexInBounds(); + + // ugly workaround + if (this->currentKey == "") // probably in a dict where the caller does not know which keys are there + { + if (this->allMemberNames.size() == 0) + { + throw error::AronException("typeIO::ReaderTokenInterface", "getCurrentKey", "The currentKey is not set and the list of all keys is empty!"); + } + return this->allMemberNames[this->currentIndex]; + } + return this->currentKey; + } + + void setCurrentKey(const std::string& s) + { + currentKey = s; + } + + void assertType(type::Descriptor t) const + { + if (getDescriptor() != t) + { + throw error::DescriptorNotValidException("typeIO::ReaderTokenInterface", "assertType", "The type was not equal.", t); + } + } + + void assertIndexInBounds() const + { + if (this->currentIndex >= getElementChildrenSize()) + { + throw error::SizeNotValidException("typeIO::ReaderTokenInterface", "assertIndexInBounds", "Index out of bounds.", this->currentIndex, getElementChildrenSize()); + } + } + + ElementTypename getNextElementAndIncreaseCnt() + { + ElementTypename next = getNextElement(); + this->currentIndex++; + return next; + } + + protected: + // members + type::Descriptor descriptor = type::eUnknown; + ElementTypename element; + std::string elementName = ""; + + unsigned int childrenSize = 0; + unsigned int currentIndex = 0; + + std::string currentKey = ""; + std::vector<std::string> allMemberNames = {}; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19a19936f8cc8e01f494c00105735a6556c1ef14 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.cpp @@ -0,0 +1,282 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NavigatorReader.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + + + +namespace armarx::aron::typeIO::reader +{ + NavigatorReader::NavigatorReader(const typenavigator::NavigatorPtr& n) : + input(n) + { + } + + NavigatorReader::NavigatorReader(const type::AronTypePtr& n) : + input(typenavigator::Navigator::FromAronType(n)) + { + } + + typenavigator::NavigatorPtr NavigatorReader::getNextAndIncrease() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + NavigatorReaderTokenPtr lastToken = stack.top(); + return lastToken->getNextElementAndIncreaseCnt(); + } + + std::tuple<std::string, int> NavigatorReader::readStartObject() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = typenavigator::ObjectNavigator::DynamicCastAndCheck(current_nav); + auto newToken = std::make_shared<NavigatorReaderToken>(type::eObject, current_nav_casted); + stack.push(newToken); + return {newToken->getElementName(), newToken->getElementChildrenSize()}; + } + + bool NavigatorReader::readEndObject() + { + auto token = stack.top(); + token->assertType(type::eObject); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NavigatorReader::readStartDict() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = typenavigator::DictNavigator::DynamicCastAndCheck(current_nav); + auto newToken = std::make_shared<NavigatorReaderToken>(type::eDict, current_nav_casted); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NavigatorReader::readEndDict() + { + auto token = stack.top(); + token->assertType(type::eDict); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NavigatorReader::readStartList() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = typenavigator::ListNavigator::DynamicCastAndCheck(current_nav); + auto newToken = std::make_shared<NavigatorReaderToken>(type::eList, current_nav_casted); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NavigatorReader::readEndList() + { + auto token = stack.top(); + token->assertType(type::eList); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NavigatorReader::readStartTuple() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = typenavigator::TupleNavigator::DynamicCastAndCheck(current_nav); + auto newToken = std::make_shared<NavigatorReaderToken>(type::eTuple, current_nav_casted); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NavigatorReader::readEndTuple() + { + auto token = stack.top(); + token->assertType(type::eTuple); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NavigatorReader::readStartPair() + { + auto current_nav = getNextAndIncrease(); + auto current_nav_casted = typenavigator::PairNavigator::DynamicCastAndCheck(current_nav); + auto newToken = std::make_shared<NavigatorReaderToken>(type::ePair, current_nav_casted); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NavigatorReader::readEndPair() + { + auto token = stack.top(); + token->assertType(type::ePair); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + std::tuple<std::vector<int>, std::string> NavigatorReader::readEigenMatrix() + { + auto nav = getNextAndIncrease(); + auto casted = typenavigator::EigenMatrixNavigator::DynamicCastAndCheck(nav); + return std::make_tuple(casted->getDimensions(), casted->getTypename()); + } + + std::string NavigatorReader::readEigenQuaternion() + { + auto nav = getNextAndIncrease(); + auto casted = typenavigator::EigenMatrixNavigator::DynamicCastAndCheck(nav); + return casted->getTypename(); + } + + std::tuple<unsigned int, unsigned int, std::string> NavigatorReader::readIVTCByteImage() + { + auto nav = getNextAndIncrease(); + auto casted = typenavigator::IVTCByteImageNavigator::DynamicCastAndCheck(nav); + return make_tuple(casted->getWidth(), casted->getHeight(), casted->getTypename()); + } + + std::tuple<std::vector<int>, std::string> NavigatorReader::readOpenCVMat() + { + auto nav = getNextAndIncrease(); + auto casted = typenavigator::OpenCVMatNavigator::DynamicCastAndCheck(nav); + return make_tuple(casted->getDimensions(), casted->getTypename()); + } + + std::tuple<unsigned int, unsigned int, std::string> NavigatorReader::readPCLPointCloud() + { + auto nav = getNextAndIncrease(); + auto casted = typenavigator::PCLPointCloudNavigator::DynamicCastAndCheck(nav); + return make_tuple(casted->getWidth(), casted->getHeight(), casted->getTypename()); + } + + void NavigatorReader::readPosition() + { + auto nav = getNextAndIncrease(); + typenavigator::PositionNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readOrientation() + { + auto nav = getNextAndIncrease(); + typenavigator::OrientationNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readPose() + { + auto nav = getNextAndIncrease(); + typenavigator::PoseNavigator::DynamicCastAndCheck(nav); + } + + // Read primitives + void NavigatorReader::readInt() + { + auto nav = getNextAndIncrease(); + typenavigator::IntNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readFloat() + { + auto nav = getNextAndIncrease(); + typenavigator::FloatNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readLong() + { + auto nav = getNextAndIncrease(); + typenavigator::LongNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readDouble() + { + auto nav = getNextAndIncrease(); + typenavigator::DoubleNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readString() + { + auto nav = getNextAndIncrease(); + typenavigator::StringNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readBool() + { + auto nav = getNextAndIncrease(); + typenavigator::BoolNavigator::DynamicCastAndCheck(nav); + } + + void NavigatorReader::readTime() + { + auto nav = getNextAndIncrease(); + typenavigator::TimeNavigator::DynamicCastAndCheck(nav); + } + + std::string NavigatorReader::readKey() + { + auto token = stack.top(); + return token->getCurrentKey(); + } + + void NavigatorReader::loadMember(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } + + // Helper functions + type::Descriptor NavigatorReader::getTypeOfNext() const + { + auto token = stack.top(); + return token->getTypeOfNext(); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.h b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.h new file mode 100644 index 0000000000000000000000000000000000000000..0b733ce7cb7bafc9965a6a08c649271c35079028 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReader.h @@ -0,0 +1,95 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/typeIO/Reader.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReaderToken.h> + + +namespace armarx::aron::typeIO::reader +{ + class NavigatorReader; + typedef std::shared_ptr<NavigatorReader> NavigatorReaderPtr; + + class NavigatorReader : + virtual public ReaderInterface + { + public: + using PointerType = NavigatorReaderPtr; + + public: + // constructors + NavigatorReader() = delete; + NavigatorReader(const typenavigator::NavigatorPtr& n); + NavigatorReader(const type::AronTypePtr& n); + + + virtual std::tuple<std::string, int> readStartObject() override; + virtual bool readEndObject() override; + virtual int readStartList() override; + virtual bool readEndList() override; + virtual int readStartDict() override; + virtual bool readEndDict() override; + virtual int readStartTuple() override; + virtual bool readEndTuple() override; + virtual int readStartPair() override; + virtual bool readEndPair() override; + + virtual std::tuple<std::vector<int>, std::string> readEigenMatrix() override; + virtual std::string readEigenQuaternion() override; + virtual std::tuple<unsigned int, unsigned int, std::string> readIVTCByteImage() override; + virtual std::tuple<std::vector<int>, std::string> readOpenCVMat() override; + virtual std::tuple<unsigned int, unsigned int, std::string> readPCLPointCloud() override; + virtual void readPosition() override; + virtual void readOrientation() override; + virtual void readPose() override; + + virtual void readInt() override; + virtual void readLong() override; + virtual void readFloat() override; + virtual void readDouble() override; + virtual void readString() override; + virtual void readBool() override; + virtual void readTime() override; + + virtual std::string readKey() override; + virtual void loadMember(const std::string&) override; + + // Helper functions + virtual type::Descriptor getTypeOfNext() const override; + + private: + typenavigator::NavigatorPtr getNextAndIncrease(); + + private: + typenavigator::NavigatorPtr input; + bool readInitialStart = false; + std::stack<NavigatorReaderTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReaderToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..9c8425ce589d6585bb6a460ea4774b76960707e7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/navigator/NavigatorReaderToken.h @@ -0,0 +1,139 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/ReaderToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + +namespace armarx::aron::typeIO::reader +{ + class NavigatorReaderToken; + typedef std::shared_ptr<NavigatorReaderToken> NavigatorReaderTokenPtr; + + class NavigatorReaderToken : + virtual public ReaderTokenInterface<typenavigator::NavigatorPtr> + { + public: + using PointerType = NavigatorReaderTokenPtr; + + public: + // constructors + NavigatorReaderToken() = delete; + NavigatorReaderToken(const type::Descriptor desc, const typenavigator::NavigatorPtr& type) + { + descriptor = desc; + element = type; + + switch (descriptor) + { + case type::Descriptor::eObject: + { + for (const auto& [key, _] : typenavigator::ObjectNavigator::DynamicCastAndCheck(element)->getMemberTypes()) + { + allMemberNames.push_back(key); + } + childrenSize = type->childrenSize(); + break; + } + case type::Descriptor::eDict: + { + typenavigator::DictNavigator::DynamicCastAndCheck(element); + childrenSize = 1; + break; + } + case type::Descriptor::eTuple: + { + typenavigator::TupleNavigator::DynamicCastAndCheck(element); + childrenSize = type->childrenSize(); + break; + } + case type::Descriptor::eList: + { + typenavigator::ListNavigator::DynamicCastAndCheck(element); + childrenSize = 1; + break; + } + case type::Descriptor::ePair: + { + typenavigator::PairNavigator::DynamicCastAndCheck(element); + childrenSize = 2; + break; + } + default: + throw error::DescriptorNotValidException("NavigatorReaderToken", "NavigatorReaderToken", "Received an invalid instance for a reader token.", desc); + } + } + + type::Descriptor getTypeOfNext() const override + { + const typenavigator::NavigatorPtr next = getNextElement(); + return next->getDescriptor(); + } + + typenavigator::NavigatorPtr getNextElement() const override + { + assertIndexInBounds(); + + switch (descriptor) + { + case type::Descriptor::eObject: + { + typenavigator::ObjectNavigatorPtr casted = typenavigator::ObjectNavigator::DynamicCastAndCheck(element); + return casted->getMemberType(getCurrentKey()); + } + case type::Descriptor::eDict: + { + typenavigator::DictNavigatorPtr casted = typenavigator::DictNavigator::DynamicCastAndCheck(element); + return casted->getAcceptedType(); + } + case type::Descriptor::eTuple: + { + typenavigator::TupleNavigatorPtr casted = typenavigator::TupleNavigator::DynamicCastAndCheck(element); + return casted->getAcceptedType(currentIndex); + } + case type::Descriptor::eList: + { + typenavigator::ListNavigatorPtr casted = typenavigator::ListNavigator::DynamicCastAndCheck(element); + return casted->getAcceptedType(); + } + case type::Descriptor::ePair: + { + typenavigator::PairNavigatorPtr casted = typenavigator::PairNavigator::DynamicCastAndCheck(element); + if (currentIndex == 0) + { + return casted->getFirstAcceptedType(); + } + return casted->getSecondAcceptedType(); + } + default: + throw error::DescriptorNotValidException("NavigatorReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); + } + } + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eea8c5dc279d527d9aa6024b1c3bfed2f2e9da8a --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.cpp @@ -0,0 +1,274 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NlohmannJSONReader.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + + + +namespace armarx::aron::typeIO::reader +{ + NlohmannJSONReader::NlohmannJSONReader(const nlohmann::json& n) : + input(n) + { + } + + NlohmannJSONReader::NlohmannJSONReader(const std::string& n) : + input(n) + { + } + + nlohmann::json NlohmannJSONReader::getNextAndIncrease() + { + if (!readInitialStart) + { + readInitialStart = true; + return input; + } + NlohmannJSONReaderTokenPtr lastToken = stack.top(); + return lastToken->getNextElementAndIncreaseCnt(); + } + + std::tuple<std::string, int> NlohmannJSONReader::readStartObject() + { + nlohmann::json current_json = getNextAndIncrease(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(type::eObject, current_json); + stack.push(newToken); + return {newToken->getElementName(), newToken->getElementChildrenSize()}; + } + + bool NlohmannJSONReader::readEndObject() + { + NlohmannJSONReaderTokenPtr token = stack.top(); + token->assertType(type::eObject); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NlohmannJSONReader::readStartDict() + { + nlohmann::json current_json = getNextAndIncrease(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(type::eDict, current_json); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NlohmannJSONReader::readEndDict() + { + NlohmannJSONReaderTokenPtr token = stack.top(); + token->assertType(type::eDict); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NlohmannJSONReader::readStartList() + { + nlohmann::json current_json = getNextAndIncrease(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(type::eList, current_json); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NlohmannJSONReader::readEndList() + { + NlohmannJSONReaderTokenPtr token = stack.top(); + token->assertType(type::eList); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NlohmannJSONReader::readStartTuple() + { + nlohmann::json current_json = getNextAndIncrease(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(type::eTuple, current_json); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NlohmannJSONReader::readEndTuple() + { + NlohmannJSONReaderTokenPtr token = stack.top(); + token->assertType(type::eTuple); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + int NlohmannJSONReader::readStartPair() + { + nlohmann::json current_json = getNextAndIncrease(); + auto newToken = std::make_shared<NlohmannJSONReaderToken>(type::ePair, current_json); + stack.push(newToken); + return newToken->getElementChildrenSize(); + } + + bool NlohmannJSONReader::readEndPair() + { + NlohmannJSONReaderTokenPtr token = stack.top(); + token->assertType(type::ePair); + + if (token->finishedElement()) + { + stack.pop(); + return true; + } + return false; + } + + std::tuple<std::vector<int>, std::string> NlohmannJSONReader::readEigenMatrix() + { + nlohmann::json j = getNextAndIncrease(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return std::make_tuple(dims, type); + } + + std::string NlohmannJSONReader::readEigenQuaternion() + { + nlohmann::json j = getNextAndIncrease(); + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return type; + } + + std::tuple<unsigned int, unsigned int, std::string> NlohmannJSONReader::readIVTCByteImage() + { + nlohmann::json j = getNextAndIncrease(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return std::make_tuple(dims[0], dims[1], type); + } + + std::tuple<std::vector<int>, std::string> NlohmannJSONReader::readOpenCVMat() + { + nlohmann::json j = getNextAndIncrease(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return std::make_tuple(dims, type); + } + + std::tuple<unsigned int, unsigned int, std::string> NlohmannJSONReader::readPCLPointCloud() + { + nlohmann::json j = getNextAndIncrease(); + std::vector<int> dims = j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG]; + std::string type = j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG]; + return std::make_tuple(dims[0], dims[1], type); + } + + void NlohmannJSONReader::readPosition() + { + getNextAndIncrease(); + return; + } + + void NlohmannJSONReader::readOrientation() + { + getNextAndIncrease(); + return; + } + + void NlohmannJSONReader::readPose() + { + getNextAndIncrease(); + return; + } + + // Read primitives + void NlohmannJSONReader::readInt() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readLong() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readFloat() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readDouble() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readString() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readBool() + { + nlohmann::json j = getNextAndIncrease(); + } + + void NlohmannJSONReader::readTime() + { + nlohmann::json j = getNextAndIncrease(); + } + + std::string NlohmannJSONReader::readKey() + { + auto token = stack.top(); + return token->getCurrentKey(); + } + + void NlohmannJSONReader::loadMember(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } + + // Helper functions + type::Descriptor NlohmannJSONReader::getTypeOfNext() const + { + auto token = stack.top(); + return token->getTypeOfNext(); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h new file mode 100644 index 0000000000000000000000000000000000000000..70efcc50ec54620533272f9493aa77c17701fa41 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReader.h @@ -0,0 +1,92 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/typeIO/Reader.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h> + +namespace armarx::aron::typeIO::reader +{ + class NlohmannJSONReader; + typedef std::shared_ptr<NlohmannJSONReader> NlohmannJSONReaderPtr; + + class NlohmannJSONReader : + virtual public ReaderInterface + { + public: + using PointerType = NlohmannJSONReaderPtr; + + public: + // constructors + NlohmannJSONReader() = delete; + NlohmannJSONReader(const nlohmann::json& n); + NlohmannJSONReader(const std::string& n); + + virtual std::tuple<std::string, int> readStartObject() override; + virtual bool readEndObject() override; + virtual int readStartList() override; + virtual bool readEndList() override; + virtual int readStartDict() override; + virtual bool readEndDict() override; + virtual int readStartTuple() override; + virtual bool readEndTuple() override; + virtual int readStartPair() override; + virtual bool readEndPair() override; + + virtual std::tuple<std::vector<int>, std::string> readEigenMatrix() override; + virtual std::string readEigenQuaternion() override; + virtual std::tuple<unsigned int, unsigned int, std::string> readIVTCByteImage() override; + virtual std::tuple<std::vector<int>, std::string> readOpenCVMat() override; + virtual std::tuple<unsigned int, unsigned int, std::string> readPCLPointCloud() override; + virtual void readPosition() override; + virtual void readOrientation() override; + virtual void readPose() override; + + virtual void readInt() override; + virtual void readLong() override; + virtual void readFloat() override; + virtual void readDouble() override; + virtual void readString() override; + virtual void readBool() override; + virtual void readTime() override; + + virtual std::string readKey() override; + virtual void loadMember(const std::string&) override; + + // Helper functions + virtual type::Descriptor getTypeOfNext() const override; + + private: + nlohmann::json getNextAndIncrease(); + + private: + nlohmann::json input; + bool readInitialStart = false; + std::stack<NlohmannJSONReaderTokenPtr> stack; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h new file mode 100644 index 0000000000000000000000000000000000000000..78b3c04ab5fe09cef34cee4c96c5749a9eff908c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/reader/nlohmannJSON/NlohmannJSONReaderToken.h @@ -0,0 +1,219 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Simox +#include <SimoxUtility/json.h> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/typeIO/reader/ReaderToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Resolver.h> + +namespace armarx::aron::typeIO::reader +{ + class NlohmannJSONReaderToken; + typedef std::shared_ptr<NlohmannJSONReaderToken> NlohmannJSONReaderTokenPtr; + + class NlohmannJSONReaderToken : + virtual public ReaderTokenInterface<nlohmann::json> + { + public: + using PointerType = NlohmannJSONReaderTokenPtr; + + public: + // constructors + NlohmannJSONReaderToken() = delete; + NlohmannJSONReaderToken(const type::Descriptor desc, const nlohmann::json& type) + { + descriptor = desc; + element = type; + + switch (descriptor) + { + case type::Descriptor::eObject: + { + for (auto it = type.begin(); it != type.end(); ++it) + { + if (it.key() == io::Data::READER_WRITER_NAME_SLUG) + { + continue; + } + + allMemberNames.push_back(it.key()); + } + childrenSize = allMemberNames.size(); + elementName = element[io::Data::READER_WRITER_NAME_SLUG]; + break; + } + case type::Descriptor::eDict: + { + childrenSize = 1; + break; + } + case type::Descriptor::eTuple: + { + childrenSize = element.size(); + break; + } + case type::Descriptor::eList: + { + childrenSize = 1; + break; + } + case type::ePair: + { + childrenSize = 2; + break; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONReaderToken", "NlohmannJSONReaderToken", "Received an invalid instance for a reader token.", desc); + } + } + + type::Descriptor getTypeOfNext() const override + { + const nlohmann::json next = getNextElement(); + + if (next.is_object()) + { + if (next.find(io::Data::READER_WRITER_DICT_ACCEPTED_TYPE_SLUG) != next.end()) + { + return type::eDict; + } + if (next.find(io::Data::READER_WRITER_LIST_ACCEPTED_TYPE_SLUG) != next.end()) + { + return type::eList; + } + if (next.find(io::Data::READER_WRITER_INT_ENUM_NAME_SLUG) != next.end()) + { + return type::eIntEnum; + } + if (next.find(io::Data::READER_WRITER_NDARRAY_NAME_SLUG) != next.end()) + { + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "EigenMatrix") + { + return type::eEigenMatrix; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "EigenQuaternion") + { + return type::eEigenQuaternion; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "IVTCByteImage") + { + return type::eIVTCByteImage; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "OpenCVMat") + { + return type::eOpenCVMat; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "PCLPointCloud") + { + return type::ePCLPointCloud; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "Position") + { + return type::ePosition; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "Orientation") + { + return type::eOrientation; + } + if (next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] == "Pose") + { + return type::ePose; + } + throw error::AronException("NlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Found indicator of NDArray but could not resolve real type. Found JSON: " + next[io::Data::READER_WRITER_NDARRAY_NAME_SLUG].dump(2)); + } + return type::eObject; + } + if (next.is_array()) + { + return type::eTuple; + } + if (next.is_string()) + { + if (next == io::Data::READER_WRITER_INT_TYPENAME_SLUG) + { + return type::eInt; + } + if (next == io::Data::READER_WRITER_LONG_TYPENAME_SLUG) + { + return type::eLong; + } + if (next == io::Data::READER_WRITER_FLOAT_TYPENAME_SLUG) + { + return type::eFloat; + } + if (next == io::Data::READER_WRITER_DOUBLE_TYPENAME_SLUG) + { + return type::eDouble; + } + if (next == io::Data::READER_WRITER_STRING_TYPENAME_SLUG) + { + return type::eString; + } + if (next == io::Data::READER_WRITER_BOOL_TYPENAME_SLUG) + { + return type::eBool; + } + if (next == io::Data::READER_WRITER_TIME_TYPENAME_SLUG) + { + return type::eTime; + } + } + throw error::AronException("NlohmannJSONReaderToken", "getTypeOfNextElement", "Could not determine the type of an nlohmann::json object. Could not convert to type::Descriptor enum. Found JSON: " + next.dump(2)); + } + + nlohmann::json getNextElement() const override + { + assertIndexInBounds(); + + switch (descriptor) + { + case type::Descriptor::eObject: + { + return element[getCurrentKey()]; + } + case type::Descriptor::eDict: + { + return element[io::Data::READER_WRITER_DICT_ACCEPTED_TYPE_SLUG]; + } + case type::Descriptor::eTuple: + { + return element[currentIndex]; + } + case type::Descriptor::eList: + { + return element[io::Data::READER_WRITER_LIST_ACCEPTED_TYPE_SLUG]; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONReaderToken", "getNextElement", "Could not resove a type of a navigator. Allowed are only container types due to performance", descriptor); + } + } + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99005c64e9a148fad4cbf4b54932d10f68332a5a --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.cpp @@ -0,0 +1,178 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "Visitor.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Resolver.h> + + + +namespace armarx::aron::typeIO +{ + + void Visitor::SetupWriterFromAronTypePtr(WriterInterface& writer, const typenavigator::NavigatorPtr& aron) + { + SetupWriterFromAronTypePtr(writer, aron->getResult()); + } + + void Visitor::SetupWriterFromAronTypePtr(WriterInterface& writer, const type::AronTypePtr& aron) + { + type::Descriptor desc = Resolver::GetDescriptor(aron); + switch (desc) + { + case type::eObject: + { + type::AronObjectPtr casted = type::AronObjectPtr::dynamicCast(aron); + writer.writeStartObject(casted->objectName); + for (const auto& [key, value] : casted->elementTypes) + { + writer.writeKey(key); + Visitor::SetupWriterFromAronTypePtr(writer, value); + } + writer.writeEndObject(); + break; + } + case type::eDict: + { + type::AronDictPtr casted = type::AronDictPtr::dynamicCast(aron); + writer.writeStartDict(); + Visitor::SetupWriterFromAronTypePtr(writer, casted->acceptedType); + writer.writeEndDict(); + break; + } + case type::eTuple: + { + type::AronTuplePtr casted = type::AronTuplePtr::dynamicCast(aron); + writer.writeStartTuple(); + for (const auto& value : casted->elementTypes) + { + Visitor::SetupWriterFromAronTypePtr(writer, value); + } + writer.writeEndTuple(); + break; + } + case type::eList: + { + type::AronListPtr casted = type::AronListPtr::dynamicCast(aron); + writer.writeStartList(); + Visitor::SetupWriterFromAronTypePtr(writer, casted->acceptedType); + writer.writeEndList(); + break; + } + case type::eEigenMatrix: + { + type::AronEigenMatrixPtr casted = type::AronEigenMatrixPtr::dynamicCast(aron); + writer.writeEigenMatrix(casted->dimensions, casted->typeName); + break; + } + case type::eEigenQuaternion: + { + type::AronEigenQuaternionPtr casted = type::AronEigenQuaternionPtr::dynamicCast(aron); + writer.writeEigenQuaternion(casted->typeName); + break; + } + case type::eIVTCByteImage: + { + type::AronIVTCByteImagePtr casted = type::AronIVTCByteImagePtr::dynamicCast(aron); + writer.writeIVTCByteImage(casted->width, casted->height, casted->typeName); + break; + } + case type::eOpenCVMat: + { + type::AronOpenCVMatPtr casted = type::AronOpenCVMatPtr::dynamicCast(aron); + writer.writeOpenCVMat(casted->dimensions, casted->typeName); + break; + } + case type::ePCLPointCloud: + { + type::AronPCLPointCloudPtr casted = type::AronPCLPointCloudPtr::dynamicCast(aron); + writer.writePCLPointCloud(casted->width, casted->height, casted->typeName); + break; + } + case type::ePosition: + { + writer.writePosition(); + break; + } + case type::eOrientation: + { + writer.writeOrientation(); + break; + } + case type::ePose: + { + writer.writePose(); + break; + } + case type::eInt: + { + type::AronIntPtr casted = type::AronIntPtr::dynamicCast(aron); + writer.writeInt(); + break; + } + case type::eLong: + { + type::AronLongPtr casted = type::AronLongPtr::dynamicCast(aron); + writer.writeLong(); + break; + } + case type::eFloat: + { + type::AronFloatPtr casted = type::AronFloatPtr::dynamicCast(aron); + writer.writeFloat(); + break; + } + case type::eDouble: + { + type::AronDoublePtr casted = type::AronDoublePtr::dynamicCast(aron); + writer.writeDouble(); + break; + } + case type::eString: + { + type::AronStringPtr casted = type::AronStringPtr::dynamicCast(aron); + writer.writeString(); + break; + } + case type::eBool: + { + type::AronBoolPtr casted = type::AronBoolPtr::dynamicCast(aron); + writer.writeBool(); + break; + } + case type::eTime: + { + type::AronTimePtr casted = type::AronTimePtr::dynamicCast(aron); + writer.writeTime(); + break; + } + default: + { + throw error::DescriptorNotValidException("LegacyAronTypeWriter", "SetupWriterFromAronTypePtr", "Type-Type could not be resolved. The ice_id of the input was: " + aron->ice_id(), desc); + } + } + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h b/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h new file mode 100644 index 0000000000000000000000000000000000000000..6f781b3dae61236e202ffffd0fd243f89732f5d7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/visitor/Visitor.h @@ -0,0 +1,49 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> + + +namespace armarx::aron::typeIO +{ + class Visitor; + typedef std::shared_ptr<Visitor> VisitorPtr; + + class Visitor + { + private: + Visitor() = delete; + + public: + static void SetupWriterFromAronTypePtr(WriterInterface&, const typenavigator::NavigatorPtr&); + static void SetupWriterFromAronTypePtr(WriterInterface&, const type::AronTypePtr&); + + public: + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/WriterToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/WriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..2b858da0c52b65d3e13d72b4ec3d11edc7ef7e4d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/WriterToken.h @@ -0,0 +1,98 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/io/Data.h> + +namespace armarx::aron::typeIO +{ + template<typename ElementTypename> + class WriterTokenInterface; + + template<typename ElementTypename> + using WriterTokenInterfacePtr = std::shared_ptr<WriterTokenInterface<ElementTypename>>; + + template<typename ElementTypename> + class WriterTokenInterface + { + public: + using PointerType = WriterTokenInterfacePtr<ElementTypename>; + + // Interface + virtual void addElement(const ElementTypename&) = 0; + virtual void setName(const std::string&) = 0; + + // General implementation + std::string toAccessor() const + { + type::Descriptor desc = this->getDescriptor(); + switch (desc) + { + case type::Descriptor::eDict: + case type::Descriptor::eList: + return "[ACCEPTED_TYPE]"; + case type::Descriptor::eObject: + return this->currentKey; + case type::Descriptor::eTuple: + return std::to_string(this->currentIndex); + default: + throw error::DescriptorNotValidException("NavigatorWriterToken", "toElementAccessor", "Could not resove a type of a navigator. Allowed are only containers.", desc); + } + } + + void setCurrentKey(const std::string& s) + { + if (s.empty()) + { + throw error::AronException("AronWriterToken", "setCurrentKey", "The passed key is empty."); + } + currentKey = s; + } + + ElementTypename getElement() const + { + return element; + } + + type::Descriptor getDescriptor() const + { + return descriptor; + } + + protected: + // members + type::Descriptor descriptor = type::eUnknown; + ElementTypename element; + + // current index + unsigned int currentIndex = 0; + + // current key + std::string currentKey = ""; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06e8c00764ed0c3c446c7fdb2b1448a780d085cb --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.cpp @@ -0,0 +1,293 @@ +/* +* 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 +*/ + +// STD/STL +#include <memory> +#include <numeric> + +// Header +#include "NavigatorWriter.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h> + +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + +namespace armarx::aron::typeIO::writer +{ + // generate Path info + Path NavigatorWriter::generatePath() + { + Path path; + if (!wroteInitialStartObject) + { + wroteInitialStartObject = true; + } + else + { + auto current = stack.top(); + path = Path(current->getElement()->getPath(), current->toAccessor()); + } + return path; + } + + // interface + void NavigatorWriter::writeStartObject(const std::string& n) + { + Path path = generatePath(); + auto type = std::make_shared<typenavigator::ObjectNavigator>(path); + type->setObjectName(n); + auto new_token = std::make_shared<NavigatorWriterToken>(type->getDescriptor(), type); + stack.push(new_token); + } + + void NavigatorWriter::writeEndObject() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeStartDict() + { + Path path = generatePath(); + auto type = std::make_shared<typenavigator::DictNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(type->getDescriptor(), type); + stack.push(new_token); + } + + void NavigatorWriter::writeEndDict() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeStartList() + { + Path path = generatePath(); + auto type = std::make_shared<typenavigator::ListNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(type->getDescriptor(), type); + stack.push(new_token); + } + + void NavigatorWriter::writeEndList() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeStartTuple() + { + Path path = generatePath(); + auto type = std::make_shared<typenavigator::TupleNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(type->getDescriptor(), type); + stack.push(new_token); + } + + void NavigatorWriter::writeEndTuple() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeStartPair() + { + Path path = generatePath(); + auto type = std::make_shared<typenavigator::PairNavigator>(path); + auto new_token = std::make_shared<NavigatorWriterToken>(type->getDescriptor(), type); + stack.push(new_token); + } + + void NavigatorWriter::writeEndPair() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + auto prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NavigatorWriter::writeEigenMatrix(const std::vector<int>& dims, const std::string& t) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::EigenMatrixNavigatorPtr aron(new typenavigator::EigenMatrixNavigator(path)); + aron->setTypename(t); + aron->setDimensions(dims); + token->addElement(aron); + } + + void NavigatorWriter::writeEigenQuaternion(const std::string& t) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::EigenQuaternionNavigatorPtr aron(new typenavigator::EigenQuaternionNavigator(path)); + aron->setTypename(t); + token->addElement(aron); + } + + void NavigatorWriter::writeIVTCByteImage(unsigned int w, unsigned int h, const std::string& t) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::IVTCByteImageNavigatorPtr aron(new typenavigator::IVTCByteImageNavigator(path)); + aron->setTypename(t); + aron->setWidth(w); + aron->setHeight(h); + token->addElement(aron); + } + + void NavigatorWriter::writeOpenCVMat(const std::vector<int>& dims, const std::string& t) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::OpenCVMatNavigatorPtr aron(new typenavigator::OpenCVMatNavigator(path)); + aron->setTypename(t); + aron->setDimensions(dims); + token->addElement(aron); + } + + void NavigatorWriter::writePCLPointCloud(unsigned int w, unsigned int h, const std::string& t) + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::PCLPointCloudNavigatorPtr aron(new typenavigator::PCLPointCloudNavigator(path)); + aron->setTypename(t); + aron->setWidth(w); + aron->setHeight(h); + token->addElement(aron); + } + + void NavigatorWriter::writePosition() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::PositionNavigatorPtr aron(new typenavigator::PositionNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeOrientation() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::OrientationNavigatorPtr aron(new typenavigator::OrientationNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writePose() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::PoseNavigatorPtr aron(new typenavigator::PoseNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeInt() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::IntNavigatorPtr aron(new typenavigator::IntNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeLong() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::LongNavigatorPtr aron(new typenavigator::LongNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeFloat() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::FloatNavigatorPtr aron(new typenavigator::FloatNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeDouble() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::DoubleNavigatorPtr aron(new typenavigator::DoubleNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeString() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::StringNavigatorPtr aron(new typenavigator::StringNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeBool() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::BoolNavigatorPtr aron(new typenavigator::BoolNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeTime() + { + Path path = generatePath(); + NavigatorWriterTokenPtr token = stack.top(); + typenavigator::TimeNavigatorPtr aron(new typenavigator::TimeNavigator(path)); + token->addElement(aron); + } + + void NavigatorWriter::writeKey(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..00b7ed96e3789deb7f72a6f370b2a8fbb9371576 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h @@ -0,0 +1,88 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <stack> + +// BaseClass +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriterToken.h> + +namespace armarx::aron::typeIO::writer +{ + class NavigatorWriter; + typedef std::shared_ptr<NavigatorWriter> NavigatorWriterPtr; + + class NavigatorWriter : + virtual public typeIO::WriterInterface + { + public: + NavigatorWriter() = default; + + virtual void writeStartObject(const std::string&) override; + virtual void writeEndObject() override; + virtual void writeStartList() override; + virtual void writeEndList() override; + virtual void writeStartDict() override; + virtual void writeEndDict() override; + virtual void writeStartTuple() override; + virtual void writeEndTuple() override; + virtual void writeStartPair() override; + virtual void writeEndPair() override; + + virtual void writeEigenMatrix(const std::vector<int>&, const std::string&) override; + virtual void writeEigenQuaternion(const std::string&) override; + virtual void writeIVTCByteImage(unsigned int w, unsigned int h, const std::string&) override; + virtual void writeOpenCVMat(const std::vector<int>&, const std::string&) override; + virtual void writePCLPointCloud(unsigned int w, unsigned int h, const std::string&) override; + virtual void writePosition() override; + virtual void writeOrientation() override; + virtual void writePose() override; + + virtual void writeInt() override; + virtual void writeLong() override; + virtual void writeFloat() override; + virtual void writeDouble() override; + virtual void writeString() override; + virtual void writeBool() override; + virtual void writeTime() override; + + virtual void writeKey(const std::string&) override; + + typenavigator::NavigatorPtr getResult() const + { + return lastRemovedToken->getElement(); + } + + private: + bool wroteInitialStartObject = false; + NavigatorWriterTokenPtr lastRemovedToken = nullptr; + std::stack<NavigatorWriterTokenPtr> stack = {}; + + Path generatePath(); + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriterToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..20b337298c61c58e0665fb1bcf21bb54eb1d845d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriterToken.h @@ -0,0 +1,121 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/WriterToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + +namespace armarx::aron::typeIO::writer +{ + class NavigatorWriterToken; + typedef std::shared_ptr<NavigatorWriterToken> NavigatorWriterTokenPtr; + + class NavigatorWriterToken : + virtual public WriterTokenInterface<typenavigator::NavigatorPtr> + { + public: + using PointerType = NavigatorWriterTokenPtr; + + public: + // constructor + NavigatorWriterToken() = delete; + NavigatorWriterToken(const type::Descriptor desc, const typenavigator::NavigatorPtr& t) + { + descriptor = desc; + element = t; + } + + // virtual member functions + virtual void addElement(const typenavigator::NavigatorPtr& n) override + { + switch (descriptor) + { + case type::eDict: + { + typenavigator::DictNavigatorPtr casted = typenavigator::DictNavigator::DynamicCastAndCheck(element); + casted->setAcceptedType(n); + break; + } + case type::eList: + { + typenavigator::ListNavigatorPtr casted = typenavigator::ListNavigator::DynamicCastAndCheck(element); + casted->setAcceptedType(n); + break; + } + case type::eObject: + { + typenavigator::ObjectNavigatorPtr casted = typenavigator::ObjectNavigator::DynamicCastAndCheck(element); + casted->addMemberType(currentKey, n); + break; + } + case type::eTuple: + { + typenavigator::TupleNavigatorPtr casted = typenavigator::TupleNavigator::DynamicCastAndCheck(element); + casted->addAcceptedType(n); + currentIndex++; + break; + } + case type::ePair: + { + typenavigator::PairNavigatorPtr casted = typenavigator::PairNavigator::DynamicCastAndCheck(element); + casted->addAcceptedType(n); + currentIndex++; + break; + } + default: + throw error::DescriptorNotValidException("NavigatorWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers. The path was: " + getElement()->pathToString(), descriptor); + } + } + + + virtual void setName(const std::string& n) override + { + switch (descriptor) + { + case type::eObject: + { + typenavigator::ObjectNavigatorPtr casted = typenavigator::ObjectNavigator::DynamicCast(element); + casted->setObjectName(n); + break; + } + case type::eIntEnum: + { + typenavigator::IntEnumNavigatorPtr casted = typenavigator::IntEnumNavigator::DynamicCast(element); + casted->setEnumName(n); + break; + } + default: + throw error::DescriptorNotValidException("NavigatorWriterToken", "setName", "Cant set the name of a non-object or non-enum token. The path was: " + getElement()->pathToString(), descriptor); + + } + } + + private: + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..187c648096a0fa0e3c9e3b406b1dbc4a7f0b1dcf --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.cpp @@ -0,0 +1,252 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller (fabian dot peller at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "NlohmannJSONWriter.h" + +namespace armarx::aron::typeIO::writer +{ + + void NlohmannJSONWriter::writeStartObject(const std::string& n) + { + nlohmann::json data; + data[io::Data::READER_WRITER_NAME_SLUG] = n; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(type::Descriptor::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndObject() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NlohmannJSONWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeStartList() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(type::Descriptor::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndList() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NlohmannJSONWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeStartDict() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(type::Descriptor::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndDict() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NlohmannJSONWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeStartTuple() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(type::Descriptor::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndTuple() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NlohmannJSONWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeStartPair() + { + nlohmann::json data; + auto new_token = std::make_shared<NlohmannJSONWriterToken>(type::Descriptor::eList, data); + stack.push(new_token); + } + + void NlohmannJSONWriter::writeEndPair() + { + lastRemovedToken = stack.top(); + stack.pop(); + + if (stack.size() > 0) + { + NlohmannJSONWriterTokenPtr prevToken = stack.top(); + prevToken->addElement(lastRemovedToken->getElement()); + } + } + + void NlohmannJSONWriter::writeEigenMatrix(const std::vector<int>& dims, const std::string& t) + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "EigenMatrix"; + j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = dims; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + token->addElement(j); + } + + void NlohmannJSONWriter::writeEigenQuaternion(const std::string& t) + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "EigenQuaternion"; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + token->addElement(j); + } + + void NlohmannJSONWriter::writeIVTCByteImage(unsigned int w, unsigned int h, const std::string& t) + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "IVTCByteImage"; + j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = {w, h}; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + token->addElement(j); + } + + void NlohmannJSONWriter::writeOpenCVMat(const std::vector<int>& dims, const std::string& t) + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "OpenCVMat"; + j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = dims; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + token->addElement(j); + } + + void NlohmannJSONWriter::writePCLPointCloud(unsigned int w, unsigned int h, const std::string& t) + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "PCLPointCloud"; + j[io::Data::READER_WRITER_NDARRAY_DIMENSIONS_SLUG] = {w, h}; + j[io::Data::READER_WRITER_NDARRAY_TYPE_SLUG] = t; + token->addElement(j); + } + + void NlohmannJSONWriter::writePosition() + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "Position"; + token->addElement(j); + } + + void NlohmannJSONWriter::writeOrientation() + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "Orientation"; + token->addElement(j); + } + + void NlohmannJSONWriter::writePose() + { + auto token = stack.top(); + nlohmann::json j; + j[io::Data::READER_WRITER_NDARRAY_NAME_SLUG] = "Pose"; + token->addElement(j); + } + + void NlohmannJSONWriter::writeInt() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_INT_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeLong() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_LONG_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeFloat() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_FLOAT_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeDouble() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_DOUBLE_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeString() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_STRING_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeBool() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_BOOL_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeTime() + { + auto token = stack.top(); + nlohmann::json j(io::Data::READER_WRITER_TIME_TYPENAME_SLUG); + token->addElement(j); + } + + void NlohmannJSONWriter::writeKey(const std::string& k) + { + auto token = stack.top(); + token->setCurrentKey(k); + } +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..7826f895e8e9fec9f3a98a12413ed1f39d12a9e9 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriter.h @@ -0,0 +1,85 @@ +/* +* 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 +*/ + +#pragma once + +// STD / STL +#include <memory> +#include <stack> +#include <sstream> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/typeIO/Writer.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h> + +namespace armarx::aron::typeIO::writer +{ + class NlohmannJSONWriter : + virtual public WriterInterface + { + public: + NlohmannJSONWriter() = default; + + virtual void writeStartObject(const std::string&) override; + virtual void writeEndObject() override; + virtual void writeStartList() override; + virtual void writeEndList() override; + virtual void writeStartDict() override; + virtual void writeEndDict() override; + virtual void writeStartTuple() override; + virtual void writeEndTuple() override; + virtual void writeStartPair() override; + virtual void writeEndPair() override; + + virtual void writeEigenMatrix(const std::vector<int>&, const std::string&) override; + virtual void writeEigenQuaternion(const std::string&) override; + virtual void writeIVTCByteImage(unsigned int w, unsigned int h, const std::string&) override; + virtual void writeOpenCVMat(const std::vector<int>&, const std::string&) override; + virtual void writePCLPointCloud(unsigned int w, unsigned int h, const std::string&) override; + virtual void writePosition() override; + virtual void writeOrientation() override; + virtual void writePose() override; + + virtual void writeInt() override; + virtual void writeLong() override; + virtual void writeFloat() override; + virtual void writeDouble() override; + virtual void writeString() override; + virtual void writeBool() override; + virtual void writeTime() override; + + virtual void writeKey(const std::string&) override; + + nlohmann::json getResult() const + { + return lastRemovedToken->getElement(); + } + + private: + bool wroteInitialStartObject = false; + NlohmannJSONWriterTokenPtr lastRemovedToken = nullptr; + std::stack<NlohmannJSONWriterTokenPtr> stack = {}; + + Path generatePath(); + }; +} diff --git a/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h new file mode 100644 index 0000000000000000000000000000000000000000..826524dddcd7c6a7d2e8bf7919240bb7d1b109b0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/io/typeIO/writer/nlohmannJSON/NlohmannJSONWriterToken.h @@ -0,0 +1,109 @@ +/* +* 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 +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// Simox +#include <SimoxUtility/json.h> + +// Base Class +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/WriterToken.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Config.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::typeIO::writer +{ + class NlohmannJSONWriterToken; + typedef std::shared_ptr<NlohmannJSONWriterToken> NlohmannJSONWriterTokenPtr; + + class NlohmannJSONWriterToken : + virtual public WriterTokenInterface<nlohmann::json> + { + public: + using PointerType = NlohmannJSONWriterTokenPtr; + + public: + // constructor + NlohmannJSONWriterToken() = delete; + NlohmannJSONWriterToken(const type::Descriptor desc, const nlohmann::json& t) + { + descriptor = desc; + element = t; + } + + // virtual member functions + virtual void addElement(const nlohmann::json& n) override + { + auto desc = getDescriptor(); + switch (desc) + { + case type::Descriptor::eDict: + { + element[io::Data::READER_WRITER_DICT_ACCEPTED_TYPE_SLUG] = n; + break; + } + case type::Descriptor::eList: + { + element[io::Data::READER_WRITER_LIST_ACCEPTED_TYPE_SLUG] = n; + break; + } + case type::Descriptor::eObject: + { + element[currentKey] = n; + break; + } + case type::Descriptor::eTuple: + { + element.push_back(n); + break; + } + default: + throw error::DescriptorNotValidException("NlohmannJSONWriterToken", "addElement", "Could not resove a type of a navigator. Allowed are only containers.", desc); + } + } + + void setName(const std::string& n) override + { + auto desc = getDescriptor(); + if (desc != type::Descriptor::eObject) + { + throw error::DescriptorNotValidException("NlohmannJSONWriterToken", "setName", "Cant set the name of a non-object token.", desc); + } + element[io::Data::READER_WRITER_NAME_SLUG] = n; + } + + private: + // members + type::Descriptor descriptor; + nlohmann::json element; + + // current index + unsigned int currentIndex; + + // current key + std::string currentKey; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/Navigator.h b/source/RobotAPI/libraries/aron/core/navigator/Navigator.h new file mode 100644 index 0000000000000000000000000000000000000000..807e24579720bffd67de117529b4a1b7f713ba32 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/Navigator.h @@ -0,0 +1,92 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <unordered_map> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> +#include <RobotAPI/libraries/aron/core/Resolver.h> +#include <RobotAPI/libraries/aron/core/Path.h> + +namespace armarx::aron +{ + template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> + class Navigator; + + template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> + using NavigatorPtr = std::shared_ptr<Navigator<Descriptor, Aron>>; + + template <typename Descriptor, typename Aron> //requires isAron<Aron>&& isTypeDescriptor<Descriptor> + class Navigator + { + public: + // constructors + Navigator() = delete; + Navigator(const Descriptor& descriptor, const Path& path) : + descriptor(descriptor), + path(path) + { + } + + // public member functions + Descriptor getDescriptor() const + { + return descriptor; + } + + Path getPath() const + { + return path; + } + + std::string pathToString() const + { + return path.toString(); + } + + // virual definitions + virtual typename Aron::PointerType getResult() const = 0; + virtual std::string getName() const = 0; + + protected: + static void CheckAronPtrForNull(const std::string& c, const std::string& m, const Path& p, const typename Aron::PointerType& data) + { + if (data.get() == nullptr) + { + throw error::AronException(c, m, "Could not cast an AronPtr. The Ptr was NULL.", p); + } + } + + private: + // members + const Descriptor descriptor; + const Path path; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/NavigatorFactory.h b/source/RobotAPI/libraries/aron/core/navigator/NavigatorFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..c8d8ea651ab62129bf1268b9aa15ec0a22cba669 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/NavigatorFactory.h @@ -0,0 +1,51 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <unordered_map> + +// Base Class +#include <RobotAPI/libraries/aron/core/Factory.h> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> +#include <RobotAPI/libraries/aron/core/Path.h> + +namespace armarx::aron +{ + template <typename Input, typename Output> // requires ... + class NavigatorFactory : + virtual public Factory<Input, Output> + { + public: + NavigatorFactory() = default; + + virtual Output create(const Input&, const Path&) const = 0; + virtual Output createSpecific(const Input&, const Path&) const = 0; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h b/source/RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h new file mode 100644 index 0000000000000000000000000000000000000000..9ea0326951e3488d1cbf9870a2a50c475f6708f5 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h @@ -0,0 +1,6 @@ +#pragma once + +#include "container/Dict.h" +#include "container/List.h" +#include "complex/NDArray.h" +#include "primitive/Primitive.h" diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/Navigator.cpp similarity index 51% rename from source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.cpp rename to source/RobotAPI/libraries/aron/core/navigator/data/Navigator.cpp index 60cd87b6092974b5dcbc12d9fd9e683e48099db1..dc6ab4b8301687d2848591569591c23ecb7066a0 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/data/Navigator.cpp @@ -22,43 +22,39 @@ */ // Header -#include "AronDataNavigator.h" +#include "Navigator.h" // ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronException.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h> -namespace armarx -{ - namespace aron - { - namespace datanavigator +namespace armarx::aron::datanavigator { // static data members - const AronDataNavigatorFactoryPtr AronDataNavigator::FACTORY = AronDataNavigatorFactoryPtr(new AronDataNavigatorFactory()); + const NavigatorFactoryPtr Navigator::FACTORY = NavigatorFactoryPtr(new NavigatorFactory()); // constructors - AronDataNavigator::AronDataNavigator(const AronDataDescriptor& descriptor, const AronPath& path) : - navigator::AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(descriptor, path) + Navigator::Navigator(const data::Descriptor& descriptor, const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(descriptor, path) { } // static methods - AronDataNavigatorPtr AronDataNavigator::FromAronData(const data::AronDataPtr& a, const AronPath& path) + NavigatorPtr Navigator::FromAronData(const data::AronDataPtr& a, const Path& path) { return FACTORY->create(a, path); } - std::vector<AronDataNavigatorPtr> AronDataNavigator::FromAronData(const std::vector<data::AronDataPtr>& a, const AronPath& path) + std::vector<NavigatorPtr> Navigator::FromAronData(const std::vector<data::AronDataPtr>& a, const Path& path) { - std::vector<AronDataNavigatorPtr> ret; + std::vector<NavigatorPtr> ret; for (const auto& aron : a) { - ret.push_back(AronDataNavigator::FromAronData(aron, path)); + ret.push_back(Navigator::FromAronData(aron, path)); } return ret; } - std::vector<data::AronDataPtr> AronDataNavigator::ToAronData(const std::vector<AronDataNavigatorPtr>& a) + std::vector<data::AronDataPtr> Navigator::ToAronData(const std::vector<NavigatorPtr>& a) { std::vector<data::AronDataPtr> ret; for (const auto& aron : a) @@ -68,30 +64,40 @@ namespace armarx return ret; } - void AronDataNavigator::CheckDataNavigatorPtrForNull(const std::string& c, const std::string& m, const AronDataNavigatorPtr& data) + void Navigator::CheckDataNavigatorPtrForNull(const std::string& c, const std::string& m, const NavigatorPtr& data) { if (data.get() == nullptr) { - throw exception::AronException(c, m, "Could not make use of an AronDataNavigatorPtr. The Ptr was NULL"); + throw error::AronException(c, m, "Could not make use of an NavigatorPtr. The Ptr was NULL"); } } - void AronDataNavigator::CheckDataNavigatorPtrForNull(const std::string& c, const std::string& m, const AronPath& p, const AronDataNavigatorPtr& data) + void Navigator::CheckDataNavigatorPtrForNull(const std::string& c, const std::string& m, const Path& p, const NavigatorPtr& data) { if (data.get() == nullptr) { - throw exception::AronExceptionWithPathInfo(c, m, "Could not make use of an AronDataNavigatorPtr. The Ptr was NULL", p); + throw error::AronException(c, m, "Could not make use of an NavigatorPtr. The Ptr was NULL", p); } } + NavigatorPtr Navigator::navigateAbsolute(const Path& path) const + { + throw error::AronException("Navigator", "navigateAbsolute", "Could not navigate through a non container navigator. The input path was: " + path.toString(), getPath()); + } - AronContainerDataNavigatorPtr AronContainerDataNavigator::DynamicCast(const AronDataNavigatorPtr& n) + NavigatorPtr Navigator::navigateRelative(const Path& path) const + { + throw error::AronException("Navigator", "navigateRelative", "Could not navigate through a non container navigator. The input path was: " + path.toString(), getPath()); + } + + + /*AronContainerDataNavigatorPtr AronContainerDataNavigator::DynamicCast(const NavigatorPtr& n) { AronContainerDataNavigatorPtr casted = std::dynamic_pointer_cast<AronContainerDataNavigator>(n); return casted; } - AronContainerDataNavigatorPtr AronContainerDataNavigator::DynamicCastAndCheck(const AronDataNavigatorPtr& n) + AronContainerDataNavigatorPtr AronContainerDataNavigator::DynamicCastAndCheck(const NavigatorPtr& n) { CheckDataNavigatorPtrForNull("AronContainerDataNavigator", "DynamicCastAndCheck[Before]", n); AronContainerDataNavigatorPtr casted = AronContainerDataNavigator::DynamicCast(n); @@ -99,11 +105,9 @@ namespace armarx return casted; } - AronDataNavigatorPtr AronContainerDataNavigator::navigateRelative(const AronPath& path) const + NavigatorPtr AronContainerDataNavigator::navigateRelative(const Path& path) const { - AronPath absoluteFromHere = path.getWithoutPrefix(getPath()); + Path absoluteFromHere = path.getWithoutPrefix(getPath()); return navigateAbsolute(absoluteFromHere); - } - } - } + }*/ } diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/Navigator.h b/source/RobotAPI/libraries/aron/core/navigator/data/Navigator.h new file mode 100644 index 0000000000000000000000000000000000000000..e703ba364db0607e0c2732bf56ca62ce72260267 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/Navigator.h @@ -0,0 +1,97 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <string> +#include <unordered_map> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/Navigator.h> +#include <RobotAPI/libraries/aron/core/Path.h> +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::datanavigator +{ + class NavigatorFactory; + typedef std::shared_ptr<NavigatorFactory> NavigatorFactoryPtr; + + class Navigator; + typedef std::shared_ptr<Navigator> NavigatorPtr; + + class Navigator : + virtual public aron::Navigator<data::Descriptor, data::AronData> + { + public: + using PointerType = NavigatorPtr; + + public: + // constructors + Navigator() = delete; + Navigator(const data::Descriptor&, const Path& p = Path()); + + // operators + virtual bool equalsDataNavigator(const NavigatorPtr&) const = 0; + + // static methods + static NavigatorPtr FromAronData(const data::AronDataPtr&, const Path& = Path()); + static std::vector<NavigatorPtr> FromAronData(const std::vector<data::AronDataPtr>&, const Path& = Path()); + static std::vector<data::AronDataPtr> ToAronData(const std::vector<NavigatorPtr>&); + + template<typename NavigatorType> + static typename NavigatorType::PointerType DynamicCast(const NavigatorPtr& n) + { + return NavigatorType::DynamicCast(n); + } + + template<typename NavigatorType> + static typename NavigatorType::PointerType DynamicCastAndCheck(const NavigatorPtr& n) + { + return NavigatorType::DynamicCastAndCheck(n); + } + + // virtual definitions of base class + virtual data::AronDataPtr getResult() const override = 0; + virtual std::string getName() const override = 0; + + // virtual definitions + virtual std::vector<NavigatorPtr> getChildren() const = 0; + virtual size_t childrenSize() const = 0; + + virtual typenavigator::NavigatorPtr recalculateType() const = 0; + virtual bool fullfillsType(const typenavigator::NavigatorPtr&) const = 0; + + virtual NavigatorPtr navigateAbsolute(const Path& path) const; + virtual NavigatorPtr navigateRelative(const Path& path) const; + + protected: + static void CheckDataNavigatorPtrForNull(const std::string&, const std::string&, const NavigatorPtr&); + static void CheckDataNavigatorPtrForNull(const std::string&, const std::string&, const Path&, const NavigatorPtr&); + + private: + static const NavigatorFactoryPtr FACTORY; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f96d2392235838ba2348642aefb5fe0ac35e51c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.cpp @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + +// Header +#include "NavigatorFactory.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> + +namespace armarx::aron::datanavigator +{ + + // Access method + NavigatorPtr NavigatorFactory::create(const data::AronDataPtr& aron, const Path& path) const + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + {data::e##upperType, NavigatorFactoryPtr(new upperType##NavigatorFactory())}, + + static const std::map<data::Descriptor, NavigatorFactoryPtr> Factories = + { + HANDLE_ALL_ARON_DATA + }; +#undef RUN_ARON_MACRO + + auto typeDescriptor = Resolver::GetDescriptor(aron); + auto factory_iterator = Factories.find(typeDescriptor); + if (factory_iterator == Factories.end()) + { + throw error::AronException("NavigatorFactory", "create", "Cannot find the desired factory for input: " + data::DESCRIPTOR_TO_STRING(typeDescriptor) + ". Cannot create navigator", path); + } + return factory_iterator->second->createSpecific(aron, path); + } + + NavigatorPtr NavigatorFactory::createSpecific(const data::AronDataPtr&, const Path& p) const + { + throw error::AronException("NavigatorFactory", "createSpecific", "Called disallowed method of an NavigatorFactory. Use child class instead!", p); + } + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +NavigatorPtr upperType##NavigatorFactory::createSpecific(const data::AronDataPtr& aron, const Path& path) const \ +{ \ +data::Aron##upperType##Ptr aronCasted = data::Aron##upperType##Ptr::dynamicCast(aron); \ +return datanavigator::NavigatorPtr(new upperType##Navigator(aronCasted, path)); \ +} + + HANDLE_ALL_ARON_DATA +#undef RUN_ARON_MACRO + +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h b/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..0f83691b526565c18e7e3fe457230b06f51db451 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h @@ -0,0 +1,64 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <unordered_map> + +// BaseClass +#include <RobotAPI/libraries/aron/core/navigator/NavigatorFactory.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::datanavigator +{ + class NavigatorFactory; + typedef std::shared_ptr<NavigatorFactory> NavigatorFactoryPtr; + + class NavigatorFactory : + virtual public Factory<data::AronDataPtr, datanavigator::NavigatorPtr> + { + public: + NavigatorFactory() = default; + virtual NavigatorPtr create(const data::AronDataPtr&, const Path&) const override; + virtual NavigatorPtr createSpecific(const data::AronDataPtr&, const Path&) const override; + }; + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##NavigatorFactory : \ + virtual public NavigatorFactory \ + { \ + public: \ + upperType##NavigatorFactory() = default; \ + virtual NavigatorPtr createSpecific(const data::AronDataPtr&, const Path&) const override; \ + }; + + HANDLE_ALL_ARON_DATA +#undef RUN_ARON_MACRO + +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a520f0140cec2013965a1f2517017033299ef05e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.cpp @@ -0,0 +1,242 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "NDArray.h" + +// Simox +#include <SimoxUtility/algorithm/string.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h> +#include <RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.h> + +namespace armarx::aron::datanavigator +{ + // constructors + NDArrayNavigator::NDArrayNavigator(const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eNDArray, path), + Navigator(data::Descriptor::eNDArray, path), + aron(new data::AronNDArray()) + { + + } + + NDArrayNavigator::NDArrayNavigator(const data::AronNDArrayPtr& o, const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eNDArray, path), + Navigator(data::Descriptor::eNDArray, path), + aron(o) + { + CheckAronPtrForNull("NDArrayNavigator", "NDArrayNavigator", getPath(), aron); + } + + NDArrayNavigator::NDArrayNavigator(const std::vector<int>& dim, const std::string& t, const std::vector<unsigned char>& data, const Path& path) : + NDArrayNavigator(data::AronNDArrayPtr(new data::AronNDArray(dim, t, data)), path) + { + } + + // operators + bool NDArrayNavigator::operator==(const NDArrayNavigator& other) const + { + const auto otherAron = other.toAronNDArrayPtr(); + if (aron->dimensions != otherAron->dimensions) + { + return false; + } + if (aron->type != otherAron->type) + { + return false; + } + // performs memcmp + if (aron->data != otherAron->data) + { + return false; + } + return true; + } + + bool NDArrayNavigator::equalsDataNavigator(const NavigatorPtr& other) const + { + if (other == nullptr) + { + return false; + } + NDArrayNavigatorPtr casted = DynamicCast(other); + return equalsDeep(casted); + } + + bool NDArrayNavigator::equalsDeep(const NDArrayNavigatorPtr& other) const + { + return *this == *other; + } + + + // static methods + NDArrayNavigatorPtr NDArrayNavigator::DynamicCast(const NavigatorPtr& n) + { + NDArrayNavigatorPtr casted = std::dynamic_pointer_cast<NDArrayNavigator>(n); + return casted; + } + + NDArrayNavigator NDArrayNavigator::DynamicCast(Navigator& n) + { + return dynamic_cast<NDArrayNavigator&>(n); + } + + NDArrayNavigatorPtr NDArrayNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckDataNavigatorPtrForNull("NDArrayNavigator", "DynamicCastAndCheck[Before]", n); + NDArrayNavigatorPtr casted = NDArrayNavigator::DynamicCast(n); + CheckDataNavigatorPtrForNull("NDArrayNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); + return casted; + } + + NDArrayNavigatorPtr NDArrayNavigator::FromAronNDArrayPtr(const data::AronNDArrayPtr& aron) + { + return std::make_shared<NDArrayNavigator>(aron); + } + + data::AronNDArrayPtr NDArrayNavigator::ToAronNDArrayPtr(const NDArrayNavigatorPtr& navigator) + { + return navigator ? navigator->toAronNDArrayPtr() : nullptr; + } + + // public member functions + unsigned char* NDArrayNavigator::getData() const + { + return aron->data.data(); + } + + void NDArrayNavigator::setData(unsigned int elements, const unsigned char* src) + { + aron->data = std::vector<unsigned char>(elements); + memcpy(aron->data.data(), src, elements); + } + + std::vector<int> NDArrayNavigator::getDimensions() const + { + return aron->dimensions; + } + + void NDArrayNavigator::setDimensions(const std::vector<int>& d) + { + aron->dimensions = d; + } + + void NDArrayNavigator::addDimension(int i) + { + aron->dimensions.push_back(i); + } + + std::string NDArrayNavigator::getType() const + { + return aron->type; + } + + void NDArrayNavigator::setType(const std::string& t) + { + if (t.empty()) + { + throw error::AronException("NDArrayNavigator", "setType", "The type cannot be empty", getPath()); + } + + aron->type = t; + } + + data::AronNDArrayPtr NDArrayNavigator::toAronNDArrayPtr() const + { + return aron; + } + + // virtual implementations + data::AronDataPtr NDArrayNavigator::getResult() const + { + return toAronNDArrayPtr(); + } + + std::string NDArrayNavigator::getName() const + { + return "AronNDArray<" + simox::alg::to_string(aron->dimensions, ", ") + ", " + aron->type + ">"; + } + + typenavigator::NavigatorPtr NDArrayNavigator::recalculateType() const + { + // We set all to openCVMat because it accepts n-dimensional types + typenavigator::OpenCVMatNavigatorPtr typenav = typenavigator::OpenCVMatNavigatorPtr(new typenavigator::OpenCVMatNavigator(getPath())); + typenav->setDimensions(std::vector<int>(aron->dimensions.begin(), std::prev(aron->dimensions.end()))); + typenav->setTypename(aron->type); + return typenav; + } + + bool NDArrayNavigator::fullfillsType(const typenavigator::NavigatorPtr& type) const + { + if (!Resolver::Correspond(type->getDescriptor(), getDescriptor())) + { + return false; + } + + switch (type->getDescriptor()) + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +case type::e##upperType: \ +{ \ +typenavigator::upperType##NavigatorPtr casted = typenavigator::upperType##Navigator::DynamicCast(type); \ +if (std::vector<int>(aron->dimensions.begin(), std::prev(aron->dimensions.end())) != casted->getDimensions() || aron->type != casted->getTypename()) \ +{ \ +return false; \ +} \ +break; \ +} + + HANDLE_NDARRAY_TYPES +#undef RUN_ARON_MACRO + default: + throw error::AronException("NDArrayNavigator", "fullfillsType", "Could not cast a type to an NDArray-Type", getPath()); + } + return true; + } + + std::string NDArrayNavigator::DimensionsToString(const std::vector<int>& dimensions) + { + std::stringstream ss; + ss << "(" << simox::alg::join(simox::alg::multi_to_string(dimensions), ", ") << ")"; + return ss.str(); + } + + std::vector<NavigatorPtr> NDArrayNavigator::getChildren() const + { + return {}; + } + + size_t NDArrayNavigator::childrenSize() const + { + return 0; + } +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h new file mode 100644 index 0000000000000000000000000000000000000000..60d8361038c5d0aeba9f9d902f038dfd0386a96f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/complex/NDArray.h @@ -0,0 +1,92 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <map> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> + +namespace armarx::aron::datanavigator +{ + class NDArrayNavigator; + typedef std::shared_ptr<NDArrayNavigator> NDArrayNavigatorPtr; + + class NDArrayNavigator : + virtual public Navigator + { + public: + using PointerType = NDArrayNavigatorPtr; + + public: + // constructors + NDArrayNavigator(const Path& path = Path()); + NDArrayNavigator(const data::AronNDArrayPtr&, const Path& path = Path()); + NDArrayNavigator(const std::vector<int>&, const std::string&, const std::vector<unsigned char>&, const Path& path = Path()); + + // operators + bool operator==(const NDArrayNavigator&) const; + virtual bool equalsDataNavigator(const NavigatorPtr&) const override; + bool equalsDeep(const NDArrayNavigatorPtr&) const; + + // static methods + static NDArrayNavigatorPtr DynamicCast(const NavigatorPtr& n); + static NDArrayNavigator DynamicCast(Navigator& n); + static NDArrayNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + static NDArrayNavigatorPtr FromAronNDArrayPtr(const data::AronNDArrayPtr& aron); + static data::AronNDArrayPtr ToAronNDArrayPtr(const NDArrayNavigatorPtr& navigator); + + /// Return dimensions in a readable string such as "(2, 3, 4)". + static std::string DimensionsToString(const std::vector<int>& dimensions); + + + // public member functions + unsigned char* getData() const; + void setData(unsigned int, const unsigned char*); + + std::vector<int> getDimensions() const; + void setDimensions(const std::vector<int>&); + void addDimension(int); + + std::string getType() const; + void setType(const std::string&); + + data::AronNDArrayPtr toAronNDArrayPtr() const; + + // virtual implementations + virtual data::AronDataPtr getResult() const override; + virtual std::string getName() const override; + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + + virtual typenavigator::NavigatorPtr recalculateType() const override; + virtual bool fullfillsType(const typenavigator::NavigatorPtr&) const override; + + private: + data::AronNDArrayPtr aron; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47c94a46ed0c90f49ecaadca8e534aa0c71b6374 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.cpp @@ -0,0 +1,296 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Dict.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Dict.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::aron::datanavigator + { + + // constructors + DictNavigator::DictNavigator(const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eDict, path), + Navigator(data::Descriptor::eDict, path), + aron(new data::AronDict()) + { + } + + DictNavigator::DictNavigator(const data::AronDictPtr& o, const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eDict, path), + Navigator(data::Descriptor::eDict, path), + aron(o) + { + CheckAronPtrForNull("DictNavigator", "DictNavigator", getPath(), aron); + + for (const auto& [key, dataPtr] : aron->elements) + { + childrenNavigators[key] = Navigator::FromAronData(dataPtr, Path(path, key)); + } + } + + DictNavigator::DictNavigator(const data::AronDataDict& d, const Path& path) : + DictNavigator(data::AronDictPtr(new data::AronDict(d)), path) + { + } + + DictNavigator::DictNavigator(const std::map<std::string, NavigatorPtr>& m, const Path& path) : + DictNavigator(path) + { + for (const auto& [key, dataPtr] : m) + { + addElement(key, dataPtr); + } + } + + // operators + bool DictNavigator::operator==(const DictNavigator& other) const + { + for (const auto& [key, nav] : childrenNavigators) + { + if (not(other.hasElement(key))) + { + return false; + } + if (not(nav->equalsDataNavigator(other.getElement(key)))) + { + return false; + } + } + return true; + } + + bool DictNavigator::equalsDataNavigator(const NavigatorPtr& other) const + { + if (other == nullptr) + { + return false; + } + DictNavigatorPtr casted = DynamicCast(other); + return equalsDeep(casted); + } + + bool DictNavigator::equalsDeep(const DictNavigatorPtr& other) const + { + return *this == *other; + } + + // static methods + DictNavigatorPtr DictNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<DictNavigator>(n); + } + + DictNavigator DictNavigator::DynamicCast(Navigator& n) + { + return dynamic_cast<DictNavigator&>(n); + } + + DictNavigatorPtr DictNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckDataNavigatorPtrForNull("DictNavigator", "DynamicCastAndCheck[Before]", n); + DictNavigatorPtr casted = DictNavigator::DynamicCast(n); + CheckDataNavigatorPtrForNull("DictNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); + return casted; + } + + DictNavigatorPtr DictNavigator::FromAronDictPtr(const data::AronDictPtr& aron) + { + return std::make_shared<DictNavigator>(aron); + } + + data::AronDictPtr DictNavigator::ToAronDictPtr(const DictNavigatorPtr& navigator) + { + return navigator ? navigator->toAronDictPtr() : nullptr; + } + + data::AronDictPtr DictNavigator::toAronDictPtr() const + { + return aron; + } + + // public member functions + std::vector<std::string> DictNavigator::getAllKeys() const + { + std::vector<std::string> ret; + for (const auto& [key, _] : childrenNavigators) + { + ret.push_back(key); + } + return ret; + } + + void DictNavigator::addElement(const std::string& key, const NavigatorPtr& data) + { + this->childrenNavigators[key] = data; + this->aron->elements[key] = data->getResult(); + } + + bool DictNavigator::hasElement(const std::string& key) const + { + return childrenNavigators.count(key) > 0; + } + + NavigatorPtr DictNavigator::getElement(const std::string& key) const + { + auto it = childrenNavigators.find(key); + if (it == childrenNavigators.end()) + { + std::string all_keys = ""; + for (const auto& child : this->getAllKeys()) + { + all_keys += child + ", "; + } + throw error::AronException("DictNavigator", "getElement", "Could not find key '" + key + "'. But I found the following keys: [" + all_keys + "]", getPath()); + } + return it->second; + } + + std::map<std::string, NavigatorPtr> DictNavigator::getElements() const + { + return childrenNavigators; + } + + void DictNavigator::clear() + { + childrenNavigators.clear(); + aron->elements.clear(); + } + + // virtual implementations + data::AronDataPtr DictNavigator::getResult() const + { + return toAronDictPtr(); + } + + std::string DictNavigator::getName() const + { + return "AronDict"; + } + + typenavigator::NavigatorPtr DictNavigator::recalculateType() const + { + typenavigator::DictNavigatorPtr typenav = typenavigator::DictNavigatorPtr(new typenavigator::DictNavigator(getPath())); + for (const auto& [key, nav] : childrenNavigators) + { + if (typenav->getAcceptedType() == nullptr) + { + typenav->setAcceptedType(nav->recalculateType()); + continue; + } + + if (!nav->fullfillsType(typenav->getAcceptedType())) + { + throw error::AronException("DictNavigator", "recalculateType", "Cannot recalculate the aronType. Inconsistency found for key: " + key, getPath()); + } + } + return typenav->getAcceptedType(); + } + + bool DictNavigator::fullfillsType(const typenavigator::NavigatorPtr& type) const + { + if (!Resolver::Correspond(type->getDescriptor(), getDescriptor())) + { + return false; + } + + type::Descriptor typeDesc = type->getDescriptor(); + switch(typeDesc) + { + case type::eObject: + { + typenavigator::ObjectNavigatorPtr objectTypeNav = typenavigator::ObjectNavigator::DynamicCast(type); + for (const auto& [key, nav] : childrenNavigators) + { + if (!nav->fullfillsType(objectTypeNav->getMemberType(key))) + { + return false; + } + } + return true; + } + case type::eDict: + { + typenavigator::DictNavigatorPtr dictTypeNav = typenavigator::DictNavigator::DynamicCast(type); + for (const auto& [_, nav] : childrenNavigators) + { + if (!nav->fullfillsType(dictTypeNav->getAcceptedType())) + { + return false; + } + } + return true; + } + default: + return false; + } + } + + std::vector<NavigatorPtr> DictNavigator::getChildren() const + { + std::vector<NavigatorPtr> ret(childrenNavigators.size()); + for (const auto& [key, nav] : childrenNavigators) + { + ret.push_back(nav); + } + return ret; + } + + size_t DictNavigator::childrenSize() const + { + return childrenNavigators.size(); + } + + NavigatorPtr DictNavigator::navigateAbsolute(const Path& path) const + { + if (!path.hasElement()) + { + throw error::AronException("DictNavigator", "navigate", "Could not navigate without a valid path. The path was empty."); + } + std::string el = path.getFirstElement(); + if (!hasElement(el)) + { + throw error::StringNotValidException("DictNavigator", "navigate", "Could not find an element of a path.", el); + } + + if (path.size() == 1) + { + return childrenNavigators.at(el); + } + else + { + Path next = path.withDetachedFirstElement(); + return childrenNavigators.at(el)->navigateAbsolute(next); + } + } + + NavigatorPtr DictNavigator::navigateRelative(const Path& path) const + { + Path absoluteFromHere = path.getWithoutPrefix(getPath()); + return navigateAbsolute(absoluteFromHere); + } +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h new file mode 100644 index 0000000000000000000000000000000000000000..98c07794a3a7cb7423ced2559ce91887bd2c2637 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/Dict.h @@ -0,0 +1,93 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <map> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Dict.h> + +namespace armarx::aron::datanavigator +{ + class DictNavigator; + typedef std::shared_ptr<DictNavigator> DictNavigatorPtr; + + class DictNavigator : + virtual public Navigator + { + public: + using PointerType = DictNavigatorPtr; + + public: + // constructors + DictNavigator(const Path& path = Path()); + DictNavigator(const data::AronDictPtr&, const Path& path = Path()); + DictNavigator(const data::AronDataDict&, const Path& path = Path()); + DictNavigator(const std::map<std::string, NavigatorPtr>&, const Path& path = Path()); + + // operators + bool operator==(const DictNavigator&) const; + virtual bool equalsDataNavigator(const NavigatorPtr&) const override; + bool equalsDeep(const DictNavigatorPtr&) const; + + // static methods + static DictNavigatorPtr DynamicCast(const NavigatorPtr& n); + static DictNavigator DynamicCast(Navigator& n); + static DictNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + static DictNavigatorPtr FromAronDictPtr(const data::AronDictPtr& aron); + static data::AronDictPtr ToAronDictPtr(const DictNavigatorPtr& navigator); + + // public member functions + data::AronDictPtr toAronDictPtr() const; + std::vector<std::string> getAllKeys() const; + + void addElement(const std::string& key, const NavigatorPtr&); + bool hasElement(const std::string&) const; + NavigatorPtr getElement(const std::string&) const; + std::map<std::string, NavigatorPtr> getElements() const; + + void clear(); + + // virtual implementations + virtual data::AronDataPtr getResult() const override; + virtual std::string getName() const override; + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + + virtual typenavigator::NavigatorPtr recalculateType() const override; + virtual bool fullfillsType(const typenavigator::NavigatorPtr&) const override; + + virtual NavigatorPtr navigateAbsolute(const Path& path) const override; + virtual NavigatorPtr navigateRelative(const Path& path) const override; + + private: + // members + std::map<std::string, NavigatorPtr> childrenNavigators; + data::AronDictPtr aron; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9c546a460d12248ecef198c2f25369e803fd0ec --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.cpp @@ -0,0 +1,292 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "List.h" + +// ArmarX +#include <ArmarXCore/core/exceptions/Exception.h> +#include <RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Pair.h> + +namespace armarx::aron::datanavigator + { + // constructors + ListNavigator::ListNavigator(const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eList, path), + Navigator(data::Descriptor::eList, path), + aron(new data::AronList()) + { + } + + ListNavigator::ListNavigator(const data::AronListPtr& l, const Path& path) : + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::eList, path), + Navigator(data::Descriptor::eList, path), + aron(l) + { + CheckAronPtrForNull("ListNavigator", "ListNavigator", getPath(), aron); + + unsigned int i = 0; + for (const auto& dataPtr : l->elements) + { + childrenNavigators.push_back(FromAronData(dataPtr, Path(path, std::to_string(i++)))); + } + } + + ListNavigator::ListNavigator(const data::AronDataList& d, const Path& path) : + ListNavigator(data::AronListPtr(new data::AronList(d)), path) + { + } + + ListNavigator::ListNavigator(const std::vector<NavigatorPtr>& n, const Path& path) : + ListNavigator(path) + { + for (const auto& dataPtr : n) + { + addElement(dataPtr); + } + } + + // operators + bool ListNavigator::operator==(const ListNavigator& other) const + { + unsigned int i = 0; + for (const auto& nav : childrenNavigators) + { + if (not(other.hasElement(i))) + { + return false; + } + if (not(nav->equalsDataNavigator(other.getElement(i)))) + { + return false; + } + i++; + } + return true; + } + + bool ListNavigator::equalsDataNavigator(const NavigatorPtr& other) const + { + if (other == nullptr) + { + return false; + } + ListNavigatorPtr casted = DynamicCast(other); + return equalsDeep(casted); + } + + bool ListNavigator::equalsDeep(const ListNavigatorPtr& other) const + { + return *this == *other; + } + + // static methods + ListNavigatorPtr ListNavigator::DynamicCast(const NavigatorPtr& n) + { + ListNavigatorPtr casted = std::dynamic_pointer_cast<ListNavigator>(n); + return casted; + } + + ListNavigator ListNavigator::DynamicCast(Navigator& n) + { + return dynamic_cast<ListNavigator&>(n); + } + + ListNavigatorPtr ListNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckDataNavigatorPtrForNull("ListNavigator", "DynamicCastAndCheck[Before]", n); + ListNavigatorPtr casted = ListNavigator::DynamicCast(n); + CheckDataNavigatorPtrForNull("ListNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); + return casted; + } + + ListNavigatorPtr ListNavigator::FromAronListPtr(const data::AronListPtr& aron) + { + return std::make_shared<ListNavigator>(aron); + } + + data::AronListPtr ListNavigator::ToAronListPtr(const ListNavigatorPtr& navigator) + { + return navigator ? navigator->toAronListPtr() : nullptr; + } + + // public member functions + void ListNavigator::addElement(const NavigatorPtr& n) + { + childrenNavigators.push_back(n); + aron->elements.push_back(n->getResult()); + } + + bool ListNavigator::hasElement(unsigned int i) const + { + return i < childrenNavigators.size(); + } + + NavigatorPtr ListNavigator::getElement(unsigned int i) const + { + if (i >= childrenNavigators.size()) + { + throw error::AronException("ListNavigator", "getElement", "The index i = " + std::to_string(i) + " is out of bounds (size = " + std::to_string(childrenNavigators.size()) + ")", getPath()); + } + return childrenNavigators[i]; + } + + std::vector<NavigatorPtr> ListNavigator::getElements() const + { + return childrenNavigators; + } + + void ListNavigator::clear() + { + childrenNavigators.clear(); + aron->elements.clear(); + } + + data::AronListPtr ListNavigator::toAronListPtr() const + { + return aron; + } + + // virtual implementations + data::AronDataPtr ListNavigator::getResult() const + { + return toAronListPtr(); + } + + std::string ListNavigator::getName() const + { + return "AronList"; + } + + typenavigator::NavigatorPtr ListNavigator::recalculateType() const + { + typenavigator::ListNavigatorPtr typenav = typenavigator::ListNavigatorPtr(new typenavigator::ListNavigator(getPath())); + unsigned int i = 0; + for (const auto& nav : childrenNavigators) + { + if (typenav->getAcceptedType() == nullptr) + { + typenav->setAcceptedType(nav->recalculateType()); + continue; + } + + if (!nav->fullfillsType(typenav->getAcceptedType())) + { + throw error::AronException("ListNavigator", "recalculateType", "Cannot recalculate the aronType. Inconsistency found for index: " + std::to_string(i), getPath()); + } + ++i; + } + return typenav->getAcceptedType(); + } + + bool ListNavigator::fullfillsType(const typenavigator::NavigatorPtr& type) const + { + if (!Resolver::Correspond(type->getDescriptor(), getDescriptor())) + { + return false; + } + + type::Descriptor typeDesc = type->getDescriptor(); + switch(typeDesc) + { + case type::eList: + { + typenavigator::ListNavigatorPtr listTypeNav = typenavigator::ListNavigator::DynamicCast(type); + for (const auto& nav : childrenNavigators) + { + if (!nav->fullfillsType(listTypeNav->getAcceptedType())) + { + return false; + } + } + return true; + } + case type::eTuple: + { + typenavigator::TupleNavigatorPtr tupleTypeNav = typenavigator::TupleNavigator::DynamicCast(type); + unsigned int i = 0; + for (const auto& nav : childrenNavigators) + { + if (!nav->fullfillsType(tupleTypeNav->getAcceptedType(i))) + { + return false; + } + } + return true; + } + case type::ePair: + { + typenavigator::PairNavigatorPtr pairTypeNav = typenavigator::PairNavigator::DynamicCast(type); + if(childrenSize() != 2) + { + return false; + } + return childrenNavigators[0]->fullfillsType(pairTypeNav->getFirstAcceptedType()) && childrenNavigators[1]->fullfillsType(pairTypeNav->getSecondAcceptedType()); + } + default: + return false; + } + } + + std::vector<NavigatorPtr> ListNavigator::getChildren() const + { + return childrenNavigators; + } + + size_t ListNavigator::childrenSize() const + { + return childrenNavigators.size(); + } + + NavigatorPtr ListNavigator::navigateAbsolute(const Path& path) const + { + if (!path.hasElement()) + { + throw error::AronException("ListNavigator", "navigate", "Could not navigate without a valid path. The path was empty."); + } + unsigned int i = std::stoi(path.getFirstElement()); + if (!hasElement(i)) + { + throw error::IndexNotValidException("ListNavigator", "navigate", "Could not find an element of a path.", i, childrenSize()); + } + + if (path.size() == 1) + { + return childrenNavigators.at(i); + } + else + { + Path next = path.withDetachedFirstElement(); + return childrenNavigators.at(i)->navigateAbsolute(next); + } + } + + NavigatorPtr ListNavigator::navigateRelative(const Path& path) const + { + Path absoluteFromHere = path.getWithoutPrefix(getPath()); + return navigateAbsolute(absoluteFromHere); + } +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h new file mode 100644 index 0000000000000000000000000000000000000000..63b2f03059d6fde007fbe84b690561b75e7d0d23 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/container/List.h @@ -0,0 +1,91 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> + +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/List.h> + +namespace armarx::aron::datanavigator +{ + class ListNavigator; + typedef std::shared_ptr<ListNavigator> ListNavigatorPtr; + + class ListNavigator : + virtual public Navigator + { + public: + using PointerType = ListNavigatorPtr; + + public: + // constructors + ListNavigator(const Path& path = Path()); + ListNavigator(const data::AronListPtr&, const Path& path = Path()); + ListNavigator(const data::AronDataList&, const Path& path = Path()); + ListNavigator(const std::vector<NavigatorPtr>&, const Path& path = Path()); + + // operators + bool operator==(const ListNavigator&) const; + virtual bool equalsDataNavigator(const NavigatorPtr&) const override; + bool equalsDeep(const ListNavigatorPtr&) const; + + // static methods + static ListNavigatorPtr DynamicCast(const NavigatorPtr& n); + static ListNavigator DynamicCast(Navigator& n); + static ListNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + static ListNavigatorPtr FromAronListPtr(const data::AronListPtr& aron); + static data::AronListPtr ToAronListPtr(const ListNavigatorPtr& navigator); + + // public member functions + data::AronListPtr toAronListPtr() const; + + void addElement(const NavigatorPtr&); + NavigatorPtr getElement(unsigned int) const; + bool hasElement(unsigned int) const; + std::vector<NavigatorPtr> getElements() const; + + void clear(); + + // virtual implementations + virtual data::AronDataPtr getResult() const override; + virtual std::string getName() const override; + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + + virtual typenavigator::NavigatorPtr recalculateType() const override; + virtual bool fullfillsType(const typenavigator::NavigatorPtr&) const override; + + virtual NavigatorPtr navigateAbsolute(const Path& path) const override; + virtual NavigatorPtr navigateRelative(const Path& path) const override; + + private: + std::vector<NavigatorPtr> childrenNavigators; + data::AronListPtr aron; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.cpp b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5b3ea636c67aee8261abedba5099ba3a8f927ea --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.cpp @@ -0,0 +1,156 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "Primitive.h" + +#include <RobotAPI/libraries/aron/core/navigator/data/NavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h> + +namespace armarx::aron::datanavigator + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + /* constructors */ \ + upperType##Navigator::upperType##Navigator(const data::Aron##upperType##Ptr& o, const Path& path) : \ + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::e##upperType, path), \ + Navigator(data::Descriptor::e##upperType, path), \ + aron(o) \ + { \ + } \ + \ + upperType##Navigator::upperType##Navigator(const Path& path) : \ + aron::Navigator<data::Descriptor, data::AronData>::Navigator(data::Descriptor::e##upperType, path), \ + Navigator(data::Descriptor::e##upperType, path), \ + aron(new data::Aron##upperType()) \ + { \ + } \ + \ + upperType##Navigator::upperType##Navigator(const lowerType& d, const Path& path) : \ + upperType##Navigator(data::Aron##upperType##Ptr(new data::Aron##upperType(d)), path) \ + { \ + } \ + \ + /* operators */ \ + bool upperType##Navigator::operator==(const upperType##Navigator& other) const \ + { \ + const auto& otherAron = other.toAron##upperType##Ptr(); \ + if(aron->value != otherAron->value) \ + return false; \ + return true; \ + } \ + \ + bool upperType##Navigator::equalsDataNavigator(const NavigatorPtr& other) const \ + { \ + if(other == nullptr) \ + { \ + return false; \ + } \ + upperType##NavigatorPtr casted = DynamicCast(other); \ + return equalsDeep(casted); \ + } \ + \ + bool upperType##Navigator::equalsDeep(const upperType##NavigatorPtr& other) const \ + { \ + /* only for consistency. There is no "deep" comparison. */ \ + return *this == *other; \ + } \ + \ + /* static methods */ \ + upperType##NavigatorPtr upperType##Navigator::DynamicCast(const NavigatorPtr& n) \ + { \ + upperType##NavigatorPtr casted = std::dynamic_pointer_cast<upperType##Navigator>(n); \ + return casted; \ + } \ + \ + upperType##Navigator upperType##Navigator::DynamicCast(Navigator& n) \ + { \ + return dynamic_cast<upperType##Navigator&>(n); \ + } \ + \ + upperType##NavigatorPtr upperType##Navigator::DynamicCastAndCheck(const NavigatorPtr& n) \ + { \ + CheckDataNavigatorPtrForNull("Aron"+std::string(#upperType)+"DataNavigator", "DynamicCastAndCheck[Before]", n); \ + upperType##NavigatorPtr casted = upperType##Navigator::DynamicCast(n); \ + CheckDataNavigatorPtrForNull("Aron"+std::string(#upperType)+"DataNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); \ + return casted; \ + } \ + \ + upperType##NavigatorPtr upperType##Navigator::FromAron##upperType##Ptr(const data::Aron##upperType##Ptr& aron) \ + { \ + return std::make_shared<upperType##Navigator>(aron); \ + } \ + \ + data::Aron##upperType##Ptr upperType##Navigator::ToAron##upperType##Ptr(const upperType##NavigatorPtr& navigator) \ + { \ + return navigator ? navigator->toAron##upperType##Ptr() : nullptr; \ + } \ + \ + /* public member functions */ \ + void upperType##Navigator::setValue(const lowerType& x) \ + { \ + aron->value = x; \ + } \ + \ + lowerType upperType##Navigator::getValue() const \ + { \ + return aron->value; \ + } \ + \ + data::Aron##upperType##Ptr upperType##Navigator::toAron##upperType##Ptr() const \ + { \ + return aron; \ + } \ + \ + /* virtual implementations */ \ + data::AronDataPtr upperType##Navigator::getResult() const \ + { \ + return aron; \ + } \ + \ + std::string upperType##Navigator::getName() const \ + { \ + return "Aron" + std::string(#upperType); \ + } \ + \ + bool upperType##Navigator::fullfillsType(const typenavigator::NavigatorPtr& type) const \ + { \ + return Resolver::Correspond(type->getDescriptor(), getDescriptor()); \ + } \ + \ + typenavigator::NavigatorPtr upperType##Navigator::recalculateType() const \ + { \ + return typenavigator::upperType##NavigatorPtr(new typenavigator::upperType##Navigator(getPath())); \ + } \ + \ + std::vector<NavigatorPtr> upperType##Navigator::getChildren() const \ + { \ + return {}; \ + } \ + \ + size_t upperType##Navigator::childrenSize() const \ + { \ + return 0; \ + } \ + + HANDLE_PRIMITIVE_DATA +#undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h similarity index 52% rename from source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h rename to source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h index 5f74de20505f749c204a594a163601c2ea1835db..195887d017be92fdd3cbeb36729d9c507834ef94 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h +++ b/source/RobotAPI/libraries/aron/core/navigator/data/primitive/Primitive.h @@ -28,47 +28,43 @@ // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> +#include <RobotAPI/libraries/aron/core/navigator/data/Navigator.h> -namespace armarx +namespace armarx::aron::datanavigator { - namespace aron - { - namespace datanavigator - { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##DataNavigator; \ - typedef std::shared_ptr<Aron##upperType##DataNavigator> Aron##upperType##DataNavigatorPtr; + class upperType##Navigator; \ + typedef std::shared_ptr<upperType##Navigator> upperType##NavigatorPtr; - HANDLE_PRIMITIVE_TYPES + HANDLE_PRIMITIVE_DATA #undef RUN_ARON_MACRO #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##DataNavigator : \ - virtual public AronPrimitiveDataNavigator \ + class upperType##Navigator : \ + virtual public Navigator \ { \ public: \ - using PointerType = Aron##upperType##DataNavigatorPtr; \ + using PointerType = upperType##NavigatorPtr; \ \ /* constructors */ \ - Aron##upperType##DataNavigator(const AronPath& = AronPath()); \ - Aron##upperType##DataNavigator(const data::Aron##upperType##Ptr&, const AronPath& = AronPath()); \ - Aron##upperType##DataNavigator(const lowerType&, const AronPath& = AronPath()); \ + upperType##Navigator(const Path& = Path()); \ + upperType##Navigator(const data::Aron##upperType##Ptr&, const Path& = Path()); \ + upperType##Navigator(const lowerType&, const Path& = Path()); \ \ /* operators */ \ - bool operator==(const Aron##upperType##DataNavigator&) const; \ - virtual bool equalsDataNavigator(const AronDataNavigatorPtr&) const override; \ - bool equalsDeep(const Aron##upperType##DataNavigatorPtr&) const; \ + bool operator==(const upperType##Navigator&) const; \ + virtual bool equalsDataNavigator(const NavigatorPtr&) const override; \ + bool equalsDeep(const upperType##NavigatorPtr&) const; \ \ /* static methods */ \ - static Aron##upperType##DataNavigatorPtr DynamicCast(const AronDataNavigatorPtr& n); \ - static Aron##upperType##DataNavigator DynamicCast(AronDataNavigator& n); \ - static Aron##upperType##DataNavigatorPtr DynamicCastAndCheck(const AronDataNavigatorPtr& n); \ + static upperType##NavigatorPtr DynamicCast(const NavigatorPtr& n); \ + static upperType##Navigator DynamicCast(Navigator& n); \ + static upperType##NavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); \ \ - static Aron##upperType##DataNavigatorPtr FromAron##upperType##Ptr(const data::Aron##upperType##Ptr& aron); \ - static data::Aron##upperType##Ptr ToAron##upperType##Ptr(const Aron##upperType##DataNavigatorPtr& navigator); \ + static upperType##NavigatorPtr FromAron##upperType##Ptr(const data::Aron##upperType##Ptr& aron); \ + static data::Aron##upperType##Ptr ToAron##upperType##Ptr(const upperType##NavigatorPtr& navigator); \ \ /* public member functions */ \ void setValue(const lowerType& x); \ @@ -79,19 +75,17 @@ namespace armarx /* virtual implementations */ \ virtual data::AronDataPtr getResult() const override; \ virtual std::string getName() const override; \ - virtual std::vector<AronDataNavigatorPtr> getChildren() const override; \ + virtual std::vector<NavigatorPtr> getChildren() const override; \ virtual size_t childrenSize() const override; \ \ - virtual typenavigator::AronTypeNavigatorPtr recalculateType() const override; \ - virtual bool fullfillsType(const typenavigator::AronTypeNavigatorPtr&) const override; \ + virtual typenavigator::NavigatorPtr recalculateType() const override; \ + virtual bool fullfillsType(const typenavigator::NavigatorPtr&) const override; \ \ private: \ /* members */ \ data::Aron##upperType##Ptr aron; \ }; - HANDLE_PRIMITIVE_TYPES + HANDLE_PRIMITIVE_DATA #undef RUN_ARON_MACRO - } - } } diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h b/source/RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h new file mode 100644 index 0000000000000000000000000000000000000000..d1b5b03a26dd0ac3784223887c43fd54ecddcd7b --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h @@ -0,0 +1,18 @@ +#pragma once + +#include "container/Dict.h" +#include "container/List.h" +#include "container/Object.h" +#include "container/Pair.h" +#include "container/Tuple.h" +#include "ndarray/EigenMatrix.h" +#include "ndarray/EigenQuaternion.h" +#include "ndarray/IVTCByteImage.h" +#include "ndarray/OpenCVMat.h" +#include "ndarray/Orientation.h" +#include "ndarray/PCLPointCloud.h" +#include "ndarray/PCLPointCloud.h" +#include "ndarray/Pose.h" +#include "ndarray/Position.h" +#include "enum/IntEnum.h" +#include "primitive/Primitive.h" diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1e38841d2647cd986a521ed2e92166dae7f1929e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.cpp @@ -0,0 +1,140 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + +// Header +#include "Navigator.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h> +#include <RobotAPI/libraries/aron/core/navigator/type/container/Object.h> + +namespace armarx::aron::typenavigator +{ + /* Navigator */ + // static data members + const NavigatorFactoryPtr Navigator::FACTORY = NavigatorFactoryPtr(new NavigatorFactory()); + + // constructors + Navigator::Navigator(const type::Descriptor& d, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(d, path) + { + } + + NavigatorPtr Navigator::FromAronType(const type::AronTypePtr& a, const Path& path) + { + return FACTORY->create(a, path); + } + + void Navigator::CheckTypeNavigatorPtrForNull(const std::string& c, const std::string& m, const NavigatorPtr& data) + { + if (data.get() == nullptr) + { + throw error::AronException(c, m, "Could not cast an NavigatorPtr. The Ptr was NULL."); + } + } + + void Navigator::CheckTypeNavigatorPtrForNull(const std::string& c, const std::string& m, const Path& p, const NavigatorPtr& data) + { + if (data.get() == nullptr) + { + throw error::AronException(c, m, "Could not cast an NavigatorPtr. The Ptr was NULL.", p); + } + } + + /* AronSingleAcceptedTypeHavingTypeNavigator */ + /*NavigatorPtr AronSingleAcceptedTypeHavingTypeNavigator::getAcceptedType() const + { + return acceptedTypeNavigator; + } + + size_t AronSingleAcceptedTypeHavingTypeNavigator::childrenSize() const + { + return 1; + }*/ + + /* AronMultipleListAcceptedTypeHavingTypeNavigator */ + /*std::vector<NavigatorPtr> AronMultipleListAcceptedTypeHavingTypeNavigator::getAcceptedTypes() const + { + return acceptedTypeNavigators; + } + + NavigatorPtr AronMultipleListAcceptedTypeHavingTypeNavigator::getAcceptedType(unsigned int i) const + { + if (i >= acceptedTypeNavigators.size()) + { + return nullptr; + } + return acceptedTypeNavigators[i]; + } + + size_t AronMultipleListAcceptedTypeHavingTypeNavigator::childrenSize() const + { + return acceptedTypeNavigators.size(); + }*/ + + /* AronMultipleDictAcceptedTypeHavingTypeNavigator */ + /*std::map<std::string, NavigatorPtr> AronMultipleDictAcceptedTypeHavingTypeNavigator::getAcceptedTypes() const + { + return acceptedTypeNavigators; + } + + NavigatorPtr AronMultipleDictAcceptedTypeHavingTypeNavigator::getAcceptedType(const std::string& s) const + { + if (acceptedTypeNavigators.find(s) == acceptedTypeNavigators.end()) + { + return nullptr; + } + return acceptedTypeNavigators.at(s); + } + + size_t AronMultipleDictAcceptedTypeHavingTypeNavigator::childrenSize() const + { + return acceptedTypeNavigators.size(); + } + + std::vector<std::string> AronMultipleDictAcceptedTypeHavingTypeNavigator::getAllKeys() const + { + std::vector<std::string> ret; + for (const auto& [key, _] : acceptedTypeNavigators) + { + ret.push_back(key); + } + return ret; + }*/ + + /* AronComplexTypeNavigator */ + /*size_t AronComplexTypeNavigator::childrenSize() const + { + return 0; + }*/ + + /* AronPrimitiveTypeNavigator */ + /*size_t AronPrimitiveTypeNavigator::childrenSize() const + { + return 0; + }*/ +} + + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.h b/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.h new file mode 100644 index 0000000000000000000000000000000000000000..863cfac1ced3afc9ea8bc04730aac956c89786fb --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/Navigator.h @@ -0,0 +1,87 @@ +/* +* This file is part of ArmarX. +* +* Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), +* Karlsruhe Institute of Technology (KIT), all rights reserved. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <vector> +#include <map> +#include <string> + +// Simox +#include <SimoxUtility/algorithm/string.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/Exception.h> +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/navigator/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class NavigatorFactory; + typedef std::shared_ptr<NavigatorFactory> NavigatorFactoryPtr; + + class Navigator; + typedef std::shared_ptr<Navigator> NavigatorPtr; + + class Navigator : + virtual public aron::Navigator<type::Descriptor, type::AronType> + { + public: + using PointerType = NavigatorPtr; + + public: + // constructors + Navigator() = delete; + Navigator(const type::Descriptor&, const Path&); + + // virtual methods + virtual std::vector<NavigatorPtr> getChildren() const = 0; + virtual size_t childrenSize() const = 0; + virtual type::AronTypePtr getResult() const override = 0; + virtual std::string getName() const override = 0; + + // static methods + static NavigatorPtr FromAronType(const type::AronTypePtr&, const Path& = Path()); + + template<typename NavigatorType> + static typename NavigatorType::PointerType DynamicCast(const NavigatorPtr& n) + { + return NavigatorType::DynamicCast(n); + } + + template<typename NavigatorType> + static typename NavigatorType::PointerType DynamicCastAndCheck(const NavigatorPtr& n) + { + return NavigatorType::DynamicCastAndCheck(n); + } + + protected: + static void CheckTypeNavigatorPtrForNull(const std::string&, const std::string&, const NavigatorPtr& data); + static void CheckTypeNavigatorPtrForNull(const std::string&, const std::string&, const Path&, const NavigatorPtr& data); + + private: + static const NavigatorFactoryPtr FACTORY; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83b72bf347b46624161b4e2133a049e261d09965 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.cpp @@ -0,0 +1,71 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL + +// Header +#include "NavigatorFactory.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> + +namespace armarx::aron::typenavigator +{ + // Access method + NavigatorPtr NavigatorFactory::create(const type::AronTypePtr& aron, const Path& path) const + { +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + {type::e##upperType, NavigatorFactoryPtr(new upperType##NavigatorFactory())}, + + static const std::map<type::Descriptor, NavigatorFactoryPtr> Factories = + { + HANDLE_ALL_ARON_TYPES + }; +#undef RUN_ARON_MACRO + + auto typeDescriptor = Resolver::GetDescriptor(aron); + auto factory_iterator = Factories.find(typeDescriptor); + if (factory_iterator == Factories.end()) + { + throw error::AronException("NavigatorFactory", "create", "Cannot find the desired factory for input: " + type::DESCRIPTOR_TO_STRING(typeDescriptor) + ". Cannot create navigator", path); + } + return factory_iterator->second->createSpecific(aron, path); + } + + NavigatorPtr NavigatorFactory::createSpecific(const type::AronTypePtr&, const Path& p) const + { + throw error::AronException("NavigatorFactory", "createSpecific", "Called disallowed method of an NavigatorFactory. Use child class instead!", p); + } + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ +NavigatorPtr upperType##NavigatorFactory::createSpecific(const type::AronTypePtr& aron, const Path& path) const \ +{ \ +type::Aron##upperType##Ptr aronCasted = type::Aron##upperType##Ptr::dynamicCast(aron); \ +return typenavigator::NavigatorPtr(new upperType##Navigator(aronCasted, path)); \ +} + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h b/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..b3fcc82e470a335687de636fee0b515996a0229c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/NavigatorFactory.h @@ -0,0 +1,64 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <memory> +#include <unordered_map> + +// BaseClass +#include <RobotAPI/libraries/aron/core/navigator/NavigatorFactory.h> + +// ArmarX +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> +#include <RobotAPI/libraries/aron/core/Descriptor.h> + +namespace armarx::aron::typenavigator +{ + class NavigatorFactory; + typedef std::shared_ptr<NavigatorFactory> NavigatorFactoryPtr; + + class NavigatorFactory : + virtual public armarx::aron::NavigatorFactory<type::AronTypePtr, typenavigator::NavigatorPtr> + { + public: + NavigatorFactory() = default; + virtual typenavigator::NavigatorPtr create(const type::AronTypePtr&, const Path&) const override; + virtual typenavigator::NavigatorPtr createSpecific(const type::AronTypePtr&, const Path&) const override; + }; + + // Factories +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + class upperType##NavigatorFactory : \ + virtual public NavigatorFactory \ + { \ + public: \ + upperType##NavigatorFactory() = default; \ + virtual typenavigator::NavigatorPtr createSpecific(const type::AronTypePtr&, const Path&) const override; \ + }; + + HANDLE_ALL_ARON_TYPES +#undef RUN_ARON_MACRO + +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd14e22ead4f1610d4f4faf4d065396f850496bc --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.cpp @@ -0,0 +1,101 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Dict.h" + + +namespace armarx::aron::typenavigator +{ + // constructors + DictNavigator::DictNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eDict, path), + Navigator(type::Descriptor::eDict, path), + type(new type::AronDict()) + { + + } + + DictNavigator::DictNavigator(const type::AronDictPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eDict, path), + Navigator(type::Descriptor::eDict, path), + type(o) + { + CheckAronPtrForNull("DictNavigator", "DictNavigator", getPath(), o); + acceptedType = FromAronType(o->acceptedType); + } + + NavigatorPtr DictNavigator::getAcceptedType() const + { + return acceptedType; + } + + void DictNavigator::setAcceptedType(const NavigatorPtr& a) + { + type->acceptedType = a->getResult(); + acceptedType = a; + } + + type::AronDictPtr DictNavigator::toAronDictPtr() const + { + CheckAronPtrForNull("DictNavigator", "getResult", getPath(), type->acceptedType); + return type; + } + + // static methods + DictNavigatorPtr DictNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<DictNavigator>(n); + } + + DictNavigatorPtr DictNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("DictNavigator", "DynamicCastAndCheck[Before]", n); + DictNavigatorPtr casted = DictNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("DictNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> DictNavigator::getChildren() const + { + return {acceptedType}; + } + + size_t DictNavigator::childrenSize() const + { + return 1; + } + + type::AronTypePtr DictNavigator::getResult() const + { + CheckAronPtrForNull("DictNavigator", "getResult", getPath(), type->acceptedType); + return type; + } + + std::string DictNavigator::getName() const + { + return "AronDictType<" + acceptedType->getName() + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h b/source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.h similarity index 55% rename from source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h rename to source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.h index b1de1358f8205c823ab05915e1ce82f046ba468f..c92d79874276b00cb9369556065dd7d010902981 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronDictTypeNavigator.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Dict.h @@ -28,47 +28,43 @@ #include <map> // Base Class -#include "AronTypeNavigator.h" +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> -namespace armarx +namespace armarx::aron::typenavigator { - namespace aron - { - namespace typenavigator - { - class AronDictTypeNavigator; - typedef std::shared_ptr<AronDictTypeNavigator> AronDictTypeNavigatorPtr; + class DictNavigator; + typedef std::shared_ptr<DictNavigator> DictNavigatorPtr; - class AronDictTypeNavigator : - virtual public AronSingleAcceptedTypeHavingTypeNavigator, - virtual public AronDictSerializerTypeNavigator + class DictNavigator : + virtual public Navigator { public: - using PointerType = AronDictTypeNavigatorPtr; + using PointerType = DictNavigatorPtr; public: // constructors - AronDictTypeNavigator() = delete; - AronDictTypeNavigator(const AronPath& path); - AronDictTypeNavigator(const type::AronDictTypePtr&, const AronPath& path); + DictNavigator(const Path& path = Path()); + DictNavigator(const type::AronDictPtr&, const Path& path = Path()); - type::AronDictTypePtr toAronDictTypePtr() const; + NavigatorPtr getAcceptedType() const; + void setAcceptedType(const NavigatorPtr&); + + type::AronDictPtr toAronDictPtr() const; // static methods - static AronDictTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronDictTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); + static DictNavigatorPtr DynamicCast(const NavigatorPtr& n); + static DictNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); // virtual implementations - virtual void setAcceptedType(const AronTypeNavigatorPtr&) override; - + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; virtual type::AronTypePtr getResult() const override; virtual std::string getName() const override; private: // members - type::AronDictTypePtr type; + NavigatorPtr acceptedType; + type::AronDictPtr type; }; - } - } } diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/List.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/container/List.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3e87c4d5fbbc7879299e9da5f20d7a2086d87465 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/List.cpp @@ -0,0 +1,99 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "List.h" + +namespace armarx::aron::typenavigator +{ + // constructors + ListNavigator::ListNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eList, path), + Navigator(type::Descriptor::eList, path), + type(new type::AronList()) + { + } + + ListNavigator::ListNavigator(const type::AronListPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eList, path), + Navigator(type::Descriptor::eList, path), + type(o) + { + CheckAronPtrForNull("ListNavigator", "ListNavigator", getPath(), o); + acceptedType = FromAronType(o->acceptedType); + } + + // Member functions + NavigatorPtr ListNavigator::getAcceptedType() const + { + return acceptedType; + } + + void ListNavigator::setAcceptedType(const NavigatorPtr& a) + { + CheckTypeNavigatorPtrForNull("ListNavigator", "setAcceptedType", a); + type->acceptedType = a->getResult(); + acceptedType = a; + } + + // static methods + ListNavigatorPtr ListNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<ListNavigator>(n); + } + + ListNavigatorPtr ListNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("ListNavigator", "DynamicCast[Before]", n); + ListNavigatorPtr casted = ListNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("ListNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + type::AronListPtr ListNavigator::toAronListPtr() const + { + CheckAronPtrForNull("ListNavigator", "getCastedResult", getPath(), type->acceptedType); + return type; + } + + // virtual implementations + std::vector<NavigatorPtr> ListNavigator::getChildren() const + { + return {acceptedType}; + } + + size_t ListNavigator::childrenSize() const + { + return 1; + } + + type::AronTypePtr ListNavigator::getResult() const + { + return toAronListPtr(); + } + + std::string ListNavigator::getName() const + { + return "AronListType<" + acceptedType->getName() + ">"; + } +} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h b/source/RobotAPI/libraries/aron/core/navigator/type/container/List.h similarity index 55% rename from source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h rename to source/RobotAPI/libraries/aron/core/navigator/type/container/List.h index 2bb8fe8c3847c7f8c9d723c6a97ce7340d9ac782..dfb38b2952867c358a4549970c2a883f5fcf5cf3 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronListTypeNavigator.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/List.h @@ -28,46 +28,42 @@ #include <vector> // Base Class -#include "AronTypeNavigator.h" +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> -namespace armarx +namespace armarx::aron::typenavigator { - namespace aron - { - namespace typenavigator - { - class AronListTypeNavigator; - typedef std::shared_ptr<AronListTypeNavigator> AronListTypeNavigatorPtr; + class ListNavigator; + typedef std::shared_ptr<ListNavigator> ListNavigatorPtr; - class AronListTypeNavigator : - virtual public AronSingleAcceptedTypeHavingTypeNavigator, - virtual public AronListSerializerTypeNavigator + class ListNavigator : + virtual public Navigator { public: - using PointerType = AronListTypeNavigatorPtr; + using PointerType = ListNavigatorPtr; public: // constructors - AronListTypeNavigator() = delete; - AronListTypeNavigator(const AronPath& path); - AronListTypeNavigator(const type::AronListTypePtr&, const AronPath& path); + ListNavigator(const Path& path = Path()); + ListNavigator(const type::AronListPtr&, const Path& path = Path()); - type::AronListTypePtr toAronListTypePtr() const; + NavigatorPtr getAcceptedType() const; + void setAcceptedType(const NavigatorPtr&); + + type::AronListPtr toAronListPtr() const; // static methods - static AronListTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronListTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); + static ListNavigatorPtr DynamicCast(const NavigatorPtr& n); + static ListNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); // virtual implementations - virtual void setAcceptedType(const AronTypeNavigatorPtr&) override; - + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; virtual type::AronTypePtr getResult() const override; virtual std::string getName() const override; private: // members - type::AronListTypePtr type; + NavigatorPtr acceptedType; + type::AronListPtr type; }; - } - } } diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f82d1d0776d9b4629f6a75379b56f70661e9531 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.cpp @@ -0,0 +1,177 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Object.h" + + +namespace armarx::aron::typenavigator +{ + + // constructors + ObjectNavigator::ObjectNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eObject, path), + Navigator(type::Descriptor::eObject, path), + type((new type::AronObject())) + { + } + + ObjectNavigator::ObjectNavigator(const std::string& name, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eObject, path), + Navigator(type::Descriptor::eObject, path), + type((new type::AronObject())) + { + setObjectName(name); + } + + ObjectNavigator::ObjectNavigator(const type::AronObjectPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eObject, path), + Navigator(type::Descriptor::eObject, path), + type(o) + { + CheckAronPtrForNull("ObjectNavigator", "ObjectNavigator", getPath(), o); + + for (const auto& [key, t] : o->elementTypes) + { + memberTypes[key] = FromAronType(t); + } + } + + bool ObjectNavigator::checkObjectName(const std::string& s) const + { + if (s.empty()) + { + throw error::AronException("ObjectNavigator", "getResult", "The object name is empty.", getPath()); + } + return true; + } + + // static methods + ObjectNavigatorPtr ObjectNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<ObjectNavigator>(n); + } + + ObjectNavigatorPtr ObjectNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("ObjectNavigator", "DynamicCast[Before]", n); + ObjectNavigatorPtr casted = ObjectNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("ObjectNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // public member functions + std::map<std::string, NavigatorPtr> ObjectNavigator::getMemberTypes() const + { + return memberTypes; + } + + NavigatorPtr ObjectNavigator::getMemberType(const std::string& s) const + { + return memberTypes.at(s); + } + + void ObjectNavigator::addMemberType(const std::string& k, const NavigatorPtr& v) + { + if (k.empty()) + { + throw error::AronException("ObjectNavigator", "addAcceptedType", "Cannot set an element with an empty key.", getPath()); + } + CheckTypeNavigatorPtrForNull("ObjectNavigator", "addAcceptedType", v); + type->elementTypes[k] = v->getResult(); + memberTypes[k] = v; + } + + void ObjectNavigator::setObjectName(const std::string& n) + { + //path.setRootIdentifier(n); + type->objectName = n; + } + + void ObjectNavigator::setExtends(const ObjectNavigatorPtr& p) + { + CheckTypeNavigatorPtrForNull("ObjectNavigator", "setExtends", p); + type::AronObjectPtr ex = p->toAronObjectPtr(); + CheckAronPtrForNull("ObjectNavigator", "setExtends", getPath(), ex); + extends = p; + } + + std::string ObjectNavigator::getObjectName() const + { + return type->objectName; + } + + ObjectNavigatorPtr ObjectNavigator::getExtends() const + { + return extends; + } + + std::vector<std::string> ObjectNavigator::getAllKeys() const + { + std::vector<std::string> ret; + for (const auto& [k, _] : memberTypes) + { + ret.push_back(k); + } + return ret; + } + + type::AronObjectPtr ObjectNavigator::toAronObjectPtr() const + { + checkObjectName(type->objectName); + + // TODO: Shall we allow empty objects? + //if(acceptedTypeNavigators.empty()) + //{ + // throw exception::AronExceptionWithPathInfo("ObjectNavigator", "getResult", "No accepted types set", getPath()); + //} + return type; + } + + // virtual implementations + std::vector<NavigatorPtr> ObjectNavigator::getChildren() const + { + std::vector<NavigatorPtr> ret; + for (const auto& [k, t] : memberTypes) + { + ret.push_back(t); + } + return ret; + } + + size_t ObjectNavigator::childrenSize() const + { + return memberTypes.size(); + } + + type::AronTypePtr ObjectNavigator::getResult() const + { + return toAronObjectPtr(); + } + + std::string ObjectNavigator::getName() const + { + return "AronObjectType<" + type->objectName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.h b/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.h new file mode 100644 index 0000000000000000000000000000000000000000..47d5016284001fe61531544fc479051343b71cf1 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Object.h @@ -0,0 +1,83 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + + +namespace armarx::aron::typenavigator +{ + class ObjectNavigator; + typedef std::shared_ptr<ObjectNavigator> ObjectNavigatorPtr; + + class ObjectNavigator : + virtual public Navigator + { + public: + using PointerType = ObjectNavigatorPtr; + + public: + // constructors + ObjectNavigator(const Path& = Path()); + ObjectNavigator(const std::string&, const Path& = Path()); + ObjectNavigator(const type::AronObjectPtr&, const Path& = Path()); + + // public member functions + bool checkObjectName(const std::string&) const; + + std::map<std::string, NavigatorPtr> getMemberTypes() const; + NavigatorPtr getMemberType(const std::string&) const; + std::string getObjectName() const; + ObjectNavigatorPtr getExtends() const; + + void setObjectName(const std::string&); + void setExtends(const ObjectNavigatorPtr&); + void addMemberType(const std::string&, const NavigatorPtr&); + + std::vector<std::string> getAllKeys() const; + + type::AronObjectPtr toAronObjectPtr() const; + + // static methods + static ObjectNavigatorPtr DynamicCast(const NavigatorPtr& n); + static ObjectNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + private: + // members + ObjectNavigatorPtr extends; + std::map<std::string, NavigatorPtr> memberTypes; + type::AronObjectPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60e8947d4f9876b61c42add47979921e33395567 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.cpp @@ -0,0 +1,135 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Pair.h" + + +namespace armarx::aron::typenavigator +{ + // constructors + PairNavigator::PairNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePair, path), + Navigator(type::Descriptor::ePair, path), + type(new type::AronPair()) + { + + } + + PairNavigator::PairNavigator(const type::AronPairPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePair, path), + Navigator(type::Descriptor::ePair, path), + type(o) + { + CheckAronPtrForNull("AronPairTypeNavigator", "AronPairTypeNavigator", getPath(), o); + + acceptedType1 = FromAronType(o->acceptedType1); + acceptedType2 = FromAronType(o->acceptedType2); + } + + // Member functions + std::pair<NavigatorPtr, NavigatorPtr> PairNavigator::getAcceptedTypes() const + { + return {acceptedType1, acceptedType2}; + } + + NavigatorPtr PairNavigator::getFirstAcceptedType() const + { + return acceptedType1; + } + + NavigatorPtr PairNavigator::getSecondAcceptedType() const + { + return acceptedType2; + } + + void PairNavigator::addAcceptedType(const NavigatorPtr& n) + { + if (acceptedType1 == nullptr) + { + acceptedType1 = n; + return; + } + if (acceptedType2 == nullptr) + { + acceptedType2 = n; + return; + } + throw error::AronException("PairNavigator", "addAcceptedType", "Both types are already set", getPath()); + } + + void PairNavigator::setFirstAcceptedType(const NavigatorPtr& n) + { + acceptedType1 = n; + } + + void PairNavigator::setSecondAcceptedType(const NavigatorPtr& n) + { + acceptedType2 = n; + } + + type::AronPairPtr PairNavigator::toAronPairPtr() const + { + CheckAronPtrForNull("PairNavigator", "getResult", getPath(), type->acceptedType1); + CheckAronPtrForNull("PairNavigator", "getResult", getPath(), type->acceptedType2); + return type; + } + + // static methods + PairNavigatorPtr PairNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<PairNavigator>(n); + } + + PairNavigatorPtr PairNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronPairTypeNavigator", "DynamicCastAndCheck[Before]", n); + PairNavigatorPtr casted = PairNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronPairTypeNavigator", "DynamicCastAndCheck[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> PairNavigator::getChildren() const + { + return {acceptedType1, acceptedType2}; + } + + size_t PairNavigator::childrenSize() const + { + return 2; + } + + type::AronTypePtr PairNavigator::getResult() const + { + CheckAronPtrForNull("PairNavigator", "getResult", getPath(), type->acceptedType1); + CheckAronPtrForNull("PairNavigator", "getResult", getPath(), type->acceptedType2); + return type; + } + + std::string PairNavigator::getName() const + { + return "AronPairType<" + acceptedType1->getName() + ", " + acceptedType2->getName() + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.h b/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.h new file mode 100644 index 0000000000000000000000000000000000000000..999a6c85656aa3ee4b5adc353e3cdbc26d770ce5 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Pair.h @@ -0,0 +1,75 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class PairNavigator; + typedef std::shared_ptr<PairNavigator> PairNavigatorPtr; + + class PairNavigator : + virtual public Navigator + { + public: + using PointerType = PairNavigatorPtr; + + public: + // constructors + PairNavigator(const Path& path = Path()); + PairNavigator(const type::AronPairPtr&, const Path& path = Path()); + + std::pair<NavigatorPtr, NavigatorPtr> getAcceptedTypes() const; + NavigatorPtr getFirstAcceptedType() const; + NavigatorPtr getSecondAcceptedType() const; + void addAcceptedType(const NavigatorPtr&); + void setFirstAcceptedType(const NavigatorPtr&); + void setSecondAcceptedType(const NavigatorPtr&); + + type::AronPairPtr toAronPairPtr() const; + + // static methods + static PairNavigatorPtr DynamicCast(const NavigatorPtr& n); + static PairNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + private: + // members + NavigatorPtr acceptedType1; + NavigatorPtr acceptedType2; + type::AronPairPtr type; + + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1699d1e737aa72600e23009e84567a60172ed33 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.cpp @@ -0,0 +1,118 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Tuple.h" + + +namespace armarx::aron::typenavigator + { + // constructors + TupleNavigator::TupleNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eTuple, path), + Navigator(type::Descriptor::eTuple, path), + type(new type::AronTuple()) + { + } + + TupleNavigator::TupleNavigator(const type::AronTuplePtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eTuple, path), + Navigator(type::Descriptor::eTuple, path), + type(o) + { + CheckAronPtrForNull("TupleNavigator", "TupleNavigator", getPath(), o); + + for (const auto& t : type->elementTypes) + { + acceptedTypes.push_back(FromAronType(t)); + } + } + + type::AronTuplePtr TupleNavigator::toAronTuplePtr() const + { + if (acceptedTypes.empty()) + { + throw error::AronException("TupleNavigator", "getCastedResult", "No accepted types set", getPath()); + } + return type; + } + + // static methods + TupleNavigatorPtr TupleNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<TupleNavigator>(n); + } + + TupleNavigatorPtr TupleNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("TupleNavigator", "DynamicCast[Before]", n); + TupleNavigatorPtr casted = TupleNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("TupleNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // public member functions + std::vector<NavigatorPtr> TupleNavigator::getAcceptedTypes() const + { + return acceptedTypes; + } + + NavigatorPtr TupleNavigator::getAcceptedType(unsigned int i) const + { + return acceptedTypes[i]; + } + + void TupleNavigator::addAcceptedType(const NavigatorPtr& v) + { + CheckTypeNavigatorPtrForNull("TupleNavigator", "addAcceptedType", getPath(), v); + type->elementTypes.push_back(v->getResult()); + acceptedTypes.push_back(v); + } + + // virtual implementations + std::vector<NavigatorPtr> TupleNavigator::getChildren() const + { + return acceptedTypes; + } + + size_t TupleNavigator::childrenSize() const + { + return acceptedTypes.size(); + } + + type::AronTypePtr TupleNavigator::getResult() const + { + return toAronTuplePtr(); + } + + std::string TupleNavigator::getName() const + { + std::vector<std::string> names; + for (const auto& n : acceptedTypes) + { + names.push_back(n->getName()); + } + return "AronTupleType<" + simox::alg::to_string(names, ", ") + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h b/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h new file mode 100644 index 0000000000000000000000000000000000000000..83348835ca0535934989354a8d63e1dcdf5d83bf --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/container/Tuple.h @@ -0,0 +1,69 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class TupleNavigator; + typedef std::shared_ptr<TupleNavigator> TupleNavigatorPtr; + + class TupleNavigator : + virtual public Navigator + { + public: + using PointerType = TupleNavigatorPtr; + + public: + // constructors + TupleNavigator(const Path& path = Path()); + TupleNavigator(const type::AronTuplePtr&, const Path& path = Path()); + + std::vector<NavigatorPtr> getAcceptedTypes() const; + NavigatorPtr getAcceptedType(unsigned int i) const; + void addAcceptedType(const NavigatorPtr&); + + type::AronTuplePtr toAronTuplePtr() const; + + // static methods + static TupleNavigatorPtr DynamicCast(const NavigatorPtr& n); + static TupleNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + private: + std::vector<NavigatorPtr> acceptedTypes; + type::AronTuplePtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b2e4e740c82d21389806eff5ba6cc109823a5d96 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.cpp @@ -0,0 +1,122 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "IntEnum.h" + +namespace armarx::aron::typenavigator +{ + // constructors + IntEnumNavigator::IntEnumNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eIntEnum, path), + Navigator(type::Descriptor::eIntEnum, path), + type(new type::AronIntEnum()) + { + } + + IntEnumNavigator::IntEnumNavigator(const type::AronIntEnumPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eIntEnum, path), + Navigator(type::Descriptor::eIntEnum, path), + type(o) + { + CheckAronPtrForNull("AronEnumTypeNavigator", "AronEnumTypeNavigator", getPath(), o); + } + + std::map<std::string, int> IntEnumNavigator::getAcceptedValues() const + { + return type->acceptedValues; + } + + std::string IntEnumNavigator::getValueName(int i) const + { + for (const auto& [k, v] : type->acceptedValues) + { + if(v == i) + { + return k; + } + } + throw error::AronException("IntEnumNavigator", "getValueName", "Enum could not be resolved. Input was: " + std::to_string(i), getPath()); + } + + int IntEnumNavigator::getValue(const std::string& s) const + { + return type->acceptedValues[s]; + } + + std::string IntEnumNavigator::getEnumName() const + { + return type->enumName; + } + + void IntEnumNavigator::setEnumName(const std::string& s) + { + type->enumName = s; + } + + void IntEnumNavigator::addAcceptedValue(const std::string& s, int i) + { + type->acceptedValues[s] = i; + } + + type::AronIntEnumPtr IntEnumNavigator::toAronIntEnumPtr() const + { + return type; + } + + // static methods + IntEnumNavigatorPtr IntEnumNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<IntEnumNavigator>(n); + } + + IntEnumNavigatorPtr IntEnumNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronEnumTypeNavigator", "DynamicCast[Before]", n); + IntEnumNavigatorPtr casted = IntEnumNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronEnumTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> IntEnumNavigator::getChildren() const + { + return {}; + } + + size_t IntEnumNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr IntEnumNavigator::getResult() const + { + return toAronIntEnumPtr(); + } + + std::string IntEnumNavigator::getName() const + { + return "AronIntEnumType"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h new file mode 100644 index 0000000000000000000000000000000000000000..9556a9d48ee6efb8ab74e37deb6493bbc8ae3ce0 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/enum/IntEnum.h @@ -0,0 +1,76 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class IntEnumNavigator; + typedef std::shared_ptr<IntEnumNavigator> IntEnumNavigatorPtr; + + class IntEnumNavigator : + virtual public Navigator + { + public: + using PointerType = IntEnumNavigatorPtr; + + public: + // constructors + IntEnumNavigator() = delete; + IntEnumNavigator(const Path& path); + IntEnumNavigator(const type::AronIntEnumPtr&, const Path& path); + + std::map<std::string, int> getAcceptedValues() const; + std::string getValueName(int) const; + int getValue(const std::string&) const; + std::string getEnumName() const; + + void setEnumName(const std::string&); + void addAcceptedValue(const std::string&, int); + + type::AronIntEnumPtr toAronIntEnumPtr() const; + + // static methods + static IntEnumNavigatorPtr DynamicCast(const NavigatorPtr& n); + static IntEnumNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + + private: + // members + type::AronIntEnumPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb76098c35a99a7a1fd8a3dbea5fd396a4c5f475 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.cpp @@ -0,0 +1,173 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "EigenMatrix.h" + +namespace armarx::aron::typenavigator +{ + // constructors + EigenMatrixNavigator::EigenMatrixNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eEigenMatrix, path), + Navigator(type::Descriptor::eEigenMatrix, path), + type(new type::AronEigenMatrix({1, 1}, "")) + { + } + + EigenMatrixNavigator::EigenMatrixNavigator(const type::AronEigenMatrixPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eDict, path), + Navigator(type::Descriptor::eEigenMatrix, path), + type(o) + { + CheckAronPtrForNull("AronEigenMatrixNavigator", "AronEigenMatrixNavigator", getPath(), o); + checkDimensions(type->dimensions); + checkTypename(type->typeName); + } + + bool EigenMatrixNavigator::checkDimensions(const std::vector<int>& d) const + { + if (d.size() < ACCEPTED_DIMENSION_MIN_SIZE) + { + throw error::AronException("AronEigenMatrixNavigator", "checkDimensions", "The dimension size is wrong. Got size: " + std::to_string(d.size()), getPath()); + } + + if (std::any_of(d.begin(), d.end(), [](int i) + { + return i < -1 || i == 0; + })) + { + throw error::AronException("AronEigenMatrixNavigator", "checkDimensions", "The dimension size is wrong. At least one empty is < -1 or 0. Got as dimension: " + simox::alg::to_string(d, ", "), getPath()); + } + return true; + } + + bool EigenMatrixNavigator::checkTypename(const std::string& s) const + { + if (s.empty()) + { + throw error::AronException("AronEigenMatrixNavigator", "checkTypename", "The typename is empty.", getPath()); + } + + if (!std::any_of(ACCEPTED_TYPES.begin(), ACCEPTED_TYPES.end(), [s](const auto & el) + { + return s == el.first || std::find(el.second.begin(), el.second.end(), s) != el.second.end(); + })) + { + throw error::AronException("AronEigenMatrixNavigator", "checkTypename", "The typename is wrong. Got " + s, getPath()); + } + return true; + } + + unsigned int EigenMatrixNavigator::getRows() const + { + return type->dimensions[0]; + } + + unsigned int EigenMatrixNavigator::getCols() const + { + return type->dimensions[1]; + } + + void EigenMatrixNavigator::setRows(const unsigned int& w) + { + if (w == 0) + { + throw error::AronException("AronEigenMatrixNavigator", "setRows", "The rows cannot be 0", getPath()); + } + type->dimensions[0] = w; + } + + void EigenMatrixNavigator::setCols(const unsigned int& h) + { + if (h == 0) + { + throw error::AronException("AronEigenMatrixNavigator", "setCols", "The cols cannot be 0", getPath()); + } + type->dimensions[1] = h; + } + + type::AronEigenMatrixPtr EigenMatrixNavigator::toAronEigenMatrixPtr() const + { + checkDimensions(type->dimensions); + checkTypename(type->typeName); + return type; + } + + std::string EigenMatrixNavigator::getTypename() const + { + return type->typeName; + } + + std::vector<int> EigenMatrixNavigator::getDimensions() const + { + return type->dimensions; + } + + void EigenMatrixNavigator::setTypename(const std::string& u) + { + checkTypename(u); + type->typeName = u; + } + + void EigenMatrixNavigator::setDimensions(const std::vector<int>& d) + { + checkDimensions(d); + type->dimensions = d; + } + + // static methods + EigenMatrixNavigatorPtr EigenMatrixNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<EigenMatrixNavigator>(n); + } + + EigenMatrixNavigatorPtr EigenMatrixNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronEigenMatrixNavigator", "DynamicCast[Before]", n); + EigenMatrixNavigatorPtr casted = EigenMatrixNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronEigenMatrixNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> EigenMatrixNavigator::getChildren() const + { + return {}; + } + + size_t EigenMatrixNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr EigenMatrixNavigator::getResult() const + { + return toAronEigenMatrixPtr(); + } + + std::string EigenMatrixNavigator::getName() const + { + return "AronEigenMatrix<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.h new file mode 100644 index 0000000000000000000000000000000000000000..d4bd2af6668045e81a601cd98aa8c40ac21e63ef --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenMatrix.h @@ -0,0 +1,92 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class EigenMatrixNavigator; + typedef std::shared_ptr<EigenMatrixNavigator> EigenMatrixNavigatorPtr; + + class EigenMatrixNavigator : + virtual public Navigator + { + public: + using PointerType = EigenMatrixNavigatorPtr; + + public: + // constructors + EigenMatrixNavigator() = delete; + EigenMatrixNavigator(const Path& path); + EigenMatrixNavigator(const type::AronEigenMatrixPtr&, const Path& path); + + bool checkDimensions(const std::vector<int>&) const; + bool checkTypename(const std::string&) const; + + unsigned int getRows() const; + unsigned int getCols() const; + std::string getTypename() const; + std::vector<int> getDimensions() const; + + void setRows(const unsigned int&); + void setCols(const unsigned int&); + void setTypename(const std::string&); + void setDimensions(const std::vector<int>&); + + type::AronEigenMatrixPtr toAronEigenMatrixPtr() const; + + // static methods + static EigenMatrixNavigatorPtr DynamicCast(const NavigatorPtr& n); + static EigenMatrixNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES = + { + {"short", {}}, + {"int", {}}, + {"long", {}}, + {"float", {}}, + {"double", {}}, + //{"complex float", {"std::complex<float>"}}, + //{"complex double", {"std::complex<double>"}}, + }; + const unsigned int ACCEPTED_DIMENSION_MIN_SIZE = 2; + + private: + // members + type::AronEigenMatrixPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ec0c21dbccc35c0ef62517787782e15c18ff33c --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.cpp @@ -0,0 +1,119 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "EigenQuaternion.h" + +namespace armarx::aron::typenavigator +{ + // constructors + EigenQuaternionNavigator::EigenQuaternionNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eEigenQuaternion, path), + Navigator(type::Descriptor::eEigenQuaternion, path), + type(new type::AronEigenQuaternion("")) + { + } + + EigenQuaternionNavigator::EigenQuaternionNavigator(const type::AronEigenQuaternionPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eEigenQuaternion, path), + Navigator(type::Descriptor::eEigenQuaternion, path), + type(o) + { + CheckAronPtrForNull("AronEigenQuaternionTypeNavigator", "AronEigenQuaternionTypeNavigator", getPath(), o); + } + + bool EigenQuaternionNavigator::checkTypename(const std::string& s) const + { + if (s.empty()) + { + throw error::AronException("AronEigenQuaternionTypeNavigator", "checkTypename", "The typename is empty.", getPath()); + } + + if (!std::any_of(ACCEPTED_TYPES.begin(), ACCEPTED_TYPES.end(), [s](const auto & el) + { + return s == el.first || std::find(el.second.begin(), el.second.end(), s) != el.second.end(); + })) + { + throw error::AronException("AronEigenQuaternionTypeNavigator", "checkTypename", "The typename is wrong. Got " + s, getPath()); + } + return true; + } + + type::AronEigenQuaternionPtr EigenQuaternionNavigator::toAronEigenQuaternionPtr() const + { + checkTypename(type->typeName); + return type; + } + + std::string EigenQuaternionNavigator::getTypename() const + { + return type->typeName; + } + + std::vector<int> EigenQuaternionNavigator::getDimensions() const + { + return ACCEPTED_DIMENSION; + } + + void EigenQuaternionNavigator::setTypename(const std::string& u) + { + checkTypename(u); + type->typeName = u; + } + + // static methods + EigenQuaternionNavigatorPtr EigenQuaternionNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<EigenQuaternionNavigator>(n); + } + + EigenQuaternionNavigatorPtr EigenQuaternionNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronEigenQuaternionTypeNavigator", "DynamicCast[Before]", n); + EigenQuaternionNavigatorPtr casted = EigenQuaternionNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronEigenQuaternionTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> EigenQuaternionNavigator::getChildren() const + { + return {}; + } + + size_t EigenQuaternionNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr EigenQuaternionNavigator::getResult() const + { + return toAronEigenQuaternionPtr(); + } + + std::string EigenQuaternionNavigator::getName() const + { + return "AronEigenQuaternionType<" + simox::alg::to_string(ACCEPTED_DIMENSION, ", ") + ", " + type->typeName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h new file mode 100644 index 0000000000000000000000000000000000000000..d450e19bd8a741e6f973fe9ca0ebb0b2a384523f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/EigenQuaternion.h @@ -0,0 +1,81 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class EigenQuaternionNavigator; + typedef std::shared_ptr<EigenQuaternionNavigator> EigenQuaternionNavigatorPtr; + + class EigenQuaternionNavigator : + virtual public Navigator + { + public: + using PointerType = EigenQuaternionNavigatorPtr; + + public: + // constructors + EigenQuaternionNavigator() = delete; + EigenQuaternionNavigator(const Path& path); + EigenQuaternionNavigator(const type::AronEigenQuaternionPtr&, const Path& path); + + bool checkTypename(const std::string&) const; + + std::string getTypename() const; + std::vector<int> getDimensions() const; + + void setTypename(const std::string&); + + type::AronEigenQuaternionPtr toAronEigenQuaternionPtr() const; + + // static methods + static EigenQuaternionNavigatorPtr DynamicCast(const NavigatorPtr& n); + static EigenQuaternionNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES = + { + {"float", {}}, + {"double", {}} + }; + const std::vector<int> ACCEPTED_DIMENSION = {1, 4}; + + private: + // members + type::AronEigenQuaternionPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d76320d402b315e5b06db15c6bbd85986da5da3 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.cpp @@ -0,0 +1,149 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "IVTCByteImage.h" + +namespace armarx::aron::typenavigator +{ + // constructors + IVTCByteImageNavigator::IVTCByteImageNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eIVTCByteImage, path), + Navigator(type::Descriptor::eIVTCByteImage, path), + type(new type::AronIVTCByteImage(0, 0, "")) + { + } + + IVTCByteImageNavigator::IVTCByteImageNavigator(const type::AronIVTCByteImagePtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eIVTCByteImage, path), + Navigator(type::Descriptor::eIVTCByteImage, path), + type(o) + { + CheckAronPtrForNull("AronIVTCByteImageTypeNavigator", "AronIVTCByteImageTypeNavigator", getPath(), o); + } + + std::string IVTCByteImageNavigator::checkTypename(const std::string& s) const + { + for (const auto& [key, list] : ACCEPTED_TYPES) + { + if (s == key) + { + return key; + } + + for (const auto& el : list) + { + if (s == el) + { + return key; + } + } + } + throw error::AronException("AronIVTCByteImageTypeNavigator", "checkTypename", "The typename is empty.", getPath()); + } + + type::AronIVTCByteImagePtr IVTCByteImageNavigator::toAronIVTCByteImagePtr() const + { + checkTypename(type->typeName); + return type; + } + + std::vector<int> IVTCByteImageNavigator::getDimensions() const + { + return {type->width, type->height}; + } + + unsigned int IVTCByteImageNavigator::getWidth() const + { + return type->width; + } + + unsigned int IVTCByteImageNavigator::getHeight() const + { + return type->height; + } + + std::string IVTCByteImageNavigator::getTypename() const + { + return type->typeName; + } + + void IVTCByteImageNavigator::setWidth(const unsigned int& w) + { + if (w == 0) + { + throw error::AronException("AronIVTCByteImageTypeNavigator", "setWidth", "The width of an image cannot be 0", getPath()); + } + type->width = w; + } + + void IVTCByteImageNavigator::setHeight(const unsigned int& h) + { + if (h == 0) + { + throw error::AronException("AronIVTCByteImageTypeNavigator", "setHeight", "The height of an image cannot be 0", getPath()); + } + type->height = h; + } + + void IVTCByteImageNavigator::setTypename(const std::string& u) + { + type->typeName = checkTypename(u); + } + + // static methods + IVTCByteImageNavigatorPtr IVTCByteImageNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<IVTCByteImageNavigator>(n); + } + + IVTCByteImageNavigatorPtr IVTCByteImageNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronIVTCByteImageTypeNavigator", "DynamicCast[Before]", n); + IVTCByteImageNavigatorPtr casted = IVTCByteImageNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronIVTCByteImageTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> IVTCByteImageNavigator::getChildren() const + { + return {}; + } + + size_t IVTCByteImageNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr IVTCByteImageNavigator::getResult() const + { + return toAronIVTCByteImagePtr(); + } + + std::string IVTCByteImageNavigator::getName() const + { + return "AronIVTCByteImageType<" + simox::alg::to_string(getDimensions(), ", ") + ", " + type->typeName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h new file mode 100644 index 0000000000000000000000000000000000000000..aeaf5a3c7f8057cda95706a91637f11ea25fec3e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/IVTCByteImage.h @@ -0,0 +1,85 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class IVTCByteImageNavigator; + typedef std::shared_ptr<IVTCByteImageNavigator> IVTCByteImageNavigatorPtr; + + class IVTCByteImageNavigator : + virtual public Navigator + { + public: + using PointerType = IVTCByteImageNavigatorPtr; + + public: + // constructors + IVTCByteImageNavigator() = delete; + IVTCByteImageNavigator(const Path& path); + IVTCByteImageNavigator(const type::AronIVTCByteImagePtr&, const Path& path); + + std::string checkTypename(const std::string&) const; + + unsigned int getWidth() const; + unsigned int getHeight() const; + std::string getTypename() const; + std::vector<int> getDimensions() const; + + void setWidth(const unsigned int&); + void setHeight(const unsigned int&); + void setTypename(const std::string&); + + type::AronIVTCByteImagePtr toAronIVTCByteImagePtr() const; + + // static methods + static IVTCByteImageNavigatorPtr DynamicCast(const NavigatorPtr& n); + static IVTCByteImageNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES = + { + {"GrayScale", {"CByteImage::ImageType::eGrayScale", "ImageType::eGrayScale"}}, + {"RGB24", {"CByteImage::ImageType::eRGB24", "ImageType::eRGB24"}}, + {"RGB24Split", {"CByteImage::ImageType::eRGB24Split", "ImageType::eRGB24Split"}} + }; + + private: + // members + type::AronIVTCByteImagePtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0d159cc3fc108c2bfb14d15fa6846e6c97d654f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.cpp @@ -0,0 +1,148 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "OpenCVMat.h" + +namespace armarx::aron::typenavigator +{ + // constructors + OpenCVMatNavigator::OpenCVMatNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eOpenCVMat, path), + Navigator(type::Descriptor::eOpenCVMat, path), + type(new type::AronOpenCVMat({}, "")) + { + } + + OpenCVMatNavigator::OpenCVMatNavigator(const type::AronOpenCVMatPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eOpenCVMat, path), + Navigator(type::Descriptor::eOpenCVMat, path), + type(o) + { + CheckAronPtrForNull("AronOpenCVMatTypeNavigator", "AronOpenCVMatTypeNavigator", getPath(), o); + checkDimensions(type->dimensions); + checkTypename(type->typeName); + } + + bool OpenCVMatNavigator::checkDimensions(const std::vector<int>& d) const + { + if (d.size() < ACCEPTED_DIMENSION_MIN_SIZE) + { + throw error::AronException("AronOpenCVMatTypeNavigator", "checkDimensions", "The dimension size is wrong. Got size: " + std::to_string(d.size()), getPath()); + } + + if (std::any_of(d.begin(), d.end(), [](int i) + { + return i < -1 || i == 0; + })) + { + throw error::AronException("AronOpenCVMatTypeNavigator", "checkDimensions", "The dimension size is wrong. At least one empty is < -1 or 0. Got as dimension: " + simox::alg::to_string(d, ", "), getPath()); + } + return true; + } + + std::string OpenCVMatNavigator::checkTypename(const std::string& s) const + { + for (const auto& [key, list] : ACCEPTED_TYPES) + { + if (s == key) + { + return key; + } + + for (const auto& el : list) + { + if (s == el) + { + return key; + } + } + } + throw error::AronException("OpenCVMatNavigator", "checkTypename", "The typename is empty.", getPath()); + } + + type::AronOpenCVMatPtr OpenCVMatNavigator::toAronOpenCVMatPtr() const + { + checkDimensions(type->dimensions); + checkTypename(type->typeName); + return type; + } + + std::string OpenCVMatNavigator::getTypename() const + { + return type->typeName; + } + + std::vector<int> OpenCVMatNavigator::getDimensions() const + { + return type->dimensions; + } + + void OpenCVMatNavigator::setTypename(const std::string& u) + { + type->typeName = checkTypename(u); + } + + void OpenCVMatNavigator::setDimensions(const std::vector<int>& d) + { + checkDimensions(d); + type->dimensions = d; + } + + + // static methods + OpenCVMatNavigatorPtr OpenCVMatNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<OpenCVMatNavigator>(n); + } + + OpenCVMatNavigatorPtr OpenCVMatNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronOpenCVMatTypeNavigator", "DynamicCast[Before]", n); + OpenCVMatNavigatorPtr casted = OpenCVMatNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronOpenCVMatTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> OpenCVMatNavigator::getChildren() const + { + return {}; + } + + size_t OpenCVMatNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr OpenCVMatNavigator::getResult() const + { + return toAronOpenCVMatPtr(); + } + + std::string OpenCVMatNavigator::getName() const + { + return "AronOpenCVMatType<" + simox::alg::to_string(type->dimensions, ", ") + ", " + type->typeName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h new file mode 100644 index 0000000000000000000000000000000000000000..4a1c0a88fb65404a0d0eab15ca54d0129af180d7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/OpenCVMat.h @@ -0,0 +1,88 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class OpenCVMatNavigator; + typedef std::shared_ptr<OpenCVMatNavigator> OpenCVMatNavigatorPtr; + + class OpenCVMatNavigator : + virtual public Navigator + { + public: + using PointerType = OpenCVMatNavigatorPtr; + + public: + // constructors + OpenCVMatNavigator() = delete; + OpenCVMatNavigator(const Path& path); + OpenCVMatNavigator(const type::AronOpenCVMatPtr&, const Path& path); + + bool checkDimensions(const std::vector<int>&) const; + std::string checkTypename(const std::string&) const; + + std::string getTypename() const; + std::vector<int> getDimensions() const; + + void setDimensions(const std::vector<int>&); + void setTypename(const std::string&); + + type::AronOpenCVMatPtr toAronOpenCVMatPtr() const; + + // static methods + static OpenCVMatNavigatorPtr DynamicCast(const NavigatorPtr& n); + static OpenCVMatNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES = + { + {"CV_8U", {"8U"}}, + {"CV_8S", {"8S"}}, + {"CV_16U", {"16U"}}, + {"CV_16S", {"16S"}}, + {"CV_32S", {"32S"}}, + {"CV_32F", {"32F"}}, + {"CV_64F", {"64F"}} + }; + const unsigned int ACCEPTED_DIMENSION_MIN_SIZE = 2; + + private: + // members + type::AronOpenCVMatPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d37436d764cd3bce392a47053e29dc652a002ea7 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.cpp @@ -0,0 +1,95 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Orientation.h" + +namespace armarx::aron::typenavigator + { + // constructors + OrientationNavigator::OrientationNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eOrientation, path), + Navigator(type::Descriptor::eOrientation, path), + type(new type::AronOrientation()) + { + } + + OrientationNavigator::OrientationNavigator(const type::AronOrientationPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::eOrientation, path), + Navigator(type::Descriptor::eOrientation, path), + type(o) + { + CheckAronPtrForNull("AronOrientationTypeNavigator", "AronOrientationTypeNavigator", getPath(), o); + } + + type::AronOrientationPtr OrientationNavigator::toAronOrientationPtr() const + { + return type; + } + + std::vector<int> OrientationNavigator::getDimensions() const + { + return ACCEPTED_DIMENSION; + } + + std::string OrientationNavigator::getTypename() const + { + return ACCEPTED_TYPE; + } + + // static methods + OrientationNavigatorPtr OrientationNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<OrientationNavigator>(n); + } + + OrientationNavigatorPtr OrientationNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronOrientationTypeNavigator", "DynamicCast[Before]", n); + OrientationNavigatorPtr casted = OrientationNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronOrientationTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> OrientationNavigator::getChildren() const + { + return {}; + } + + size_t OrientationNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr OrientationNavigator::getResult() const + { + return toAronOrientationPtr(); + } + + std::string OrientationNavigator::getName() const + { + return "AronOrientationType"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h new file mode 100644 index 0000000000000000000000000000000000000000..4c9c9929b7b466b14d54617be897d01562d2e39d --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Orientation.h @@ -0,0 +1,76 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class OrientationNavigator; + typedef std::shared_ptr<OrientationNavigator> OrientationNavigatorPtr; + + class OrientationNavigator : + virtual public Navigator + { + public: + using PointerType = OrientationNavigatorPtr; + + public: + // constructors + OrientationNavigator() = delete; + OrientationNavigator(const Path& path); + OrientationNavigator(const type::AronOrientationPtr&, const Path& path); + + bool checkDimensions(const std::vector<int>&) const; + bool checkTypename(const std::string&) const; + + std::string getTypename() const; + std::vector<int> getDimensions() const; + + type::AronOrientationPtr toAronOrientationPtr() const; + + // static methods + static OrientationNavigatorPtr DynamicCast(const NavigatorPtr& n); + static OrientationNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::string ACCEPTED_TYPE = "float"; + const std::vector<int> ACCEPTED_DIMENSION = {1, 4}; + + private: + // members + type::AronOrientationPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2de0158a82ac9243202becc23a12272ebed0cd43 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.cpp @@ -0,0 +1,151 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "PCLPointCloud.h" + +namespace armarx::aron::typenavigator +{ + // constructors + PCLPointCloudNavigator::PCLPointCloudNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePCLPointCloud, path), + Navigator(type::Descriptor::ePCLPointCloud, path), + type(new type::AronPCLPointCloud(0, 0, "")) + { + } + + PCLPointCloudNavigator::PCLPointCloudNavigator(const type::AronPCLPointCloudPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePCLPointCloud, path), + Navigator(type::Descriptor::ePCLPointCloud, path), + type(o) + { + CheckAronPtrForNull("AronPCLPointCloudTypeNavigator", "AronPCLPointCloudTypeNavigator", getPath(), o); + checkTypename(type->typeName); + } + + std::string PCLPointCloudNavigator::checkTypename(const std::string& s) const + { + for (const auto& [key, list] : ACCEPTED_TYPES) + { + if (s == key) + { + return key; + } + + for (const auto& el : list) + { + if (s == el) + { + return key; + } + } + } + throw error::AronException("PCLPointCloudNavigator", "checkTypename", "The typename is empty.", getPath()); + } + + type::AronPCLPointCloudPtr PCLPointCloudNavigator::toAronPCLPointCloudPtr() const + { + checkTypename(type->typeName); + return type; + } + + std::vector<int> PCLPointCloudNavigator::getDimensions() const + { + return {type->width, type->height}; + } + + unsigned int PCLPointCloudNavigator::getWidth() const + { + return type->width; + } + + unsigned int PCLPointCloudNavigator::getHeight() const + { + return type->height; + } + + std::string PCLPointCloudNavigator::getTypename() const + { + return type->typeName; + } + + void PCLPointCloudNavigator::setWidth(const unsigned int& w) + { + if (w == 0) + { + throw error::AronException("AronPCLPointCloudTypeNavigator", "setWidth", "The width of aa pointcloud cannot be 0", getPath()); + } + type->width = w; + } + + void PCLPointCloudNavigator::setHeight(const unsigned int& h) + { + if (h == 0) + { + throw error::AronException("AronPCLPointCloudTypeNavigator", "setHeight", "The height of aa pointcloud cannot be 0", getPath()); + } + type->height = h; + } + + void PCLPointCloudNavigator::setTypename(const std::string& u) + { + type->typeName = checkTypename(u); + } + + + // static methods + PCLPointCloudNavigatorPtr PCLPointCloudNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<PCLPointCloudNavigator>(n); + } + + PCLPointCloudNavigatorPtr PCLPointCloudNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronPCLPointCloudTypeNavigator", "DynamicCast[Before]", n); + PCLPointCloudNavigatorPtr casted = PCLPointCloudNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronPCLPointCloudTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> PCLPointCloudNavigator::getChildren() const + { + return {}; + } + + size_t PCLPointCloudNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr PCLPointCloudNavigator::getResult() const + { + return toAronPCLPointCloudPtr(); + } + + std::string PCLPointCloudNavigator::getName() const + { + return "AronPCLPointCloudType<" + simox::alg::to_string(getDimensions(), ", ") + ", " + type->typeName + ">"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h new file mode 100644 index 0000000000000000000000000000000000000000..2f62f1b579b5e84b3acc93aa7a72d70329492736 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/PCLPointCloud.h @@ -0,0 +1,91 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class PCLPointCloudNavigator; + typedef std::shared_ptr<PCLPointCloudNavigator> PCLPointCloudNavigatorPtr; + + class PCLPointCloudNavigator : + virtual public Navigator + { + public: + using PointerType = PCLPointCloudNavigatorPtr; + + public: + // constructors + PCLPointCloudNavigator() = delete; + PCLPointCloudNavigator(const Path& path); + PCLPointCloudNavigator(const type::AronPCLPointCloudPtr&, const Path& path); + + std::string checkTypename(const std::string&) const; + + unsigned int getWidth() const; + unsigned int getHeight() const; + std::string getTypename() const; + std::vector<int> getDimensions() const; + + void setWidth(const unsigned int&); + void setHeight(const unsigned int&); + void setTypename(const std::string&); + + type::AronPCLPointCloudPtr toAronPCLPointCloudPtr() const; + + // static methods + static PCLPointCloudNavigatorPtr DynamicCast(const NavigatorPtr& n); + static PCLPointCloudNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + virtual type::AronTypePtr getResult() const override; + virtual std::string getName() const override; + + public: + const std::map<std::string, std::vector<std::string>> ACCEPTED_TYPES = + { + {"PointXYZ", {"pcl::PointXYZ"}}, + {"PointXYZI", {"pcl::PointXYZI"}}, + {"PointXYZL", {"pcl::PointXYZL"}}, + {"PointXYZRGB", {"pcl::PointXYZRGB"}}, + {"PointXYZRGBL", {"pcl::PointXYZRGBL"}}, + {"PointXYZRGBA", {"pcl::PointXYZRGBA"}}, + {"PointXYZHSV", {"pcl::PointXYZHSV"}} + }; + const unsigned int ACCEPTED_DIMENSION_MIN_SIZE = 2; + const unsigned int ACCEPTED_DIMENSION_MAX_SIZE = 2; + + private: + // members + type::AronPCLPointCloudPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.cpp new file mode 100644 index 0000000000000000000000000000000000000000..830c3550ec5560ca212e2a01a3538a6371cb1b9a --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.cpp @@ -0,0 +1,95 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Pose.h" + +namespace armarx::aron::typenavigator + { + // constructors + PoseNavigator::PoseNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePose, path), + Navigator(type::Descriptor::ePose, path), + type(new type::AronPose()) + { + } + + PoseNavigator::PoseNavigator(const type::AronPosePtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePose, path), + Navigator(type::Descriptor::ePose, path), + type(o) + { + CheckAronPtrForNull("AronPoseTypeNavigator", "AronPoseTypeNavigator", getPath(), o); + } + + type::AronPosePtr PoseNavigator::toAronPosePtr() const + { + return type; + } + + std::vector<int> PoseNavigator::getDimensions() const + { + return ACCEPTED_DIMENSION; + } + + std::string PoseNavigator::getTypename() const + { + return ACCEPTED_TYPE; + } + + // static methods + PoseNavigatorPtr PoseNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<PoseNavigator>(n); + } + + PoseNavigatorPtr PoseNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronPoseTypeNavigator", "DynamicCast[Before]", n); + PoseNavigatorPtr casted = PoseNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronPoseTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> PoseNavigator::getChildren() const + { + return {}; + } + + size_t PoseNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr PoseNavigator::getResult() const + { + return toAronPosePtr(); + } + + std::string PoseNavigator::getName() const + { + return "AronPoseType"; + } +} + diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.h similarity index 53% rename from source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h rename to source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.h index 785438e1d7ca42c659460cf3508495498f54360a..c109c2a89b9738bc5c07c5f47d5f66dbdccfea6d 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTupleTypeNavigator.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Pose.h @@ -28,46 +28,45 @@ #include <map> // Base Class -#include "AronTypeNavigator.h" +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> -namespace armarx +namespace armarx::aron::typenavigator { - namespace aron - { - namespace typenavigator - { + class PoseNavigator; + typedef std::shared_ptr<PoseNavigator> PoseNavigatorPtr; - class AronTupleTypeNavigator; - typedef std::shared_ptr<AronTupleTypeNavigator> AronTupleTypeNavigatorPtr; - - class AronTupleTypeNavigator : - virtual public AronMultipleListAcceptedTypeHavingTypeNavigator, - virtual public AronListSerializerTypeNavigator + class PoseNavigator : + virtual public Navigator { public: - using PointerType = AronTupleTypeNavigatorPtr; + using PointerType = PoseNavigatorPtr; public: // constructors - AronTupleTypeNavigator() = delete; - AronTupleTypeNavigator(const AronPath& path); - AronTupleTypeNavigator(const type::AronTupleTypePtr&, const AronPath& path); + PoseNavigator(const Path& path = Path()); + PoseNavigator(const type::AronPosePtr&, const Path& path = Path()); + + std::string getTypename() const; + std::vector<int> getDimensions() const; - type::AronTupleTypePtr toAronTupleTypePtr() const; + type::AronPosePtr toAronPosePtr() const; // static methods - static AronTupleTypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr& n); - static AronTupleTypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); + static PoseNavigatorPtr DynamicCast(const NavigatorPtr& n); + static PoseNavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); // virtual implementations - virtual void addAcceptedType(const AronTypeNavigatorPtr&) override; - + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; virtual type::AronTypePtr getResult() const override; virtual std::string getName() const override; + public: + const std::string ACCEPTED_TYPE = "float"; + const std::vector<int> ACCEPTED_DIMENSION = {4, 4}; + private: - type::AronTupleTypePtr type; + // members + type::AronPosePtr type; }; - } - } } diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d81efd888bbc1081fa5f3c484c3229514183862e --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.cpp @@ -0,0 +1,95 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// Header +#include "Position.h" + +namespace armarx::aron::typenavigator + { + // constructors + PositionNavigator::PositionNavigator(const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePosition, path), + Navigator(type::Descriptor::ePosition, path), + type(new type::AronPosition()) + { + } + + PositionNavigator::PositionNavigator(const type::AronPositionPtr& o, const Path& path) : + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::ePosition, path), + Navigator(type::Descriptor::ePosition, path), + type(o) + { + CheckAronPtrForNull("AronPositionTypeNavigator", "AronPositionTypeNavigator", getPath(), o); + } + + type::AronPositionPtr PositionNavigator::toAronPositionPtr() const + { + return type; + } + + std::vector<int> PositionNavigator::getDimensions() const + { + return ACCEPTED_DIMENSION; + } + + std::string PositionNavigator::getTypename() const + { + return ACCEPTED_TYPE; + } + + // static methods + PositionNavigatorPtr PositionNavigator::DynamicCast(const NavigatorPtr& n) + { + return std::dynamic_pointer_cast<PositionNavigator>(n); + } + + PositionNavigatorPtr PositionNavigator::DynamicCastAndCheck(const NavigatorPtr& n) + { + CheckTypeNavigatorPtrForNull("AronPositionTypeNavigator", "DynamicCast[Before]", n); + PositionNavigatorPtr casted = PositionNavigator::DynamicCast(n); + CheckTypeNavigatorPtrForNull("AronPositionTypeNavigator", "DynamicCast[After]", n->getPath(), casted); + return casted; + } + + // virtual implementations + std::vector<NavigatorPtr> PositionNavigator::getChildren() const + { + return {}; + } + + size_t PositionNavigator::childrenSize() const + { + return 0; + } + + type::AronTypePtr PositionNavigator::getResult() const + { + return toAronPositionPtr(); + } + + std::string PositionNavigator::getName() const + { + return "AronPositionType"; + } +} + diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.h b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.h new file mode 100644 index 0000000000000000000000000000000000000000..16361d61de4122ba8f40be5c941061df5737e30f --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/ndarray/Position.h @@ -0,0 +1,72 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +// STD/STL +#include <string> +#include <map> + +// Base Class +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> + +namespace armarx::aron::typenavigator +{ + class PositionNavigator; + typedef std::shared_ptr<PositionNavigator> PositionNavigatorPtr; + + class PositionNavigator : + virtual public Navigator + { + public: + using PointerType = PositionNavigatorPtr; + + public: + // constructors + PositionNavigator(const Path& path = Path()); + PositionNavigator(const type::AronPositionPtr&, const Path& path = Path()); + + std::string getTypename() const; + std::vector<int> getDimensions() const; + + type::AronPositionPtr toAronPositionPtr() const; + + // static methods + static PositionNavigatorPtr DynamicCast(const NavigatorPtr&); + static PositionNavigatorPtr DynamicCastAndCheck(const NavigatorPtr&); + + // virtual implementations + virtual std::vector<NavigatorPtr> getChildren() const override; + virtual size_t childrenSize() const override; + type::AronTypePtr getResult() const override; + std::string getName() const override; + + public: + const std::string ACCEPTED_TYPE = "float"; + const std::vector<int> ACCEPTED_DIMENSION = {3, 1}; + + private: + // members + type::AronPositionPtr type; + }; +} diff --git a/source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.cpp b/source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.cpp new file mode 100644 index 0000000000000000000000000000000000000000..94ecf88a70c86df542590009baed8b0d9b1d5e13 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.cpp @@ -0,0 +1,96 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * ArmarX is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ArmarX is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + + +// STD/STL +#include <string> +#include <map> + +// Header +#include "Primitive.h" + +// ArmarX +#include <RobotAPI/libraries/aron/core/Concepts.h> + +namespace armarx::aron::typenavigator +{ +#define RUN_ARON_MACRO(upperType, lowerType, capsType) \ + /* constructors */ \ + upperType##Navigator::upperType##Navigator(const Path& path) : \ + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::e##upperType, path), \ + Navigator(type::Descriptor::e##upperType, path), \ + type(new type::Aron##upperType()) \ + { \ + } \ + \ + upperType##Navigator::upperType##Navigator(const type::Aron##upperType##Ptr&o, const Path& path) : \ + aron::Navigator<type::Descriptor, type::AronType>::Navigator(type::Descriptor::e##upperType, path), \ + Navigator(type::Descriptor::e##upperType, path), \ + type(o) \ + { \ + CheckAronPtrForNull("typenavigator::" + std::string(#upperType) + "Navigator", std::string(#upperType) + "Navigator", getPath(), o); \ + } \ + \ + type::Aron##upperType##Ptr upperType##Navigator::toAron##upperType##Ptr() const \ + { \ + return type; \ + } \ + \ + /* static methods */ \ + upperType##NavigatorPtr upperType##Navigator::DynamicCastAndCheck(const NavigatorPtr& n) \ + {\ + CheckTypeNavigatorPtrForNull("typenavigator::" + std::string(#upperType) + "Navigator", "DynamicCast[Before]", n); \ + upperType##NavigatorPtr casted = upperType##Navigator::DynamicCast(n); \ + CheckTypeNavigatorPtrForNull("typenavigator::" + std::string(#upperType) + "Navigator", "DynamicCast[After]", n->getPath(), casted); \ + return casted; \ + }\ + \ + upperType##NavigatorPtr upperType##Navigator::DynamicCast(const NavigatorPtr& n) \ + {\ + return std::dynamic_pointer_cast<upperType##Navigator>(n); \ + }\ + \ + /* virtual implementations */ \ + std::vector<NavigatorPtr> upperType##Navigator::getChildren() const \ + { \ + return {}; \ + } \ + \ + size_t upperType##Navigator::childrenSize() const \ + { \ + return 0; \ + } \ + \ + type::AronTypePtr upperType##Navigator::getResult() const \ + {\ + return toAron##upperType##Ptr(); \ + }\ + \ + std::string upperType##Navigator::getName() const \ + {\ + return "type::Aron" + std::string(#upperType); \ + } + + HANDLE_PRIMITIVE_TYPES +#undef RUN_ARON_MACRO +} diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h b/source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h similarity index 59% rename from source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h rename to source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h index 5b6090ed54db95331a2e3962b073fc71506086f4..5b2fbee827d6046c50f17b8803e6456ee01395a5 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronPrimitiveTypeNavigator.h +++ b/source/RobotAPI/libraries/aron/core/navigator/type/primitive/Primitive.h @@ -27,48 +27,44 @@ #include <string> // Base Class -#include "AronTypeNavigator.h" +#include <RobotAPI/libraries/aron/core/navigator/type/Navigator.h> // ArmarX -#include <RobotAPI/libraries/aron/aroncore/AronConcepts.h> +#include <RobotAPI/libraries/aron/core/Concepts.h> -namespace armarx +namespace armarx::aron::typenavigator { - namespace aron - { - namespace typenavigator - { #define RUN_ARON_MACRO(upperType, lowerType, capsType) \ - class Aron##upperType##TypeNavigator; \ - typedef std::shared_ptr<Aron##upperType##TypeNavigator> Aron##upperType##TypeNavigatorPtr; \ + class upperType##Navigator; \ + typedef std::shared_ptr<upperType##Navigator> upperType##NavigatorPtr; \ \ - class Aron##upperType##TypeNavigator : \ - virtual public AronPrimitiveTypeNavigator \ + class upperType##Navigator : \ + virtual public Navigator \ { \ public: \ - using PointerType = Aron##upperType##TypeNavigatorPtr; \ + using PointerType = upperType##NavigatorPtr; \ \ /* constructors */ \ - Aron##upperType##TypeNavigator(const AronPath& = AronPath()); \ - Aron##upperType##TypeNavigator(const type::Aron##upperType##TypePtr&, const AronPath& = AronPath()); \ + upperType##Navigator(const Path& = Path()); \ + upperType##Navigator(const type::Aron##upperType##Ptr&, const Path& = Path()); \ \ - type::Aron##upperType##TypePtr toAron##upperType##TypePtr() const; \ + type::Aron##upperType##Ptr toAron##upperType##Ptr() const; \ \ /* static methods */ \ - static Aron##upperType##TypeNavigatorPtr DynamicCast(const AronTypeNavigatorPtr&); \ - static Aron##upperType##TypeNavigatorPtr DynamicCastAndCheck(const AronTypeNavigatorPtr& n); \ + static upperType##NavigatorPtr DynamicCast(const NavigatorPtr&); \ + static upperType##NavigatorPtr DynamicCastAndCheck(const NavigatorPtr& n); \ \ /* virtual implementations */ \ + virtual std::vector<NavigatorPtr> getChildren() const override; \ + virtual size_t childrenSize() const override; \ virtual type::AronTypePtr getResult() const override; \ virtual std::string getName() const override; \ \ private: \ - type::Aron##upperType##TypePtr type; \ + type::Aron##upperType##Ptr type; \ }; HANDLE_PRIMITIVE_TYPES #undef RUN_ARON_MACRO - } - } } diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.cpp b/source/RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.cpp similarity index 100% rename from source/RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.cpp rename to source/RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.cpp diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h b/source/RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h similarity index 85% rename from source/RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h rename to source/RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h index a3c37ac2d02fb5274bd65b0b42a39b1d6ee4b397..ad890f92e5e5cf59a04fdbf4a6b908b5069fb7d4 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/DataVisitor.h +++ b/source/RobotAPI/libraries/aron/core/navigator/visitors/DataVisitor.h @@ -2,7 +2,7 @@ #include <string> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> namespace armarx::aron::visitor @@ -10,7 +10,7 @@ namespace armarx::aron::visitor /** * @brief A visitor traversing an `aron::data::AronDataPtr` using - * `aron::datanavigator::AronDataNavigator`s, taking care of type checking, + * `aron::datanavigator::Navigator`s, taking care of type checking, * casting and hierarchical traversal. * * To use it, create a class deriving from `AronDataVisitor` and @@ -18,7 +18,7 @@ namespace armarx::aron::visitor * for the types you would like to handle (see blow for a copy-and-paste * example). * Then, instantiate your derived visitor and call `applyTo()`, passing - * the `AronDataPtr` or the root `AronDataNavigator`. + * the `AronDataPtr` or the root `Navigator`. * * For dicts and lists, you will get a `visitEnter()`/`visitExit()` pair. * For types without children (e.g. primitive types), you get a single @@ -31,7 +31,7 @@ namespace armarx::aron::visitor * use `navigator.getPath()`. * * @see `aron::data::AronDataPtr` - * @see `aron::datanavigator::AronDataNavigator` + * @see `aron::datanavigator::Navigator` * @see `std::stack` To manage data with stack semantics. */ class DataVisitor @@ -40,18 +40,18 @@ namespace armarx::aron::visitor // Define types to ease writing code in this and derived classes. - using DataNavigator = datanavigator::AronDataNavigator; + using DataNavigator = datanavigator::Navigator; - using DictDataNavigator = datanavigator::AronDictDataNavigator; - using ListDataNavigator = datanavigator::AronListDataNavigator; + using DictDataNavigator = datanavigator::DictNavigator; + using ListDataNavigator = datanavigator::ListNavigator; - using BoolDataNavigator = datanavigator::AronBoolDataNavigator; - using DoubleDataNavigator = datanavigator::AronDoubleDataNavigator; - using FloatDataNavigator = datanavigator::AronFloatDataNavigator; - using IntDataNavigator = datanavigator::AronIntDataNavigator; - using LongDataNavigator = datanavigator::AronLongDataNavigator; - using NDArrayDataNavigator = datanavigator::AronNDArrayDataNavigator; - using StringDataNavigator = datanavigator::AronStringDataNavigator; + using BoolDataNavigator = datanavigator::BoolNavigator; + using DoubleDataNavigator = datanavigator::DoubleNavigator; + using FloatDataNavigator = datanavigator::FloatNavigator; + using IntDataNavigator = datanavigator::IntNavigator; + using LongDataNavigator = datanavigator::LongNavigator; + using NDArrayDataNavigator = datanavigator::NDArrayNavigator; + using StringDataNavigator = datanavigator::StringNavigator; public: diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.cpp b/source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.cpp similarity index 98% rename from source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.cpp rename to source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.cpp index 7936152be03cd09575812d80a48e3fd5eb18a24c..263253c8830ccd065648fd210be9721a1ea28030 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.cpp +++ b/source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.cpp @@ -113,7 +113,7 @@ namespace armarx::aron::visitor { for (const std::string& key : type.getAllKeys()) { - TypeNavigator::PointerType childType = type.getAcceptedType(key); + TypeNavigator::PointerType childType = type.getMemberType(key); DataNavigator::PointerType childData = data.getElement(key); if (childType && childData) { diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.h b/source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.h similarity index 82% rename from source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.h rename to source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.h index ac67b9fbde35432be646b824eccd34c89de7feac..13800fa67e320bfa45d144b004baf3ec584f7225 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/visitors/TypedDataVisitor.h +++ b/source/RobotAPI/libraries/aron/core/navigator/visitors/TypedDataVisitor.h @@ -1,7 +1,7 @@ #pragma once -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/data/AllNavigators.h> +#include <RobotAPI/libraries/aron/core/navigator/type/AllNavigators.h> namespace armarx::aron::visitor @@ -9,7 +9,7 @@ namespace armarx::aron::visitor /** * @brief A visitor traversing an `aron::Type::AronTypePtr` using - * `aron::Typenavigator::AronTypeNavigator`s, taking care of type checking, + * `aron::Typenavigator::Navigator`s, taking care of type checking, * casting and hierarchical traversal. * * To use it, create a class deriving from `AronTypeVisitor` and @@ -17,7 +17,7 @@ namespace armarx::aron::visitor * for the types you would like to handle (see blow for a copy-and-paste * example). * Then, instantiate your derived visitor and call `applyTo()`, passing - * the `AronTypePtr` or the root `AronTypeNavigator`. + * the `AronTypePtr` or the root `Navigator`. * * For dicts and lists, you will get a `visitEnter()`/`visitExit()` pair. * For types without children (e.g. primitive types), you get a single @@ -30,7 +30,7 @@ namespace armarx::aron::visitor * use `navigator.getPath()`. * * @see `aron::Type::AronTypePtr` - * @see `aron::Typenavigator::AronTypeNavigator` + * @see `aron::Typenavigator::Navigator` * @see `std::stack` To manage Type with stack semantics. */ class TypedDataVisitor @@ -40,45 +40,45 @@ namespace armarx::aron::visitor // Define types to ease writing code in this and derived classes. // Data - possible data representations - using DataNavigator = datanavigator::AronDataNavigator; + using DataNavigator = datanavigator::Navigator; - using DictDataNavigator = datanavigator::AronDictDataNavigator; - using ListDataNavigator = datanavigator::AronListDataNavigator; + using DictDataNavigator = datanavigator::DictNavigator; + using ListDataNavigator = datanavigator::ListNavigator; - using BoolDataNavigator = datanavigator::AronBoolDataNavigator; - using DoubleDataNavigator = datanavigator::AronDoubleDataNavigator; - using FloatDataNavigator = datanavigator::AronFloatDataNavigator; - using IntDataNavigator = datanavigator::AronIntDataNavigator; - using LongDataNavigator = datanavigator::AronLongDataNavigator; - using StringDataNavigator = datanavigator::AronStringDataNavigator; + using BoolDataNavigator = datanavigator::BoolNavigator; + using DoubleDataNavigator = datanavigator::DoubleNavigator; + using FloatDataNavigator = datanavigator::FloatNavigator; + using IntDataNavigator = datanavigator::IntNavigator; + using LongDataNavigator = datanavigator::LongNavigator; + using StringDataNavigator = datanavigator::StringNavigator; - using NDArrayDataNavigator = datanavigator::AronNDArrayDataNavigator; + using NDArrayDataNavigator = datanavigator::NDArrayNavigator; // Type - using TypeNavigator = typenavigator::AronTypeNavigator; + using TypeNavigator = typenavigator::Navigator; // Dict-valued - using DictTypeNavigator = typenavigator::AronDictTypeNavigator; - using ObjectTypeNavigator = typenavigator::AronObjectTypeNavigator; + using DictTypeNavigator = typenavigator::DictNavigator; + using ObjectTypeNavigator = typenavigator::ObjectNavigator; // List-valued - using ListTypeNavigator = typenavigator::AronListTypeNavigator; - using TupleTypeNavigator = typenavigator::AronTupleTypeNavigator; + using ListTypeNavigator = typenavigator::ListNavigator; + using TupleTypeNavigator = typenavigator::TupleNavigator; // Primitive-valued - using BoolTypeNavigator = typenavigator::AronBoolTypeNavigator; - using DoubleTypeNavigator = typenavigator::AronDoubleTypeNavigator; - using FloatTypeNavigator = typenavigator::AronFloatTypeNavigator; - using IntTypeNavigator = typenavigator::AronIntTypeNavigator; - using LongTypeNavigator = typenavigator::AronLongTypeNavigator; - using StringTypeNavigator = typenavigator::AronStringTypeNavigator; + using BoolTypeNavigator = typenavigator::BoolNavigator; + using DoubleTypeNavigator = typenavigator::DoubleNavigator; + using FloatTypeNavigator = typenavigator::FloatNavigator; + using IntTypeNavigator = typenavigator::IntNavigator; + using LongTypeNavigator = typenavigator::LongNavigator; + using StringTypeNavigator = typenavigator::StringNavigator; // Array-valued - using EigenMatrixTypeNavigator = typenavigator::AronEigenMatrixTypeNavigator; - using IVTCByteImageTypeNavigator = typenavigator::AronIVTCByteImageTypeNavigator; - using OpenCVMatTypeNavigator = typenavigator::AronOpenCVMatTypeNavigator; - using PCLPointCloudTypeNavigator = typenavigator::AronPCLPointCloudTypeNavigator; + using EigenMatrixTypeNavigator = typenavigator::EigenMatrixNavigator; + using IVTCByteImageTypeNavigator = typenavigator::IVTCByteImageNavigator; + using OpenCVMatTypeNavigator = typenavigator::OpenCVMatNavigator; + using PCLPointCloudTypeNavigator = typenavigator::PCLPointCloudNavigator; public: diff --git a/source/RobotAPI/libraries/aron/aroncore/test/CMakeLists.txt b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt similarity index 82% rename from source/RobotAPI/libraries/aron/aroncore/test/CMakeLists.txt rename to source/RobotAPI/libraries/aron/core/test/CMakeLists.txt index 33657aed38683de124c5fd12174f15c1a72a9825..7eeffdbb49db4b321b77ed47fa1e58361d538094 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron/core/test/CMakeLists.txt @@ -41,14 +41,19 @@ armarx_enable_aron_file_generation_for_target( ${TEST_NAME} ARON_FILES xmls/HumanPoseTest.xml - xmls/SimpleDictTest.xml + xmls/DictTest.xml xmls/ListTest.xml - xmls/NaturalIK.xml - xmls/SimpleObjectTest.xml + xmls/NaturalIKTest.xml + xmls/ObjectTest.xml xmls/PrimitiveTest.xml - xmls/ImageTest.xml + xmls/IVTCByteImageTest.xml xmls/EigenMatrixTest.xml + xmls/EigenQuaternionTest.xml xmls/OpenCVMatTest.xml xmls/PCLPointCloudTest.xml + xmls/PositionTest.xml + xmls/OrientationTest.xml + xmls/PoseTest.xml + xmls/EnumTest.xml #ENABLE_DEBUG_INFO ) diff --git a/source/RobotAPI/libraries/aron/aroncore/test/aronDataWithoutCodeGeneration.h b/source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h similarity index 70% rename from source/RobotAPI/libraries/aron/aroncore/test/aronDataWithoutCodeGeneration.h rename to source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h index 67fd71120c0946be7d21c4df0229b78ec90eff6f..0e7e29371456eb156a786976eb838ab4444d5a9a 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/aronDataWithoutCodeGeneration.h +++ b/source/RobotAPI/libraries/aron/core/test/aronDataWithoutCodeGeneration.h @@ -2,14 +2,14 @@ #include <vector> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/AronTypeClassWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/Writer.h> +#include <RobotAPI/libraries/aron/core/io/typeIO/writer/navigator/NavigatorWriter.h> namespace armarx { @@ -35,7 +35,7 @@ namespace armarx w.writeEndDict(); } - void writeType(armarx::aron::io::AronTypeWriter& w) const + void writeType(armarx::aron::io::Writer& w) const { w.writeStartObjectType(); w.writeObjectName("AronTrivialDataWithoutCodeGeneration"); @@ -59,24 +59,24 @@ namespace armarx w.readEndDict(); } - armarx::aron::datanavigator::AronDictDataNavigatorPtr toAron() const + armarx::aron::datanavigator::DictNavigatorPtr toAron() const { - armarx::aron::io::AronDataNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->write(writer); - return armarx::aron::datanavigator::AronDictDataNavigator::DynamicCast(writer.getResult()); + return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); } - void fromAron(const armarx::aron::datanavigator::AronDictDataNavigatorPtr& input) + void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) { - armarx::aron::io::AronDataNavigatorReader reader(input); + armarx::aron::io::NavigatorReader reader(input); //this->read(reader); } - armarx::aron::typenavigator::AronObjectTypeNavigatorPtr toInitialAronType() const + armarx::aron::typenavigator::ObjectNavigatorPtr toInitialAronType() const { - armarx::aron::io::AronTypeNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->writeType(writer); - return armarx::aron::typenavigator::AronObjectTypeNavigator::DynamicCast(writer.getResult()); + return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); } }; @@ -109,7 +109,7 @@ namespace armarx w.writeEndDict(); } - void writeType(armarx::aron::io::AronTypeWriter& w) const + void writeType(armarx::aron::io::Writer& w) const { w.writeStartObjectType(); w.writeObjectName("AronSimpleDataWithoutCodeGeneration"); @@ -144,24 +144,24 @@ namespace armarx } - armarx::aron::datanavigator::AronDictDataNavigatorPtr toAron() const + armarx::aron::datanavigator::DictNavigatorPtr toAron() const { - armarx::aron::io::AronDataNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->write(writer); - return armarx::aron::datanavigator::AronDictDataNavigator::DynamicCast(writer.getResult()); + return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); } - void fromAron(const armarx::aron::datanavigator::AronDictDataNavigatorPtr& input) + void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) { - //armarx::aron::io::AronDataNavigatorReader reader(input); + //armarx::aron::io::NavigatorReader reader(input); //this->read(reader); } - armarx::aron::typenavigator::AronObjectTypeNavigatorPtr toInitialAronType() const + armarx::aron::typenavigator::ObjectNavigatorPtr toInitialAronType() const { - armarx::aron::io::AronTypeNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->writeType(writer); - return armarx::aron::typenavigator::AronObjectTypeNavigator::DynamicCast(writer.getResult()); + return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); } }; @@ -208,7 +208,7 @@ namespace armarx w.writeEndDict(); } - void writeType(armarx::aron::io::AronTypeWriter& w) const + void writeType(armarx::aron::io::Writer& w) const { w.writeStartObjectType(); w.writeObjectName("AronNestedDataWithoutCodeGeneration"); @@ -267,24 +267,24 @@ namespace armarx w.readEndDict(); } - armarx::aron::datanavigator::AronDictDataNavigatorPtr toAron() const + armarx::aron::datanavigator::DictNavigatorPtr toAron() const { - armarx::aron::io::AronDataNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->write(writer); - return armarx::aron::datanavigator::AronDictDataNavigator::DynamicCast(writer.getResult()); + return armarx::aron::datanavigator::DictNavigator::DynamicCast(writer.getResult()); } - void fromAron(const armarx::aron::datanavigator::AronDictDataNavigatorPtr& input) + void fromAron(const armarx::aron::datanavigator::DictNavigatorPtr& input) { - armarx::aron::io::AronDataNavigatorReader reader(input); + armarx::aron::io::NavigatorReader reader(input); //this->read(reader); } - armarx::aron::typenavigator::AronObjectTypeNavigatorPtr toInitialAronType() const + armarx::aron::typenavigator::ObjectNavigatorPtr toInitialAronType() const { - armarx::aron::io::AronTypeNavigatorWriter writer; + armarx::aron::io::NavigatorWriter writer; this->writeType(writer); - return armarx::aron::typenavigator::AronObjectTypeNavigator::DynamicCast(writer.getResult()); + return armarx::aron::typenavigator::ObjectNavigator::DynamicCast(writer.getResult()); } }; @@ -306,9 +306,9 @@ namespace armarx } { - armarx::aron::io::AronDataNavigatorWriter wrt; + armarx::aron::io::NavigatorWriter wrt; write(orig, wrt); - armarx::aron::io::AronDataNavigatorReader rdr(wrt.getResult()); + armarx::aron::io::NavigatorReader rdr(wrt.getResult()); read(round, rdr); } diff --git a/source/RobotAPI/libraries/aron/aroncore/test/aronTest.cpp b/source/RobotAPI/libraries/aron/core/test/aronTest.cpp similarity index 59% rename from source/RobotAPI/libraries/aron/aroncore/test/aronTest.cpp rename to source/RobotAPI/libraries/aron/core/test/aronTest.cpp index dc4bb4d4dfcb21b87ba8c24b1dd43f3da920d8a0..1210ed0a5d0058825dede94196653f0af3fc201f 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/aronTest.cpp +++ b/source/RobotAPI/libraries/aron/core/test/aronTest.cpp @@ -52,32 +52,36 @@ // ArmarX #include <ArmarXCore/libraries/cppgen/CppMethod.h> #include <ArmarXCore/libraries/cppgen/CppClass.h> -#include <RobotAPI/libraries/aron/aroncore/AronException.h> +#include <RobotAPI/libraries/aron/core/Exception.h> // Aron -#include <RobotAPI/libraries/aron/aroncore/AronDebug.h> -#include <RobotAPI/libraries/aron/aroncore/AronRandomizer.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NavigatorReader/AronDataNavigatorReader.h> +#include <RobotAPI/libraries/aron/core/Debug.h> +#include <RobotAPI/libraries/aron/core/Randomizer.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/RapidXMLWriter/AronDataRapidXMLWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/navigator/NavigatorReader.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.h> + +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/navigator/NavigatorWriter.h> +#include <RobotAPI/libraries/aron/core/io/dataIO/writer/nlohmannJSON/NlohmannJSONWriter.h> // Files without code generation -#include "aronDataWithoutCodeGeneration.h" +//#include "aronDataWithoutCodeGeneration.h" // Generated File -#include <RobotAPI/libraries/aron/aroncore/test/aron/NaturalIK.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/ListTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/SimpleDictTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/PrimitiveTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/SimpleObjectTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/ImageTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/EigenMatrixTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/OpenCVMatTest.aron.generated.h> -#include <RobotAPI/libraries/aron/aroncore/test/aron/PCLPointCloudTest.aron.generated.h> - +#include <RobotAPI/libraries/aron/core/test/aron/NaturalIKTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/ListTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/DictTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PrimitiveTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/ObjectTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/IVTCByteImageTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EigenMatrixTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EigenQuaternionTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/OpenCVMatTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PCLPointCloudTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PositionTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/OrientationTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/PoseTest.aron.generated.h> +#include <RobotAPI/libraries/aron/core/test/aron/EnumTest.aron.generated.h> using namespace armarx; using namespace aron; @@ -85,20 +89,20 @@ using namespace aron; template <typename T> void runTestWithInstances(T& k1, T& k2) { - AronRandomizer r; + Randomizer r; std::cout << "\t getting type 1" << std::endl; - typenavigator::AronObjectTypeNavigatorPtr k1_type_nav = k1.toInitialAronType(); - type::AronObjectTypePtr k1_type = k1_type_nav->toAronObjectTypePtr(); + typenavigator::ObjectNavigatorPtr k1_type_nav = k1.toInitialAronType(); + type::AronObjectPtr k1_type = k1_type_nav->toAronObjectPtr(); BOOST_CHECK_NE(k1_type.get(), nullptr); std::cout << "\t getting type 2" << std::endl; - typenavigator::AronObjectTypeNavigatorPtr k2_type_nav = k2.toInitialAronType(); - type::AronObjectTypePtr k2_type = k2_type_nav->toAronObjectTypePtr(); + typenavigator::ObjectNavigatorPtr k2_type_nav = k2.toInitialAronType(); + type::AronObjectPtr k2_type = k2_type_nav->toAronObjectPtr(); BOOST_CHECK_NE(k2_type.get(), nullptr); std::cout << "\t getting aron 1" << std::endl; - datanavigator::AronDictDataNavigatorPtr k1_aron_nav = k1.toAron(); + datanavigator::DictNavigatorPtr k1_aron_nav = k1.toAron(); data::AronDictPtr k1_aron = k1_aron_nav->toAronDictPtr(); BOOST_CHECK_NE(k1_aron.get(), nullptr); @@ -112,7 +116,7 @@ void runTestWithInstances(T& k1, T& k2) k2.fromAron(k1_aron); std::cout << "\t getting aron 2" << std::endl; - datanavigator::AronDictDataNavigatorPtr k2_aron_nav = k2.toAron(); + datanavigator::DictNavigatorPtr k2_aron_nav = k2.toAron(); data::AronDictPtr k2_aron = k2_aron_nav->toAronDictPtr(); BOOST_CHECK_NE(k2_aron.get(), nullptr); @@ -120,38 +124,42 @@ void runTestWithInstances(T& k1, T& k2) //std::cout << AronDebug::AronDataPtrToString(k2_aron) << std::endl; std::cout << "\t setting aron 1 from aron 2 and check for equality" << std::endl; + k1.fromAron(k2_aron_nav); BOOST_CHECK_EQUAL((k1 == k2), true); + //std::cout << "\t getting current type 1" << std::endl; - //typenavigator::AronTypeNavigatorPtr k1_current_type_nav = k1.toCurrentAronType(); + //typenavigator::NavigatorPtr k1_current_type_nav = k1.toCurrentAronType(); //type::AronTypePtr k1_current_type = k1_current_type_nav->getResult(); //BOOST_CHECK_NE(k1_current_type.get(), nullptr); //std::cout << "\t getting type 2" << std::endl; - //typenavigator::AronTypeNavigatorPtr k2_current_type_nav = k2.toCurrentAronType(); + //typenavigator::NavigatorPtr k2_current_type_nav = k2.toCurrentAronType(); //type::AronTypePtr k2_current_type = k2_current_type_nav->getResult(); //BOOST_CHECK_NE(k2_current_type.get(), nullptr); r.initializeRandomly(k1_aron_nav, k1_type_nav); + k1.fromAron(k1_aron); + std::cout << "\t check JSON export of k and k2 for equality" << std::endl; - armarx::aron::io::AronDataNlohmannJSONWriter json_writer_for_k1; - armarx::aron::io::AronDataNlohmannJSONWriter json_writer_for_k2; + armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k1; + armarx::aron::dataIO::writer::NlohmannJSONWriter json_writer_for_k2; k1.write(json_writer_for_k1); nlohmann::json k1_aron_json = json_writer_for_k1.getResult(); std::string k1_aron_json_str = k1_aron_json.dump(4); - armarx::aron::io::AronDataNlohmannJSONWriter direct_json_writer_for_k1; - armarx::aron::io::AronDataWriterVisitor::SetupWriterFromAronDataPtr(direct_json_writer_for_k1, k1_aron); + armarx::aron::dataIO::writer::NlohmannJSONWriter direct_json_writer_for_k1; + armarx::aron::dataIO::Visitor::SetupWriterFromAronDataPtr(direct_json_writer_for_k1, k1_aron); nlohmann::json direct_k1_aron_json = direct_json_writer_for_k1.getResult(); std::string direct_k1_aron_json_str = direct_k1_aron_json.dump(4); BOOST_CHECK_EQUAL((k1_aron_json_str == direct_k1_aron_json_str), true); - armarx::aron::io::AronDataNlohmannJSONReader json_reader_for_k2(k1_aron_json); + armarx::aron::dataIO::reader::NlohmannJSONReader json_reader_for_k2(k1_aron_json); k2.read(json_reader_for_k2); k2.write(json_writer_for_k2); @@ -161,20 +169,6 @@ void runTestWithInstances(T& k1, T& k2) //std::cout << "\t K1 as json: " << std::endl << k1_aron_json_str << std::endl; //std::cout << "\t K2 as json: " << std::endl << k2_aron_json_str << std::endl; BOOST_CHECK_EQUAL((k1_aron_json_str == k2_aron_json_str), true); - - //std::cout << "\t check XML export of k and k2 for equality" << std::endl; - //armarx::aron::io::AronDataRapidXMLWriter xml_writer1; - //armarx::aron::io::AronDataRapidXMLWriter xml_writer2; - - //k.write(xml_writer1); - //k_aron_rapid_xml = xml_writer1.getResult(); - - //k2.write(xml_writer2); - //k2_aron_xml = xml_writer2.getResult(); - - //std::cout << "\t K as XML: " << std::endl << k_aron_xml << std::endl; - //std::cout << "\t K2: " << std::endl << k2_aron_json << std::endl; - //BOOST_CHECK_EQUAL((k_aron_xml == k2_aron_xml), true);*/ } @@ -185,13 +179,13 @@ BOOST_AUTO_TEST_CASE(AronNaturalIKTest) NaturalIKResult k2; runTestWithInstances<NaturalIKResult>(k, k2); - // also test AronPath - datanavigator::AronDictDataNavigatorPtr aron = k.toAron(); - AronPath path = aron->getPath(); // should be empty since aron is top level object - AronPath memberReached(path, "reached"); - AronPath memberJointValues(path, "jointValues"); - AronPath indexJointValues0(memberJointValues, "0"); - AronPath indexJointValues1(memberJointValues, "1"); + // also test Path + datanavigator::DictNavigatorPtr aron = k.toAron(); + Path path = aron->getPath(); // should be empty since aron is top level object + Path memberReached(path, "reached"); + Path memberJointValues(path, "jointValues"); + Path indexJointValues0(memberJointValues, "0"); + Path indexJointValues1(memberJointValues, "1"); BOOST_CHECK_EQUAL(path.toString(), "\\"); BOOST_CHECK_EQUAL(path.size(), 0); @@ -208,19 +202,19 @@ BOOST_AUTO_TEST_CASE(AronNaturalIKTest) BOOST_CHECK_EQUAL(indexJointValues1.toString(), "\\->jointValues->1"); BOOST_CHECK_EQUAL(indexJointValues1.size(), 2); - datanavigator::AronBoolDataNavigatorPtr reached = datanavigator::AronBoolDataNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberReached)); - datanavigator::AronListDataNavigatorPtr jointValues = datanavigator::AronListDataNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberJointValues)); + datanavigator::BoolNavigatorPtr reached = datanavigator::BoolNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberReached)); + datanavigator::ListNavigatorPtr jointValues = datanavigator::ListNavigator::DynamicCastAndCheck(aron->navigateAbsolute(memberJointValues)); if (jointValues->childrenSize() > 0) { - datanavigator::AronFloatDataNavigatorPtr el = datanavigator::AronFloatDataNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues0)); + datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues0)); } if (jointValues->childrenSize() > 1) { - datanavigator::AronFloatDataNavigatorPtr el = datanavigator::AronFloatDataNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues1)); + datanavigator::FloatNavigatorPtr el = datanavigator::FloatNavigator::DynamicCastAndCheck(aron->navigateAbsolute(indexJointValues1)); } - AronPath diff = indexJointValues1.getWithoutPrefix(indexJointValues0); + Path diff = indexJointValues1.getWithoutPrefix(indexJointValues0); BOOST_CHECK_EQUAL(diff.toString(), "\\->1"); BOOST_CHECK_EQUAL(diff.size(), 1); } @@ -250,39 +244,35 @@ BOOST_AUTO_TEST_CASE(AronPrimitiveTest) runTestWithInstances<PrimitiveTest>(p, p2); } -BOOST_AUTO_TEST_CASE(AronSimpleClassTest) -{ - std::cout << "Running SimpleClass test" << std::endl; - SimpleClass o1; - SimpleClass o12; - runTestWithInstances<SimpleClass>(o1, o12); -} - BOOST_AUTO_TEST_CASE(AronObjectTest) { std::cout << "Running Object test" << std::endl; - ObjectTest o2; - ObjectTest o22; - runTestWithInstances<ObjectTest>(o2, o22); + ObjectTest1 o1; + ObjectTest1 o12; + runTestWithInstances<ObjectTest1>(o1, o12); + + ObjectTest2 o2; + ObjectTest2 o22; + runTestWithInstances<ObjectTest2>(o2, o22); } BOOST_AUTO_TEST_CASE(AronImageTest) { std::cout << "Running Image test" << std::endl; - ImageTest i; - ImageTest i2; - runTestWithInstances<ImageTest>(i, i2); + IVTCByteImageTest i; + IVTCByteImageTest i2; + runTestWithInstances<IVTCByteImageTest>(i, i2); } -BOOST_AUTO_TEST_CASE(AronImageChangeSizeTest) +/*BOOST_AUTO_TEST_CASE(AronImageChangeSizeTest) { std::cout << "Running Image test with changed sizes" << std::endl; - ImageTest ii; - ImageTest ii2; - ii.the_ivt_image->Set(100, 100, ii.the_ivt_image->type); - ii2.the_ivt_image->Set(10, 10, ii.the_ivt_image->type); - runTestWithInstances<ImageTest>(ii, ii2); -} + IVTCByteImageTest ii; + IVTCByteImageTest ii2; + ii.the_ivt_image.Set(100, 100, ii.the_ivt_image.type); + ii2.the_ivt_image.Set(10, 10, ii.the_ivt_image.type); + runTestWithInstances<IVTCByteImageTest>(ii, ii2); +}*/ BOOST_AUTO_TEST_CASE(AronEigenMatrixTest) { @@ -328,3 +318,35 @@ BOOST_AUTO_TEST_CASE(AronTests) AronNestedDataWithoutCodeGeneration rn2; runTestWithInstances<AronNestedDataWithoutCodeGeneration>(rn1, rn2); }*/ + +BOOST_AUTO_TEST_CASE(AronEigenQuaternionTest) +{ + std::cout << "Running EigenQuaternion test" << std::endl; + EigenQuaternionTest eq; + EigenQuaternionTest eq2; + runTestWithInstances<EigenQuaternionTest>(eq, eq2); +} + +BOOST_AUTO_TEST_CASE(AronPositionTest) +{ + std::cout << "Running Position test" << std::endl; + PositionTest pc; + PositionTest pc2; + runTestWithInstances<PositionTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronOrientationTest) +{ + std::cout << "Running Orientation test" << std::endl; + OrientationTest pc; + OrientationTest pc2; + runTestWithInstances<OrientationTest>(pc, pc2); +} + +BOOST_AUTO_TEST_CASE(AronPoseTest) +{ + std::cout << "Running Pose test" << std::endl; + PoseTest pc; + PoseTest pc2; + runTestWithInstances<PoseTest>(pc, pc2); +} diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/BaseClass.xml b/source/RobotAPI/libraries/aron/core/test/xmls/BaseClass.xml similarity index 90% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/BaseClass.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/BaseClass.xml index 8cab5e6fd4eb572192e7db5df327883760288327..57d4e6951e98ccb690b8e2c61e6730c067cf01e0 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/BaseClass.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/BaseClass.xml @@ -2,7 +2,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::BaseClassTest'> + <GenerateObject name='armarx::BaseClassTest'> <ObjectChild key='base_class_member1'> <Bool /> @@ -24,6 +24,6 @@ </List> </ObjectChild> - </GenerateType> + </GenerateObject> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/DerivedClassTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/DerivedClassTest.xml similarity index 84% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/DerivedClassTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/DerivedClassTest.xml index 4d06665c2ac40ebfcfcb4514e75bff8dc637ce68..de4be250d23c90f27d8198d890e7ef0576d672cb 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/DerivedClassTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/DerivedClassTest.xml @@ -8,12 +8,12 @@ <Include include="/home/fabian/Software/ArmarX/RobotAPI/source/RobotAPI/libraries/aron/test/xmls/BaseClass.xml" /> </AronIncludes> <GenerateTypes> - <GenerateType name='armarx::DerivedClass' extends="armarx::BaseClassTest"> + <GenerateObject name='armarx::DerivedClass' extends="armarx::BaseClassTest"> <ObjectChild key='derived_class_member1'> <Bool /> </ObjectChild> - </GenerateType> + </GenerateObject> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleDictTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/DictTest.xml similarity index 80% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleDictTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/DictTest.xml index 003b22dbaad241b3f3d93685f96a3d173183c9b8..fadec8226455e878c6a98ed7a76131c66a3944e6 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleDictTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/DictTest.xml @@ -2,12 +2,12 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::DictTest'> + <Object name='armarx::DictTest'> <objectchild key='dict'> <Dict> <Float /> </Dict> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..b3f5f6447c6fc6f3d3a8851e00578156ad4560b3 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/EigenMatrixTest.xml @@ -0,0 +1,28 @@ +<!--Some fancy comment --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + <AronIncludes> + </AronIncludes> + <GenerateTypes> + <Object name='armarx::EigenMatrixTest'> + <ObjectChild key='the_short_eigen_matrix'> + <EigenMatrix rows="10" cols="25" type="short" /> + </ObjectChild> + <ObjectChild key='the_int_eigen_matrix'> + <EigenMatrix rows="25" cols="25" type="int" /> + </ObjectChild> + <ObjectChild key='the_long_eigen_matrix'> + <EigenMatrix rows="25" cols="10" type="long" /> + </ObjectChild> + <ObjectChild key='the_float_eigen_matrix'> + <EigenMatrix rows="1" cols="200" type="float" /> + </ObjectChild> + <ObjectChild key='the_double_eigen_matrix'> + <EigenMatrix rows="200" cols="1" type="double" /> + </ObjectChild> + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/EigenQuaternionTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/EigenQuaternionTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..a5760ba3b259ab6824f8a9bcb1fb9c5cd5855f53 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/EigenQuaternionTest.xml @@ -0,0 +1,20 @@ +<!--Some fancy comment --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + <Include include="<Eigen/Geometry>" /> + </CodeIncludes> + <AronIncludes> + </AronIncludes> + <GenerateTypes> + <Object name='armarx::EigenQuaternionTest'> + <ObjectChild key='the_float_eigen_matrix'> + <EigenQuaternion type="float" /> + </ObjectChild> + <ObjectChild key='the_double_eigen_matrix'> + <EigenQuaternion type="double" /> + </ObjectChild> + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/EnumTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/EnumTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..789959fc609e8c15b62733199439bd1506aae8dc --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/EnumTest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <GenerateTypes> + <IntEnum name="TheIntEnum"> + <EnumValue key="INT_ENUM_VALUE_0" value="0" /> + <EnumValue key="INT_ENUM_VALUE_1" value="1" /> + <EnumValue key="INT_ENUM_VALUE_2" value="2" /> + <EnumValue key="INT_ENUM_VALUE_3" value="3" /> + <EnumValue key="INT_ENUM_VALUE_4" value="4" /> + <EnumValue key="INT_ENUM_VALUE_5" value="5" /> + <EnumValue key="INT_ENUM_VALUE_6" value="6" /> + <EnumValue key="INT_ENUM_VALUE_7" value="7" /> + <EnumValue key="INT_ENUM_VALUE_8" value="8" /> + </IntEnum> + <Object name="TheObjectThatUsesTheIntEnum"> + <objectchild key="some_string"> + <string /> + </objectchild> + <objectchild key="the_int_enum"> + <TheIntEnum /> + </objectchild> + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/HumanPoseTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/HumanPoseTest.xml similarity index 69% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/HumanPoseTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/HumanPoseTest.xml index 4a0948ed12871ce2010603ffaacb701ee2dfd9c9..78f4fd166c505e6e8b2d0cd4f4ac5c73f391d371 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/HumanPoseTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/HumanPoseTest.xml @@ -1,8 +1,7 @@ -<!--This class contains the data structure for OpenPoseEstimationResults --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::OpenPoseEstimationResult'> + <Object name='armarx::HumanPoseTest'> <ObjectChild key='reached'> <Bool /> @@ -14,6 +13,6 @@ </List> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/ImageTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/IVTCByteImageTest.xml similarity index 50% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/ImageTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/IVTCByteImageTest.xml index 074128ebef8a32e4b7b5d631ec2336f41d1c06ef..5abc5d5a15e3e3b17fc842e958a5216c862999a3 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/ImageTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/IVTCByteImageTest.xml @@ -1,16 +1,19 @@ -<!--Some fancy comment --> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <CodeIncludes> <Include include="<Image/ByteImage.h>" /> </CodeIncludes> - <AronIncludes> - </AronIncludes> <GenerateTypes> - <GenerateType name='armarx::ImageTest'> - <ObjectChild key='the_ivt_image'> + <Object name='armarx::IVTCByteImageTest'> + + <ObjectChild key='the_grayscale_image'> <IVTCByteImage width="25" height="25" type="GrayScale" /> </ObjectChild> - </GenerateType> + + <ObjectChild key='the_rgb_image'> + <IVTCByteImage width="1920" height="1080" type="RGB24" /> + </ObjectChild> + + </Object> </GenerateTypes> -</AronTypeDefinition> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/ListTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/ListTest.xml similarity index 92% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/ListTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/ListTest.xml index 0917c8ea0f34e98b1b250f11b7b94cef35f3f43c..1c8ed164015d99ad0b5eddc8881dc4d43d626c28 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/ListTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/ListTest.xml @@ -2,7 +2,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::ListTest'> + <Object name='armarx::ListTest'> <ObjectChild key='floatList'> <List> <Float /> @@ -45,14 +45,14 @@ <Bool /> </ObjectChild> <ObjectChild key='element1'> - <Bool /> + <Int /> </ObjectChild> <ObjectChild key='element2'> - <Bool /> + <Double /> </ObjectChild> </Object> </List> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/NaturalIK.xml b/source/RobotAPI/libraries/aron/core/test/xmls/NaturalIKTest.xml similarity index 84% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/NaturalIK.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/NaturalIKTest.xml index 87f43c9e43eb4f0e938b123c0e45693ba7824c4e..06dc659d12d955b30b2113ffe7125e2320d96127 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/NaturalIK.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/NaturalIKTest.xml @@ -2,7 +2,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::NaturalIKResult'> + <Object name='armarx::NaturalIKResult'> <ObjectChild key='reached'> <Bool /> @@ -14,6 +14,6 @@ </List> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleObjectTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/ObjectTest.xml similarity index 62% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleObjectTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/ObjectTest.xml index ee51a55a389a4fbd6833b7f13bf555795c4371bd..43903d1ce67236c564145ef79ed2732ff4fb522c 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/SimpleObjectTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/ObjectTest.xml @@ -3,34 +3,34 @@ <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::SimpleClass'> + <Object name='armarx::ObjectTest1'> <objectchild key='the_bool'> <bool /> </objectchild> - </GenerateType> + </Object> - <GenerateType name='armarx::ObjectTest'> + <Object name='armarx::ObjectTest2'> <objectchild key='local_object'> - <object name='OtherFancyObject'> - <objectchild key='blarg'> + <object name='LocalObjectTest1'> + <objectchild key='the_bool'> <bool /> </objectchild> - <objectchild key='other_blarg'> + <objectchild key='the_int'> <int /> </objectchild> </object> </ObjectChild> <objectchild key='another_local_object'> - <object name='VisionClass'> - <objectchild key='blarg'> + <object name='LocalObjectTest2'> + <objectchild key='the_bool'> <bool /> </objectchild> - <objectchild key='other_object'> + <objectchild key='the_int'> <int /> </objectchild> </object> </ObjectChild> - </GenerateType> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/OpenCVMatTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/OpenCVMatTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c5cfb1e95c41d72790a7a6a65b5d028adbeb0576 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/OpenCVMatTest.xml @@ -0,0 +1,25 @@ +<!--Some fancy comment --> +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<opencv2/core/core.hpp>" /> + </CodeIncludes> + <AronIncludes> + </AronIncludes> + <GenerateTypes> + <Object name='armarx::OpenCVMatTest'> + <ObjectChild key='the_2d_opencv_matrix'> + <OpenCVMat dimensions="25, 25" type="64F" /> + </ObjectChild> + <ObjectChild key='the_3d_opencv_matrix'> + <OpenCVMat dimensions="25, 25, 25" type="CV_32F" /> + </ObjectChild> + <ObjectChild key='the_4d_opencv_matrix'> + <OpenCVMat dimensions="25, 25, 25, 25" type="CV_32S" /> + </ObjectChild> + <ObjectChild key='the_5d_opencv_matrix'> + <OpenCVMat dimensions="25, 25, 25, 25, 25" type="16U" /> + </ObjectChild> + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/OrientationTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/OrientationTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..c5c531e48855014722aa5ad91b29799c995eb098 --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/OrientationTest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + + <GenerateTypes> + <Object name='armarx::OrientationTest'> + + <ObjectChild key='orientation'> + <Orientation /> + </ObjectChild> + + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/PCLPointCloudTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/PCLPointCloudTest.xml similarity index 59% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/PCLPointCloudTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/PCLPointCloudTest.xml index b09c7f2ab2397454224f9db56c764919e781cc4c..dff170ce43a968424e05839de91ada689e49ecf1 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/PCLPointCloudTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/PCLPointCloudTest.xml @@ -8,10 +8,13 @@ <AronIncludes> </AronIncludes> <GenerateTypes> - <GenerateType name='armarx::PointCloudTest'> - <ObjectChild key='the_pcl_pointcloud'> + <Object name='armarx::PointCloudTest'> + <ObjectChild key='the_xyzrgb_pcl_pointcloud'> <PCLPointCloud width="25" height="25" type="PointXYZRGB" /> </ObjectChild> - </GenerateType> + <ObjectChild key='the_xyzrgba_pcl_pointcloud'> + <PCLPointCloud width="128" height="128" type="pcl::PointXYZRGBA" /> + </ObjectChild> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/PoseTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/PoseTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..4af320525509ee7ce05b0b5c60e22d14fd555f6b --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/PoseTest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + <GenerateTypes> + <Object name='armarx::PoseTest'> + + <ObjectChild key='pose'> + <Pose /> + </ObjectChild> + + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/core/test/xmls/PositionTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/PositionTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..64d9392fe8415b75ee59f896d3be7aa4b42bd9ae --- /dev/null +++ b/source/RobotAPI/libraries/aron/core/test/xmls/PositionTest.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<AronTypeDefinition> + <CodeIncludes> + <Include include="<Eigen/Core>" /> + </CodeIncludes> + <GenerateTypes> + <Object name='armarx::PositionTest'> + + <ObjectChild key='position'> + <Position /> + </ObjectChild> + + </Object> + </GenerateTypes> +</AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron/aroncore/test/xmls/PrimitiveTest.xml b/source/RobotAPI/libraries/aron/core/test/xmls/PrimitiveTest.xml similarity index 82% rename from source/RobotAPI/libraries/aron/aroncore/test/xmls/PrimitiveTest.xml rename to source/RobotAPI/libraries/aron/core/test/xmls/PrimitiveTest.xml index d2dc7bb640b4e089a5508a055ada41352fd6539d..ea38c815ffb08531d29d1ae9401aba7ff72ba479 100644 --- a/source/RobotAPI/libraries/aron/aroncore/test/xmls/PrimitiveTest.xml +++ b/source/RobotAPI/libraries/aron/core/test/xmls/PrimitiveTest.xml @@ -2,7 +2,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> <GenerateTypes> - <GenerateType name='armarx::PrimitiveTest'> + <Object name='armarx::PrimitiveTest'> <objectchild key='the_int'> <int /> </ObjectChild> @@ -21,6 +21,9 @@ <objectchild key='the_bool'> <bool /> </ObjectChild> - </GenerateType> + <objectchild key='the_time'> + <time /> + </ObjectChild> + </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/natik/CartesianNaturalPositionControllerProxy.cpp b/source/RobotAPI/libraries/natik/CartesianNaturalPositionControllerProxy.cpp index aa28c50cffd92b857c88bbe339179311e9ae8ff3..7a57d550daa7a14141bd3ddfc3e93193df11b394 100644 --- a/source/RobotAPI/libraries/natik/CartesianNaturalPositionControllerProxy.cpp +++ b/source/RobotAPI/libraries/natik/CartesianNaturalPositionControllerProxy.cpp @@ -25,7 +25,7 @@ #include <ArmarXCore/core/logging/Logging.h> #include <RobotAPI/libraries/core/CartesianPositionController.h> #include <ArmarXCore/core/exceptions/local/ExpressionException.h> -//#include <RobotAPI/libraries/aron/aroncore/navigators/AronNavigator.h> +//#include <RobotAPI/libraries/aron/core/navigator/Navigator.h> #include <VirtualRobot/math/Helpers.h> #include <VirtualRobot/MathTools.h> @@ -488,7 +488,7 @@ CartesianNaturalPositionControllerProxy::Waypoint& CartesianNaturalPositionContr aron::AronObjectPtr CartesianNaturalPositionControllerProxy::Waypoint::toAron() { aron::AronObjectPtr obj = new aron::AronObject(); - aron::AronNavigator nav(obj); + aron::Navigator nav(obj); nav.appendMatrix4f("tcpTarget", tcpTarget); nav.appendVector3f("elbTarget", elbTarget); nav.appendVec("userNullspaceTargets", userNullspaceTargets); @@ -505,7 +505,7 @@ aron::AronObjectPtr CartesianNaturalPositionControllerProxy::Waypoint::toAron() void CartesianNaturalPositionControllerProxy::Waypoint::fromAron(aron::AronObjectPtr aron) { - aron::AronNavigator nav(aron); + aron::Navigator nav(aron); tcpTarget = nav.atKey("tcpTarget").asMatrix4f(); elbTarget = nav.atKey("elbTarget").asVector3f(); userNullspaceTargets = nav.atKey("userNullspaceTargets").asVecFloat();