#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& 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 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)); }