From 09bf8f9ffaa8f875635b147cfd4473ed5a018756 Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Fri, 6 Sep 2024 18:55:13 +0100 Subject: [PATCH] Restructured objects to support optional (nullable) members --- .../Bridge/Config/Arg/ConnectorConfig.cpp | 2 +- .../Browser/Bridge/Config/GetConfig.cpp | 2 +- .../Browser/Bridge/Config/UpdateConfig.cpp | 2 +- .../Browser/Bridge/Test/GetComplexType.cpp | 2 +- .../ConnectorTests/AccountTests.cpp | 2 +- .../Speckle/Database/AccountDatabase.cpp | 2 +- .../Browser/Bridge/Functions/RunMethod.cpp | 2 +- .../Speckle/Interface/Browser/JSFunction.h | 2 +- .../Speckle/Record/Credentials/Account.cpp | 2 +- .../Speckle/Record/Credentials/ServerInfo.cpp | 41 +++++--- .../Speckle/Record/Credentials/ServerInfo.h | 99 +++++++++++++++---- .../Record/Credentials/ServerMigration.cpp | 15 +-- .../Record/Credentials/ServerMigration.h | 18 ++-- .../Speckle/Record/Credentials/UserInfo.cpp | 10 +- .../Speckle/Record/Credentials/UserInfo.h | 4 +- .../Serialise/JSBase/JSBaseTransport.cpp | 2 +- 16 files changed, 137 insertions(+), 70 deletions(-) diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.cpp index 65ffacb..a22a310 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/Arg/ConnectorConfig.cpp @@ -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 diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/GetConfig.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/GetConfig.cpp index b3e17f1..c486370 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/GetConfig.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/GetConfig.cpp @@ -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; diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/UpdateConfig.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/UpdateConfig.cpp index f97ccf4..1977dc6 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/UpdateConfig.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Config/UpdateConfig.cpp @@ -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; diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Test/GetComplexType.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Test/GetComplexType.cpp index d082d4a..873bb6f 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Test/GetComplexType.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Test/GetComplexType.cpp @@ -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 diff --git a/SpeckleConnector/ConnectorTests/AccountTests.cpp b/SpeckleConnector/ConnectorTests/AccountTests.cpp index 849dc31..19d1108 100644 --- a/SpeckleConnector/ConnectorTests/AccountTests.cpp +++ b/SpeckleConnector/ConnectorTests/AccountTests.cpp @@ -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" diff --git a/SpeckleLib/Speckle/Database/AccountDatabase.cpp b/SpeckleLib/Speckle/Database/AccountDatabase.cpp index 94f0ac5..c6847c1 100644 --- a/SpeckleLib/Speckle/Database/AccountDatabase.cpp +++ b/SpeckleLib/Speckle/Database/AccountDatabase.cpp @@ -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" diff --git a/SpeckleLib/Speckle/Interface/Browser/Bridge/Functions/RunMethod.cpp b/SpeckleLib/Speckle/Interface/Browser/Bridge/Functions/RunMethod.cpp index 9887230..17f3376 100644 --- a/SpeckleLib/Speckle/Interface/Browser/Bridge/Functions/RunMethod.cpp +++ b/SpeckleLib/Speckle/Interface/Browser/Bridge/Functions/RunMethod.cpp @@ -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" diff --git a/SpeckleLib/Speckle/Interface/Browser/JSFunction.h b/SpeckleLib/Speckle/Interface/Browser/JSFunction.h index ade0b6e..0044ebf 100644 --- a/SpeckleLib/Speckle/Interface/Browser/JSFunction.h +++ b/SpeckleLib/Speckle/Interface/Browser/JSFunction.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" diff --git a/SpeckleLib/Speckle/Record/Credentials/Account.cpp b/SpeckleLib/Speckle/Record/Credentials/Account.cpp index 1e9fc13..adfe089 100644 --- a/SpeckleLib/Speckle/Record/Credentials/Account.cpp +++ b/SpeckleLib/Speckle/Record/Credentials/Account.cpp @@ -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; diff --git a/SpeckleLib/Speckle/Record/Credentials/ServerInfo.cpp b/SpeckleLib/Speckle/Record/Credentials/ServerInfo.cpp index f8cfe91..db98ce8 100644 --- a/SpeckleLib/Speckle/Record/Credentials/ServerInfo.cpp +++ b/SpeckleLib/Speckle/Record/Credentials/ServerInfo.cpp @@ -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 @@ -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>(m_name); + return std::make_unique(m_name); case companyID: - return std::make_unique>(m_company); + return std::make_unique(m_company); case versionID: - return std::make_unique>(m_version); + return std::make_unique(m_version); case contactID: - return std::make_unique>(m_adminContact); + return std::make_unique(m_adminContact); case descriptionID: - return std::make_unique>(m_description); + return std::make_unique(m_description); case frontEndID: return std::make_unique>(m_frontend2); case urlID: - return std::make_unique>(m_url); + return std::make_unique(m_url); case migrationID: - return std::make_unique(m_migration); + return std::make_unique>(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(*source.m_migration) : nullptr; +} //ServerInfo::copy diff --git a/SpeckleLib/Speckle/Record/Credentials/ServerInfo.h b/SpeckleLib/Speckle/Record/Credentials/ServerInfo.h index 16d76cc..7e7d1a0 100644 --- a/SpeckleLib/Speckle/Record/Credentials/ServerInfo.h +++ b/SpeckleLib/Speckle/Record/Credentials/ServerInfo.h @@ -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 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 m_migration; }; } diff --git a/SpeckleLib/Speckle/Record/Credentials/ServerMigration.cpp b/SpeckleLib/Speckle/Record/Credentials/ServerMigration.cpp index e6ac223..7479bf7 100644 --- a/SpeckleLib/Speckle/Record/Credentials/ServerMigration.cpp +++ b/SpeckleLib/Speckle/Record/Credentials/ServerMigration.cpp @@ -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>(movedTo); + return std::make_unique(movedTo); case movedFromID: - return std::make_unique>(movedFrom); + return std::make_unique(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 diff --git a/SpeckleLib/Speckle/Record/Credentials/ServerMigration.h b/SpeckleLib/Speckle/Record/Credentials/ServerMigration.h index 7020c7b..60f42f6 100644 --- a/SpeckleLib/Speckle/Record/Credentials/ServerMigration.h +++ b/SpeckleLib/Speckle/Record/Credentials/ServerMigration.h @@ -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; + ///Shared pointer + using Shared = std::shared_ptr; + ///Optional + using Option = std::optional; + // 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; }; } diff --git a/SpeckleLib/Speckle/Record/Credentials/UserInfo.cpp b/SpeckleLib/Speckle/Record/Credentials/UserInfo.cpp index 2063e44..f6a9773 100644 --- a/SpeckleLib/Speckle/Record/Credentials/UserInfo.cpp +++ b/SpeckleLib/Speckle/Record/Credentials/UserInfo.cpp @@ -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 @@ -73,9 +73,9 @@ Cargo::Unique UserInfo::getCargo(const Inventory::Item& item) const { case emailID: return std::make_unique>(m_email); case companyID: - return std::make_unique>(m_company); + return std::make_unique(m_company); case avatarID: - return std::make_unique>(m_avatar); + return std::make_unique(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 diff --git a/SpeckleLib/Speckle/Record/Credentials/UserInfo.h b/SpeckleLib/Speckle/Record/Credentials/UserInfo.h index 7813a68..59552eb 100644 --- a/SpeckleLib/Speckle/Record/Credentials/UserInfo.h +++ b/SpeckleLib/Speckle/Record/Credentials/UserInfo.h @@ -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; }; } diff --git a/SpeckleLib/Speckle/Serialise/JSBase/JSBaseTransport.cpp b/SpeckleLib/Speckle/Serialise/JSBase/JSBaseTransport.cpp index 0e47fca..8d859e9 100644 --- a/SpeckleLib/Speckle/Serialise/JSBase/JSBaseTransport.cpp +++ b/SpeckleLib/Speckle/Serialise/JSBase/JSBaseTransport.cpp @@ -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"