summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2020-01-29 16:42:19 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2020-02-06 23:54:19 +0200
commitf30aec6c1a4397e524dc885767ccb349856fed0b (patch)
tree5aed895a2237a64dc8ffc5d565ff0cb73487fa44 /include
parentd4d96fd88c83a5640fdef408f1ff3f69db0a584c (diff)
downloadqtlocation-mapboxgl-f30aec6c1a4397e524dc885767ccb349856fed0b.tar.gz
[core] Add global settings object
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/platform/settings.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/mbgl/platform/settings.hpp b/include/mbgl/platform/settings.hpp
new file mode 100644
index 0000000000..80bfe1d60f
--- /dev/null
+++ b/include/mbgl/platform/settings.hpp
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <mapbox/value.hpp>
+
+#include <memory>
+
+namespace mbgl {
+namespace platform {
+
+#define DECLARE_MAPBOX_SETTING(name, value) constexpr const char* name = "mapbox_" #value
+
+// The value for EXPERIMENTAL_THREAD_PRIORITY_* keys, must be a double.
+DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_WORKER, thread_priority_worker);
+DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_FILE, thread_priority_file);
+DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_NETWORK, thread_priority_network);
+DECLARE_MAPBOX_SETTING(EXPERIMENTAL_THREAD_PRIORITY_DATABASE, thread_priority_database);
+
+// Settings class provides non-persistent, in-process key-value storage.
+class Settings final {
+public:
+ // Returns singleton instance
+ static Settings& getInstance() noexcept;
+
+ // Sets setting value for a specified key.
+ void set(const std::string& key, mapbox::base::Value value) noexcept;
+
+ // Sets multiple setting values by merging current Settings object
+ // with provided `values` object.
+ void set(mapbox::base::ValueObject values) noexcept;
+
+ // Returns setting value for a specified key or NullValue if element
+ // for specified key is missing.
+ mapbox::base::Value get(const std::string& key) const noexcept;
+
+ // Returns values for settings whose keys are equal to the ones provided in `keys` argument.
+ // Null values would be provided for keys whose elements are missing in Settings.
+ mapbox::base::ValueObject get(const std::vector<std::string>& keys) const noexcept;
+
+private:
+ Settings();
+
+private:
+ class Impl;
+ std::unique_ptr<Impl> impl;
+};
+
+} // namespace platform
+} // namespace mbgl