From 88ec179d9519221744240e347bc94da09bbc2157 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 1 Jul 2017 16:41:36 -0400 Subject: expose Settings 'Set' APIs to C++ --- settings.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'settings.cpp') diff --git a/settings.cpp b/settings.cpp index b7e08793..a60b7e3a 100644 --- a/settings.cpp +++ b/settings.cpp @@ -96,3 +96,69 @@ bool Setting::IsDouble(const std::string& pluginName, const std::string& name) { return BNSettingIsDouble(pluginName.c_str(), name.c_str()); } + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + bool value, + bool autoFlush) +{ + return BNSettingSetBool(settingGroup.c_str(), name.c_str(), value, autoFlush); +} + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + uint64_t value, + bool autoFlush) +{ + return BNSettingSetInteger(settingGroup.c_str(), name.c_str(), value, autoFlush); +} + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + const std::string& value, + bool autoFlush) +{ + return BNSettingSetString(settingGroup.c_str(), name.c_str(), value.c_str(), autoFlush); +} + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + const std::vector& value, + bool autoFlush) +{ + return BNSettingSetIntegerList(settingGroup.c_str(), name.c_str(), &value[0], value.size(), autoFlush); +} + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + const std::vector& value, + bool autoFlush) +{ + char** buffer = new char*[value.size()]; + if (!buffer) + return false; + for (size_t i = 0; i < value.size(); i++) + buffer[i] = BNAllocString(value[i].c_str()); + + bool result = BNSettingSetStringList(settingGroup.c_str(), + name.c_str(), + (const char**)buffer, + value.size(), + autoFlush); + + BNFreeStringList(buffer, value.size()); + return result; +} + +bool Setting::Set(const std::string& settingGroup, + const std::string& name, + double value, + bool autoFlush) +{ + return BNSettingSetDouble(settingGroup.c_str(), name.c_str(), value, autoFlush); +} + +bool Setting::FlushSettings() +{ + return BNSettingFlushSettings(); +} \ No newline at end of file -- cgit v1.3.1