From 0592bcc947ae1e814c8f3e1674c3bf4ff3e8104f Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Thu, 3 Oct 2024 16:31:58 +0100 Subject: [PATCH] BIMRecord is a type of Record (adds applicationID) --- .../Speckle/Database/Content/BIMRecord.cpp | 44 +++++++++++++++++-- .../Speckle/Database/Content/BIMRecord.h | 31 ++++++++++--- .../Speckle/Database/Content/Record.cpp | 4 +- SpeckleLib/Speckle/Database/Content/Record.h | 11 ++--- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp b/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp index 49ebd75..b6a7100 100644 --- a/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp +++ b/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp @@ -2,10 +2,26 @@ #include "Speckle/Utility/Guid.h" +#include + using namespace active::serialise; using namespace speckle::database; using namespace speckle::utility; +namespace { + + ///Serialisation fields + enum FieldIndex { + applicID, + }; + + ///Serialisation field IDs + static std::array fieldID = { + Identity{"applicationId"}, + }; + +} + /*-------------------------------------------------------------------- Fill an inventory with the package items @@ -13,12 +29,32 @@ using namespace speckle::utility; return: True if the package has added items to the inventory --------------------------------------------------------------------*/ -bool BIMRecord::fillInventory(active::serialise::Inventory& inventory) const { +bool BIMRecord::fillInventory(Inventory& inventory) const { using enum Entry::Type; inventory.merge(Inventory{ { - { Identity{"id"}, active::database::record::FieldIndex::idIndex, element }, + { Identity{fieldID[applicID]}, applicID, element }, }, - }.withType(&typeid(base))); - return true; + }.withType(&typeid(BIMRecord))); + return base::fillInventory(inventory); } //BIMRecord::fillInventory + + +/*-------------------------------------------------------------------- + Get the specified cargo + + item: The inventory item to retrieve + + return: The requested cargo (nullptr on failure) + --------------------------------------------------------------------*/ +Cargo::Unique BIMRecord::getCargo(const Inventory::Item& item) const { + if (item.ownerType != &typeid(BIMRecord)) + return base::getCargo(item); + using namespace active::serialise; + switch (item.index) { + case applicID: + return std::make_unique>(m_applicationID); + default: + return nullptr; //Requested an unknown index + } +} //BIMRecord::getCargo diff --git a/SpeckleLib/Speckle/Database/Content/BIMRecord.h b/SpeckleLib/Speckle/Database/Content/BIMRecord.h index f202c40..133912a 100644 --- a/SpeckleLib/Speckle/Database/Content/BIMRecord.h +++ b/SpeckleLib/Speckle/Database/Content/BIMRecord.h @@ -1,7 +1,7 @@ #ifndef SPECKLE_DATABASE_BIM_RECORD #define SPECKLE_DATABASE_BIM_RECORD -#include "Active/Database/Content/Record.h" +#include "Speckle/Database/Content/Record.h" #include "Speckle/Database/Identity/Link.h" #include "Speckle/Database/Identity/BIMRecordID.h" @@ -10,12 +10,12 @@ namespace speckle::database { /*! Base class for a database record */ - class BIMRecord : public active::database::Record{ + class BIMRecord : public Record { public: // MARK: - Types - using base = active::database::Record; + using base = Record; ///Unique pointer using Unique = std::unique_ptr; ///Shared pointer @@ -28,13 +28,12 @@ namespace speckle::database { /*! Default constructor */ - BIMRecord() : base{active::utility::Guid{true}, active::utility::Guid{true}} {} //TODO: Implement a better default for the ID + BIMRecord() : base{} {} /*! Constructor @param ID The record ID */ - BIMRecord(speckle::utility::Guid ID, speckle::utility::Guid::Option globID = std::nullopt) : //TODO: Implement a better default for the ID - base{ID, globID.value_or(active::utility::Guid{true})} {} + BIMRecord(speckle::utility::Guid ID) : base{}, m_applicationID{ID} {} /*! Destructor */ @@ -42,9 +41,19 @@ namespace speckle::database { // MARK: - Functions (const) + /*! + Get the BIM application ID + @return The BIM application ID + */ + BIMRecordID getBIMID() const { return m_applicationID; } // MARK: - Functions (mutating) + /*! + Set the BIM application ID + @param ID The BIM application ID + */ + void setBIMID(const BIMRecordID& ID) { m_applicationID = ID; } // MARK: - Serialisation @@ -54,6 +63,16 @@ namespace speckle::database { @return True if the package has added items to the inventory */ bool fillInventory(active::serialise::Inventory& inventory) const override; + /*! + Get the specified cargo + @param item The inventory item to retrieve + @return The requested cargo (nullptr on failure) + */ + active::serialise::Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override; + + private: + ///The BIM application record ID + BIMRecordID m_applicationID; }; } diff --git a/SpeckleLib/Speckle/Database/Content/Record.cpp b/SpeckleLib/Speckle/Database/Content/Record.cpp index 09c065c..ea79570 100644 --- a/SpeckleLib/Speckle/Database/Content/Record.cpp +++ b/SpeckleLib/Speckle/Database/Content/Record.cpp @@ -2,12 +2,12 @@ #include "Speckle/Utility/Guid.h" +#include + using namespace active::serialise; using namespace speckle::database; using namespace speckle::utility; -#include - namespace { ///Serialisation fields diff --git a/SpeckleLib/Speckle/Database/Content/Record.h b/SpeckleLib/Speckle/Database/Content/Record.h index 2cabaf9..f609223 100644 --- a/SpeckleLib/Speckle/Database/Content/Record.h +++ b/SpeckleLib/Speckle/Database/Content/Record.h @@ -27,15 +27,12 @@ namespace speckle::database { /*! Default constructor - */ - Record() : base{active::utility::Guid{true}.operator active::utility::String(), - active::utility::Guid{true}.operator active::utility::String()} {} //TODO: Implement a better default for the ID - /*! - Constructor @param ID The record ID + @param globID The global ID */ - Record(speckle::utility::String ID, speckle::utility::String::Option globID = std::nullopt) : - base{ID, globID.value_or(active::utility::Guid{true}.operator active::utility::String())} {} + Record(speckle::utility::String::Option ID = std::nullopt, speckle::utility::String::Option globID = std::nullopt) : + base{ID.value_or(active::utility::Guid{true}.operator active::utility::String()), + globID.value_or(active::utility::Guid{true}.operator active::utility::String())} {} /*! Destructor */