Skip to content

Commit ebfda8b

Browse files
committed
feat: improve settings
1 parent 9c9e481 commit ebfda8b

File tree

7 files changed

+281
-869
lines changed

7 files changed

+281
-869
lines changed

include/REX/REX/INI.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,21 @@
55
#ifdef REX_OPTION_INI
66
namespace REX::INI
77
{
8-
namespace detail
8+
namespace Impl
99
{
10-
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
11-
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
1210
template <class T>
13-
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_section, std::string_view& a_key);
11+
void SettingLoad(void* a_file, std::string_view a_section, std::string_view a_key, T& a_value, T& a_valueDefault);
12+
1413
template <class T>
15-
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_section, std::string_view& a_key);
14+
void SettingSave(void* a_file, std::string_view a_section, std::string_view a_key, T& a_value);
1615
}
1716

1817
class SettingStore :
1918
public TSettingStore<SettingStore>
2019
{
2120
public:
22-
virtual void Load() override
23-
{
24-
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
25-
}
26-
27-
virtual void Save() override
28-
{
29-
detail::StoreSaveImpl(m_fileBase, m_settings);
30-
}
21+
virtual void Load() override;
22+
virtual void Save() override;
3123
};
3224

3325
template <class T, class Store = SettingStore>
@@ -42,19 +34,19 @@ namespace REX::INI
4234
{}
4335

4436
public:
45-
virtual void Load(void* a_file) override
46-
{
47-
Load(a_file, true);
48-
}
49-
50-
virtual void Load(void* a_file, bool a_useDefault) override
37+
virtual void Load(void* a_data, bool a_isBase) override
5138
{
52-
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_section, m_key);
39+
if (a_isBase) {
40+
Impl::SettingLoad(a_data, m_section, m_key, this->m_valueDefault, this->m_valueDefault);
41+
this->SetValue(this->m_valueDefault);
42+
} else {
43+
Impl::SettingLoad(a_data, m_section, m_key, this->m_value, this->m_valueDefault);
44+
}
5345
}
5446

55-
virtual void Save(void* a_file) override
47+
virtual void Save(void* a_data) override
5648
{
57-
detail::SettingSaveImpl(a_file, this->m_value, m_section, m_key);
49+
Impl::SettingSave(a_data, m_section, m_key, this->m_value);
5850
}
5951

6052
private:

include/REX/REX/JSON.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,21 @@
55
#ifdef REX_OPTION_JSON
66
namespace REX::JSON
77
{
8-
namespace detail
8+
namespace Impl
99
{
10-
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
11-
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
1210
template <class T>
13-
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_path);
11+
void SettingLoad(void* a_file, std::string_view a_path, T& a_value, T& a_valueDefault);
12+
1413
template <class T>
15-
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_path);
14+
void SettingSave(void* a_file, std::string_view a_path, T& a_value);
1615
}
1716

1817
class SettingStore :
1918
public TSettingStore<SettingStore>
2019
{
2120
public:
22-
virtual void Load() override
23-
{
24-
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
25-
}
26-
27-
virtual void Save() override
28-
{
29-
detail::StoreSaveImpl(m_fileBase, m_settings);
30-
}
21+
virtual void Load() override;
22+
virtual void Save() override;
3123
};
3224

3325
template <class T, class Store = SettingStore>
@@ -41,19 +33,19 @@ namespace REX::JSON
4133
{}
4234

4335
public:
44-
virtual void Load(void* a_file) override
45-
{
46-
Load(a_file, true);
47-
}
48-
49-
virtual void Load(void* a_file, bool a_useDefault) override
36+
virtual void Load(void* a_data, bool a_isBase) override
5037
{
51-
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_path);
38+
if (a_isBase) {
39+
Impl::SettingLoad(a_data, m_path, this->m_valueDefault, this->m_valueDefault);
40+
this->SetValue(this->m_valueDefault);
41+
} else {
42+
Impl::SettingLoad(a_data, m_path, this->m_value, this->m_valueDefault);
43+
}
5244
}
5345

54-
virtual void Save(void* a_file) override
46+
virtual void Save(void* a_data) override
5547
{
56-
detail::SettingSaveImpl(a_file, this->m_value, m_path);
48+
Impl::SettingSave(a_data, m_path, this->m_value);
5749
}
5850

5951
private:

include/REX/REX/Setting.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ namespace REX
77
class ISetting
88
{
99
public:
10-
virtual void Load(void* a_file) = 0;
11-
virtual void Load(void* a_file, bool a_useDefault) = 0;
12-
virtual void Save(void* a_file) = 0;
10+
virtual void Load(void* a_data, bool a_isBase) = 0;
11+
virtual void Save(void* a_data) = 0;
1312
};
1413

1514
class ISettingStore

include/REX/REX/TOML.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,21 @@
55
#ifdef REX_OPTION_TOML
66
namespace REX::TOML
77
{
8-
namespace detail
8+
namespace Impl
99
{
10-
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
11-
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
1210
template <class T>
13-
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_path);
11+
void SettingLoad(void* a_file, std::string_view a_path, T& a_value, T& a_valueDefault);
12+
1413
template <class T>
15-
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_path);
14+
void SettingSave(void* a_file, std::string_view a_path, T& a_value);
1615
}
1716

1817
class SettingStore :
1918
public TSettingStore<SettingStore>
2019
{
2120
public:
22-
virtual void Load() override
23-
{
24-
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
25-
}
26-
27-
virtual void Save() override
28-
{
29-
detail::StoreSaveImpl(m_fileBase, m_settings);
30-
}
21+
virtual void Load() override;
22+
virtual void Save() override;
3123
};
3224

3325
template <class T, class Store = SettingStore>
@@ -41,19 +33,19 @@ namespace REX::TOML
4133
{}
4234

4335
public:
44-
virtual void Load(void* a_file) override
45-
{
46-
Load(a_file, true);
47-
}
48-
49-
virtual void Load(void* a_file, bool a_useDefault) override
36+
virtual void Load(void* a_data, bool a_isBase) override
5037
{
51-
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_path);
38+
if (a_isBase) {
39+
Impl::SettingLoad(a_data, m_path, this->m_valueDefault, this->m_valueDefault);
40+
this->SetValue(this->m_valueDefault);
41+
} else {
42+
Impl::SettingLoad(a_data, m_path, this->m_value, this->m_valueDefault);
43+
}
5244
}
5345

54-
virtual void Save(void* a_file) override
46+
virtual void Save(void* a_data) override
5547
{
56-
detail::SettingSaveImpl(a_file, this->m_value, m_path);
48+
Impl::SettingSave(a_data, m_path, this->m_value);
5749
}
5850

5951
private:

include/SKSE/Impl/PCH.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static_assert(
5858
std::is_integral_v<std::time_t> && sizeof(std::time_t) == sizeof(std::size_t),
5959
"wrap std::time_t instead");
6060

61-
#include "REX/REX.h"
61+
#include "REX/REX/Enum.h"
62+
#include "REX/REX/EnumSet.h"
6263
#include "REX/W32/KERNEL32.h"
6364
#include "REX/W32/USER32.h"
6465

0 commit comments

Comments
 (0)