15 #ifndef DD_DD_ACCESS_MAP_H_INCLUDED
16 #define DD_DD_ACCESS_MAP_H_INCLUDED
22 #include <unordered_map>
72 template <
typename DDL_TYPE_TO_ACCESS,
typename TYPE_VALIDATOR_CLASS>
82 typedef typename container_type::iterator
iterator;
127 *
this = std::move(other);
137 _validation_info = std::move(other._validation_info);
138 _types = std::move(other._types);
140 for (
const auto& current: _types) {
148 _validator =
nullptr;
158 : _validator(nullptr), _validation_info(other._validation_info)
160 for (
auto current: other._types) {
161 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current.second);
165 _types[current.first] = new_type;
177 _validation_info = other._validation_info;
178 for (
auto current: other._types) {
179 auto new_type = std::make_shared<DDL_TYPE_TO_ACCESS>(*current.second);
183 _types[current.first] = new_type;
185 _validator =
nullptr;
196 std::shared_ptr<const DDL_TYPE_TO_ACCESS>
get(
const std::string& type_name)
const
198 auto it_find = _types.find(type_name);
199 if (it_find != _types.cend()) {
200 std::shared_ptr<const DDL_TYPE_TO_ACCESS> const_return = it_find->second;
214 const auto& it_find = _types.find(type_name);
215 if (it_find != _types.cend()) {
227 bool contains(
const DDL_TYPE_TO_ACCESS& type_to_find)
const
229 const auto& it_find = _types.find(type_to_find.getName());
230 if (it_find != _types.cend()) {
231 return type_to_find == *(it_find->second);
244 for (
const auto& other_content: other._types) {
245 if (!
contains(*(other_content.second))) {
257 void add(
const DDL_TYPE_TO_ACCESS& type_to_add)
259 const auto type_found =
get(type_to_add.getName());
263 if (*type_found != type_to_add) {
265 {type_to_add.getName()},
266 "value with the given name already exists");
272 bool already_exists =
contains(type_to_add.getName());
273 if (_validator && !already_exists) {
274 already_exists = _validator->validateContains(type_to_add);
276 if (already_exists) {
278 {type_to_add.getName()},
279 "value with the given name already exists");
282 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(type_to_add);
286 _types[type_to_add.getName()] = new_type_value;
288 _validator->notifyChangedMapContent(
289 TypeAccessMapEventCode::map_item_added, *new_type_value, type_to_add.getName());
299 void emplace(DDL_TYPE_TO_ACCESS&& type_to_add)
301 const auto type_found =
get(type_to_add.getName());
305 if (*type_found != type_to_add) {
307 {type_to_add.getName()},
308 "value with the given name already exists");
313 bool already_exists =
contains(type_to_add.getName());
314 if (_validator && !already_exists) {
315 already_exists = _validator->validateContains(type_to_add);
317 if (already_exists) {
319 {type_to_add.getName()},
320 "value with the given name already exists");
323 auto new_type_value = std::make_shared<DDL_TYPE_TO_ACCESS>(std::move(type_to_add));
327 _types[new_type_value->getName()] = new_type_value;
329 _validator->notifyChangedMapContent(
330 TypeAccessMapEventCode::map_item_added, *new_type_value, new_type_value->getName());
338 void remove(
const std::string& type_name)
340 auto removed_value =
access(type_name);
342 _types.erase(type_name);
346 _validator->notifyChangedMapContent(
347 TypeAccessMapEventCode::map_item_removed, *removed_value, type_name);
352 _validation_info +
"::remove", {type_name},
"value with the given name does not exist");
360 std::shared_ptr<DDL_TYPE_TO_ACCESS>
access(
const std::string& type_name)
362 auto it_find = _types.find(type_name);
363 if (it_find != _types.end()) {
364 return it_find->second;
375 return _types.size();
384 return _types.begin();
402 return _types.cbegin();
411 return _types.cend();
464 for (
auto& current: _types) {
482 const std::string& additional_info)
484 if (event_code == map_item_renamed) {
485 bool already_exists =
contains(subject_changed.getName());
486 if (_validator && !already_exists) {
487 already_exists = _validator->validateContains(subject_changed);
489 if (already_exists) {
491 _validation_info +
"::modelChanged",
492 {subject_changed.getName()},
493 "Renaming not possible. Value with the given name already exists");
497 iterator current = _types.find(additional_info);
499 auto value = current->second;
500 _types.erase(current);
501 _types[value->getName()] = value;
508 _validator->notifyChangedMapContent(event_code, subject_changed, additional_info);
524 destination._validator = validator;
528 std::string _validation_info;
The ModelObserver utility template.
MODEL_SUBJECT_T subject_type
local definition of the subject code type
EVENT_CODE_T event_code_type
local definition of the event code type
Model Subject utility to define a Model Subject that notifies one or more observers.
Utility class for observable named items where the order is NOT important.
void add(const DDL_TYPE_TO_ACCESS &type_to_add)
adds the given item
TypeAccessMapObserver< DDL_TYPE_TO_ACCESS > parent_type
local definition of the parent type to register observe
TypeAccessMap()=delete
no default CTOR!
container_type::const_iterator const_iterator
local definition of the container const_iterator
const_iterator begin() const
range based begin operator for const access
TypeAccessMapSubject< DDL_TYPE_TO_ACCESS > map_subject_type
local definition of the internal subject type
const_iterator cbegin() const
const begin iterator access
container_type::iterator iterator
local definition of the container iterator
TypeAccessMap & operator=(TypeAccessMap &&other)
move assignment operator
TypeAccessMap(TypeAccessMap &&other)
move CTOR
void remove(const std::string &type_name)
item to remove
void emplace(DDL_TYPE_TO_ACCESS &&type_to_add)
emplaces the given item
TypeAccessMap(const TypeAccessMap &other)
copies (deepcopy!) CTOR
bool contains(const std::string &type_name) const
determines is the type name exists in this map
void deepCopy(TypeAccessMap &destination, TYPE_VALIDATOR_CLASS *validator) const
copies the content of the of the list (by reseting the observer) and resets the validator to the give...
std::shared_ptr< DDL_TYPE_TO_ACCESS > value_type
local definition of the value type
parent_type::event_code_type event_code_type
local definition of the eventcode type
map_subject_type::observer_type observer_type
local definition of the observer type
void modelChanged(event_code_type event_code, subject_type &subject_changed, const std::string &additional_info)
overrides the observers utility function.
TypeAccessMap & operator=(const TypeAccessMap &other)
copies (deepcopy!) and overwrite the current content.
const_iterator cend() const
const end iterator access
size_t getSize() const
Get the Size.
virtual ~TypeAccessMap()
DTOR.
bool contains(const TypeAccessMap &other) const
determines if the other is a subset of this map
bool contains(const DDL_TYPE_TO_ACCESS &type_to_find) const
determines if the item is in this map.
DDL_TYPE_TO_ACCESS access_type
local definition of the access type
std::shared_ptr< const DDL_TYPE_TO_ACCESS > get(const std::string &type_name) const
get the item with the given name type_name
friend TYPE_VALIDATOR_CLASS
friend validator class
std::shared_ptr< DDL_TYPE_TO_ACCESS > access(const std::string &type_name)
change access to an item
void clear()
clears the list and remove this as observer
iterator end()
the range based end iterator
std::unordered_map< std::string, value_type > container_type
local definition of the container type
const_iterator end() const
range based end operator for const access
parent_type::subject_type subject_type
local definition of the subject type
iterator begin()
the range based begin iterator
bool operator!=(const TypeAccessMap &other) const
non equality operator.
TypeAccessMap(TYPE_VALIDATOR_CLASS *validator, const std::string &validation_info)
CTOR.
bool operator==(const TypeAccessMap &other) const
equality operator.
DataDefinition Model-Observer pattern utility.
OO DataDefinition Redesign.
Error
Enumerates possible error values for filesystem interaction.
TypeAccessMapEventCode
Internal event code to inform the parent DD Object about the change of an item within the list.
@ validation_info
Validation Info.
definition of the ddl namespace