forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.hpp
107 lines (84 loc) · 2.3 KB
/
settings.hpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include "platform/string_storage_base.hpp"
#include "base/macros.hpp"
#include <string>
namespace settings
{
/// Metric or Imperial.
extern char const * kMeasurementUnits;
extern char const * kDeveloperMode;
template <class T>
bool FromString(std::string const & str, T & outValue);
template <class T>
std::string ToString(T const & value);
class StringStorage : public platform::StringStorageBase
{
public:
static StringStorage & Instance();
private:
StringStorage();
};
/// Retrieve setting
/// @return false if setting is absent
template <class Value>
[[nodiscard]] bool Get(std::string const & key, Value & outValue)
{
std::string strVal;
return StringStorage::Instance().GetValue(key, strVal) && FromString(strVal, outValue);
}
template <class Value>
void TryGet(std::string const & key, Value & outValue)
{
bool unused = Get(key, outValue);
UNUSED_VALUE(unused);
}
/// Automatically saves setting to external file
template <class Value>
void Set(std::string const & key, Value const & value)
{
StringStorage::Instance().SetValue(key, ToString(value));
}
/// Automatically saves settings to external file
inline void Update(std::map<std::string, std::string> const & settings)
{
StringStorage::Instance().Update(settings);
}
inline void Delete(std::string const & key) { StringStorage::Instance().DeleteKeyAndValue(key); }
inline void Clear() { StringStorage::Instance().Clear(); }
class UsageStats
{
static uint64_t TimeSinceEpoch();
uint64_t m_enterForegroundTime = 0;
uint64_t m_totalForegroundTime = 0;
uint64_t m_sessionsCount = 0;
std::string m_firstLaunch, m_lastBackground, m_totalForeground, m_sessions;
StringStorage & m_ss;
public:
UsageStats();
void EnterForeground();
void EnterBackground();
};
} // namespace settings
/*
namespace marketing
{
class Settings : public platform::StringStorageBase
{
public:
template <class Value>
static void Set(std::string const & key, Value const & value)
{
Instance().SetValue(key, settings::ToString(value));
}
template <class Value>
[[nodiscard]] static bool Get(std::string const & key, Value & outValue)
{
std::string strVal;
return Instance().GetValue(key, strVal) && settings::FromString(strVal, outValue);
}
private:
static Settings & Instance();
Settings();
};
} // namespace marketing
*/