stuff-from-scratch/src/core/Dictionary.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

2022-01-01 18:46:31 +00:00
#include "Dictionary.h"
2022-12-02 08:44:04 +00:00
bool Dictionary::hasKey(const std::string& key) const
2022-01-01 18:46:31 +00:00
{
2022-12-02 08:44:04 +00:00
return hasStringKey(key) || hasDictKey(key);
2022-01-01 18:46:31 +00:00
}
2022-12-02 08:44:04 +00:00
bool Dictionary::hasStringKey(const std::string& key) const
2022-01-01 18:46:31 +00:00
{
return mStringData.count(key) > 0;
}
2022-12-02 08:44:04 +00:00
bool Dictionary::hasDictKey(const std::string& key) const
2022-01-01 18:46:31 +00:00
{
return mDictData.count(key) > 0;
}
2022-12-02 08:44:04 +00:00
std::vector<std::string> Dictionary::getStringKeys() const
2022-01-01 18:46:31 +00:00
{
std::vector<std::string> keys;
for (const auto& item : mStringData)
{
keys.push_back(item.first);
}
return keys;
}
2022-12-02 08:44:04 +00:00
std::vector<std::string> Dictionary::getDictKeys() const
2022-01-01 18:46:31 +00:00
{
std::vector<std::string> keys;
for (const auto& item : mDictData)
{
keys.push_back(item.first);
}
return keys;
}
2022-12-02 08:44:04 +00:00
Dictionary* Dictionary::getDict(const std::string& key) const
2022-01-01 18:46:31 +00:00
{
return mDictData.at(key).get();
}
2022-12-02 08:44:04 +00:00
std::string Dictionary::getItem(const std::string& key) const
2022-01-01 18:46:31 +00:00
{
return mStringData.at(key);
}
2022-12-02 08:44:04 +00:00
void Dictionary::addStringItem(const std::string& key, const std::string& item)
2022-01-01 18:46:31 +00:00
{
mStringData[key] = item;
}
2022-12-02 08:44:04 +00:00
void Dictionary::addDictItem(const std::string& key, std::unique_ptr<Dictionary> dict)
2022-01-01 18:46:31 +00:00
{
mDictData[key] = std::move(dict);
}