Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identifier for V3 metamodel #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed src/libaas/basyx/asset/asset.cpp
Empty file.
66 changes: 0 additions & 66 deletions src/libaas/basyx/asset/asset.h

This file was deleted.

29 changes: 10 additions & 19 deletions src/libaas/basyx/asset/assetinformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <basyx/reference.h>
#include <basyx/identifiable.h>
#include <basyx/identifierkeyvaluepair.h>
#include <basyx/asset/asset.h>

#include <basyx/enums/AssetKind.h>

Expand All @@ -17,10 +16,9 @@ class AssetInformation
{
private:
AssetKind assetKind;
util::optional<Asset> asset;
util::optional<Reference> globalAssetIdRef;
util::optional<Identifier> globalAssetId;
std::vector<IdentifierKeyValuePair> specificAssetId;
std::vector<Reference> billOfMaterial;
util::optional<Identifier> assetType;
util::optional<File> defaultThumbnail;
public:
AssetInformation(AssetKind assetkind) : assetKind(assetkind) {};
Expand All @@ -34,25 +32,18 @@ class AssetInformation
AssetKind getAssetKind() const { return assetKind; };
void setAssetKind(AssetKind kind) { this->assetKind = kind; };

void setAsset(Asset asset) {
//this->globalAssetIdRef = asset;
this->asset.emplace(std::move(asset));
};
const util::optional<Asset> & getAsset() const { return asset; };

const util::optional<Reference> & getGlobalAssetId() const { return this->globalAssetIdRef; };
void setGlobalAssetId(Reference globalAssetId) { this->globalAssetIdRef.emplace(std::move(globalAssetId)); };

const util::optional<File> & getDefaultThumbnail() const { return defaultThumbnail; };
void setDefaultThumbnail(File file) { this->defaultThumbnail.emplace(std::move(file)); };

void addBillOfMaterial(Reference bom) { this->billOfMaterial.emplace_back(std::move(bom)); };
const std::vector<Reference> & getBillOfMaterials() const { return this->billOfMaterial; };
std::vector<Reference> & getBillOfMaterials() { return this->billOfMaterial; };
const util::optional<Identifier> & getGlobalAssetId() const { return this->globalAssetId; };
void setGlobalAssetId(Identifier globalAssetId) { this->globalAssetId.emplace(std::move(globalAssetId)); };

void addSpecificAssetId(IdentifierKeyValuePair specificAssetId) { this->specificAssetId.emplace_back(std::move(specificAssetId)); };
const std::vector<IdentifierKeyValuePair> & getSpecificAssetIds() const { return this->specificAssetId; };
std::vector<IdentifierKeyValuePair> & getSpecificAssetIds() { return this->specificAssetId; };

const util::optional<Identifier> & getAssetType() const { return this->assetType; };
void setAssetType(Identifier assetType) { this->assetType.emplace(std::move(assetType)); };

const util::optional<File> & getDefaultThumbnail() const { return defaultThumbnail; };
void setDefaultThumbnail(File file) { this->defaultThumbnail.emplace(std::move(file)); };
};


Expand Down
1 change: 1 addition & 0 deletions src/libaas/basyx/enums/AssetKind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static const std::array<enum_pair_t, 3> string_to_enum =
{
std::make_pair("Type", AssetKind::Type),
std::make_pair("Instance", AssetKind::Instance),
std::make_pair("NotApplicable", AssetKind::NotApplicable),
};

AssetKind AssetKind_::from_string(util::string_view name)
Expand Down
1 change: 1 addition & 0 deletions src/libaas/basyx/enums/AssetKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace basyx {
enum class AssetKind {
Type,
Instance,
NotApplicable,
};

class AssetKind_
Expand Down
6 changes: 0 additions & 6 deletions src/libaas/basyx/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <basyx/base/elementcontainer.h>
#include <basyx/base/elementvector.h>
#include <basyx/assetadministrationshell.h>
#include <basyx/asset/asset.h>

namespace basyx
{
Expand All @@ -17,7 +16,6 @@ class Environment
{
private:
ElementContainer<AssetAdministrationShell> aass;
ElementVector<Asset> assets;
public:
Environment() = default;
public:
Expand All @@ -30,10 +28,6 @@ class Environment
const ElementContainer<AssetAdministrationShell> & getAssetAdministrationShells() const { return this->aass; };
ElementContainer<AssetAdministrationShell> & getAssetAdministrationShells() { return this->aass; };
void setAssetAdministrationShells(ElementContainer<AssetAdministrationShell> aass) { this->aass = aass; };

const ElementVector<Asset> & getAssets() const { return this->assets; };
ElementVector<Asset> & getAssets() { return this->assets; };
void setAssets(ElementVector<Asset> assets) { this->assets = std::move(assets); };
};

};
Expand Down
35 changes: 19 additions & 16 deletions src/libaas/basyx/identifier.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#include "identifier.h"

namespace basyx
{
#include <basyx/identifier.h>

Identifier::Identifier(KeyType idType, util::string_view id)
: idType(idType)
, id(id.to_string())
{};
namespace basyx {

Identifier::Identifier(util::string_view id)
: idType(KeyType_::from_id(id))
, id(id.to_string())
{};
Identifier &Identifier::operator=(const Identifier &id) noexcept {
std::string::operator=(id);
return *this;
}

Identifier &Identifier::operator=(const basyx::util::string_view& id) noexcept {
std::string::operator=(id.to_string());
return *this;
}

bool Identifier::operator==(const Identifier & other) const
{
return (this->getIdType() == other.getIdType()) && (this->getId() == other.getId());
};
Identifier &Identifier::operator=(const std::string& id) noexcept {
std::string::operator=(id);
return *this;
}

std::string Identifier::getId() const {
return static_cast<std::string>(*this);
}

};
};
47 changes: 17 additions & 30 deletions src/libaas/basyx/identifier.h
Original file line number Diff line number Diff line change
@@ -1,42 +1,29 @@
#pragma once

#include <basyx/util/optional/optional.hpp>

#include <basyx/langstringset.h>

#include <basyx/key.h>
#ifndef IDENTIFIER_H
#define IDENTIFIER_H

#include <string>
#include <basyx/util/string_view/string_view.hpp>

namespace basyx
{

class Identifier
{
private:
KeyType idType;
std::string id;
private:
class Identifier: public std::string {
public:
Identifier(KeyType idType, util::string_view id);
Identifier(util::string_view id);
Identifier() = default;
Identifier(const Identifier&) = default;
Identifier(const basyx::util::string_view &v) {
std::string::operator=(v.to_string());
}
Identifier(Identifier&&) = default;

Identifier(const Identifier&) = default;
Identifier(Identifier&&) = default;
Identifier& operator=(const Identifier& id) noexcept;
Identifier& operator=(const basyx::util::string_view& id) noexcept;
Identifier& operator=(const std::string& id) noexcept;
//Identifier& operator=(Identifier &) noexcept = default;

Identifier & operator=(const Identifier&) = default;
Identifier & operator=(Identifier&&) = default;
std::string getId() const;

~Identifier() = default;
public:
const std::string & getId() const { return id; };
KeyType getIdType() const { return idType; };
public:
bool operator==(const Identifier & other) const;
public:
static Identifier Custom(util::string_view id) { return Identifier(KeyType::Custom, id); }
static Identifier IRDI(util::string_view id) { return Identifier(KeyType::IRDI, id); }
static Identifier IRI(util::string_view id) { return Identifier(KeyType::IRI, id); }
~Identifier() = default;
};

};
#endif /* IDENTIFIER_H */
14 changes: 3 additions & 11 deletions src/libaas/basyx/serialization/json/deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ namespace basyx::serialization::json
return langstrings;
};

Identifier deserialize_identifier(const json_t & json)
{
std::string identifier = json["id"];
std::string idType = json["idType"];

return Identifier{KeyType_::from_string(idType), identifier};
};

template<typename Obj>
void deserialize_referable(const json_t & json, Obj & obj)
{
Expand Down Expand Up @@ -154,7 +146,7 @@ namespace basyx::serialization::json
Submodel deserialize_submodel(const json_t & json)
{
std::string idShort = json["idShort"];
auto identifier = deserialize_identifier(json["identification"]);
Identifier identifier = json["identification"];

Submodel submodel(std::move(idShort), std::move(identifier));

Expand All @@ -170,9 +162,9 @@ namespace basyx::serialization::json
AssetAdministrationShell deserialize_aas(const json_t & json)
{
std::string idShort = json["idShort"];
auto identifier = deserialize_identifier(json["identification"]);
Identifier identifier = json["identification"];

AssetAdministrationShell aas(idShort, identifier, basyx::AssetInformation(AssetKind::Instance));
AssetAdministrationShell aas(idShort, identifier, basyx::AssetInformation(AssetKind::Instance));

deserialize_referable(json, aas);

Expand Down
13 changes: 1 addition & 12 deletions src/libaas/basyx/serialization/json/serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ void serialize_helper(json_t & json, const File & file)

void serialize_helper(json_t & json, const Identifier & identifier)
{
json["id"] = identifier.getId();
json["idType"] = KeyType_::to_string( identifier.getIdType() );
json = identifier.getId();
};

void serialize_helper(json_t & json, const Identifiable & identifiable)
Expand Down Expand Up @@ -279,11 +278,6 @@ void serialize_helper(json_t & json, const Submodel & submodel)
};


void serialize_helper(json_t & json, const Asset & asset)
{
serialize_helper_h<Identifiable>(json, asset);
}

void serialize_helper(json_t & json, const AssetInformation & assetInf)
{
json["assetKind"] = AssetKind_::to_string(assetInf.getAssetKind());
Expand All @@ -296,11 +290,6 @@ void serialize_helper(json_t & json, const AssetInformation & assetInf)
specificAssetIds.emplace_back(serialize(assetId));
json["specificAssetIds"] = specificAssetIds;

auto billOfMaterial = json_t::array();
for (const auto & bom : assetInf.getBillOfMaterials())
billOfMaterial.emplace_back(serialize(bom));
json["billOfMaterial"] = billOfMaterial;

if(assetInf.getDefaultThumbnail())
json["thumbnail"] = serialize(*assetInf.getDefaultThumbnail());
}
Expand Down
2 changes: 0 additions & 2 deletions src/libaas/basyx/serialization/json/serializer_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace basyx
class Submodel;
class File;
class Blob;
class Asset;
class AssetInformation;

template<typename T>
Expand All @@ -49,7 +48,6 @@ namespace basyx::serialization::json
void serialize_helper(json_t & json, const HasSemantics &);
void serialize_helper(json_t & json, const HasKind &);
void serialize_helper(json_t & json, const modeltype_base &);
void serialize_helper(json_t & json, const Asset &);
void serialize_helper(json_t & json, const AssetInformation &);
void serialize_helper(json_t & json, const Identifier &);
void serialize_helper(json_t & json, const IdentifierKeyValuePair &);
Expand Down
Loading
Loading