Thomas Psota | 7e562b6 | 2020-04-30 15:11:32 +0200 | [diff] [blame] | 1 | #include <BaSyx/submodel/simple/common/LangStringSet.h> |
| 2 | |
jwendelil4 | ee5bf28 | 2020-05-25 16:20:07 +0200 | [diff] [blame] | 3 | #include <BaSyx/shared/types.h> |
| 4 | |
Thomas Psota | 7e562b6 | 2020-04-30 15:11:32 +0200 | [diff] [blame] | 5 | namespace basyx { |
| 6 | namespace submodel { |
| 7 | namespace simple { |
| 8 | |
| 9 | const std::string empty_string{}; |
| 10 | |
| 11 | LangStringSet::LangStringSet() |
| 12 | { |
| 13 | }; |
| 14 | |
| 15 | LangStringSet::LangStringSet(const std::string & languageCode, const std::string & langString) |
| 16 | { |
| 17 | this->langStrings.emplace(languageCode, langString); |
| 18 | }; |
| 19 | |
| 20 | LangStringSet::langCodeSet_t LangStringSet::getLanguageCodes() const |
| 21 | { |
jwendelil4 | f53a4fc | 2020-06-03 16:41:47 +0200 | [diff] [blame] | 22 | LangStringSet::langCodeSet_t langCodes; |
| 23 | for (auto & langCode : this->langStrings) |
| 24 | langCodes.insert(langCode.first); |
| 25 | return langCodes; |
Thomas Psota | 7e562b6 | 2020-04-30 15:11:32 +0200 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | |
| 29 | LangStringSet::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 Ziesche | 02817f1 | 2020-08-04 21:40:43 +0200 | [diff] [blame^] | 35 | LangStringSet::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 Psota | 7e562b6 | 2020-04-30 15:11:32 +0200 | [diff] [blame] | 41 | const 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 | |
| 51 | void LangStringSet::add(const std::string & languageCode, const std::string & langString) |
| 52 | { |
| 53 | this->langStrings.emplace(languageCode, langString); |
| 54 | }; |
| 55 | |
| 56 | bool LangStringSet::empty() const noexcept |
| 57 | { |
| 58 | return this->langStrings.empty(); |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | } |
| 63 | } |