blob: 50c5184a460d7496dddf20f543228233b19e84e3 (
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
43
44
45
46
47
48
|
#pragma once
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/unordered_map.hpp"
#include "std/utility.hpp"
namespace platform
{
// class GetTextById is ready to work with different sources of text strings.
// For the time being it's only strings for TTS.
enum class TextSource
{
TtsSound = 0
};
/// GetTextById represents text messages which are saved in textsDir
/// in a specified locale.
class GetTextById
{
public:
/// @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
|