blob: debb5008e883939945fcdc043cf689f0ad13f7c2 [file] [log] [blame]
Thomas Psota0187a4e2020-04-30 15:12:54 +02001#ifndef BASYX_SUBMODEL_MAP_V2_SUBMODELELEMENT_PROPERTY_PROPERTY_H
2#define BASYX_SUBMODEL_MAP_V2_SUBMODELELEMENT_PROPERTY_PROPERTY_H
3
4#include <BaSyx/submodel/api_v2/submodelelement/property/IProperty.h>
5#include <BaSyx/submodel/map_v2/submodelelement/SubmodelElement.h>
Thomas Psota9256f0a2020-05-08 19:07:28 +02006#include <BaSyx/submodel/map_v2/common/ModelType.h>
Thomas Psota0187a4e2020-04-30 15:12:54 +02007
8#include <BaSyx/shared/object.h>
9
10namespace basyx {
11namespace submodel {
12namespace map {
13
14template<typename T>
Constantin Ziesche02817f12020-08-04 21:40:43 +020015class Property
16 : public virtual api::IProperty
17 , public virtual SubmodelElement
18 , public virtual vab::ElementMap
19 , public ModelType<ModelTypes::Property>
Thomas Psota0187a4e2020-04-30 15:12:54 +020020{
21public:
22 Property(const std::string & idShort)
jwendelil425bb0e92020-06-15 12:09:42 +020023 : SubmodelElement(idShort, ModelingKind::Instance)
Thomas Psota0187a4e2020-04-30 15:12:54 +020024 {
25 };
26
Thomas Psota9256f0a2020-05-08 19:07:28 +020027 Property(const vab::ElementMap & elementMap)
Constantin Ziesche02817f12020-08-04 21:40:43 +020028 : vab::ElementMap(elementMap.getMap())
29 , SubmodelElement(elementMap.getMap().getProperty(Referable::Path::IdShort).GetStringContent(), ModelingKind::Instance)
Thomas Psota9256f0a2020-05-08 19:07:28 +020030 {
31 };
32
Thomas Psota0187a4e2020-04-30 15:12:54 +020033 virtual ~Property() = default;
34
35 void setValue(const T & t)
36 {
37 this->map.insertKey("value", t);
38 }
39
40 const T & getValue() const
41 {
Thomas Psotad214dc02020-04-30 15:35:04 +020042 return this->map.getProperty("value").template Get<T&>();
Thomas Psota0187a4e2020-04-30 15:12:54 +020043 }
44
45 virtual const std::string & getValueType() const override
46 {
Thomas Psotad214dc02020-04-30 15:35:04 +020047 return this->map.getProperty("valueType").template Get<std::string&>();
Thomas Psota0187a4e2020-04-30 15:12:54 +020048 }
49
50 virtual void setValueType(const std::string & valueType) override
51 {
52 this->map.insertKey("valueType", valueType);
53 }
54
55 virtual void setObject(basyx::object & object) override
56 {
57 if (object.InstanceOf<T>())
58 this->map.insertKey("value", object);
59 }
60
61 virtual basyx::object getObject() override
62 {
63 return this->map.getProperty("value");
64 }
65
66 virtual const Reference * const getValueId() const override
67 {
68 return nullptr;
69 }
70
71 virtual void setValueId(const api::IReference & valueId) override
72 {
73 }
74};
75
76}
77}
78}
79
80#endif /* BASYX_SUBMODEL_MAP_V2_SUBMODELELEMENT_PROPERTY_PROPERTY_H */