blob: 11b785cf31df30ac18a2d9d2c0655ab6c9c43201 (
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
50
51
|
#ifndef CLIENT_SETTINGS_HH_
#define CLIENT_SETTINGS_HH_
#include <filesystem>
#include <fstream>
#include <optional>
#include <stdlib.h>
#include <string>
#include <boost/lexical_cast.hpp>
//#include "client/shared.hh"
#include "shared/shared.hh"
// This settings file just provides functionality for persistent variables,
// it has nothing to do with rendering or our window manager.
namespace client {
namespace settings {
using setting_pair_t = std::pair<std::string, std::string>;
std::optional<std::string> maybe_get_setting_str(const setting_pair_t&);
void set_setting_str(const setting_pair_t& loc, const std::string& value);
std::string get_setting_str(const setting_pair_t& loc,
const std::string default_value);
// Attempts to read the setting in the file, returning it if it exists.
// If either name or category does not exist, writes the default value in
// the file under the expected headings.
template <typename T>
T get(const setting_pair_t& loc, const T& default_value) {
const std::string value =
get_setting_str(loc, boost::lexical_cast<std::string>(default_value));
return boost::lexical_cast<T>(value);
}
// Attempts to set the setting in the file, overwriting the pre-existing
// value or writing a new entry.
template <typename T>
void set(const setting_pair_t& loc, const T& value) {
set_setting_str(loc, boost::lexical_cast<std::string>(value));
}
void save();
} // namespace settings
} // namespace client
#endif
|