|
1
|
1 #pragma once
|
|
|
2 #include <mutex>
|
|
|
3 #include <atomic>
|
|
|
4
|
|
|
5 namespace fb2k {
|
|
|
6 // cache of config values
|
|
|
7 // STATIC USE ONLY
|
|
|
8 class configBoolCache {
|
|
|
9 public:
|
|
|
10 configBoolCache(const char* var, bool def = false) : m_var(var), m_def(def) {}
|
|
|
11 bool get();
|
|
|
12 operator bool() { return get(); }
|
|
|
13 void set(bool);
|
|
|
14 void operator=(bool v) { set(v); }
|
|
|
15
|
|
|
16 configBoolCache(const configBoolCache&) = delete;
|
|
|
17 void operator=(const configBoolCache&) = delete;
|
|
|
18 private:
|
|
|
19 const char* const m_var;
|
|
|
20 const bool m_def;
|
|
|
21 std::atomic_bool m_value = { false };
|
|
|
22 std::once_flag m_init;
|
|
|
23 };
|
|
|
24
|
|
|
25 class configIntCache {
|
|
|
26 public:
|
|
|
27 configIntCache(const char* var, int64_t def = 0) : m_var(var), m_def(def) {}
|
|
|
28 int64_t get();
|
|
|
29 operator int64_t() { return get(); }
|
|
|
30 void set(int64_t);
|
|
|
31 void operator=(int64_t v) { set(v); }
|
|
|
32
|
|
|
33 configIntCache(const configIntCache&) = delete;
|
|
|
34 void operator=(const configIntCache&) = delete;
|
|
|
35 private:
|
|
|
36 const char* const m_var;
|
|
|
37 const int64_t m_def;
|
|
|
38 std::atomic_int64_t m_value = { 0 };
|
|
|
39 std::once_flag m_init;
|
|
|
40 };
|
|
|
41 } |