From 038121e530364471196d6b13bd4bee74a318af73 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 10:46:07 +0200 Subject: [PATCH 01/12] Identifiable: Rename identification to id This reflects the name in the V3 metamodel Signed-off-by: Tobias Klausmann --- src/libaas/basyx/assetadministrationshell.h | 8 ++++---- src/libaas/basyx/identifiable.h | 10 +++++----- src/libaas/basyx/serialization/json/serializer.cpp | 2 +- src/libaas/basyx/serialization/xml/xmldeserializer.cpp | 2 +- src/libaas/basyx/submodel.h | 8 ++++---- tests/tests_libaas/test_json_deserializer.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libaas/basyx/assetadministrationshell.h b/src/libaas/basyx/assetadministrationshell.h index 00a5d7f..52759c2 100644 --- a/src/libaas/basyx/assetadministrationshell.h +++ b/src/libaas/basyx/assetadministrationshell.h @@ -41,7 +41,7 @@ class AssetAdministrationShell : : Identifiable(idShort, Identifier(id)), assetInformation(std::move(assetInformation)) {}; public: AssetAdministrationShell(const AssetAdministrationShell &aas): - Identifiable(aas.getIdShort(), std::move(aas.getIdentification())), + Identifiable(aas.getIdShort(), std::move(aas.getId())), assetInformation(aas.getAssetInformation()) { this->submodels.append(aas.getSubmodels()); @@ -53,7 +53,7 @@ class AssetAdministrationShell : } AssetAdministrationShell& operator=(const AssetAdministrationShell &aas) { - this->Identifiable::setIdentification(aas.getIdentification()); + this->Identifiable::setId(aas.getId()); this->getIdShort() = aas.getIdShort(); this->submodels.append(aas.getSubmodels()); @@ -83,8 +83,8 @@ class AssetAdministrationShell : void setSubmodels(ElementContainer submodels) { this->submodels = std::move(submodels); }; // Identifiable - special purpose - void setIdentification(Token t, Identifier identifier) { - this->Identifiable::setIdentification(identifier); + void setId(Token t, Identifier id) { + this->Identifiable::setId(id); } }; diff --git a/src/libaas/basyx/identifiable.h b/src/libaas/basyx/identifiable.h index a92a129..b5125a2 100644 --- a/src/libaas/basyx/identifiable.h +++ b/src/libaas/basyx/identifiable.h @@ -15,10 +15,10 @@ class Identifiable : public Referable { private: util::optional administration; - Identifier identification; + Identifier id; public: - Identifiable(util::string_view idShort, util::string_view id) : Referable(idShort), identification(id) {}; - Identifiable(util::string_view idShort, Identifier identification) : Referable(idShort), identification(std::move(identification)) {}; + Identifiable(util::string_view idShort, util::string_view id) : Referable(idShort), id(id) {}; + Identifiable(util::string_view idShort, Identifier id) : Referable(idShort), id(std::move(id)) {}; Identifiable(const Identifiable&) = default; Identifiable(Identifiable&&) = default; @@ -32,8 +32,8 @@ class Identifiable : public Referable util::optional & getAdministration() { return administration; }; void setAdministration(AdministrativeInformation administrativeInformation) { this->administration = std::move(administrativeInformation); } - const Identifier & getIdentification() const { return identification; }; - void setIdentification(Identifier identifier) { this->identification = std::move(identifier); }; + const Identifier & getId() const { return id; }; + void setId(Identifier id) { this->id = std::move(id); }; }; }; diff --git a/src/libaas/basyx/serialization/json/serializer.cpp b/src/libaas/basyx/serialization/json/serializer.cpp index ee3b019..0b8cba4 100644 --- a/src/libaas/basyx/serialization/json/serializer.cpp +++ b/src/libaas/basyx/serialization/json/serializer.cpp @@ -239,7 +239,7 @@ void serialize_helper(json_t & json, const Identifiable & identifiable) { serialize_helper_h(json, identifiable); - json["identification"] = serialize(identifiable.getIdentification()); + json["identification"] = serialize(identifiable.getId()); if (identifiable.getAdministration()) json["administration"] = serialize(*identifiable.getAdministration()); diff --git a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp index bf21f6b..c3fecfc 100644 --- a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp +++ b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp @@ -283,7 +283,7 @@ void XMLDeSerializer::deSerializeIdentifiable(xml_node node, xml_node ident_node = findChildByName(node, XML_identification); if (ident_node.root()) { Identifier ident = deSerializeIdentifier(ident_node); - metamodelElement.setIdentification(ds->getToken(), ident); + metamodelElement.setId(ds->getToken(), ident); } } diff --git a/src/libaas/basyx/submodel.h b/src/libaas/basyx/submodel.h index 44aaab6..3c77976 100644 --- a/src/libaas/basyx/submodel.h +++ b/src/libaas/basyx/submodel.h @@ -38,12 +38,12 @@ class Submodel : Submodel(util::string_view idShort, util::string_view identifier) : Identifiable(idShort, Identifier(identifier)) {}; Submodel(util::string_view idShort, Identifier identifier) : Identifiable(idShort, std::move(identifier)) {}; public: - Submodel(const Submodel &sm) : Identifiable(sm.getIdShort(), std::move(sm.getIdentification().getId())) { + Submodel(const Submodel &sm) : Identifiable(sm.getIdShort(), std::move(sm.getId().getId())) { this->submodelElements.append(sm.getSubmodelElements()); }; Submodel& operator=(const Submodel &sm) { - this->Identifiable::setIdentification(sm.getIdentification()); + this->Identifiable::setId(sm.getId()); this->getIdShort() = sm.getIdShort(); this->submodelElements.append(sm.getSubmodelElements()); return *this; @@ -61,8 +61,8 @@ class Submodel : void setSubmodelElements(ElementContainer elements) { this->submodelElements = std::move(elements); }; // Identifiable - special purpose - void setIdentification(Token t, Identifier identifier) { - this->Identifiable::setIdentification(identifier); + void setId(Token t, Identifier id) { + this->Identifiable::setId(id); } }; diff --git a/tests/tests_libaas/test_json_deserializer.cpp b/tests/tests_libaas/test_json_deserializer.cpp index 3ec72c7..7f59787 100644 --- a/tests/tests_libaas/test_json_deserializer.cpp +++ b/tests/tests_libaas/test_json_deserializer.cpp @@ -204,7 +204,7 @@ TEST_F(JsonDeserializerTest, Submodel) auto sm = basyx::serialization::json::deserialize_submodel(json_submodel); ASSERT_EQ(sm.getIdShort(), "sm_1"); - ASSERT_EQ(sm.getIdentification().getId(), "submodel"); + ASSERT_EQ(sm.getId().getId(), "submodel"); ASSERT_EQ(sm.getSubmodelElements().size(), 2); }; @@ -227,7 +227,7 @@ TEST_F(JsonDeserializerTest, AssetAdministrationShell) auto aas = basyx::serialization::json::deserialize_aas(json_aas); ASSERT_EQ(aas.getIdShort(), "aas_1"); - ASSERT_EQ(aas.getIdentification().getId(), "asset_admin_shell_1"); + ASSERT_EQ(aas.getId().getId(), "asset_admin_shell_1"); ASSERT_EQ(aas.getSubmodels().size(), 1); }; From edfeb386dc24c17e0692384a357e992045975c77 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 13:14:36 +0200 Subject: [PATCH 02/12] VersionRevisionType: Add to build Yet another size constrained string we have to honor. Another constrained is that the string need to match the following regex pattern: ^([0-9]|[1-9][0-9]*)$ , this is the main reason this class is created. Signed-off-by: Tobias Klausmann --- src/libaas/basyx/versionRevisionType.cpp | 29 ++++++++++++++++++ src/libaas/basyx/versionRevisionType.h | 39 ++++++++++++++++++++++++ src/libaas/sources.cmake | 2 ++ tests/tests_libaas/test_basyx.cpp | 14 +++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/libaas/basyx/versionRevisionType.cpp create mode 100644 src/libaas/basyx/versionRevisionType.h diff --git a/src/libaas/basyx/versionRevisionType.cpp b/src/libaas/basyx/versionRevisionType.cpp new file mode 100644 index 0000000..1552beb --- /dev/null +++ b/src/libaas/basyx/versionRevisionType.cpp @@ -0,0 +1,29 @@ +#include + +namespace basyx { + +VersionRevisionType &VersionRevisionType::operator=(const VersionRevisionType &id) noexcept { + operator=(id.get()); + return *this; +} + +VersionRevisionType &VersionRevisionType::operator=(const basyx::util::string_view& id) noexcept { + operator=(id.to_string()); + return *this; +} + +/* Funnel for all operator= of this class */ +VersionRevisionType &VersionRevisionType::operator=(const std::string& id) noexcept { + std::smatch matches; + if (std::regex_match(id, matches, VERSIONREVISIONTYPEREGEX)) + base::MinMaxString::operator=(id); + else + base::MinMaxString::operator=(std::string(&DEFAULT_VERSION)); + return *this; +} + +std::string VersionRevisionType::get() const { + return static_cast(*this); +} + +}; diff --git a/src/libaas/basyx/versionRevisionType.h b/src/libaas/basyx/versionRevisionType.h new file mode 100644 index 0000000..ae5c615 --- /dev/null +++ b/src/libaas/basyx/versionRevisionType.h @@ -0,0 +1,39 @@ +#ifndef VERSIONREVISIONTYPE_H +#define VERSIONREVISIONTYPE_H + +#include + +#include +#include + +namespace basyx +{ + +static const char DEFAULT_VERSION = '0'; +static std::regex VERSIONREVISIONTYPEREGEX("^([0-9]|[1-9][0-9]*)$"); + +class VersionRevisionType: public base::MinMaxString { +private: + static const unsigned int minLenght = 1; + static const unsigned int maxLenght = 4; +public: + VersionRevisionType(): base::MinMaxString(minLenght, maxLenght) {} + VersionRevisionType(const VersionRevisionType&) = default; + VersionRevisionType(const basyx::util::string_view &v): + base::MinMaxString(minLenght, maxLenght) { + operator=(v.to_string()); + } + VersionRevisionType(VersionRevisionType&&) = default; + + VersionRevisionType& operator=(const VersionRevisionType& id) noexcept; + VersionRevisionType& operator=(const basyx::util::string_view& id) noexcept; + VersionRevisionType& operator=(const std::string& id) noexcept; + //VersionRevisionType& operator=(VersionRevisionType &) noexcept = default; + + std::string get() const; + + ~VersionRevisionType() = default; +}; +}; + +#endif // VERSIONREVISIONTYPE_H diff --git a/src/libaas/sources.cmake b/src/libaas/sources.cmake index ee197c3..30aa165 100644 --- a/src/libaas/sources.cmake +++ b/src/libaas/sources.cmake @@ -61,6 +61,7 @@ SET(SOURCE_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/relationshipelement.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/submodelelement.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/submodelelementcollection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/versionRevisionType.cpp ) SET(HEADER_FILES_BASYX_AAS @@ -145,4 +146,5 @@ SET(HEADER_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/relationshipelement.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/submodelelement.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/submodelelement/submodelelementcollection.h + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/versionRevisionType.h ) diff --git a/tests/tests_libaas/test_basyx.cpp b/tests/tests_libaas/test_basyx.cpp index e532ee6..4a7e492 100644 --- a/tests/tests_libaas/test_basyx.cpp +++ b/tests/tests_libaas/test_basyx.cpp @@ -18,6 +18,8 @@ #include #include +#include + #include #include @@ -76,6 +78,18 @@ TEST_F(BaseTest, MinMaxString) { } +TEST_F(BaseTest, VersionRevisionType) +{ + VersionRevisionType vrt1("22"); + ASSERT_STREQ("22", vrt1.str().data()); + + VersionRevisionType vrt2("Bad"); + ASSERT_STREQ("0", vrt2.str().data()); + + VersionRevisionType vrt3("1234567890"); + ASSERT_STREQ("1234", vrt3.str().data()); +} + TEST_F(BaseTest, LangStringSet) { basyx::langstring_t l { "de", "test" }; From a9c435f9b4bf7e59b230e33405880c7ef5bfb546 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 14:41:27 +0200 Subject: [PATCH 03/12] HasDataSpecification: Adapt to metamodel V3 This will be used in further commits Signed-off-by: Tobias Klausmann --- .../basyx/semantics/hasDataSpecification.cpp | 6 +++ .../basyx/semantics/hasDataSpecification.h | 50 +++++++++++++++++++ .../basyx/semantics/hasdataspecification.cpp | 0 .../basyx/semantics/hasdataspecification.h | 41 --------------- src/libaas/sources.cmake | 4 +- 5 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 src/libaas/basyx/semantics/hasDataSpecification.cpp create mode 100644 src/libaas/basyx/semantics/hasDataSpecification.h delete mode 100644 src/libaas/basyx/semantics/hasdataspecification.cpp delete mode 100644 src/libaas/basyx/semantics/hasdataspecification.h diff --git a/src/libaas/basyx/semantics/hasDataSpecification.cpp b/src/libaas/basyx/semantics/hasDataSpecification.cpp new file mode 100644 index 0000000..ac53d66 --- /dev/null +++ b/src/libaas/basyx/semantics/hasDataSpecification.cpp @@ -0,0 +1,6 @@ +#include + +namespace basyx +{ + +}; diff --git a/src/libaas/basyx/semantics/hasDataSpecification.h b/src/libaas/basyx/semantics/hasDataSpecification.h new file mode 100644 index 0000000..5086e94 --- /dev/null +++ b/src/libaas/basyx/semantics/hasDataSpecification.h @@ -0,0 +1,50 @@ +#ifndef HASDATASPECIFICATION_H +#define HASDATASPECIFICATION_H + +#include + +#include + +#include + +namespace basyx +{ + +class HasDataSpecification +{ +private: + ElementVector dataSpecification; +public: + HasDataSpecification() = default; + + HasDataSpecification(const HasDataSpecification&) = default; + HasDataSpecification(HasDataSpecification&&) = default; + + HasDataSpecification & operator=(const HasDataSpecification&) noexcept = default; + HasDataSpecification & operator=(HasDataSpecification&&) noexcept = default; + + ~HasDataSpecification() = default; +public: + const ElementVector & getDataSpecification() const { + return this->dataSpecification; + }; + ElementVector & getDataSpecification() { + return this->dataSpecification; + }; + + void addDataSpecification(Reference dataSpecification) { + this->dataSpecification.add(dataSpecification); + }; + void addDataSpecification(util::string_view dataSpecification) { + this->dataSpecification.add(dataSpecification); + }; + + void setDataSpecication(ElementVector & dataSpecification) { + this->dataSpecification = std::move(dataSpecification); + } + +}; + +}; + +#endif /* HASDATASPECIFICATION_H */ diff --git a/src/libaas/basyx/semantics/hasdataspecification.cpp b/src/libaas/basyx/semantics/hasdataspecification.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/libaas/basyx/semantics/hasdataspecification.h b/src/libaas/basyx/semantics/hasdataspecification.h deleted file mode 100644 index ede38a9..0000000 --- a/src/libaas/basyx/semantics/hasdataspecification.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include - -namespace basyx -{ - -class HasDataSpecification -{ -public: - using dataSpecification_t = std::vector; -private: - dataSpecification_t dataSpecification; -public: - HasDataSpecification() {}; -public: - HasDataSpecification(const HasDataSpecification &) = default; - HasDataSpecification& operator=(const HasDataSpecification &) = default; - - HasDataSpecification(HasDataSpecification &&) noexcept = default; - HasDataSpecification& operator=(HasDataSpecification &&) noexcept = default; -public: - std::size_t size() const { return dataSpecification.size(); }; -public: - const dataSpecification_t & getDataSpecification() const { return dataSpecification; }; - dataSpecification_t & getContainedElments() { return dataSpecification; }; - void setDataSpecification(dataSpecification_t dataSpecification) { this->dataSpecification = std::move(dataSpecification); }; -}; - -}; diff --git a/src/libaas/sources.cmake b/src/libaas/sources.cmake index 30aa165..0e2cfff 100644 --- a/src/libaas/sources.cmake +++ b/src/libaas/sources.cmake @@ -37,7 +37,7 @@ SET(SOURCE_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/referable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/reference.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/conceptdescription.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/hasdataspecification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/hasDataSpecification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/json/deserializer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/json/serializer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/private/deserializer_priv.cpp @@ -115,7 +115,7 @@ SET(HEADER_FILES_BASYX_AAS ${CMAKE_CURRENT_SOURCE_DIR}/basyx/referable.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/reference.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/conceptdescription.h - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/hasdataspecification.h + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/semantics/hasDataSpecification.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/base/serialization.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/json/deserializer.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/serialization/json/serializer.h From 95d333d118151e520186afe20eba00cc106806e5 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 13:53:37 +0200 Subject: [PATCH 04/12] AdministrativeInformation: Adapt to metamodel Version 3 - Rename to the common filename schema - Use the newly introduce VersionRevisionType - Add HasDataSpecification parent Signed-off-by: Tobias Klausmann --- ...tion.cpp => administrativeInformation.cpp} | 4 +- src/libaas/basyx/administrativeInformation.h | 57 +++++++++++++++++++ src/libaas/basyx/administrative_information.h | 39 ------------- src/libaas/basyx/identifiable.h | 2 +- .../basyx/serialization/json/serializer.cpp | 20 +++++-- src/libaas/sources.cmake | 4 +- 6 files changed, 76 insertions(+), 50 deletions(-) rename src/libaas/basyx/{administrative_information.cpp => administrativeInformation.cpp} (86%) create mode 100644 src/libaas/basyx/administrativeInformation.h delete mode 100644 src/libaas/basyx/administrative_information.h diff --git a/src/libaas/basyx/administrative_information.cpp b/src/libaas/basyx/administrativeInformation.cpp similarity index 86% rename from src/libaas/basyx/administrative_information.cpp rename to src/libaas/basyx/administrativeInformation.cpp index 454cc43..5c4b24e 100644 --- a/src/libaas/basyx/administrative_information.cpp +++ b/src/libaas/basyx/administrativeInformation.cpp @@ -1,4 +1,4 @@ -#include "administrative_information.h" +#include namespace basyx { @@ -9,4 +9,4 @@ AdministrativeInformation::AdministrativeInformation(util::string_view version) AdministrativeInformation::AdministrativeInformation(util::string_view version, util::string_view revision) : version(version.to_string()), revision(revision.to_string()) {} -}; \ No newline at end of file +}; diff --git a/src/libaas/basyx/administrativeInformation.h b/src/libaas/basyx/administrativeInformation.h new file mode 100644 index 0000000..3c58204 --- /dev/null +++ b/src/libaas/basyx/administrativeInformation.h @@ -0,0 +1,57 @@ +#ifndef ADMINISTRATIVEINFORMATION_H +#define ADMINISTRATIVEINFORMATION_H + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace basyx +{ + +class AdministrativeInformation: public HasDataSpecification +{ +public: + using VersionType = basyx::VersionRevisionType; + using RevisionType = basyx::VersionRevisionType; +private: + util::optional version; + util::optional revision; + util::optional creator; + util::optional templateId; +public: + AdministrativeInformation() = default; + AdministrativeInformation(util::string_view version); + AdministrativeInformation(util::string_view version, util::string_view revision); + + AdministrativeInformation(const AdministrativeInformation&) = default; + AdministrativeInformation(AdministrativeInformation&&) = default; + + AdministrativeInformation & operator=(const AdministrativeInformation&) = default; + AdministrativeInformation & operator=(AdministrativeInformation&&) = default; + + ~AdministrativeInformation() = default; +public: + const util::optional getVersion() const { return version; }; + void setVersion(util::string_view version) { this->version = version; }; + + const util::optional getRevision() const { return revision; }; + void setRevision(util::string_view revision) { this->revision = revision; }; + + const util::optional & getCreator() const { return creator; }; + void setCreator(Reference & creator) { this->creator = std::move(creator); }; + + const util::optional & getTemplateId() const { return templateId; }; + void setTemplateId(Identifier templateId) { + this->templateId = std::move(templateId); + }; +}; + +}; + +#endif /* ADMINISTRATIVEINFORMATION_H */ diff --git a/src/libaas/basyx/administrative_information.h b/src/libaas/basyx/administrative_information.h deleted file mode 100644 index 0ba8342..0000000 --- a/src/libaas/basyx/administrative_information.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include - -#include - -#include - -namespace basyx -{ - -class AdministrativeInformation -{ -private: - util::optional version; - util::optional revision; -public: - AdministrativeInformation() = default; - AdministrativeInformation(util::string_view version); - AdministrativeInformation(util::string_view version, util::string_view revision); - - AdministrativeInformation(const AdministrativeInformation&) = default; - AdministrativeInformation(AdministrativeInformation&&) = default; - - AdministrativeInformation & operator=(const AdministrativeInformation&) = default; - AdministrativeInformation & operator=(AdministrativeInformation&&) = default; - - ~AdministrativeInformation() = default; -public: - const util::optional & get_version() const { return version; }; - void set_version(util::string_view version) { this->version = version.to_string(); }; - - const util::optional & get_revision() const { return revision; }; - void set_revision(util::string_view revision) { this->revision = revision.to_string(); }; -}; - -}; diff --git a/src/libaas/basyx/identifiable.h b/src/libaas/basyx/identifiable.h index b5125a2..7a1e161 100644 --- a/src/libaas/basyx/identifiable.h +++ b/src/libaas/basyx/identifiable.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/src/libaas/basyx/serialization/json/serializer.cpp b/src/libaas/basyx/serialization/json/serializer.cpp index 0b8cba4..da6d173 100644 --- a/src/libaas/basyx/serialization/json/serializer.cpp +++ b/src/libaas/basyx/serialization/json/serializer.cpp @@ -159,14 +159,22 @@ void serialize_helper(json_t & json, const Capability & capability) void serialize_helper(json_t & json, const AdministrativeInformation & administrativeInformation) { - auto & version = administrativeInformation.get_version(); - auto & revision = administrativeInformation.get_revision(); + auto & version = administrativeInformation.getVersion(); + auto & revision = administrativeInformation.getRevision(); + auto & creator = administrativeInformation.getCreator(); + auto & templateId = administrativeInformation.getTemplateId(); - if(version) - json["version"] = *version; + if(version) + json["version"] = version->get(); - if(revision) - json["revision"] = *revision; + if(revision) + json["revision"] = revision->get(); + + if (creator) + json["creator"] = serialize(creator.value()); + + if (templateId) + json["templateId"] = serialize(templateId.value()); }; void serialize_helper(json_t & json, const ReferenceElement & ref_element) diff --git a/src/libaas/sources.cmake b/src/libaas/sources.cmake index 0e2cfff..05d1b74 100644 --- a/src/libaas/sources.cmake +++ b/src/libaas/sources.cmake @@ -1,5 +1,5 @@ SET(SOURCE_FILES_BASYX_AAS - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrative_information.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrativeInformation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/assetinformation.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/assetadministrationshell.cpp ${CMAKE_CURRENT_SOURCE_DIR}/basyx/base/basyx_enums.cpp @@ -65,7 +65,7 @@ SET(SOURCE_FILES_BASYX_AAS ) SET(HEADER_FILES_BASYX_AAS - ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrative_information.h + ${CMAKE_CURRENT_SOURCE_DIR}/basyx/administrativeInformation.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/asset/assetinformation.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/assetadministrationshell.h ${CMAKE_CURRENT_SOURCE_DIR}/basyx/base/basyx_enum_base.h From 20bc4b965dbe3f2560d281a7b863fafc22d15ae0 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 14:55:36 +0200 Subject: [PATCH 05/12] Submodel: Add HasDataSpecification as parent class Signed-off-by: Tobias Klausmann --- src/libaas/basyx/submodel.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libaas/basyx/submodel.h b/src/libaas/basyx/submodel.h index 3c77976..4db80a9 100644 --- a/src/libaas/basyx/submodel.h +++ b/src/libaas/basyx/submodel.h @@ -15,6 +15,8 @@ #include +#include + #include #include #include @@ -27,8 +29,9 @@ using namespace basyx::serialization::priv; class Submodel : public Identifiable, - public HasKind, + public HasKind, public HasSemantics, + public HasDataSpecification, public ModelType, private Identifiable::Copyable { From c7920e8fa2bee2756ec234ac5e0e4c49c8d73737 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 14:55:49 +0200 Subject: [PATCH 06/12] AssetAdministrationShell: Add HasDataSpecification as parent class Signed-off-by: Tobias Klausmann --- src/libaas/basyx/assetadministrationshell.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libaas/basyx/assetadministrationshell.h b/src/libaas/basyx/assetadministrationshell.h index 52759c2..0eca563 100644 --- a/src/libaas/basyx/assetadministrationshell.h +++ b/src/libaas/basyx/assetadministrationshell.h @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -23,8 +24,9 @@ using Security = int; //using AssetInformation = int; // -------------------------- -class AssetAdministrationShell : - public Identifiable, +class AssetAdministrationShell : + public Identifiable, + public HasDataSpecification, public ModelType, private Identifiable::Copyable { From f8eff7f4628af269176368af84be684a5927fdcf Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 14:59:26 +0200 Subject: [PATCH 07/12] ConceptDescription: Adapt include path for HasDataSpecification Signed-off-by: Tobias Klausmann --- src/libaas/basyx/semantics/conceptdescription.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libaas/basyx/semantics/conceptdescription.h b/src/libaas/basyx/semantics/conceptdescription.h index 1776435..d493c31 100644 --- a/src/libaas/basyx/semantics/conceptdescription.h +++ b/src/libaas/basyx/semantics/conceptdescription.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include From 3185c422a150bf89f22dfa5e0a7fd1619e744e83 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 15:10:12 +0200 Subject: [PATCH 08/12] SubmodelElement: Add HasDataSpecification as parent class Signed-off-by: Tobias Klausmann --- .../basyx/submodelelement/submodelelement.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libaas/basyx/submodelelement/submodelelement.h b/src/libaas/basyx/submodelelement/submodelelement.h index e89b3d3..621adba 100644 --- a/src/libaas/basyx/submodelelement/submodelelement.h +++ b/src/libaas/basyx/submodelelement/submodelelement.h @@ -10,16 +10,19 @@ #include +#include + #include namespace basyx { -class SubmodelElement : - public Referable, - public HasKind, - public HasSemantics, - public virtual serialization::serializable_base +class SubmodelElement : + public Referable, + public HasKind, + public HasSemantics, + public HasDataSpecification, + public virtual serialization::serializable_base { protected: SubmodelElement(util::string_view idShort) : Referable(idShort) {}; @@ -47,4 +50,4 @@ class SubmodelElementHelper static bool IsSubmodelElementCollection(const SubmodelElement& ele); }; -} \ No newline at end of file +} From 7f2e10b9b9b02f03e3ca9194eca379e0f1e8b119 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 15:14:51 +0200 Subject: [PATCH 09/12] Submodel: Add Qualifible base class Signed-off-by: Tobias Klausmann --- src/libaas/basyx/submodel.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libaas/basyx/submodel.h b/src/libaas/basyx/submodel.h index 4db80a9..28a69df 100644 --- a/src/libaas/basyx/submodel.h +++ b/src/libaas/basyx/submodel.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -30,7 +31,8 @@ using namespace basyx::serialization::priv; class Submodel : public Identifiable, public HasKind, - public HasSemantics, + public HasSemantics, + public Qualifiable, public HasDataSpecification, public ModelType, private Identifiable::Copyable From 91c95dbdec9be84b053b8d859e51773bc63a56dd Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 15:18:18 +0200 Subject: [PATCH 10/12] SubmodelElement: Add Qualifiable base class Signed-off-by: Tobias Klausmann --- src/libaas/basyx/submodelelement/submodelelement.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libaas/basyx/submodelelement/submodelelement.h b/src/libaas/basyx/submodelelement/submodelelement.h index 621adba..6f13c35 100644 --- a/src/libaas/basyx/submodelelement/submodelelement.h +++ b/src/libaas/basyx/submodelelement/submodelelement.h @@ -11,6 +11,7 @@ #include #include +#include #include @@ -21,6 +22,7 @@ class SubmodelElement : public Referable, public HasKind, public HasSemantics, + public Qualifiable, public HasDataSpecification, public virtual serialization::serializable_base { From b00271637b43a70cf721f0f2ab0ea5d2c1630cf3 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 15:34:40 +0200 Subject: [PATCH 11/12] HasKind: Add getter and setter This is the common way for all other properties, thus implement it as well Signed-off-by: Tobias Klausmann --- src/libaas/basyx/haskind.h | 5 ++++- src/libaas/basyx/serialization/json/serializer.cpp | 2 +- src/libaas/basyx/serialization/xml/xmldeserializer.cpp | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libaas/basyx/haskind.h b/src/libaas/basyx/haskind.h index 76e4b2d..fff5b1d 100644 --- a/src/libaas/basyx/haskind.h +++ b/src/libaas/basyx/haskind.h @@ -6,8 +6,11 @@ namespace basyx { class HasKind { +private: + ModelingKind kind = ModelingKind::Instance; public: - ModelingKind kind = ModelingKind::Instance; + void setKind(ModelingKind kind) { this->kind = kind; } + const ModelingKind getKind() const { return kind; } }; }; diff --git a/src/libaas/basyx/serialization/json/serializer.cpp b/src/libaas/basyx/serialization/json/serializer.cpp index da6d173..1d7e12a 100644 --- a/src/libaas/basyx/serialization/json/serializer.cpp +++ b/src/libaas/basyx/serialization/json/serializer.cpp @@ -45,7 +45,7 @@ void serialize_helper(json_t & json, const HasSemantics & hasSemantics) void serialize_helper(json_t & json, const HasKind & hasKind) { - json["kind"] = ModelingKind_::to_string(hasKind.kind); + json["kind"] = ModelingKind_::to_string(hasKind.getKind()); }; void serialize_helper(json_t & json, const modeltype_base & modelType) diff --git a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp index c3fecfc..58013b7 100644 --- a/src/libaas/basyx/serialization/xml/xmldeserializer.cpp +++ b/src/libaas/basyx/serialization/xml/xmldeserializer.cpp @@ -345,13 +345,13 @@ void XMLDeSerializer::deSerializeHasKind(pugi::xml_node node, xml_node mk_node = findChildByName(node, XML_modelingKind); if (mk_node.root()) { std::string mk_str = deSerializeString(mk_node); - metamodelElement.kind = ModelingKind_::from_string(mk_str); + metamodelElement.setKind(ModelingKind_::from_string(mk_str)); } /* As per spec: * "Default for an element is that it is representing an instance." */ else - metamodelElement.kind = ModelingKind::Instance; + metamodelElement.setKind(ModelingKind::Instance); } template From 4f711360f88360cfd489d00a0471b10032304484 Mon Sep 17 00:00:00 2001 From: Tobias Klausmann Date: Mon, 18 Sep 2023 15:20:40 +0200 Subject: [PATCH 12/12] SubmodelElement: Remove base class HasKind As the tests used this, pick submodel as a test for HasKind Signed-off-by: Tobias Klausmann --- src/libaas/basyx/submodelelement/submodelelement.h | 1 - tests/tests_libaas/test_basyx.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libaas/basyx/submodelelement/submodelelement.h b/src/libaas/basyx/submodelelement/submodelelement.h index 6f13c35..5bfc77a 100644 --- a/src/libaas/basyx/submodelelement/submodelelement.h +++ b/src/libaas/basyx/submodelelement/submodelelement.h @@ -20,7 +20,6 @@ namespace basyx class SubmodelElement : public Referable, - public HasKind, public HasSemantics, public Qualifiable, public HasDataSpecification, diff --git a/tests/tests_libaas/test_basyx.cpp b/tests/tests_libaas/test_basyx.cpp index 4a7e492..2738ea0 100644 --- a/tests/tests_libaas/test_basyx.cpp +++ b/tests/tests_libaas/test_basyx.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -185,7 +186,6 @@ TEST_F(BaseTest, MultiLangProp) ASSERT_EQ(*ls1, "example"); ASSERT_EQ(*ls2, "beispiel"); - mlp.kind = basyx::ModelingKind::Instance; }; TEST_F(BaseTest, Enum) @@ -203,11 +203,11 @@ TEST_F(BaseTest, Enum) TEST_F(BaseTest, HasKind) { - auto mlp = std::make_unique("test"); + Submodel sm("test",Identifier("testId")); + sm.setKind(ModelingKind::Template); - mlp->kind = ModelingKind::Template; - HasKind* has_kind = mlp.get(); - has_kind->kind = ModelingKind::Instance; + HasKind has_kind = static_cast(sm); + ASSERT_EQ(ModelingKind::Template, has_kind.getKind()); }; TEST_F(BaseTest, RangeTest)