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