Thomas Psota | b49d8df | 2019-11-27 15:55:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ElementMap.h |
| 3 | * |
| 4 | * Author: wendel |
| 5 | */ |
| 6 | |
| 7 | #ifndef BASYX_AAS_METAMODEL_ELEMENTMAP_H_ |
| 8 | #define BASYX_AAS_METAMODEL_ELEMENTMAP_H_ |
| 9 | |
| 10 | #include "basyx/object.h" |
| 11 | |
| 12 | namespace basyx { |
| 13 | namespace vab { |
| 14 | |
| 15 | |
| 16 | class ElementMap |
| 17 | { |
| 18 | protected: |
| 19 | mutable basyx::object map; |
Johannes Wendel | 10dc552 | 2019-12-04 11:20:14 +0100 | [diff] [blame^] | 20 | |
| 21 | protected: |
| 22 | void insertMapElement(const std::string & key, const ElementMap & element); |
| 23 | |
Thomas Psota | b49d8df | 2019-11-27 15:55:41 +0100 | [diff] [blame] | 24 | public: |
| 25 | ElementMap(); |
| 26 | ElementMap(basyx::object object); |
Johannes Wendel | 10dc552 | 2019-12-04 11:20:14 +0100 | [diff] [blame^] | 27 | ElementMap(const ElementMap & other); |
Thomas Psota | b49d8df | 2019-11-27 15:55:41 +0100 | [diff] [blame] | 28 | virtual ~ElementMap() = default; |
| 29 | |
| 30 | basyx::object getMap() const; |
Johannes Wendel | 10dc552 | 2019-12-04 11:20:14 +0100 | [diff] [blame^] | 31 | |
Thomas Psota | b49d8df | 2019-11-27 15:55:41 +0100 | [diff] [blame] | 32 | public: |
| 33 | template<typename AbstractType, typename SpecificType> |
| 34 | static basyx::specificCollection_t<AbstractType> make_specific_collection(basyx::object::object_list_t & obj_list) |
| 35 | { |
| 36 | basyx::specificCollection_t<AbstractType> list; |
| 37 | |
| 38 | for (auto & obj : obj_list) |
| 39 | list.emplace_back(std::make_shared<SpecificType>(obj)); |
| 40 | |
| 41 | return list; |
| 42 | }; |
| 43 | |
| 44 | template<typename AbstractType, typename SpecificType> |
| 45 | static basyx::object make_object_list(const basyx::specificCollection_t<AbstractType> & abst_list) |
| 46 | { |
| 47 | auto list = basyx::object::make_list<basyx::object>(); |
| 48 | |
| 49 | for (auto & abstract : abst_list) |
| 50 | list.insert(SpecificType{ *abstract }.getMap()); |
| 51 | |
| 52 | return list; |
| 53 | }; |
| 54 | }; |
| 55 | |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | #endif |