blob: 106e48ddb255b2b5a6af8654a09a01cbba737217 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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));
}
|