Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings.hpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 122075d8bab1241e9672f8440c72e6183af22f85 (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
49
#pragma once

#include "std/string.hpp"
#include "std/map.hpp"

namespace Settings
{
  template <class T> bool FromString(string const & str, T & outValue);
  template <class T> string ToString(T const & value);

  class StringStorage
  {
    typedef map<string, string> ContainerT;
    ContainerT m_values;

    StringStorage();
    void Save() const;

  public:
    static StringStorage & Instance();

    bool GetValue(string const & key, string & outValue);
    void SetValue(string const & key, string const & value);
  };

  /// Retrieve setting
  /// @return false if setting is absent
  template <class ValueT> bool Get(string const & key, ValueT & outValue)
  {
    string strVal;
    return StringStorage::Instance().GetValue(key, strVal)
        && FromString(strVal, outValue);
  }
  /// Automatically saves setting to external file
  template <class ValueT> void Set(string const & key, ValueT const & value)
  {
    StringStorage::Instance().SetValue(key, ToString(value));
  }

  enum Units { Metric = 0, Yard, Foot };

  /// Use this function for running some stuff once according to date.
  /// @param[in]  date  Current date in format yymmdd.
  bool IsFirstLaunchForDate(int date);
  /// @Returns true when user launched app first time
  /// Use to track new installs
  /// @warning Can be used only before IsFirstLaunchForDate(int) call
  bool IsFirstLaunch();
}