85 virtual size_t size()
const = 0;
180 template <
class KeyT,
class ValT>
220 size_t size()
const override {
return m_values.size();}
222 bool empty()
const override {
return m_values.empty();}
229 if (it!=m_values.end())
247 if (it!=m_values.end())
253 throw std::out_of_range(
"Key is not in dictionary");
277 for (
const_iterator it=m_values.begin(); it!=m_values.end(); ++it)
279 if (it->second.IsChanged())
293 for (
iterator it=m_values.begin(); it!=m_values.end(); ++it)
295 it->second.SetChanged(changed);
315 InsertHelper<ContainedType, ValueContainerType>::SetVal(val, container);
321 size_t count=m_values.erase(key);
347 val.Copy(it->second);
348 m_values.insert(std::make_pair(it->first, val));
370 (L
"DictionaryContainer::GetKey: Index outside range!",
__WFILE__, __LINE__);
372 return std::next(m_values.begin(),index)->second;
380 if (typeInfo ==
typeid(
KeyType) || std::is_enum_v<KeyType> )
384 auto result = m_values.insert(
value_type(*
static_cast<const KeyType*
>(key), container));
385 return result.first->second;
388 std::wostringstream os;
389 os << L
"DictionaryContainer::InsertNull: The supplied key has wrong type! "
390 << L
"Expected type: " <<
typeid(
KeyType).name() << L
", got type: "
391 << typeInfo.name() << std::endl;
401 (L
"DictionaryContainer::GetKeyAt: Index outside range!",
__WFILE__, __LINE__);
403 return &(std::next(m_values.begin(),index)->first);
417 if (fromContainerOB != NULL)
425 (L
"DictionaryContainer::Merge: Changed key not found in target!",
429 findIt->second.Copy(*fromContainerOB);
436 throw SoftwareViolationException
437 (L
"DictionaryContainer::Merge: Changed key not found in target!",
440 ObjectContainerBase* intoContainerOB =
dynamic_cast<ObjectContainerBase*
>(&findIt->second);
442 ObjectPtr into = intoContainerOB->GetObjectPointer();
451 if (it->second.IsChanged())
456 throw SoftwareViolationException
457 (L
"DictionaryContainer::Merge: Changed key not found in target!",
461 findIt->second.Copy(it->second);
467 std::map<KeyT, ValT> m_values;
469 template <
class V,
class C>
struct InsertHelper
471 static void SetVal(
const V& v, C& c) {c.SetVal(v);}
474 template <
class V,
class C>
struct InsertHelper< std::shared_ptr<V>, C >
476 static void SetVal(
const std::shared_ptr<V>& v, C& c) {c.SetPtr(v);}
479 static DictionaryContainer<KeyT,ValT>& Cast(
ContainerBase& base)
482 if (
typeid(DictionaryContainer<KeyT,ValT>) !=
typeid(base))
484 throw SoftwareViolationException(L
"Invalid call to Copy or Merge, containers are not of same type",
488 return static_cast<DictionaryContainer<KeyT, ValT>&
>(base);
491 static const DictionaryContainer<KeyT,ValT>& Cast(
const ContainerBase& base)
#define __WFILE__
Definition Exceptions.h:31
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
std::shared_ptr< const Object > ObjectConstPtr
A smart pointer to a const Object.
Definition Object.h:47
std::shared_ptr< Object > ObjectPtr
A smart pointer to an Object.
Definition Object.h:44
DOTS_CPP_API void MergeChanges(ObjectPtr into, const ObjectConstPtr &from)
Merge the changed members (recursively) from one object into another.
Base class for all Containers.
Definition ContainerBase.h:44
bool m_bIsChanged
The variable containing the change flag.
Definition ContainerBase.h:127
constexpr ContainerBase()
Default Constructor.
Definition ContainerBase.h:51
virtual bool IsChanged() const
Is the change flag set on the container?
Definition ContainerBase.h:85
Base class for all dictionary containers.
Definition DictionaryContainer.h:48
virtual bool empty() const =0
Check if dictionary is empty.
DictionaryContainerBase()
Default Constructor.
Definition DictionaryContainer.h:51
virtual size_t size() const =0
Get the size of the dictionary, i.e number of contained keys.
virtual ContainerBase & InsertNullInternal(const void *key, const std::type_info &typeInfo)=0
virtual ContainerBase & GetValueContainerAt(const size_t index)=0
Get the container of the value at a particular position in the dictionary.
ContainerBase & InsertNull(const KeyT &key)
Adds a new key to the dictionary and return the value container.
Definition DictionaryContainer.h:116
virtual const void * GetKeyAtInternal(const size_t index) const =0
bool IsChangedHere() const
Is the change flag in the container set?
Definition DictionaryContainer.h:63
void SetChangedHere(const bool changed)
Set the change flag in the container.
Definition DictionaryContainer.h:75
const KeyT & GetKeyAt(const size_t index) const
Get the key at a particular position in the dictionary.
Definition DictionaryContainer.h:138
virtual const ContainerBase & GetValueContainerAt(const size_t index) const =0
Const version of GetValueContainerAt()
Container class for dictionaries of key value pairs.
Definition DictionaryContainer.h:182
DictionaryContainer()
Default Constructor.
Definition DictionaryContainer.h:198
void Insert(const KeyType &key, const ContainedType &val)
Definition DictionaryContainer.h:311
ValueContainerType & at(const KeyType &key)
Like operator[], but throws std::out_of_range if key is not in dictionary.
Definition DictionaryContainer.h:244
std::map< KeyType, ValueContainerType > StorageType
Definition DictionaryContainer.h:188
const_iterator begin() const
Definition DictionaryContainer.h:212
ValueContainerType::ContainedType ContainedType
Definition DictionaryContainer.h:187
void SetNull() override
Set the container to null.
Definition DictionaryContainer.h:206
KeyT KeyType
Definition DictionaryContainer.h:185
ContainerBase & InsertNullInternal(const void *key, const std::type_info &typeInfo) override
Definition DictionaryContainer.h:378
iterator find(const KeyType &key)
Definition DictionaryContainer.h:217
bool empty() const override
Check if dictionary is empty.
Definition DictionaryContainer.h:222
bool IsNull() const override
Is the container set to null?
Definition DictionaryContainer.h:204
const void * GetKeyAtInternal(const size_t index) const override
Definition DictionaryContainer.h:396
StorageType::iterator iterator
Definition DictionaryContainer.h:190
size_t count(const KeyType &key) const
Definition DictionaryContainer.h:224
ValT ValueContainerType
Definition DictionaryContainer.h:186
size_t size() const override
Get the size of the dictionary, i.e number of contained keys.
Definition DictionaryContainer.h:220
iterator begin()
Definition DictionaryContainer.h:211
size_t erase(const KeyType &key)
Definition DictionaryContainer.h:319
ValueContainerType & operator[](const KeyType &key)
Definition DictionaryContainer.h:226
ContainerBase & GetValueContainerAt(const size_t index) override
Get the container of the value at a particular position in the dictionary.
Definition DictionaryContainer.h:365
const_iterator end() const
Definition DictionaryContainer.h:215
void clear()
clear - Clear the dictionary, i.e remove all keys/values.
Definition DictionaryContainer.h:304
const_iterator find(const KeyType &key) const
Definition DictionaryContainer.h:218
bool IsChanged() const override
IsChanged - Check if the dictionary has changed.
Definition DictionaryContainer.h:270
StorageType::const_iterator const_iterator
Definition DictionaryContainer.h:189
void Copy(const ContainerBase &that) override
Copy - Copy all the members from "that" into "this".
Definition DictionaryContainer.h:335
const ValueContainerType & at(const KeyType &key) const
Like operator[], but throws std::out_of_range if key is not in dictionary.
Definition DictionaryContainer.h:261
void SetChanged(const bool changed) override
SetChanged - Set the change state of the dictionary.
Definition DictionaryContainer.h:290
const ContainerBase & GetValueContainerAt(const size_t index) const override
Const version of GetValueContainerAt()
Definition DictionaryContainer.h:360
iterator end()
Definition DictionaryContainer.h:214
StorageType::value_type value_type
Definition DictionaryContainer.h:191
Meant to be used when something goes very wrong.
Definition Exceptions.h:364
Base class for all object containers.
Definition ObjectContainer.h:45
virtual const ObjectPtr GetObjectPointer() const =0
Get a smart pointer to the contained object.
bool IsChangedHere() const
Is the change flag in the container set?
Definition ObjectContainer.h:73