diff options
author | rtk0c <[email protected]> | 2021-06-03 12:17:46 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-06-03 12:17:46 -0700 |
commit | beb1f3969e13af72bd9098d484b693e397cf7235 (patch) | |
tree | 32f5e15393116a487b59b8dd7f4dbc7e5e6ddc59 /core/src/Model/Workflow/Values/Dictionary.cpp | |
parent | aca69f01a9cf4e8a12fe8d67882c05a1131e21b6 (diff) |
Dictionary value (string key)
Diffstat (limited to 'core/src/Model/Workflow/Values/Dictionary.cpp')
-rw-r--r-- | core/src/Model/Workflow/Values/Dictionary.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/src/Model/Workflow/Values/Dictionary.cpp b/core/src/Model/Workflow/Values/Dictionary.cpp new file mode 100644 index 0000000..106e48d --- /dev/null +++ b/core/src/Model/Workflow/Values/Dictionary.cpp @@ -0,0 +1,49 @@ +#include "Dictionary.hpp" + +#include "Utils/Macros.hpp" + +bool DictionaryValue::IsInstance(const BaseValue* value) +{ + return value->GetKind() == KD_Dictionary; +} + +DictionaryValue::DictionaryValue() + : BaseValue(KD_Dictionary) +{ +} + +int DictionaryValue::GetCount() const +{ + return mElements.size(); +} + +BaseValue* DictionaryValue::Find(std::string_view key) +{ + auto iter = mElements.find(key); + if (iter != mElements.end()) { + return iter.value().get(); + } else { + return nullptr; + } +} + +BaseValue* DictionaryValue::Insert(std::string_view key, std::unique_ptr<BaseValue>& value) +{ + auto [iter, success] = mElements.insert(key, std::move(value)); + if (success) { + return iter.value().get(); + } else { + return nullptr; + } +} + +BaseValue& DictionaryValue::InsertOrReplace(std::string_view key, std::unique_ptr<BaseValue> value) +{ + auto [iter, DISCARD] = mElements.emplace(key, std::move(value)); + return *iter.value(); +} + +void DictionaryValue::Remove(std::string_view key) +{ + mElements.erase(mElements.find(key)); +} |