layered_settings_interface.h (3168B)
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 "settings_interface.h" 6 #include <array> 7 8 class LayeredSettingsInterface final : public SettingsInterface 9 { 10 public: 11 enum Layer : u32 12 { 13 LAYER_GAME, 14 LAYER_INPUT, 15 LAYER_BASE, 16 NUM_LAYERS 17 }; 18 19 LayeredSettingsInterface(); 20 ~LayeredSettingsInterface() override; 21 22 SettingsInterface* GetLayer(Layer layer) const { return m_layers[layer]; } 23 void SetLayer(Layer layer, SettingsInterface* sif) { m_layers[layer] = sif; } 24 25 bool Save(Error* error = nullptr) override; 26 27 void Clear() override; 28 29 bool IsEmpty() override; 30 31 bool GetIntValue(const char* section, const char* key, s32* value) const override; 32 bool GetUIntValue(const char* section, const char* key, u32* value) const override; 33 bool GetFloatValue(const char* section, const char* key, float* value) const override; 34 bool GetDoubleValue(const char* section, const char* key, double* value) const override; 35 bool GetBoolValue(const char* section, const char* key, bool* value) const override; 36 bool GetStringValue(const char* section, const char* key, std::string* value) const override; 37 bool GetStringValue(const char* section, const char* key, SmallStringBase* value) const override; 38 39 void SetIntValue(const char* section, const char* key, s32 value) override; 40 void SetUIntValue(const char* section, const char* key, u32 value) override; 41 void SetFloatValue(const char* section, const char* key, float value) override; 42 void SetDoubleValue(const char* section, const char* key, double value) override; 43 void SetBoolValue(const char* section, const char* key, bool value) override; 44 void SetStringValue(const char* section, const char* key, const char* value) override; 45 bool ContainsValue(const char* section, const char* key) const override; 46 void DeleteValue(const char* section, const char* key) override; 47 void ClearSection(const char* section) override; 48 void RemoveSection(const char* section) override; 49 void RemoveEmptySections() override; 50 51 std::vector<std::string> GetStringList(const char* section, const char* key) const override; 52 void SetStringList(const char* section, const char* key, const std::vector<std::string>& items) override; 53 bool RemoveFromStringList(const char* section, const char* key, const char* item) override; 54 bool AddToStringList(const char* section, const char* key, const char* item) override; 55 56 std::vector<std::pair<std::string, std::string>> GetKeyValueList(const char* section) const override; 57 void SetKeyValueList(const char* section, const std::vector<std::pair<std::string, std::string>>& items) override; 58 59 // default parameter overloads 60 using SettingsInterface::GetBoolValue; 61 using SettingsInterface::GetDoubleValue; 62 using SettingsInterface::GetFloatValue; 63 using SettingsInterface::GetIntValue; 64 using SettingsInterface::GetStringValue; 65 using SettingsInterface::GetUIntValue; 66 67 private: 68 static constexpr Layer FIRST_LAYER = LAYER_GAME; 69 static constexpr Layer LAST_LAYER = LAYER_BASE; 70 71 std::array<SettingsInterface*, NUM_LAYERS> m_layers{}; 72 };