15#ifndef DD_DD_ACCESS_MAP_H_INCLUDED
16#define DD_DD_ACCESS_MAP_H_INCLUDED
24#include <unordered_map>
78template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
88 typedef typename container_type::iterator
iterator;
133 *
this = std::move(other);
143 _validation_info = std::move(other._validation_info);
144 _types = std::move(other._types);
146 for (
const auto& current: _types) {
154 _validator =
nullptr;
164 : _validator(nullptr), _validation_info(other._validation_info)
166 for (
auto current: other._types) {
167 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current.second);
169 (static_cast<map_subject_type*>(new_type.get()))
170 ->attachObserver(static_cast<observer_type*>(this));
171 _types[current.first] = new_type;
183 _validation_info = other._validation_info;
184 for (
auto current: other._types) {
185 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current.second);
189 _types[current.first] = new_type;
191 _validator =
nullptr;
202 std::shared_ptr<const DDL_TYPE_TO_ACCESS>
get(
const std::string& type_name)
const
204 auto it_find = _types.find(type_name);
205 if (it_find != _types.cend()) {
206 std::shared_ptr<const DDL_TYPE_TO_ACCESS> const_return = it_find->second;
220 const auto& it_find = _types.find(type_name);
221 if (it_find != _types.cend()) {
233 bool contains(
const DDL_TYPE_TO_ACCESS& type_to_find)
const
235 const auto& it_find = _types.find(type_to_find.getName());
236 if (it_find != _types.cend()) {
237 return type_to_find == *(it_find->second);
250 for (
const auto& other_content: other._types) {
251 if (!
contains(*(other_content.second))) {
265 std::shared_ptr<DDL_TYPE_TO_ACCESS>
create(
const DDL_TYPE_TO_ACCESS& type_to_add)
267 const auto type_found =
access(type_to_add.getName());
271 if (*type_found != type_to_add) {
273 _validation_info +
"::create",
274 {type_to_add.getName()},
275 "value with the given name already exists and differs in " +
282 const bool already_exists_other_type =
283 _validator && _validator->validateContains(type_to_add);
284 if (already_exists_other_type) {
286 _validation_info +
"::create",
287 {type_to_add.getName()},
288 std::string(
"value with the given name already exists with another type of ") +
292 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
296 _types[type_to_add.getName()] = new_type_value;
298 _validator->notifyChangedMapContent(
299 TypeAccessMapEventCode::map_item_added, *new_type_value, type_to_add.getName());
301 return new_type_value;
310 void add(
const DDL_TYPE_TO_ACCESS& type_to_add)
322 std::shared_ptr<DDL_TYPE_TO_ACCESS>
create(DDL_TYPE_TO_ACCESS&& type_to_add)
324 const auto type_found =
access(type_to_add.getName());
328 if (*type_found != type_to_add) {
330 _validation_info +
"::create",
331 {type_to_add.getName()},
332 "value with the given name already exists and differs in " +
340 const bool already_exists_other_type =
341 _validator && _validator->validateContains(type_to_add);
342 if (already_exists_other_type) {
344 _validation_info +
"::create",
345 {type_to_add.getName()},
346 std::string(
"value with the given name already exists with another type of ") +
350 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(std::move(type_to_add));
354 _types[new_type_value->getName()] = new_type_value;
356 _validator->notifyChangedMapContent(
357 TypeAccessMapEventCode::map_item_added, *new_type_value, new_type_value->getName());
359 return new_type_value;
368 void emplace(DDL_TYPE_TO_ACCESS&& type_to_add)
370 create(std::move(type_to_add));
378 void remove(
const std::string& type_name)
380 auto removed_value =
access(type_name);
383 _validator->notifyChangedMapContent(
384 TypeAccessMapEventCode::map_item_removing, *removed_value, type_name);
386 _types.erase(type_name);
390 _validator->notifyChangedMapContent(
391 TypeAccessMapEventCode::map_item_removed, *removed_value, type_name);
396 _validation_info +
"::remove", {type_name},
"value with the given name does not exist");
404 std::shared_ptr<DDL_TYPE_TO_ACCESS>
access(
const std::string& type_name)
406 auto it_find = _types.find(type_name);
407 if (it_find != _types.end()) {
408 return it_find->second;
419 return _types.size();
428 return _types.begin();
446 return _types.cbegin();
455 return _types.cend();
508 for (
auto& current: _types) {
526 const std::string& additional_info)
528 if (event_code == map_item_renamed) {
529 bool already_exists =
contains(subject_changed.getName());
530 if (_validator && !already_exists) {
534 already_exists = _validator->validateContains(subject_changed);
536 if (already_exists) {
538 _validation_info +
"::modelChanged",
539 {subject_changed.getName()},
540 "Renaming not possible. Value with the given name already exists");
544 iterator current = _types.find(additional_info);
546 auto value = current->second;
547 _types.erase(current);
548 _types[value->getName()] = value;
555 _validator->notifyChangedMapContent(event_code, subject_changed, additional_info);
571 destination._validator = validator;
575 std::string _validation_info;
585 using ::ddl::dd::utility::TypeAccessMap;
Exception helper class to collect information while parsing, adding DD Objects or other failed operat...
Definition ddl_error.h:31
The ModelObserver utility template.
Definition access_observer.h:34
T subject_type
Definition access_observer.h:39
TypeAccessMapEventCode event_code_type
Definition access_observer.h:37
Model Subject utility to define a Model Subject that notifies one or more observers.
Definition access_observer.h:68
ModelObserverUtility< T, TypeAccessMapEventCode > observer_type
Definition access_observer.h:75
Utility class for observable named items where the order is NOT important.
Definition access_map.h:79
const_iterator cend() const
const end iterator access
Definition access_map.h:453
const_iterator end() const
range based end operator for const access
Definition access_map.h:471
TypeAccessMapObserver< BaseUnit > parent_type
Definition access_map.h:92
iterator begin()
the range based begin iterator
Definition access_map.h:426
parent_type::event_code_type event_code_type
Definition access_map.h:98
std::shared_ptr< BaseUnit > value_type
Definition access_map.h:84
TypeAccessMap & operator=(const TypeAccessMap &other)
copies (deepcopy!) and overwrite the current content.
Definition access_map.h:180
std::shared_ptr< DDL_TYPE_TO_ACCESS > access(const std::string &type_name)
change access to an item
Definition access_map.h:404
container_type::const_iterator const_iterator
Definition access_map.h:90
bool contains(const DDL_TYPE_TO_ACCESS &type_to_find) const
determines if the item is in this map.
Definition access_map.h:233
friend TYPE_VALIDATOR_CLASS
Definition access_map.h:102
bool operator!=(const TypeAccessMap &other) const
non equality operator.
Definition access_map.h:498
std::shared_ptr< DDL_TYPE_TO_ACCESS > create(DDL_TYPE_TO_ACCESS &&type_to_add)
creates the given item in place
Definition access_map.h:322
const_iterator cbegin() const
const begin iterator access
Definition access_map.h:444
TypeAccessMap & operator=(TypeAccessMap &&other)
move assignment operator
Definition access_map.h:140
void modelChanged(event_code_type event_code, subject_type &subject_changed, const std::string &additional_info)
overrides the observers utility function.
Definition access_map.h:524
size_t getSize() const
Get the Size.
Definition access_map.h:417
TypeAccessMap(TYPE_VALIDATOR_CLASS *validator, const std::string &validation_info)
CTOR.
Definition access_map.h:116
bool operator==(const TypeAccessMap &other) const
equality operator.
Definition access_map.h:482
bool contains(const TypeAccessMap &other) const
determines if the other is a subset of this map
Definition access_map.h:248
parent_type::subject_type subject_type
Definition access_map.h:100
std::shared_ptr< DDL_TYPE_TO_ACCESS > create(const DDL_TYPE_TO_ACCESS &type_to_add)
creates the given item by copy
Definition access_map.h:265
container_type::iterator iterator
Definition access_map.h:88
virtual ~TypeAccessMap()
DTOR.
Definition access_map.h:124
void add(const DDL_TYPE_TO_ACCESS &type_to_add)
adds the given item
Definition access_map.h:310
std::unordered_map< std::string, value_type > container_type
Definition access_map.h:86
void remove(const std::string &type_name)
item to remove
Definition access_map.h:378
void clear()
clears the list and remove this as observer
Definition access_map.h:506
TypeAccessMap(TypeAccessMap &&other)
move CTOR
Definition access_map.h:131
TypeAccessMapSubject< BaseUnit > map_subject_type
Definition access_map.h:94
TypeAccessMap()=delete
no default CTOR!
BaseUnit access_type
Definition access_map.h:82
map_subject_type::observer_type observer_type
Definition access_map.h:96
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplaces the given item
Definition access_map.h:368
bool contains(const std::string &type_name) const
determines is the type name exists in this map
Definition access_map.h:218
iterator end()
the range based end iterator
Definition access_map.h:435
std::shared_ptr< const DDL_TYPE_TO_ACCESS > get(const std::string &type_name) const
get the item with the given name type_name
Definition access_map.h:202
TypeAccessMap(const TypeAccessMap &other)
copies (deepcopy!) CTOR
Definition access_map.h:163
const_iterator begin() const
range based begin operator for const access
Definition access_map.h:462
definition of the old compatibility utility namespace
Definition datamodel_keyvalue.h:160
ModelObserverUtility< T, TypeAccessMapEventCode > TypeAccessMapObserver
helper template to observe map content.
Definition access_map.h:70
ModelSubjectUtility< T, TypeAccessMapEventCode > TypeAccessMapSubject
helper template to observe map content.
Definition access_map.h:61
TypeAccessMapEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
Definition access_map.h:37
definition of the dd namespace
Definition datamodel_base.h:26
@ validation_info
Validation Info.
Definition dd_infomodel_type.h:32
definition of the utility namespace
Definition ddl.h:66
definition of the ddl namespace
Definition codec.h:21
static constexpr auto _other_types
validation other types
Definition access_validation.h:41
static std::string getDifference(const T &, const T &)
validation difference message
Definition access_validation.h:45