Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/cfg_var.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 #include "cfg_var_legacy.h" | |
| 3 | |
| 4 using cfg_var_legacy::cfg_var_reader; | |
| 5 | |
| 6 #include <atomic> | |
| 7 #include <mutex> | |
| 8 #include <vector> | |
| 9 | |
| 10 namespace cfg_var_modern { | |
| 11 class cfg_var_common : public cfg_var_reader { | |
| 12 protected: | |
| 13 cfg_var_common(const GUID& id) : cfg_var_reader(id) {} | |
| 14 pfc::string8 formatName() const; | |
| 15 public: | |
| 16 static pfc::string8 formatVarName(const GUID&); | |
| 17 cfg_var_common(const cfg_var_common&) = delete; | |
| 18 void operator=(const cfg_var_common&) = delete; | |
| 19 }; | |
| 20 | |
| 21 class cfg_string : private cfg_var_common { | |
| 22 public: | |
| 23 cfg_string(const GUID& id, const char* initVal) : cfg_var_common(id), m_initVal(initVal) {} | |
| 24 | |
| 25 void set(const char* v); | |
| 26 pfc::string8 get(); | |
| 27 void get(pfc::string_base& out); | |
| 28 | |
| 29 void operator=(const char* v) { set(v); } | |
| 30 | |
| 31 pfc::string8 get_value() { return get(); } | |
| 32 | |
| 33 operator pfc::string8() { return get(); } | |
| 34 private: | |
| 35 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 36 void set_data_raw(stream_reader* p_stream, t_size p_sizehint, abort_callback& p_abort) override; | |
| 37 #endif | |
| 38 | |
| 39 const pfc::string8 m_initVal; | |
| 40 pfc::readWriteLock m_valueGuard; | |
| 41 pfc::string8 m_value; | |
| 42 std::once_flag m_init; | |
| 43 }; | |
| 44 | |
| 45 typedef cfg_string cfg_string_mt; | |
| 46 | |
| 47 class cfg_int : private cfg_var_common { | |
| 48 public: | |
| 49 cfg_int(const GUID& id, int64_t initVal) : cfg_var_common(id), m_initVal(initVal) {} | |
| 50 | |
| 51 int64_t get(); | |
| 52 void set(int64_t v); | |
| 53 operator int64_t() { return get(); } | |
| 54 void operator=(int64_t v) { set(v); } | |
| 55 | |
| 56 int64_t get_value() { return get(); } | |
| 57 private: | |
| 58 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 59 void set_data_raw(stream_reader* p_stream, t_size p_sizehint, abort_callback& p_abort) override; | |
| 60 #endif | |
| 61 | |
| 62 const int64_t m_initVal; | |
| 63 std::atomic_int64_t m_val = { 0 }; | |
| 64 std::once_flag m_init; | |
| 65 }; | |
| 66 | |
| 67 typedef cfg_int cfg_uint; | |
| 68 | |
| 69 class cfg_bool : private cfg_var_common { | |
| 70 public: | |
| 71 cfg_bool(const GUID& id, bool initVal) : cfg_var_common(id), m_initVal(initVal) {} | |
| 72 | |
| 73 bool get(); | |
| 74 void set(bool v); | |
| 75 operator bool() { return get(); } | |
| 76 void operator=(bool v) { set(v); } | |
| 77 private: | |
| 78 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 79 void set_data_raw(stream_reader* p_stream, t_size p_sizehint, abort_callback& p_abort) override; | |
| 80 #endif | |
| 81 | |
| 82 const bool m_initVal; | |
| 83 std::atomic_bool m_val = { false }; | |
| 84 std::once_flag m_init; | |
| 85 }; | |
| 86 | |
| 87 class cfg_blob : private cfg_var_common { | |
| 88 public: | |
| 89 cfg_blob(const GUID& id) : cfg_var_common(id) {} | |
| 90 cfg_blob(const GUID& id, const void* ptr, size_t size) : cfg_var_common(id) { | |
| 91 m_initVal = fb2k::makeMemBlock(ptr, size); | |
| 92 } | |
| 93 | |
| 94 fb2k::memBlockRef get(); | |
| 95 void set(fb2k::memBlockRef ref); | |
| 96 void set(const void* ptr, size_t size); | |
| 97 private: | |
| 98 void set_(fb2k::memBlockRef); | |
| 99 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 100 void set_data_raw(stream_reader* p_stream, t_size p_sizehint, abort_callback& p_abort) override; | |
| 101 #endif | |
| 102 | |
| 103 fb2k::memBlockRef m_data, m_initVal; | |
| 104 pfc::readWriteLock m_dataGuard; | |
| 105 std::once_flag m_init; | |
| 106 }; | |
| 107 | |
| 108 template<typename struct_t> class cfg_struct_t : private cfg_blob { | |
| 109 public: | |
| 110 cfg_struct_t(const GUID& id) : cfg_blob(id) {} | |
| 111 cfg_struct_t(const GUID& id, const struct_t& init) : cfg_blob(id, &init, sizeof(init)) {} | |
| 112 | |
| 113 struct_t get() { | |
| 114 struct_t data = {}; | |
| 115 auto v = cfg_blob::get(); | |
| 116 if (v.is_valid() && v->size() == sizeof(data)) { | |
| 117 memcpy(&data, v->get_ptr(), sizeof(data)); | |
| 118 } | |
| 119 return data; | |
| 120 } | |
| 121 operator struct_t() { return get(); } | |
| 122 | |
| 123 void set(const struct_t& data) { cfg_blob::set(&data, sizeof(data)); } | |
| 124 void operator=(const struct_t& data) { set(data); } | |
| 125 | |
| 126 struct_t get_value() { return get(); } | |
| 127 }; | |
| 128 | |
| 129 typedef cfg_struct_t<GUID> cfg_guid; | |
| 130 | |
| 131 class cfg_float : private cfg_var_common { | |
| 132 public: | |
| 133 cfg_float(const GUID& id, double initVal) : cfg_var_common(id), m_initVal(initVal) {} | |
| 134 | |
| 135 double get(); | |
| 136 void set(double v); | |
| 137 operator double() { return get(); } | |
| 138 void operator=(double v) { set(v); } | |
| 139 | |
| 140 double get_value() { return get(); } | |
| 141 private: | |
| 142 #ifdef FOOBAR2000_HAVE_CFG_VAR_LEGACY | |
| 143 void set_data_raw(stream_reader* p_stream, t_size p_sizehint, abort_callback& p_abort) override; | |
| 144 #endif | |
| 145 | |
| 146 const double m_initVal; | |
| 147 std::atomic<double> m_val = { 0 }; | |
| 148 std::once_flag m_init; | |
| 149 }; | |
| 150 } | |
| 151 | |
| 152 #if FOOBAR2000_TARGET_VERSION < 81 | |
| 153 using namespace cfg_var_legacy; | |
| 154 #else | |
| 155 using namespace cfg_var_modern; | |
| 156 #endif | |
| 157 |
