31 #ifndef LEDGER_CORE_PREFERENCES_HPP 32 #define LEDGER_CORE_PREFERENCES_HPP 34 #include "../api/Preferences.hpp" 35 #include "../api/PreferencesEditor.hpp" 36 #include "PreferencesBackend.hpp" 37 #include "PreferencesEditor.hpp" 38 #include "../utils/Option.hpp" 39 #include <cereal/cereal.hpp> 40 #include <cereal/archives/portable_binary.hpp> 41 #include <cereal/types/set.hpp> 42 #include <boost/iostreams/device/array.hpp> 43 #include <boost/iostreams/stream.hpp> 47 class PreferencesBackend;
48 class PreferencesEditor;
54 std::string
getString(
const std::string &key,
const std::string &fallbackValue)
override;
56 int32_t
getInt(
const std::string &key, int32_t fallbackValue)
override;
58 int64_t
getLong(
const std::string &key, int64_t fallbackValue)
override;
60 bool getBoolean(
const std::string &key,
bool fallbackValue)
override;
62 std::vector<std::string>
63 getStringArray(
const std::string &key,
const std::vector<std::string> &fallbackValue)
override;
65 bool contains(
const std::string &key)
override;
67 std::shared_ptr<api::PreferencesEditor>
edit()
override;
68 std::shared_ptr<PreferencesEditor> editor();
70 std::vector<uint8_t>
getData(
const std::string &key,
const std::vector<uint8_t> &fallbackValue)
override;
73 Option<T> getObject(
const std::string& key) {
75 if (data.size() == 0) {
79 boost::iostreams::array_source my_vec_source(reinterpret_cast<char*>(&data[0]), data.size());
80 boost::iostreams::stream<boost::iostreams::array_source> is(my_vec_source);
81 ::cereal::PortableBinaryInputArchive archive(is);
90 iterate([f] (leveldb::Slice&& key, leveldb::Slice&& value) {
93 boost::iostreams::array_source my_vec_source(reinterpret_cast<const char *>(&value.data()[0]),
95 boost::iostreams::stream<boost::iostreams::array_source> is(my_vec_source);
96 ::cereal::PortableBinaryInputArchive archive(is);
98 }
catch (
const std::exception& ex) {
101 return f(std::move(key),
object);
105 std::shared_ptr<Preferences> getSubPreferences(std::string prefix);
108 std::vector<uint8_t> wrapKey(
const std::string& key)
const;
112 std::vector<uint8_t> _keyPrefix;
119 #endif //LEDGER_CORE_PREFERENCES_HPP std::vector< std::string > getStringArray(const std::string &key, const std::vector< std::string > &fallbackValue) override
Definition: Preferences.cpp:73
std::vector< uint8_t > getData(const std::string &key, const std::vector< uint8_t > &fallbackValue) override
Definition: Preferences.cpp:135
std::shared_ptr< api::PreferencesEditor > edit() override
Definition: Preferences.cpp:93
Definition: Option.hpp:49
Definition: PreferencesBackend.hpp:70
Definition: PreferencesEditor.hpp:46
bool getBoolean(const std::string &key, bool fallbackValue) override
Definition: Preferences.cpp:64
Definition: Preferences.hpp:50
bool contains(const std::string &key) override
Definition: Preferences.cpp:89
Definition: Account.cpp:8
std::string getString(const std::string &key, const std::string &fallbackValue) override
Definition: Preferences.cpp:41
Definition: Preferences.hpp:29
int32_t getInt(const std::string &key, int32_t fallbackValue) override
Definition: Preferences.cpp:48
int64_t getLong(const std::string &key, int64_t fallbackValue) override
Definition: Preferences.cpp:56