Skip to content

Commit

Permalink
feat: improve settings
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Nov 13, 2024
1 parent 9c9e481 commit ebfda8b
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 869 deletions.
38 changes: 15 additions & 23 deletions include/REX/REX/INI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,21 @@
#ifdef REX_OPTION_INI
namespace REX::INI
{
namespace detail
namespace Impl
{
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
template <class T>
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_section, std::string_view& a_key);
void SettingLoad(void* a_file, std::string_view a_section, std::string_view a_key, T& a_value, T& a_valueDefault);

template <class T>
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_section, std::string_view& a_key);
void SettingSave(void* a_file, std::string_view a_section, std::string_view a_key, T& a_value);
}

class SettingStore :
public TSettingStore<SettingStore>
{
public:
virtual void Load() override
{
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
}

virtual void Save() override
{
detail::StoreSaveImpl(m_fileBase, m_settings);
}
virtual void Load() override;
virtual void Save() override;
};

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

public:
virtual void Load(void* a_file) override
{
Load(a_file, true);
}

virtual void Load(void* a_file, bool a_useDefault) override
virtual void Load(void* a_data, bool a_isBase) override
{
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_section, m_key);
if (a_isBase) {
Impl::SettingLoad(a_data, m_section, m_key, this->m_valueDefault, this->m_valueDefault);
this->SetValue(this->m_valueDefault);
} else {
Impl::SettingLoad(a_data, m_section, m_key, this->m_value, this->m_valueDefault);
}
}

virtual void Save(void* a_file) override
virtual void Save(void* a_data) override
{
detail::SettingSaveImpl(a_file, this->m_value, m_section, m_key);
Impl::SettingSave(a_data, m_section, m_key, this->m_value);
}

private:
Expand Down
38 changes: 15 additions & 23 deletions include/REX/REX/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,21 @@
#ifdef REX_OPTION_JSON
namespace REX::JSON
{
namespace detail
namespace Impl
{
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
template <class T>
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_path);
void SettingLoad(void* a_file, std::string_view a_path, T& a_value, T& a_valueDefault);

template <class T>
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_path);
void SettingSave(void* a_file, std::string_view a_path, T& a_value);
}

class SettingStore :
public TSettingStore<SettingStore>
{
public:
virtual void Load() override
{
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
}

virtual void Save() override
{
detail::StoreSaveImpl(m_fileBase, m_settings);
}
virtual void Load() override;
virtual void Save() override;
};

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

public:
virtual void Load(void* a_file) override
{
Load(a_file, true);
}

virtual void Load(void* a_file, bool a_useDefault) override
virtual void Load(void* a_data, bool a_isBase) override
{
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_path);
if (a_isBase) {
Impl::SettingLoad(a_data, m_path, this->m_valueDefault, this->m_valueDefault);
this->SetValue(this->m_valueDefault);
} else {
Impl::SettingLoad(a_data, m_path, this->m_value, this->m_valueDefault);
}
}

virtual void Save(void* a_file) override
virtual void Save(void* a_data) override
{
detail::SettingSaveImpl(a_file, this->m_value, m_path);
Impl::SettingSave(a_data, m_path, this->m_value);
}

private:
Expand Down
5 changes: 2 additions & 3 deletions include/REX/REX/Setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ namespace REX
class ISetting
{
public:
virtual void Load(void* a_file) = 0;
virtual void Load(void* a_file, bool a_useDefault) = 0;
virtual void Save(void* a_file) = 0;
virtual void Load(void* a_data, bool a_isBase) = 0;
virtual void Save(void* a_data) = 0;
};

class ISettingStore
Expand Down
38 changes: 15 additions & 23 deletions include/REX/REX/TOML.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,21 @@
#ifdef REX_OPTION_TOML
namespace REX::TOML
{
namespace detail
namespace Impl
{
void StoreLoadImpl(std::string_view& a_fileBase, std::string_view& a_fileUser, std::vector<ISetting*>& a_settings);
void StoreSaveImpl(std::string_view& a_fileBase, std::vector<ISetting*>& a_settings);
template <class T>
void SettingLoadImpl(void* a_file, T& a_value, T& a_valueDefault, bool a_useDefault, std::string_view& a_path);
void SettingLoad(void* a_file, std::string_view a_path, T& a_value, T& a_valueDefault);

template <class T>
void SettingSaveImpl(void* a_file, T& a_value, std::string_view& a_path);
void SettingSave(void* a_file, std::string_view a_path, T& a_value);
}

class SettingStore :
public TSettingStore<SettingStore>
{
public:
virtual void Load() override
{
detail::StoreLoadImpl(m_fileBase, m_fileUser, m_settings);
}

virtual void Save() override
{
detail::StoreSaveImpl(m_fileBase, m_settings);
}
virtual void Load() override;
virtual void Save() override;
};

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

public:
virtual void Load(void* a_file) override
{
Load(a_file, true);
}

virtual void Load(void* a_file, bool a_useDefault) override
virtual void Load(void* a_data, bool a_isBase) override
{
detail::SettingLoadImpl(a_file, this->m_value, this->m_valueDefault, a_useDefault, m_path);
if (a_isBase) {
Impl::SettingLoad(a_data, m_path, this->m_valueDefault, this->m_valueDefault);
this->SetValue(this->m_valueDefault);
} else {
Impl::SettingLoad(a_data, m_path, this->m_value, this->m_valueDefault);
}
}

virtual void Save(void* a_file) override
virtual void Save(void* a_data) override
{
detail::SettingSaveImpl(a_file, this->m_value, m_path);
Impl::SettingSave(a_data, m_path, this->m_value);
}

private:
Expand Down
3 changes: 2 additions & 1 deletion include/SKSE/Impl/PCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static_assert(
std::is_integral_v<std::time_t> && sizeof(std::time_t) == sizeof(std::size_t),
"wrap std::time_t instead");

#include "REX/REX.h"
#include "REX/REX/Enum.h"
#include "REX/REX/EnumSet.h"
#include "REX/W32/KERNEL32.h"
#include "REX/W32/USER32.h"

Expand Down
Loading

0 comments on commit ebfda8b

Please sign in to comment.