Add MemorySettingsInterface

This commit is contained in:
Connor McLaughlin
2022-07-09 14:17:57 +10:00
parent 462eb2c155
commit f6b3652ae6
11 changed files with 395 additions and 213 deletions

View File

@ -3,8 +3,6 @@ add_executable(duckstation-regtest
regtest_host_display.h
regtest_host_interface.cpp
regtest_host_interface.h
regtest_settings_interface.cpp
regtest_settings_interface.h
)
target_link_libraries(duckstation-regtest PRIVATE core common frontend-common scmversion)

View File

@ -7,12 +7,10 @@
<ItemGroup>
<ClCompile Include="regtest_host_display.cpp" />
<ClCompile Include="regtest_host_interface.cpp" />
<ClCompile Include="regtest_settings_interface.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="regtest_host_display.h" />
<ClInclude Include="regtest_host_interface.h" />
<ClInclude Include="regtest_settings_interface.h" />
</ItemGroup>
<Import Project="..\..\dep\msvc\vsprops\ConsoleApplication.props" />
<Import Project="..\frontend-common\frontend-common.props" />

View File

@ -3,11 +3,9 @@
<ItemGroup>
<ClCompile Include="regtest_host_interface.cpp" />
<ClCompile Include="regtest_host_display.cpp" />
<ClCompile Include="regtest_settings_interface.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="regtest_host_interface.h" />
<ClInclude Include="regtest_host_display.h" />
<ClInclude Include="regtest_settings_interface.h" />
</ItemGroup>
</Project>

View File

@ -1,6 +1,6 @@
#pragma once
#include "core/host_interface.h"
#include "regtest_settings_interface.h"
#include "common/memory_settings_interface.h"
class RegTestHostInterface final : public HostInterface
{
@ -60,6 +60,6 @@ private:
void InitializeSettings();
void UpdateSettings();
RegTestSettingsInterface m_settings_interface;
MemorySettingsInterface m_settings_interface;
std::recursive_mutex m_settings_mutex;
};

View File

@ -1,198 +0,0 @@
#include "regtest_settings_interface.h"
#include "common/assert.h"
#include "common/log.h"
#include "common/string_util.h"
Log_SetChannel(RegTestSettingsInterface);
RegTestSettingsInterface::RegTestSettingsInterface() = default;
RegTestSettingsInterface::~RegTestSettingsInterface() = default;
bool RegTestSettingsInterface::Save()
{
return false;
}
void RegTestSettingsInterface::Clear()
{
m_keys.clear();
}
static std::string GetFullKey(const char* section, const char* key)
{
return StringUtil::StdStringFromFormat("%s/%s", section, key);
}
bool RegTestSettingsInterface::GetIntValue(const char* section, const char* key, s32* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
std::optional<s32> parsed = StringUtil::FromChars<s32>(iter->second, 10);
if (!parsed.has_value())
return false;
*value = parsed.value();
return true;
}
bool RegTestSettingsInterface::GetUIntValue(const char* section, const char* key, u32* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
std::optional<u32> parsed = StringUtil::FromChars<u32>(iter->second, 10);
if (!parsed.has_value())
return false;
*value = parsed.value();
return true;
}
bool RegTestSettingsInterface::GetFloatValue(const char* section, const char* key, float* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
std::optional<float> parsed = StringUtil::FromChars<float>(iter->second);
if (!parsed.has_value())
return false;
*value = parsed.value();
return true;
}
bool RegTestSettingsInterface::GetDoubleValue(const char* section, const char* key, double* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
std::optional<double> parsed = StringUtil::FromChars<double>(iter->second);
if (!parsed.has_value())
return false;
*value = parsed.value();
return true;
}
bool RegTestSettingsInterface::GetBoolValue(const char* section, const char* key, bool* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
std::optional<bool> parsed = StringUtil::FromChars<bool>(iter->second);
if (!parsed.has_value())
return false;
*value = parsed.value();
return true;
}
bool RegTestSettingsInterface::GetStringValue(const char* section, const char* key, std::string* value) const
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter == m_keys.end())
return false;
*value = iter->second;
return true;
}
void RegTestSettingsInterface::SetIntValue(const char* section, const char* key, s32 value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = std::to_string(value);
}
void RegTestSettingsInterface::SetUIntValue(const char* section, const char* key, u32 value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = std::to_string(value);
}
void RegTestSettingsInterface::SetFloatValue(const char* section, const char* key, float value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = std::to_string(value);
}
void RegTestSettingsInterface::SetDoubleValue(const char* section, const char* key, double value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = std::to_string(value);
}
void RegTestSettingsInterface::SetBoolValue(const char* section, const char* key, bool value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = std::string(value ? "true" : "false");
}
void RegTestSettingsInterface::SetStringValue(const char* section, const char* key, const char* value)
{
const std::string fullkey(GetFullKey(section, key));
m_keys[std::move(fullkey)] = value;
}
std::vector<std::string> RegTestSettingsInterface::GetStringList(const char* section, const char* key) const
{
std::vector<std::string> ret;
Panic("Not implemented");
return ret;
}
void RegTestSettingsInterface::SetStringList(const char* section, const char* key,
const std::vector<std::string>& items)
{
Panic("Not implemented");
}
bool RegTestSettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
{
Panic("Not implemented");
return false;
}
bool RegTestSettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
{
Panic("Not implemented");
return false;
}
bool RegTestSettingsInterface::ContainsValue(const char* section, const char* key) const
{
const std::string fullkey(GetFullKey(section, key));
return (m_keys.find(fullkey) != m_keys.end());
}
void RegTestSettingsInterface::DeleteValue(const char* section, const char* key)
{
const std::string fullkey(GetFullKey(section, key));
auto iter = m_keys.find(fullkey);
if (iter != m_keys.end())
m_keys.erase(iter);
}
void RegTestSettingsInterface::ClearSection(const char* section)
{
const std::string start(StringUtil::StdStringFromFormat("%s/", section));
for (auto iter = m_keys.begin(); iter != m_keys.end();)
{
if (StringUtil::StartsWith(iter->first, start.c_str()))
iter = m_keys.erase(iter);
else
++iter;
}
}

View File

@ -1,49 +0,0 @@
#pragma once
#include "core/settings.h"
#include <string>
#include <unordered_map>
class RegTestSettingsInterface final : public SettingsInterface
{
public:
RegTestSettingsInterface();
~RegTestSettingsInterface();
bool Save() override;
void Clear() override;
bool GetIntValue(const char* section, const char* key, s32* value) const override;
bool GetUIntValue(const char* section, const char* key, u32* value) const override;
bool GetFloatValue(const char* section, const char* key, float* value) const override;
bool GetDoubleValue(const char* section, const char* key, double* value) const override;
bool GetBoolValue(const char* section, const char* key, bool* value) const override;
bool GetStringValue(const char* section, const char* key, std::string* value) const override;
void SetIntValue(const char* section, const char* key, s32 value) override;
void SetUIntValue(const char* section, const char* key, u32 value) override;
void SetFloatValue(const char* section, const char* key, float value) override;
void SetDoubleValue(const char* section, const char* key, double value) override;
void SetBoolValue(const char* section, const char* key, bool value) override;
void SetStringValue(const char* section, const char* key, const char* value) override;
bool ContainsValue(const char* section, const char* key) const override;
void DeleteValue(const char* section, const char* key) override;
void ClearSection(const char* section) override;
std::vector<std::string> GetStringList(const char* section, const char* key) const override;
void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override;
bool RemoveFromStringList(const char* section, const char* key, const char* item) override;
bool AddToStringList(const char* section, const char* key, const char* item) override;
// default parameter overloads
using SettingsInterface::GetBoolValue;
using SettingsInterface::GetDoubleValue;
using SettingsInterface::GetFloatValue;
using SettingsInterface::GetIntValue;
using SettingsInterface::GetStringValue;
using SettingsInterface::GetUIntValue;
private:
using KeyMap = std::unordered_map<std::string, std::string>;
KeyMap m_keys;
};