aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Model/Workflow/Values/Dictionary.cpp
blob: 718a0c89fb20759cec7970d880d0ec1398c28c2a (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
#include "Dictionary.hpp"

#include <Cplt/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));
}