From 80cb1f68c83112c4d99893ad2f23bf22abdc4a6d Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Sun, 14 Oct 2018 22:47:22 -0400 Subject: Initial Enhanced Settings System. --- binaryninjaapi.h | 85 +++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 44 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 4afc8617..6f6778da 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4211,54 +4211,51 @@ namespace BinaryNinja Ref GetDefaultRepository(); }; - class Setting + class Settings { + std::string m_registry; + public: - static bool GetBool(const std::string& settingGroup, const std::string& name, bool defaultValue); - static int64_t GetInteger(const std::string& settingGroup, const std::string& name, int64_t defaultValue=0); - static std::string GetString(const std::string& settingGroup, const std::string& name, const std::string& defaultValue=""); - static std::vector GetIntegerList(const std::string& settingGroup, const std::string& name, const std::vector& defaultValue={}); - static std::vector GetStringList(const std::string& settingGroup, const std::string& name, const std::vector& defaultValue={}); - static double GetDouble(const std::string& settingGroup, const std::string& name, double defaultValue=0.0); - - static bool IsPresent(const std::string& settingGroup, const std::string& name); - static bool IsBool(const std::string& settingGroup, const std::string& name); - static bool IsInteger(const std::string& settingGroup, const std::string& name); - static bool IsString(const std::string& settingGroup, const std::string& name); - static bool IsIntegerList(const std::string& settingGroup, const std::string& name); - static bool IsStringList(const std::string& settingGroup, const std::string& name); - static bool IsDouble(const std::string& settingGroup, const std::string& name); - - static bool Set(const std::string& settingGroup, - const std::string& name, - bool value, - bool autoFlush=true); - static bool Set(const std::string& settingGroup, - const std::string& name, - int64_t value, - bool autoFlush=true); - static bool Set(const std::string& settingGroup, - const std::string& name, - const std::string& value, - bool autoFlush=true); - static bool Set(const std::string& settingGroup, - const std::string& name, - const std::vector& value, - bool autoFlush=true); - static bool Set(const std::string& settingGroup, - const std::string& name, - const std::vector& value, - bool autoFlush=true); - static bool Set(const std::string& settingGroup, - const std::string& name, - double value, - bool autoFlush=true); - - static bool RemoveSettingGroup(const std::string& settingGroup, bool autoFlush=true); - static bool RemoveSetting(const std::string& settingGroup, const std::string& setting, bool autoFlush=true); - static bool FlushSettings(); + Settings(const std::string& registry = "default") : m_registry(registry) { } + + bool RegisterGroup(const std::string& group, const std::string& title); + bool RegisterSetting(const std::string& id, const std::string& properties); + + bool UpdateProperty(const std::string& id, const std::string& property); + bool UpdateProperty(const std::string& id, const std::string& property, bool value); + bool UpdateProperty(const std::string& id, const std::string& property, double value); + bool UpdateProperty(const std::string& id, const std::string& property, int value); + bool UpdateProperty(const std::string& id, const std::string& property, int64_t value); + bool UpdateProperty(const std::string& id, const std::string& property, uint64_t value); + bool UpdateProperty(const std::string& id, const std::string& property, const char* value); + bool UpdateProperty(const std::string& id, const std::string& property, const std::string& value); + bool UpdateProperty(const std::string& id, const std::string& property, const std::vector& value); + + std::string GetSchema(); + + bool Reset(const std::string& id, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool ResetAll(Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + + template T Get(const std::string& id, Ref view = nullptr, BNSettingsScope* scope = nullptr); + + bool Set(const std::string& id, bool value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, double value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, int value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, int64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, uint64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, const char* value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, const std::string& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& id, const std::vector& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); }; + // explicit specializations + template<> bool Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); + template<> double Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); + template<> int64_t Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); + template<> uint64_t Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); + template<> std::string Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); + template<> std::vector Settings::Get>(const std::string& id, Ref view, BNSettingsScope* scope); + typedef BNMetadataType MetadataType; class Metadata: public CoreRefCountObject -- cgit v1.3.1