Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 1 | #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 Psota | 9256f0a | 2020-05-08 19:07:28 +0200 | [diff] [blame] | 6 | #include <BaSyx/submodel/map_v2/common/ModelType.h> |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 7 | |
| 8 | #include <BaSyx/shared/object.h> |
| 9 | |
| 10 | namespace basyx { |
| 11 | namespace submodel { |
| 12 | namespace map { |
| 13 | |
| 14 | template<typename T> |
Constantin Ziesche | 02817f1 | 2020-08-04 21:40:43 +0200 | [diff] [blame^] | 15 | class Property |
| 16 | : public virtual api::IProperty |
| 17 | , public virtual SubmodelElement |
| 18 | , public virtual vab::ElementMap |
| 19 | , public ModelType<ModelTypes::Property> |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 20 | { |
| 21 | public: |
| 22 | Property(const std::string & idShort) |
jwendelil4 | 25bb0e9 | 2020-06-15 12:09:42 +0200 | [diff] [blame] | 23 | : SubmodelElement(idShort, ModelingKind::Instance) |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 24 | { |
| 25 | }; |
| 26 | |
Thomas Psota | 9256f0a | 2020-05-08 19:07:28 +0200 | [diff] [blame] | 27 | Property(const vab::ElementMap & elementMap) |
Constantin Ziesche | 02817f1 | 2020-08-04 21:40:43 +0200 | [diff] [blame^] | 28 | : vab::ElementMap(elementMap.getMap()) |
| 29 | , SubmodelElement(elementMap.getMap().getProperty(Referable::Path::IdShort).GetStringContent(), ModelingKind::Instance) |
Thomas Psota | 9256f0a | 2020-05-08 19:07:28 +0200 | [diff] [blame] | 30 | { |
| 31 | }; |
| 32 | |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 33 | 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 Psota | d214dc0 | 2020-04-30 15:35:04 +0200 | [diff] [blame] | 42 | return this->map.getProperty("value").template Get<T&>(); |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | virtual const std::string & getValueType() const override |
| 46 | { |
Thomas Psota | d214dc0 | 2020-04-30 15:35:04 +0200 | [diff] [blame] | 47 | return this->map.getProperty("valueType").template Get<std::string&>(); |
Thomas Psota | 0187a4e | 2020-04-30 15:12:54 +0200 | [diff] [blame] | 48 | } |
| 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 */ |