summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Config/Section.cpp
diff options
context:
space:
mode:
authorMerryMage <MerryMage@users.noreply.github.com>2017-10-29 19:11:15 +0000
committerMerryMage <MerryMage@users.noreply.github.com>2017-11-15 18:04:40 +0000
commit4c24629b9551cab8af653a2bbcbe6d1639b3edb2 (patch)
tree95f17ded4d887ad4df99463e49078c5de0377aa4 /Source/Core/Common/Config/Section.cpp
parentf3b52c07d74d528a81c818d86c12981a6028f351 (diff)
Config: Flatten structures
Originally, Layer contained a std::map of Sections, which containted a std::map containing the (key, value) pairs. Here we flattern this structure so that only one std::map is required, reducing the number of indirections required and vastly simplifying the code.
Diffstat (limited to 'Source/Core/Common/Config/Section.cpp')
-rw-r--r--Source/Core/Common/Config/Section.cpp249
1 files changed, 0 insertions, 249 deletions
diff --git a/Source/Core/Common/Config/Section.cpp b/Source/Core/Common/Config/Section.cpp
deleted file mode 100644
index 12adff2b1f..0000000000
--- a/Source/Core/Common/Config/Section.cpp
+++ /dev/null
@@ -1,249 +0,0 @@
-// Copyright 2017 Dolphin Emulator Project
-// Licensed under GPLv2+
-// Refer to the license.txt file included.
-
-#include <cstddef>
-#include <map>
-#include <memory>
-
-#include "Common/Assert.h"
-#include "Common/Config/Config.h"
-#include "Common/Config/Layer.h"
-#include "Common/Config/Section.h"
-#include "Common/StringUtil.h"
-
-namespace Config
-{
-const std::string& Section::NULL_STRING = "";
-
-Section::Section(LayerType layer, System system, const std::string& name)
- : m_layer(layer), m_system(system), m_name(name)
-{
-}
-
-bool Section::Exists(const std::string& key) const
-{
- return m_values.find(key) != m_values.end();
-}
-
-bool Section::Delete(const std::string& key)
-{
- auto it = m_values.find(key);
- if (it == m_values.end())
- return false;
-
- m_values.erase(it);
-
- m_deleted_keys.push_back(key);
- m_dirty = true;
- return true;
-}
-
-void Section::Set(const std::string& key, const std::string& value)
-{
- auto it = m_values.find(key);
- if (it != m_values.end() && it->second != value)
- {
- it->second = value;
- m_dirty = true;
- }
- else if (it == m_values.end())
- {
- m_values[key] = value;
- m_dirty = true;
- }
-}
-
-void Section::Set(const std::string& key, u16 newValue)
-{
- Section::Set(key, StringFromFormat("0x%04x", newValue));
-}
-
-void Section::Set(const std::string& key, u32 newValue)
-{
- Section::Set(key, StringFromFormat("0x%08x", newValue));
-}
-
-void Section::Set(const std::string& key, float newValue)
-{
- Section::Set(key, StringFromFormat("%#.9g", newValue));
-}
-
-void Section::Set(const std::string& key, double newValue)
-{
- Section::Set(key, StringFromFormat("%#.17g", newValue));
-}
-
-void Section::Set(const std::string& key, int newValue)
-{
- Section::Set(key, std::to_string(newValue));
-}
-
-void Section::Set(const std::string& key, bool newValue)
-{
- Section::Set(key, StringFromBool(newValue));
-}
-
-void Section::Set(const std::string& key, const std::string& newValue,
- const std::string& defaultValue)
-{
- if (newValue != defaultValue)
- Set(key, newValue);
- else
- Delete(key);
-}
-
-void Section::SetLines(const std::vector<std::string>& lines)
-{
- m_lines = lines;
- m_dirty = true;
-}
-
-bool Section::Get(const std::string& key, std::string* value,
- const std::string& default_value) const
-{
- const auto& it = m_values.find(key);
- if (it != m_values.end())
- {
- *value = it->second;
- return true;
- }
- else if (&default_value != &NULL_STRING)
- {
- *value = default_value;
- return true;
- }
-
- return false;
-}
-
-bool Section::Get(const std::string& key, int* value, int defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool Section::Get(const std::string& key, u16* value, u16 defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool Section::Get(const std::string& key, u32* value, u32 defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool Section::Get(const std::string& key, bool* value, bool defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool Section::Get(const std::string& key, float* value, float defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-bool Section::Get(const std::string& key, double* value, double defaultValue) const
-{
- std::string temp;
- bool retval = Get(key, &temp);
-
- if (retval && TryParse(temp, value))
- return true;
-
- *value = defaultValue;
- return false;
-}
-
-// Return a list of all lines in a section
-bool Section::GetLines(std::vector<std::string>* lines, const bool remove_comments) const
-{
- lines->clear();
-
- for (std::string line : m_lines)
- {
- line = StripSpaces(line);
-
- if (remove_comments)
- {
- size_t commentPos = line.find('#');
- if (commentPos == 0)
- {
- continue;
- }
-
- if (commentPos != std::string::npos)
- {
- line = StripSpaces(line.substr(0, commentPos));
- }
- }
-
- lines->push_back(line);
- }
-
- return true;
-}
-
-bool Section::HasLines() const
-{
- return !m_lines.empty();
-}
-
-const std::string& Section::GetName() const
-{
- return m_name;
-}
-
-const SectionValueMap& Section::GetValues() const
-{
- return m_values;
-}
-
-const std::vector<std::string>& Section::GetDeletedKeys() const
-{
- return m_deleted_keys;
-}
-
-bool Section::IsDirty() const
-{
- return m_dirty;
-}
-void Section::ClearDirty()
-{
- m_dirty = false;
-}
-}