21#ifndef DD__UTILITY_ACCESS_VECTOR_H_INCLUDED
22#define DD__UTILITY_ACCESS_VECTOR_H_INCLUDED
45 vector_subitem_removed,
46 vector_subitem_changed,
48 vector_subitem_popped,
50 vector_subitem_inserted,
51 vector_subitem_renamed,
53 vector_subitem_removing,
55 vector_subitem_renaming
82template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
92 typedef typename container_type::iterator
iterator;
121 : _validator(validator), _validation_info(validation_info)
137 *
this = std::move(other);
147 _validation_info = std::move(other._validation_info);
148 _types = std::move(other._types);
150 for (
const auto& current: _types) {
167 : _validator(nullptr), _validation_info(other._validation_info)
169 for (
auto current: other._types) {
170 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current);
172 (static_cast<observer_subject_type*>(new_type.get()))
173 ->attachObserver(static_cast<observer_type*>(this));
174 _types.push_back(new_type);
186 _validation_info = other._validation_info;
187 for (
auto current: other._types) {
188 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current);
192 _types.push_back(new_type);
204 std::shared_ptr<const DDL_TYPE_TO_ACCESS>
get(
size_t index)
const
206 if (_types.size() > index) {
207 std::shared_ptr<const DDL_TYPE_TO_ACCESS> const_return = _types[index];
219 void add(
const DDL_TYPE_TO_ACCESS& type_to_add)
221 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
225 _types.push_back(new_type_value);
228 _validator->notifyChangedVectorContent(TypeAccessVectorEventCode::vector_item_added,
230 std::to_string(_types.size() - 1));
242 void insert(
const size_t pos_idx,
const DDL_TYPE_TO_ACCESS& type_to_add)
246 _validation_info +
"::insert", {type_to_add.getName()},
"given pos_idx is invalid");
248 else if (pos_idx ==
getSize()) {
252 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
258 std::advance(cit, pos_idx);
259 _types.insert(cit, new_type_value);
262 _validator->notifyChangedVectorContent(
263 TypeAccessVectorEventCode::vector_item_inserted,
265 std::to_string(pos_idx));
276 void emplace(DDL_TYPE_TO_ACCESS&& type_to_add)
278 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(std::move(type_to_add));
282 _types.push_back(new_type_value);
284 _validator->notifyChangedVectorContent(TypeAccessVectorEventCode::vector_item_added,
286 std::to_string(_types.size() - 1));
297 if (_types.size() > index) {
299 typename container_type::iterator current_it =
begin();
300 std::advance(current_it, index);
301 removed_value = *current_it;
304 _validator->notifyChangedVectorContent(
305 TypeAccessVectorEventCode::vector_item_removing,
307 std::to_string(index));
309 _types.erase(current_it);
313 _validator->notifyChangedVectorContent(
314 TypeAccessVectorEventCode::vector_item_removed,
316 std::to_string(index));
322 {std::to_string(index)},
323 "value with the index does not exist");
332 std::shared_ptr<DDL_TYPE_TO_ACCESS>
access(
size_t index)
334 if (index < _types.size()) {
335 return _types[index];
347 return _types.size();
357 return _types.begin();
377 return _types.cbegin();
387 return _types.cend();
420 begin(),
end(), other.
begin(), other.
end(), [](
const auto& local,
const auto& other) {
421 return *(local) == *(other);
443 for (
auto& current: _types) {
457 if (!_types.empty()) {
458 auto last_element = _types[_types.size() - 1];
464 _validator->notifyChangedVectorContent(
465 TypeAccessVectorEventCode::vector_item_popped, *last_element,
"-1");
469 throw ddl::dd::Error(_validation_info +
"::popBack", {},
"vector is empty");
483 const std::string& additional_info)
487 _validator->notifyChangedVectorContent(event_code, subject_changed, additional_info);
503 destination.setValidator(validator);
508 _validator = validator;
513 std::string _validation_info;
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
Model Subject utility to define a Model Subject that notifies one or more observers.
Definition access_observer.h:68
ModelObserverUtility< MODEL_SUBJECT_T, EVENT_CODE_T > observer_type
local definition of the observer type to notify
Definition access_observer.h:75
Utility class for observable named items where the order is important.
Definition access_vector.h:83
const_iterator cend() const
const end iterator access
Definition access_vector.h:385
size_t getSize() const
Get the Size.
Definition access_vector.h:345
TypeAccessVectorSubject< Trigger > observer_subject_type
Definition access_vector.h:98
void popBack()
removes the last element if exists.
Definition access_vector.h:455
parent_type::subject_type subject_type
Definition access_vector.h:104
TypeAccessVector & operator=(TypeAccessVector &&other)
move assignment operator
Definition access_vector.h:144
iterator begin()
the range based begin iterator
Definition access_vector.h:355
parent_type::event_code_type event_code_type
Definition access_vector.h:102
std::vector< value_type > container_type
Definition access_vector.h:90
container_type::iterator iterator
Definition access_vector.h:92
void clear()
clears the list and remove this as observer
Definition access_vector.h:441
TypeAccessVector(const TypeAccessVector &other)
copies (deepcopy!) CTOR
Definition access_vector.h:166
void remove(size_t index)
item to remove
Definition access_vector.h:295
iterator end()
the range based end iterator
Definition access_vector.h:365
std::shared_ptr< const DDL_TYPE_TO_ACCESS > get(size_t index) const
get the item with the given index
Definition access_vector.h:204
const_iterator end() const
range based end operator for const access
Definition access_vector.h:405
friend TYPE_VALIDATOR_CLASS
Definition access_vector.h:106
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplace the given item
Definition access_vector.h:276
TypeAccessVector()=delete
no default CTOR!
const_iterator cbegin() const
const begin iterator access
Definition access_vector.h:375
std::shared_ptr< DDL_TYPE_TO_ACCESS > access(size_t index)
change access to an item
Definition access_vector.h:332
container_type::const_iterator const_iterator
Definition access_vector.h:94
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_vector.h:242
observer_subject_type::observer_type observer_type
Definition access_vector.h:100
virtual ~TypeAccessVector()
DTOR.
Definition access_vector.h:128
void modelChanged(event_code_type event_code, subject_type &subject_changed, const std::string &additional_info)
overrides the observers utility function.
Definition access_vector.h:481
void add(const DDL_TYPE_TO_ACCESS &type_to_add)
adds the given item
Definition access_vector.h:219
Trigger access_type
Definition access_vector.h:86
bool operator!=(const TypeAccessVector &other) const
non equality operator.
Definition access_vector.h:432
TypeAccessVector(TypeAccessVector &&other)
move CTOR
Definition access_vector.h:135
TypeAccessVector & operator=(const TypeAccessVector &other)
copies (deepcopy!) and overwrite the current content.
Definition access_vector.h:183
TypeAccessVector(TYPE_VALIDATOR_CLASS *validator, const std::string &validation_info)
CTOR.
Definition access_vector.h:120
const_iterator begin() const
range based begin operator for const access
Definition access_vector.h:395
std::shared_ptr< Trigger > value_type
Definition access_vector.h:88
bool operator==(const TypeAccessVector &other) const
equality operator.
Definition access_vector.h:417
TypeAccessVectorObserver< Trigger > parent_type
Definition access_vector.h:96
definition of the utility namespace
Definition ddl.h:66
ModelObserverUtility< T, TypeAccessVectorEventCode > TypeAccessVectorObserver
helper template to observe vector content.
Definition access_vector.h:74
ModelSubjectUtility< T, TypeAccessVectorEventCode > TypeAccessVectorSubject
helper template to observe vector content.
Definition access_vector.h:65
TypeAccessVectorEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
Definition access_vector.h:39
definition of the ddl namespace
Definition codec.h:21