15#ifndef DDL_UTILITY_ACCESS_LIST_H_INCLUDED
16#define DDL_UTILITY_ACCESS_LIST_H_INCLUDED
25#include <unordered_map>
31 template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
54 list_subitem_inserted,
57 list_subitem_removing,
86template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
98 typedef typename container_type::iterator
iterator;
143 *
this = std::move(other);
153 _validation_info = std::move(other._validation_info);
154 _types = std::move(other._types);
156 for (
const auto& current: _types) {
173 : _validator(nullptr), _validation_info(other._validation_info)
175 for (
auto current: other._types) {
176 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current);
178 (static_cast<map_subject_type*>(new_type.get()))
179 ->attachObserver(static_cast<observer_type*>(this));
180 _types.push_back(new_type);
192 _validation_info = other._validation_info;
193 for (
auto current: other._types) {
194 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current);
198 _types.push_back(new_type);
200 _validator =
nullptr;
211 std::shared_ptr<const DDL_TYPE_TO_ACCESS>
get(std::string_view type_name)
const
214 const auto named_items = getNamedContainer();
215 const auto found = named_items->find(type_name);
216 if (found != named_items->end()) {
217 return found->second;
221 for (
auto& current: _types) {
222 if (current->getName() == type_name) {
223 std::shared_ptr<const DDL_TYPE_TO_ACCESS> const_return = current;
240 size_t current_pos = 0;
241 for (
auto& current: _types) {
242 if (current->getName() == type_name) {
261 const auto named_items = getNamedContainer();
262 const auto found = named_items->find(type_name);
263 if (found != named_items->end()) {
268 for (
auto& current: _types) {
269 if (current->getName() == type_name) {
284 bool contains(
const DDL_TYPE_TO_ACCESS& type_to_find)
const
286 const auto value_found =
get(type_to_find.getName());
288 return type_to_find == *value_found;
302 for (
const auto& other_content: other._types) {
317 std::shared_ptr<DDL_TYPE_TO_ACCESS>
create(
const DDL_TYPE_TO_ACCESS& type_to_add)
319 if (checkExistenceAndEquality(type_to_add)) {
322 return access(type_to_add.getName());
325 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
329 _types.push_back(new_type_value);
331 const auto named_items = getNamedContainer();
332 (*named_items)[new_type_value->getName()] = new_type_value;
335 _validator->notifyChangedListContent(
336 TypeAccessListEventCode::list_item_added, *new_type_value, type_to_add.getName());
338 return new_type_value;
347 void add(
const DDL_TYPE_TO_ACCESS& type_to_add)
360 void insert(
const size_t pos_idx,
const DDL_TYPE_TO_ACCESS& type_to_add)
364 _validation_info +
"::insert", {type_to_add.getName()},
"given pos_idx is invalid");
366 else if (pos_idx ==
getSize()) {
370 if (checkExistenceAndEquality(type_to_add)) {
375 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
381 std::advance(cit, pos_idx);
382 _types.insert(cit, new_type_value);
384 const auto named_items = getNamedContainer();
385 (*named_items)[new_type_value->getName()] = new_type_value;
388 _validator->notifyChangedListContent(TypeAccessListEventCode::list_item_inserted,
390 type_to_add.getName());
402 std::shared_ptr<DDL_TYPE_TO_ACCESS>
create(DDL_TYPE_TO_ACCESS&& type_to_add)
404 if (checkExistenceAndEquality(type_to_add)) {
407 return access(type_to_add.getName());
409 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(std::move(type_to_add));
413 _types.push_back(new_type_value);
415 const auto named_items = getNamedContainer();
416 (*named_items)[new_type_value->getName()] = new_type_value;
419 _validator->notifyChangedListContent(TypeAccessListEventCode::list_item_added,
421 new_type_value->getName());
423 return new_type_value;
432 void emplace(DDL_TYPE_TO_ACCESS&& type_to_add)
434 create(std::move(type_to_add));
442 void remove(
const std::string& type_name)
445 typename container_type::iterator current_it;
446 for (current_it = _types.begin(); current_it != _types.end(); ++current_it) {
447 if ((*current_it)->getName() == type_name) {
448 removed_value = (*current_it);
454 _validator->notifyChangedListContent(
455 TypeAccessListEventCode::list_item_removing, *removed_value, type_name);
457 _types.erase(current_it);
459 const auto named_items = getNamedContainer();
460 named_items->erase(type_name);
465 _validator->notifyChangedListContent(
466 TypeAccessListEventCode::list_item_removed, *removed_value, type_name);
471 _validation_info +
"::remove", {type_name},
"value with the given name does not exist");
480 std::shared_ptr<DDL_TYPE_TO_ACCESS>
access(
const std::string& type_name)
483 const auto named_items = getNamedContainer();
484 auto value_found = named_items->find(type_name);
485 if (value_found != named_items->end()) {
486 return value_found->second;
490 for (
const auto& current: _types) {
491 if (current->getName() == type_name) {
506 return _types.size();
516 return _types.begin();
536 return _types.cbegin();
546 return _types.cend();
579 begin(),
end(), other.
begin(), other.
end(), [](
const auto& local,
const auto& other) {
580 return *(local) == *(other);
602 for (
auto& current: _types) {
608 const auto named_items = getNamedContainer();
609 named_items->clear();
620 if (!_types.empty()) {
621 auto last_element = _types[_types.size() - 1];
623 _validator->notifyChangedListContent(TypeAccessListEventCode::list_item_removing,
625 last_element->getName());
632 const auto named_items = getNamedContainer();
633 named_items->erase(last_element->getName());
637 _validator->notifyChangedListContent(TypeAccessListEventCode::list_item_popped,
639 last_element->getName());
643 throw ddl::dd::Error(_validation_info +
"::popBack", {},
"list is empty");
657 const std::string& additional_info)
659 if (event_code == list_item_renaming) {
662 if (countContains(additional_info) != 0) {
664 _validation_info +
"::modelChanged",
666 "Renaming not possible. Value with the given name already exists");
670 const auto named_items = getNamedContainer();
672 named_items->erase(subject_changed.getName());
676 else if (event_code == list_item_renamed) {
678 const auto named_items = getNamedContainer();
679 for (
auto& current: _types) {
680 if (current->getName() == subject_changed.getName()) {
681 named_items->emplace(current->getName(), current);
689 _validator->notifyChangedListContent(event_code, subject_changed, additional_info);
695 friend class ::ddl::utility::TypeAccessList<DDL_TYPE_TO_ACCESS,
708 destination.setValidator(validator);
717 size_t countContains(
const std::string& type_name)
const
719 return std::count_if(_types.begin(), _types.end(), [type_name](
const value_type& value) {
720 return value->getName() == type_name;
724 bool checkExistenceAndEquality(
const DDL_TYPE_TO_ACCESS& type_to_add)
727 bool already_exists =
false;
729 already_exists = _validator->validateContains(type_to_add);
732 already_exists =
contains(type_to_add.getName());
734 if (already_exists) {
736 const auto type_found =
get(type_to_add.getName());
740 if (*type_found == type_to_add) {
744 throw ddl::dd::Error(_validation_info +
"::create",
745 {type_to_add.getName()},
746 "value with the given name already exists and differs in " +
748 *type_found, type_to_add));
751 throw ddl::dd::Error(
752 _validation_info +
"::create",
753 {type_to_add.getName()},
754 std::string(
"value with the given name already exists with another type of ") +
763 _validator = validator;
765 auto named_items = getNamedContainer();
766 named_items->clear();
767 for (
auto& value: _types) {
768 (*named_items)[value->getName()] = value;
777 return _validator->getNamedItemViewList();
784 return _validator->getNamedItemViewList();
789 std::string _validation_info;
825template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
829 ::ddl::utility::TypeAccessList<DDL_TYPE_TO_ACCESS, TYPE_VALIDATOR_CLASS>> {
852 :
base_type(this, validation_info), _validator(validator)
860 base_type::_validator = {};
880 other.deepCopy(*
this,
this);
881 for (
auto& current: *
this) {
882 _named_types[current->getName()] = current;
893 other.deepCopy(*
this,
this);
894 for (
auto& current: *
this) {
895 _named_types[current->getName()] = current;
904 return _validator->validateContains(subject);
911 const std::string& additional_info)
914 return _validator->notifyChangedListContent(code, subject, additional_info);
920 return &_named_types;
925 return &_named_types;
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
TypeAccessListEventCode 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, TypeAccessListEventCode > observer_type
Definition access_observer.h:75
Utility class for observable named items where the order is important.
Definition access_list.h:87
std::shared_ptr< Struct > value_type
Definition access_list.h:92
iterator end()
the range based end iterator
Definition access_list.h:524
const_iterator end() const
range based end operator for const access
Definition access_list.h:564
parent_type::event_code_type event_code_type
Definition access_list.h:108
bool operator!=(const TypeAccessList &other) const
non equality operator.
Definition access_list.h:591
Struct access_type
Definition access_list.h:90
void add(const DDL_TYPE_TO_ACCESS &type_to_add)
creates the given item by copy
Definition access_list.h:347
TypeAccessListSubject< Struct > map_subject_type
Definition access_list.h:104
size_t getSize() const
Get the Size.
Definition access_list.h:504
TypeAccessList()=delete
no default CTOR!
TypeAccessList(TYPE_VALIDATOR_CLASS *validator, const std::string &validation_info)
CTOR.
Definition access_list.h:126
bool contains(const TypeAccessList &other) const
determines if the other is a subset of this list
Definition access_list.h:300
TypeAccessListObserver< Struct > parent_type
Definition access_list.h:102
std::shared_ptr< DDL_TYPE_TO_ACCESS > create(DDL_TYPE_TO_ACCESS &&type_to_add)
create the given item by emplace
Definition access_list.h:402
map_subject_type::observer_type observer_type
Definition access_list.h:106
bool contains(const DDL_TYPE_TO_ACCESS &type_to_find) const
determines if the item is in this list.
Definition access_list.h:284
std::shared_ptr< DDL_TYPE_TO_ACCESS > access(const std::string &type_name)
change access to an item
Definition access_list.h:480
std::shared_ptr< const DDL_TYPE_TO_ACCESS > get(std::string_view type_name) const
get the item with the given name type_name
Definition access_list.h:211
void clear()
clears the list and remove this as observer
Definition access_list.h:600
bool contains(const std::string &type_name) const
determines is the type name exists in this list
Definition access_list.h:258
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplace the given item
Definition access_list.h:432
container_type::iterator iterator
Definition access_list.h:98
void popBack()
removes the last element if exists.
Definition access_list.h:618
std::unordered_map< std::string_view, value_type > container_named_type
Definition access_list.h:96
const_iterator begin() const
range based begin operator for const access
Definition access_list.h:554
const_iterator cbegin() const
const begin iterator access
Definition access_list.h:534
const_iterator cend() const
const end iterator access
Definition access_list.h:544
parent_type::subject_type subject_type
Definition access_list.h:110
bool operator==(const TypeAccessList &other) const
equality operator.
Definition access_list.h:576
void insert(const size_t pos_idx, const DDL_TYPE_TO_ACCESS &type_to_add)
inserts the given item at the given pos
Definition access_list.h:360
friend TYPE_VALIDATOR_CLASS
Definition access_list.h:112
virtual ~TypeAccessList()
DTOR.
Definition access_list.h:134
Optional< size_t > getPosOf(const std::string &type_name) const
Get the Pos Of the item with the name type_name.
Definition access_list.h:238
void remove(const std::string &type_name)
item to remove
Definition access_list.h:442
TypeAccessList(TypeAccessList &&other)
move CTOR
Definition access_list.h:141
TypeAccessList & operator=(TypeAccessList &&other)
move assignment operator
Definition access_list.h:150
std::shared_ptr< DDL_TYPE_TO_ACCESS > create(const DDL_TYPE_TO_ACCESS &type_to_add)
creates the given item by copy
Definition access_list.h:317
TypeAccessList(const TypeAccessList &other)
copies (deepcopy!) CTOR
Definition access_list.h:172
std::vector< value_type > container_type
Definition access_list.h:94
iterator begin()
the range based begin iterator
Definition access_list.h:514
container_type::const_iterator const_iterator
Definition access_list.h:100
TypeAccessList & operator=(const TypeAccessList &other)
copies (deepcopy!) and overwrite the current content.
Definition access_list.h:189
void modelChanged(event_code_type event_code, subject_type &subject_changed, const std::string &additional_info)
overrides the observers utility function.
Definition access_list.h:655
Bug fix class for ddl::dd::utility::TypeAccessList to get rid of providing getNamedItemList in valida...
Definition access_list.h:829
TypeAccessList(const TypeAccessList &other)
copies (deepcopy!) CTOR
Definition access_list.h:878
TypeAccessList()=delete
no default CTOR!
TypeAccessList(TypeAccessList &&other)=default
move CTOR
::ddl::dd::utility::TypeAccessList< ParameterValue, ::ddl::utility::TypeAccessList< ParameterValue, Assignment > > base_type
Definition access_list.h:834
TypeAccessList(TYPE_VALIDATOR_CLASS *validator, const std::string &validation_info)
CTOR.
Definition access_list.h:851
virtual ~TypeAccessList()
DTOR.
Definition access_list.h:858
TypeAccessList & operator=(TypeAccessList &&other)=default
move assignment operator
TypeAccessList & operator=(const TypeAccessList &other)
copies (deepcopy!) and overwrite the current content.
Definition access_list.h:891
definition of the old compatibility utility namespace
Definition datamodel_keyvalue.h:160
ModelObserverUtility< T, TypeAccessListEventCode > TypeAccessListObserver
helper template to observe list content.
Definition access_list.h:78
ModelSubjectUtility< T, TypeAccessListEventCode > TypeAccessListSubject
helper template to observe list content.
Definition access_list.h:69
TypeAccessListEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
Definition access_list.h:43
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
ModelSubjectUtility< T, TypeAccessListEventCode > TypeAccessListSubject
helper template to observe list content.
Definition access_list.h:808
ModelObserverUtility< T, TypeAccessListEventCode > TypeAccessListObserver
helper template to observe list content.
Definition access_list.h:817
definition of the ddl namespace
Definition codec.h:21
An optional template as long as the std::optional is not available here.
Definition access_optional.h:31
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