CommonLibSSE (powerof3)
Loading...
Searching...
No Matches
JSON.h
Go to the documentation of this file.
1#pragma once
2
3#include "REX/REX/Setting.h"
4
5#ifdef REX_OPTION_JSON
6namespace REX::JSON
7{
8 using path_t = std::string_view;
9
10 namespace Impl
11 {
12 template <class T>
13 void SettingLoad(void* a_file, path_t a_path, T& a_value, T& a_valueDefault);
14
15 template <class T>
16 void SettingSave(void* a_file, path_t a_path, T& a_value);
17 }
18
19 class SettingStore :
20 public TSettingStore<SettingStore>
21 {
22 public:
23 virtual void Load() override;
24 virtual void Save() override;
25 };
26
27 template <class T, class Store = SettingStore>
28 class Setting :
29 public TSetting<T, Store>
30 {
31 public:
32 Setting(path_t a_path, T a_default) :
33 TSetting<T, Store>(a_default),
34 m_path(a_path)
35 {}
36
37 public:
38 virtual void Load(void* a_data, bool a_isBase) override
39 {
40 if (a_isBase) {
41 Impl::SettingLoad(a_data, m_path, this->m_valueDefault, this->m_valueDefault);
42 this->SetValue(this->m_valueDefault);
43 } else {
44 Impl::SettingLoad(a_data, m_path, this->m_value, this->m_valueDefault);
45 }
46 }
47
48 virtual void Save(void* a_data) override
49 {
50 Impl::SettingSave(a_data, m_path, this->m_value);
51 }
52
53 private:
54 path_t m_path;
55 };
56
57 template <class Store = SettingStore>
58 using Bool = Setting<bool, Store>;
59
60 template <class Store = SettingStore>
61 using F32 = Setting<float, Store>;
62
63 template <class Store = SettingStore>
64 using F64 = Setting<double, Store>;
65
66 template <class Store = SettingStore>
67 using I8 = Setting<std::int8_t, Store>;
68
69 template <class Store = SettingStore>
70 using I16 = Setting<std::int16_t, Store>;
71
72 template <class Store = SettingStore>
73 using I32 = Setting<std::int32_t, Store>;
74
75 template <class Store = SettingStore>
76 using U8 = Setting<std::uint8_t, Store>;
77
78 template <class Store = SettingStore>
79 using U16 = Setting<std::uint16_t, Store>;
80
81 template <class Store = SettingStore>
82 using U32 = Setting<std::uint32_t, Store>;
83
84 template <class Store = SettingStore>
85 using Str = Setting<std::string, Store>;
86}
87
88template <class T, class S, class CharT>
89struct std::formatter<REX::JSON::Setting<T, S>, CharT> : std::formatter<T, CharT>
90{
91 template <class FormatContext>
92 auto format(const REX::JSON::Setting<T, S>& a_setting, FormatContext& a_ctx) const
93 {
94 return std::formatter<T, CharT>::format(a_setting.GetValue(), a_ctx);
95 }
96};
97#endif
Definition BSDirectInputManager.h:8
constexpr REL::ID Save(static_cast< std::uint64_t >(34818))
constexpr REL::ID Load(static_cast< std::uint64_t >(34819))