summaryrefslogtreecommitdiff
path: root/settings.cpp
diff options
context:
space:
mode:
authorJosh Ferrell <josh@vector35.com>2023-11-10 17:52:21 -0500
committerJosh Ferrell <josh@vector35.com>2023-11-10 17:53:16 -0500
commitd211211ac87d30e4774c01e6765c2419dce3fe1f (patch)
tree01f3becef2bfab16bcd4736cf78652ce076bbade /settings.cpp
parenta39efb484087474fdf18a40249bf0bb5b608b6f3 (diff)
Add support for object settings
Diffstat (limited to 'settings.cpp')
-rw-r--r--settings.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/settings.cpp b/settings.cpp
index 59394c42..6066aa1e 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -259,6 +259,26 @@ vector<string> Settings::Get<vector<string>>(const string& key, Ref<BinaryView>
}
+template <>
+map<string, string> Settings::Get<map<string, string>>(const string& key, Ref<BinaryView> view, BNSettingsScope* scope)
+{
+ // [[key, val], ...]
+ size_t size = 0;
+ char*** outBuffer =
+ (char***)BNSettingsGetStringObject(m_object, key.c_str(), view ? view->GetObject() : nullptr, scope, &size);
+
+ map<string, string> result;
+ for (size_t i = 0; i < size; i++)
+ {
+ char** entry = outBuffer[i];
+ result[entry[0]] = entry[1];
+ }
+
+ BNFreeStringObject(outBuffer, size);
+ return result;
+}
+
+
string Settings::GetJson(const string& key, Ref<BinaryView> view, BNSettingsScope* scope)
{
char* tmpStr = BNSettingsGetJson(m_object, key.c_str(), view ? view->GetObject() : nullptr, scope);
@@ -329,6 +349,29 @@ bool Settings::Set(const string& key, const vector<string>& value, Ref<BinaryVie
}
+bool Settings::Set(const string& key, const map<string, string>& value, Ref<BinaryView> view, BNSettingsScope scope)
+{
+ char*** buffer = new char**[value.size()];
+ if (!buffer)
+ return false;
+
+ size_t i = 0;
+ for (const auto& entry : value)
+ {
+ buffer[i] = new char*[2];
+ buffer[i][0] = BNAllocString(entry.first.c_str());
+ buffer[i][1] = BNAllocString(entry.second.c_str());
+ i++;
+ }
+
+ bool result = BNSettingsSetStringObject(
+ m_object, view ? view->GetObject() : nullptr, scope, key.c_str(), (const char***)buffer, value.size());
+
+ BNFreeStringObject(buffer, value.size());
+ return result;
+}
+
+
bool Settings::SetJson(const string& key, const string& value, Ref<BinaryView> view, BNSettingsScope scope)
{
return BNSettingsSetJson(m_object, view ? view->GetObject() : nullptr, scope, key.c_str(), value.c_str());