From 0336b1b6f99af2ce7b65f4f24b0b5b5972c298da Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Mon, 23 Sep 2024 09:18:04 +0100 Subject: [PATCH] DocumentStoreEngine can return its records as wrapped cargo for external serialisation --- .../DocumentStore/DocumentStoreEngine.h | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/SpeckleLib/Speckle/Database/Storage/DocumentStore/DocumentStoreEngine.h b/SpeckleLib/Speckle/Database/Storage/DocumentStore/DocumentStoreEngine.h index fcb3edd..202ea0c 100644 --- a/SpeckleLib/Speckle/Database/Storage/DocumentStore/DocumentStoreEngine.h +++ b/SpeckleLib/Speckle/Database/Storage/DocumentStore/DocumentStoreEngine.h @@ -67,6 +67,14 @@ namespace speckle::database { @return The requested object (nullptr on failure) */ std::unique_ptr getObject(const ObjID& objID, std::optional tableID = std::nullopt, std::optional documentID = std::nullopt) const override; + /*! + Get an object in a transportable form, e.g. packaged for serialisation + @param ID The object ID + @param tableID Optional table ID (defaults to the first table) + @param documentID Optional document ID (when the object is bound to a specific document) + @return: The requested wrapped cargo (nullptr on failure) + */ + active::serialise::Cargo::Unique getObjectCargo(const ObjID& objID, std::optional tableID = std::nullopt, std::optional documentID = std::nullopt) const override; /*! Get all objects @param tableID Optional table ID (defaults to the first table) @@ -186,6 +194,25 @@ namespace speckle::database { } //DocumentStoreEngine::getObject + /*-------------------------------------------------------------------- + Get an object in a transportable form, e.g. packaged for serialisation + + index: The object index + tableID: Optional table ID (defaults to the first table) + documentID: Optional document ID (when the object is bound to a specific document) + + return: The requested wrapped cargo (nullptr on failure) + --------------------------------------------------------------------*/ + template + requires DocumentStorable + active::serialise::Cargo::Unique DocumentStoreEngine::getObjectCargo(const ObjID& ID, std::optional tableID, + std::optional documentID) const { + if (auto object = getObject(ID, tableID, documentID); object) + return std::make_unique>(std::move(object)); + return nullptr; + } //DocumentStoreEngine::getObject + + /*-------------------------------------------------------------------- Get all objects