diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-10-13 18:32:03 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2015-10-13 18:32:03 +0300 |
commit | dae80d699d379a9a05d24b9625f988fa6a8d9259 (patch) | |
tree | b87cf943ec0cd8c47c41df3eb22edfdad91dc995 /platform/get_text_by_id.hpp | |
parent | ff5c6a457909c94b558795e7c401b8386c31cb19 (diff) |
Using english in TTS if sound.txt doesn't contain the current language. Some refactoring.
Diffstat (limited to 'platform/get_text_by_id.hpp')
-rw-r--r-- | platform/get_text_by_id.hpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/platform/get_text_by_id.hpp b/platform/get_text_by_id.hpp index 7d1c5cac50..50c5184a46 100644 --- a/platform/get_text_by_id.hpp +++ b/platform/get_text_by_id.hpp @@ -1,6 +1,7 @@ #pragma once #include "std/string.hpp" +#include "std/unique_ptr.hpp" #include "std/unordered_map.hpp" #include "std/utility.hpp" @@ -18,19 +19,30 @@ enum class TextSource class GetTextById { public: - GetTextById(TextSource textSouce, string const & localeName); - /// The constructor is used for writing unit tests only. - explicit GetTextById(string const & jsonBuffer); - - bool IsValid() const { return !m_localeTexts.empty(); } /// @return a pair of a text string in a specified locale for textId and a boolean flag. /// If textId is found in m_localeTexts then the boolean flag is set to true. /// The boolean flag is set to false otherwise. string operator()(string const & textId) const; - + string GetLocale() const { return m_locale; } private: + friend unique_ptr<GetTextById> GetTextByIdFactory(TextSource textSouce, string const & localeName); + friend unique_ptr<GetTextById> ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); + friend unique_ptr<GetTextById> MakeGetTextById(string const & jsonBuffer, string const & localeName); + + GetTextById(string const & jsonBuffer, string const & localeName); void InitFromJson(string const & jsonBuffer); + /// \note IsValid is used only in factories and shall be private. + bool IsValid() const { return !m_localeTexts.empty(); } + string m_locale; unordered_map<string, string> m_localeTexts; }; + +/// Factoris to create intances of GetTextById. +/// If unique_ptr<GetTextById> is created by GetTextByIdFactory or ForTestingGetTextByIdFactory +/// threre are only two possibities. +/// * a factory returns a valid instance +/// * a factory returns nullptr +unique_ptr<GetTextById> GetTextByIdFactory(TextSource textSouce, string const & localeName); +unique_ptr<GetTextById> ForTestingGetTextByIdFactory(string const & jsonBuffer, string const & localeName); } // namespace platform |