BIMRecord is a type of Record (adds applicationID)

This commit is contained in:
Ralph Wessel
2024-10-03 16:31:58 +01:00
parent 76348c8fd1
commit 0592bcc947
4 changed files with 71 additions and 19 deletions
@@ -2,10 +2,26 @@
#include "Speckle/Utility/Guid.h"
#include <array>
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<ValueWrap<BIMRecordID>>(m_applicationID);
default:
return nullptr; //Requested an unknown index
}
} //BIMRecord::getCargo
@@ -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<BIMRecordID>{
class BIMRecord : public Record {
public:
// MARK: - Types
using base = active::database::Record<BIMRecordID>;
using base = Record;
///Unique pointer
using Unique = std::unique_ptr<BIMRecord>;
///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;
};
}
@@ -2,12 +2,12 @@
#include "Speckle/Utility/Guid.h"
#include <array>
using namespace active::serialise;
using namespace speckle::database;
using namespace speckle::utility;
#include <array>
namespace {
///Serialisation fields
+4 -7
View File
@@ -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
*/