ini_settings_interface.h (3034B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 #include "common/settings_interface.h" 6 7 // being a pain here... 8 #ifdef _WIN32 9 #include "common/windows_headers.h" 10 #endif 11 #include "SimpleIni.h" 12 13 class INISettingsInterface final : public SettingsInterface 14 { 15 public: 16 INISettingsInterface(std::string filename); 17 ~INISettingsInterface() override; 18 19 const std::string& GetFileName() const { return m_filename; } 20 21 bool Load(Error* error = nullptr); 22 bool Save(Error* error = nullptr) override; 23 24 void Clear() override; 25 bool IsEmpty() override; 26 27 bool GetIntValue(const char* section, const char* key, s32* value) const override; 28 bool GetUIntValue(const char* section, const char* key, u32* value) const override; 29 bool GetFloatValue(const char* section, const char* key, float* value) const override; 30 bool GetDoubleValue(const char* section, const char* key, double* value) const override; 31 bool GetBoolValue(const char* section, const char* key, bool* value) const override; 32 bool GetStringValue(const char* section, const char* key, std::string* value) const override; 33 bool GetStringValue(const char* section, const char* key, SmallStringBase* value) const override; 34 35 void SetIntValue(const char* section, const char* key, s32 value) override; 36 void SetUIntValue(const char* section, const char* key, u32 value) override; 37 void SetFloatValue(const char* section, const char* key, float value) override; 38 void SetDoubleValue(const char* section, const char* key, double value) override; 39 void SetBoolValue(const char* section, const char* key, bool value) override; 40 void SetStringValue(const char* section, const char* key, const char* value) override; 41 bool ContainsValue(const char* section, const char* key) const override; 42 void DeleteValue(const char* section, const char* key) override; 43 void ClearSection(const char* section) override; 44 void RemoveSection(const char* section) override; 45 void RemoveEmptySections() override; 46 47 std::vector<std::string> GetStringList(const char* section, const char* key) const override; 48 void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override; 49 bool RemoveFromStringList(const char* section, const char* key, const char* item) override; 50 bool AddToStringList(const char* section, const char* key, const char* item) override; 51 52 std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override; 53 void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override; 54 55 // default parameter overloads 56 using SettingsInterface::GetBoolValue; 57 using SettingsInterface::GetDoubleValue; 58 using SettingsInterface::GetFloatValue; 59 using SettingsInterface::GetIntValue; 60 using SettingsInterface::GetStringValue; 61 using SettingsInterface::GetUIntValue; 62 63 private: 64 std::string m_filename; 65 CSimpleIniA m_ini; 66 bool m_dirty = false; 67 };