diff --git a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/DiskWriter.h b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/DiskWriter.h index ee8485cc9c789815002769b0637e7714ef12a43d..4cbd3f01acf8fb033ab18b2debcdf55580a5e2a6 100644 --- a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/DiskWriter.h +++ b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/DiskWriter.h @@ -30,8 +30,8 @@ // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.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/LegacyAronDataWriter/LegacyAronDataWriter.h> #include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> //#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/ @@ -62,12 +62,12 @@ namespace armarx::armem DiskWriter(const std::string& r) : rootPath(r) { - if(!std::filesystem::exists(rootPath)) + if (!std::filesystem::exists(rootPath)) { std::filesystem::create_directory(rootPath); } - if(!std::filesystem::is_directory(rootPath)) + if (!std::filesystem::is_directory(rootPath)) { throw LocalException("The Path is not valid. It points to a file instead of a folder!"); } @@ -95,12 +95,13 @@ namespace armarx::armem for (unsigned int i = 0; i < entitySnapshot->instances.size(); ++i) { std::filesystem::path entityElementPath = createEntityElementPath(coreKey, providerKey, entityKey, entityHistoryTimestamp, i); - if(!entityElementPathExists(entityElementPath)) + if (!entityElementPathExists(entityElementPath)) { std::ofstream ofs; ofs.open(entityElementPath); - ofs << getEntityAsString(entitySnapshot->instances[i]); + + ofs << getDataAsString(wrapData(entitySnapshot->instances[i])); ofs.close(); } // check content if file already existent? @@ -113,7 +114,20 @@ namespace armarx::armem } protected: - virtual std::string getEntityAsString(const EntityInstancePtr&) = 0; + aron::datanavigator::AronDictDataNavigatorPtr wrapData(const EntityInstancePtr& e) const + { + aron::datanavigator::AronDictDataNavigatorPtr dataWrapped(new aron::datanavigator::AronDictDataNavigator()); + dataWrapped->addElement("instanceData", e->data()); + + aron::datanavigator::AronLongDataNavigatorPtr timeWrapped(new aron::datanavigator::AronLongDataNavigator()); + timeWrapped->setValue(Time::now().toMilliSeconds()); + dataWrapped->addElement("timeWrapped", timeWrapped); + + // TODO add more metadata + return dataWrapped; + } + + virtual std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) = 0; std::filesystem::path createCoreSegmentPath(const std::string& name) const { @@ -150,7 +164,7 @@ namespace armarx::armem } bool ensureCoreSegmentPathExists(const std::filesystem::path& p) const { - if(!std::filesystem::exists(p)) + if (!std::filesystem::exists(p)) { return std::filesystem::create_directory(p); } @@ -170,7 +184,7 @@ namespace armarx::armem } bool ensureProviderSegmentPathExists(const std::filesystem::path& p) const { - if(!std::filesystem::exists(p)) + if (!std::filesystem::exists(p)) { return std::filesystem::create_directory(p); } @@ -190,7 +204,7 @@ namespace armarx::armem } bool ensureEntityPathExists(const std::filesystem::path& p) const { - if(!std::filesystem::exists(p)) + if (!std::filesystem::exists(p)) { return std::filesystem::create_directory(p); } @@ -210,7 +224,7 @@ namespace armarx::armem } bool ensureTimestampPathExists(const std::filesystem::path& p) const { - if(!std::filesystem::exists(p)) + if (!std::filesystem::exists(p)) { return std::filesystem::create_directory(p); } diff --git a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp index 39fc7877e6a47cf26bf43efbab014337a27905cd..62ff8d75ff2b55444352fc1c908fe292e4e4a11d 100644 --- a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp @@ -8,10 +8,8 @@ namespace armarx::armem::ltm::io { } - std::string NlohmannJSONDiskWriter::getEntityAsString(const EntityInstancePtr& i) + std::string NlohmannJSONDiskWriter::getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr& aronDataNav) { - const aron::datanavigator::AronDataNavigatorPtr aronDataNav = i->data(); - aron::io::AronDataNlohmannJSONWriter dataWriter; aron::io::LegacyAronDataWriter::SetupWriterFromAronDataPtr(dataWriter, aronDataNav->getResult()); return dataWriter.getResult().dump(4); diff --git a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h index 1daac1f1113e016e0e39275b18388eb40e45221b..c2c2ed9c4cc27536862ca499eed28e5446afe716 100644 --- a/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h +++ b/source/RobotAPI/libraries/armem/ltm/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h @@ -42,13 +42,13 @@ namespace armarx::armem typedef std::shared_ptr<NlohmannJSONDiskWriter> NlohmannJSONDiskWriterPtr; class NlohmannJSONDiskWriter : - virtual public DiskWriter + virtual public DiskWriter { public: NlohmannJSONDiskWriter() = delete; NlohmannJSONDiskWriter(const std::string& rootPath); - virtual std::string getEntityAsString(const EntityInstancePtr&) override; + virtual std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) override; }; } } diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h index c14fede048d6c48f0817cccd52dc50d8bdac34e6..08f001f7e926ef8d84f73d73780ea084528f44b1 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDataNavigator.h @@ -86,6 +86,61 @@ namespace armarx private: static const AronDataNavigatorFactoryPtr FACTORY; }; + + class AronContainerDataNavigator; + typedef std::shared_ptr<AronContainerDataNavigator> AronContainerDataNavigatorPtr; + + class AronContainerDataNavigator : + virtual public AronDataNavigator + { + public: + using PointerType = AronContainerDataNavigatorPtr; + + // constructors + AronContainerDataNavigator() = delete; + AronContainerDataNavigator(const AronDataDescriptor& d, const AronPath& p = AronPath()) : + AronDataNavigator(d, p) + { + + } + }; + + class AronComplexDataNavigator; + typedef std::shared_ptr<AronComplexDataNavigator> AronComplexDataNavigatorPtr; + + class AronComplexDataNavigator : + virtual public AronDataNavigator + { + public: + using PointerType = AronComplexDataNavigatorPtr; + + // constructors + AronComplexDataNavigator() = delete; + AronComplexDataNavigator(const AronDataDescriptor& d, const AronPath& p = AronPath()) : + AronDataNavigator(d, p) + { + + } + }; + + class AronPrimitiveDataNavigator; + typedef std::shared_ptr<AronPrimitiveDataNavigator> AronPrimitiveDataNavigatorPtr; + + class AronPrimitiveDataNavigator : + virtual public AronDataNavigator + { + public: + using PointerType = AronPrimitiveDataNavigatorPtr; + + // constructors + AronPrimitiveDataNavigator() = delete; + AronPrimitiveDataNavigator(const AronDataDescriptor& d, const AronPath& p = AronPath()) : + AronDataNavigator(d, p) + { + + } + }; + } } } diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp index b72d694a486e67e55bdcdf4f81c631de27c36f77..43f756bba635144c03c498149c9a07d383ffa257 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.cpp @@ -40,6 +40,7 @@ namespace armarx AronDictDataNavigator::AronDictDataNavigator(const data::AronDictPtr& o, const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronDict, path), AronDataNavigator(AronDataDescriptor::eAronDict, path), + AronContainerDataNavigator(AronDataDescriptor::eAronDict, path), aron(o) { CheckAronPtrForNull("AronDictDataNavigator", "AronDictDataNavigator", getPath(), aron); @@ -53,6 +54,7 @@ namespace armarx AronDictDataNavigator::AronDictDataNavigator(const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronDict, path), AronDataNavigator(AronDataDescriptor::eAronDict, path), + AronContainerDataNavigator(AronDataDescriptor::eAronDict, path), aron(new data::AronDict()) { } diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h index 3b1124c4c398f88951a8274c7be3064d7387fc5c..287718efe7b433f5c653ea83e34483d08d073762 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h @@ -42,7 +42,7 @@ namespace armarx typedef std::shared_ptr<AronDictDataNavigator> AronDictDataNavigatorPtr; class AronDictDataNavigator : - virtual public AronDataNavigator + virtual public AronContainerDataNavigator { public: using PointerType = AronDictDataNavigatorPtr; diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp index c57bea07ff8737e66fa62c1f2a2c247f17d94c4e..63e0840087beb63471f2ad60478c0b9b75b0aa04 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.cpp @@ -39,6 +39,7 @@ namespace armarx AronListDataNavigator::AronListDataNavigator(const data::AronListPtr& l, const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronList, path), AronDataNavigator(AronDataDescriptor::eAronList, path), + AronContainerDataNavigator(AronDataDescriptor::eAronList, path), aron(l) { CheckAronPtrForNull("AronListDataNavigator", "AronListDataNavigator", getPath(), aron); @@ -53,6 +54,7 @@ namespace armarx AronListDataNavigator::AronListDataNavigator(const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronList, path), AronDataNavigator(AronDataDescriptor::eAronList, path), + AronContainerDataNavigator(AronDataDescriptor::eAronList, path), aron(new data::AronList()) { } diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h index 87b0b00d6cbd00ccb2a0c60c072b365393ab8ffc..2a7ea718f405223b7f6d11b3d53f6289f9c62a0f 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronListDataNavigator.h @@ -41,7 +41,7 @@ namespace armarx typedef std::shared_ptr<AronListDataNavigator> AronListDataNavigatorPtr; class AronListDataNavigator : - virtual public AronDataNavigator + virtual public AronContainerDataNavigator { public: using PointerType = AronListDataNavigatorPtr; diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp index bd252a0d7f071fd10ba6b3fbcb5377a63fa70f61..5c748218f11e8262bee7d7fbb424966e0830372a 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.cpp @@ -42,6 +42,7 @@ namespace armarx AronNDArrayDataNavigator::AronNDArrayDataNavigator(const data::AronNDArrayPtr& o, const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronNDArray, path), AronDataNavigator(AronDataDescriptor::eAronNDArray, path), + AronComplexDataNavigator(AronDataDescriptor::eAronNDArray, path), aron(o) { CheckAronPtrForNull("AronNDArrayDataNavigator", "AronNDArrayDataNavigator", getPath(), aron); @@ -50,6 +51,7 @@ namespace armarx AronNDArrayDataNavigator::AronNDArrayDataNavigator(const AronPath& path) : AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAronNDArray, path), AronDataNavigator(AronDataDescriptor::eAronNDArray, path), + AronComplexDataNavigator(AronDataDescriptor::eAronNDArray, path), aron(new data::AronNDArray()) { diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h index 96a88acf3a06ccee70096da5c45732a6622b3ac0..3a32dd987cca25d01015ee5e15be396be9209c59 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronNDArrayDataNavigator.h @@ -41,7 +41,7 @@ namespace armarx typedef std::shared_ptr<AronNDArrayDataNavigator> AronNDArrayDataNavigatorPtr; class AronNDArrayDataNavigator : - virtual public AronDataNavigator + virtual public AronComplexDataNavigator { public: using PointerType = AronNDArrayDataNavigatorPtr; diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp index 66b98dcbc53ce24e306fabf101cc08acbfb68404..a1c14461afe71328a4d352e74840386aab42e56f 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.cpp @@ -38,6 +38,7 @@ namespace armarx Aron##upperType##DataNavigator::Aron##upperType##DataNavigator(const AronPath& path) : \ AronNavigator<AronDataDescriptor, data::AronData>::AronNavigator(AronDataDescriptor::eAron##upperType, path), \ AronDataNavigator(AronDataDescriptor::eAron##upperType, path), \ + AronPrimitiveDataNavigator(AronDataDescriptor::eAron##upperType, path), \ aron(new data::Aron##upperType()) \ { \ aron->value = {}; \ @@ -45,6 +46,7 @@ namespace armarx 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), \ + AronPrimitiveDataNavigator(AronDataDescriptor::eAron##upperType, path), \ aron(o) \ { \ } \ diff --git a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h index 10f9fe6dcd1bbb4ecdf070d4a3075d3f6fbd95bb..2dc5f7a58e903b361ff9aab5a35a8207f9849519 100644 --- a/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h +++ b/source/RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronPrimitiveDataNavigator.h @@ -42,7 +42,7 @@ namespace armarx typedef std::shared_ptr<Aron##upperType##DataNavigator> Aron##upperType##DataNavigatorPtr; \ \ class Aron##upperType##DataNavigator : \ - virtual public AronDataNavigator \ + virtual public AronPrimitiveDataNavigator \ { \ public: \ using PointerType = Aron##upperType##DataNavigatorPtr; \