blob: 9b5dacf5fa1f53329c0ea1e286258faf5936d053 [file] [log] [blame]
Thomas Psota7e562b62020-04-30 15:11:32 +02001#include <BaSyx/submodel/simple/common/LangStringSet.h>
2
jwendelil4ee5bf282020-05-25 16:20:07 +02003#include <BaSyx/shared/types.h>
4
Thomas Psota7e562b62020-04-30 15:11:32 +02005namespace basyx {
6namespace submodel {
7namespace simple {
8
9const std::string empty_string{};
10
11LangStringSet::LangStringSet()
12{
13};
14
15LangStringSet::LangStringSet(const std::string & languageCode, const std::string & langString)
16{
17 this->langStrings.emplace(languageCode, langString);
18};
19
20LangStringSet::langCodeSet_t LangStringSet::getLanguageCodes() const
21{
jwendelil4f53a4fc2020-06-03 16:41:47 +020022 LangStringSet::langCodeSet_t langCodes;
23 for (auto & langCode : this->langStrings)
24 langCodes.insert(langCode.first);
25 return langCodes;
Thomas Psota7e562b62020-04-30 15:11:32 +020026};
27
28
29LangStringSet::LangStringSet(std::initializer_list<LangStringSet::langStringMap_t::value_type> il)
30{
31 for (const auto & entry : il)
32 this->add(entry.first, entry.second);
33}
34
Constantin Ziesche02817f12020-08-04 21:40:43 +020035LangStringSet::LangStringSet(const api::ILangStringSet &other)
36{
37 for( auto & lang_code : other.getLanguageCodes())
38 this->add(lang_code, other.get(lang_code));
39}
40
Thomas Psota7e562b62020-04-30 15:11:32 +020041const std::string & LangStringSet::get(const std::string & languageCode) const
42{
43 if (this->langStrings.find(languageCode) != langStrings.end()) {
44 return langStrings.at(languageCode);
45 }
46
47 return empty_string;
48};
49
50
51void LangStringSet::add(const std::string & languageCode, const std::string & langString)
52{
53 this->langStrings.emplace(languageCode, langString);
54};
55
56bool LangStringSet::empty() const noexcept
57{
58 return this->langStrings.empty();
59}
60
61}
62}
63}