Restructured objects to support optional (nullable) members

This commit is contained in:
Ralph Wessel
2024-09-06 18:55:13 +01:00
parent 7aa4cc9a51
commit 09bf8f9ffa
16 changed files with 137 additions and 70 deletions
@@ -1,7 +1,7 @@
#include "Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include <array>
@@ -1,7 +1,7 @@
#include "Connector/Interface/Browser/Bridge/Config/GetConfig.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.h"
using namespace active::serialise;
@@ -1,7 +1,7 @@
#include "Connector/Interface/Browser/Bridge/Config/UpdateConfig.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
using namespace active::serialise;
using namespace connector::interfac::browser::bridge;
@@ -2,7 +2,7 @@
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include <array>
@@ -1,7 +1,7 @@
#include "ActiveLibDoctest/TestingPlatforms.h"
#include "Active/Serialise/JSON/JSONTransport.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Active/Utility/BufferIn.h"
#include "Speckle/Record/Credentials/Account.h"
@@ -1,4 +1,4 @@
#include "Active/Database/Storage/SQLiteEngine.h"
#include "Active/Database/Storage/SQLite/SQLiteEngine.h"
#include "Active/Database/Storage/Storage.h"
#include "Active/Serialise/JSON/JSONTransport.h"
#include "Active/Setting/ValueSetting.h"
@@ -2,7 +2,7 @@
#include "Active/Serialise/CargoHold.h"
#include "Active/Serialise/Null.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Speckle/Interface/Browser/Bridge/BrowserBridge.h"
#include "Speckle/Interface/Browser/Bridge/Functions/ErrorReport.h"
#include "Speckle/Utility/Exception.h"
@@ -4,7 +4,7 @@
#include "Active/Serialise/Inventory/Identity.h"
#include "Active/Serialise/Item/Wrapper/ItemWrap.h"
#include "Active/Serialise/Package/NullPackage.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Speckle/Interface/Browser/JSBinding.h"
#include "Speckle/Interface/Browser/NamedFunction.h"
#include "Speckle/Utility/String.h"
@@ -1,7 +1,7 @@
#include "Speckle/Record/Credentials/Account.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Speckle/Utility/Guid.h"
using namespace active::serialise;
@@ -1,7 +1,7 @@
#include "Speckle/Record/Credentials/ServerInfo.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Item/Wrapper/ValueOptionWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageUnoWrap.h"
#include "Speckle/Utility/Guid.h"
#include <array>
@@ -76,21 +76,21 @@ Cargo::Unique ServerInfo::getCargo(const Inventory::Item& item) const {
using namespace active::serialise;
switch (item.index) {
case nameID:
return std::make_unique<ValueWrap<String>>(m_name);
return std::make_unique<StringWrap>(m_name);
case companyID:
return std::make_unique<ValueWrap<String>>(m_company);
return std::make_unique<StringOptWrap>(m_company);
case versionID:
return std::make_unique<ValueWrap<String>>(m_version);
return std::make_unique<StringOptWrap>(m_version);
case contactID:
return std::make_unique<ValueWrap<String>>(m_adminContact);
return std::make_unique<StringOptWrap>(m_adminContact);
case descriptionID:
return std::make_unique<ValueWrap<String>>(m_description);
return std::make_unique<StringOptWrap>(m_description);
case frontEndID:
return std::make_unique<ValueWrap<bool>>(m_frontend2);
case urlID:
return std::make_unique<ValueWrap<String>>(m_url);
return std::make_unique<StringOptWrap>(m_url);
case migrationID:
return std::make_unique<PackageWrap>(m_migration);
return std::make_unique<PackageUnoWrap<ServerMigration>>(m_migration);
default:
return nullptr; //Requested an unknown index
}
@@ -102,10 +102,23 @@ Cargo::Unique ServerInfo::getCargo(const Inventory::Item& item) const {
--------------------------------------------------------------------*/
void ServerInfo::setDefault() {
m_name.clear();
m_company.clear();
m_version.clear();
m_adminContact.clear();
m_description.clear();
m_frontend2 = false;
m_url.clear();
} //ServerInfo::setDefault
/*--------------------------------------------------------------------
Copy from another object
source: The object to copy
--------------------------------------------------------------------*/
void ServerInfo::copy(const ServerInfo& source) {
if (this == &source)
return;
m_name = source.m_name;
m_version = source.m_version;
m_adminContact = source.m_adminContact;
m_description = source.m_description;
m_frontend2 = source.m_frontend2;
m_url = source.m_url;
m_migration = (source.m_migration) ? std::make_unique<ServerMigration>(*source.m_migration) : nullptr;
} //ServerInfo::copy
@@ -30,11 +30,29 @@ namespace speckle::record::cred {
@param isFrontEnd ?
@param migration Server migration record
*/
ServerInfo(const utility::String& name, const utility::String& company, const utility::String& version, const utility::String& contact,
const utility::String& description, const utility::String& url, bool isFrontEnd, const ServerMigration& migration) :
ServerInfo(const utility::String& name, const utility::String::Option company = std::nullopt,
const utility::String::Option version = std::nullopt, const utility::String::Option contact = std::nullopt,
const utility::String::Option description = std::nullopt, const utility::String::Option url = std::nullopt,
bool isFrontEnd = false, std::unique_ptr<ServerMigration> migration = nullptr) :
m_name{name}, m_company{company}, m_version{version}, m_adminContact{contact}, m_description{description},
m_url{url}, m_frontend2{isFrontEnd}, m_migration{migration} {}
ServerInfo(const ServerInfo&) = default;
m_url{url}, m_frontend2{isFrontEnd}, m_migration{std::move(migration)} {}
/*!
Copy constructor
@param source The object to copy
*/
ServerInfo(const ServerInfo& source) { copy(source); }
/*!
Destructor
*/
~ServerInfo() {}
// MARK: - Operators
/*!
Assignment operator
@param source The object to copy
*/
ServerInfo& operator=(const ServerInfo& source) { copy(source); return *this; }
// MARK: - Functions (const)
@@ -43,37 +61,78 @@ namespace speckle::record::cred {
@return The server name
*/
const utility::String& getName() const { return m_name; }
/*!
Get the company name
@return The company name
*/
const utility::String::Option& getCompany() const { return m_company; }
/*!
Get the version
@return The version
*/
const utility::String::Option& getVersion() const { return m_version; }
/*!
Get the admin contact email
@return The admin contact email
*/
const utility::String::Option& getAdminContact() const { return m_adminContact; }
/*!
Get the description
@return The description
*/
const utility::String::Option& getDescription() const { return m_description; }
/*!
Determine if ?
@return ?
*/
bool isFrontEnd() const { return m_frontend2; }
/*!
Get the URL
@return The URL
*/
const utility::String::Option& getURL() const { return m_url; }
/*!
Get the migration history
@return The migration history (nullptr = no history)
*/
const ServerMigration* getMigration() const { return m_migration.get(); }
// MARK: - Serialisation
/*!
Fill an inventory with the package items
@param inventory The inventory to receive the package items
@return True if the package has added items to the inventory
*/
Fill an inventory with the package items
@param inventory The inventory to receive the package items
@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)
*/
Get the specified cargo
@param item The inventory item to retrieve
@return The requested cargo (nullptr on failure)
*/
Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
/*!
Set to the default package content
*/
Set to the default package content
*/
void setDefault() override;
private:
/*!
Copy from another object
@param source The object to copy
*/
void copy(const ServerInfo& source);
///Server name
utility::String m_name;
///Company name
utility::String m_company;
utility::String::Option m_company;
///Server version
utility::String m_version;
utility::String::Option m_version;
///Admin contact email
utility::String m_adminContact;
utility::String::Option m_adminContact;
///Server description
utility::String m_description;
utility::String::Option m_description;
/*!
This field is not returned from the GQL API, it should be populated after construction from the response headers.
See "Speckle.Core.Credentials.AccountManager"
@@ -84,9 +143,9 @@ namespace speckle::record::cred {
This field is not returned from the GQL API, it should be populated after construction.
See "Speckle.Core.Credentials.AccountManager"
*/
utility::String m_url;
utility::String::Option m_url;
///Server migration record
ServerMigration m_migration;
std::unique_ptr<ServerMigration> m_migration;
};
}
@@ -1,6 +1,6 @@
#include "Speckle/Record/Credentials/ServerMigration.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Item/Wrapper/ValueOptionWrap.h"
#include "Speckle/Utility/Guid.h"
using namespace active::serialise;
@@ -57,19 +57,10 @@ Cargo::Unique ServerMigration::getCargo(const Inventory::Item& item) const {
using namespace active::serialise;
switch (item.index) {
case movedToID:
return std::make_unique<ValueWrap<String>>(movedTo);
return std::make_unique<StringOptWrap>(movedTo);
case movedFromID:
return std::make_unique<ValueWrap<String>>(movedFrom);
return std::make_unique<StringOptWrap>(movedFrom);
default:
return nullptr; //Requested an unknown index
}
} //ServerMigration::getCargo
/*--------------------------------------------------------------------
Set to the default package content
--------------------------------------------------------------------*/
void ServerMigration::setDefault() {
movedTo.clear();
movedFrom.clear();
} //ServerMigration::setDefault
@@ -12,6 +12,16 @@ namespace speckle::record::cred {
class ServerMigration : public active::serialise::Package {
public:
// MARK: - Types
using base = active::serialise::Package;
///Unique pointer
using Unique = std::unique_ptr<ServerMigration>;
///Shared pointer
using Shared = std::shared_ptr<ServerMigration>;
///Optional
using Option = std::optional<ServerMigration>;
// MARK: - Constructors
/*!
@@ -25,9 +35,9 @@ namespace speckle::record::cred {
// MARK: - Public variables
///New URI where this server is now deployed
speckle::utility::String movedTo;
speckle::utility::String::Option movedTo;
///Previous URI where this server used to be deployed
speckle::utility::String movedFrom;
speckle::utility::String::Option movedFrom;
// MARK: - Serialisation
@@ -43,10 +53,6 @@ namespace speckle::record::cred {
@return The requested cargo (nullptr on failure)
*/
Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
/*!
Set to the default package content
*/
void setDefault() override;
};
}
@@ -1,7 +1,7 @@
#include "Speckle/Record/Credentials/UserInfo.h"
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Item/Wrapper/ValueOptionWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Speckle/Utility/Guid.h"
#include <array>
@@ -73,9 +73,9 @@ Cargo::Unique UserInfo::getCargo(const Inventory::Item& item) const {
case emailID:
return std::make_unique<ValueWrap<String>>(m_email);
case companyID:
return std::make_unique<ValueWrap<String>>(m_company);
return std::make_unique<StringOptWrap>(m_company);
case avatarID:
return std::make_unique<ValueWrap<String>>(m_avatar);
return std::make_unique<StringOptWrap>(m_avatar);
default:
return nullptr; //Requested an unknown index
}
@@ -88,7 +88,5 @@ Cargo::Unique UserInfo::getCargo(const Inventory::Item& item) const {
void UserInfo::setDefault() {
m_id.clear();
m_name.clear();
m_company.clear();
m_email.clear();
m_avatar.clear();
} //UserInfo::setDefault
@@ -71,9 +71,9 @@ namespace speckle::record::cred {
///User email
utility::String m_email;
///Compsny name
utility::String m_company;
utility::String::Option m_company;
///Avatar?
utility::String m_avatar;
utility::String::Option m_avatar;
};
}
@@ -9,7 +9,7 @@
#include "Active/Setting/Values/StringValue.h"
#include "Active/Setting/Values/UInt32Value.h"
#include "Active/Serialise/Package/Package.h"
#include "Active/Serialise/Package/PackageWrap.h"
#include "Active/Serialise/Package/Wrapper/PackageWrap.h"
#include "Active/Serialise/XML/Item/XMLDateTime.h"
#include "Speckle/Environment/Platform.h"