mirror of https://github.com/stella-emu/stella.git
More conversion of 'const string&' to 'string_view'.
This commit is contained in:
parent
adbedfbbcf
commit
d4f1509def
|
@ -23,11 +23,11 @@
|
||||||
namespace {
|
namespace {
|
||||||
class ProxyRepository : public KeyValueRepository {
|
class ProxyRepository : public KeyValueRepository {
|
||||||
public:
|
public:
|
||||||
ProxyRepository(KeyValueRepositoryAtomic& kvr, const string& key)
|
ProxyRepository(KeyValueRepositoryAtomic& kvr, string_view key)
|
||||||
: myKvr{kvr}, myKey{key}
|
: myKvr{kvr}, myKey{key}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::map<string, Variant> load() override {
|
KVRMap load() override {
|
||||||
if (!myKvr.has(myKey)) return {};
|
if (!myKvr.has(myKey)) return {};
|
||||||
|
|
||||||
Variant serialized;
|
Variant serialized;
|
||||||
|
@ -38,7 +38,7 @@ namespace {
|
||||||
return KeyValueRepositoryJsonFile::load(in);
|
return KeyValueRepositoryJsonFile::load(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool save(const std::map<string, Variant>& values) override {
|
bool save(const KVRMap& values) override {
|
||||||
stringstream out;
|
stringstream out;
|
||||||
|
|
||||||
if (!KeyValueRepositoryJsonFile::save(out, values)) return false;
|
if (!KeyValueRepositoryJsonFile::save(out, values)) return false;
|
||||||
|
@ -50,7 +50,7 @@ namespace {
|
||||||
|
|
||||||
// NOLINT: cppcoreguidelines-avoid-const-or-ref-data-members
|
// NOLINT: cppcoreguidelines-avoid-const-or-ref-data-members
|
||||||
KeyValueRepositoryAtomic& myKvr; // NOLINT
|
KeyValueRepositoryAtomic& myKvr; // NOLINT
|
||||||
const string& myKey; // NOLINT
|
string myKey;
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -61,19 +61,19 @@ CompositeKVRJsonAdapter::CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
shared_ptr<KeyValueRepository> CompositeKVRJsonAdapter::get(const string& key)
|
shared_ptr<KeyValueRepository> CompositeKVRJsonAdapter::get(string_view key)
|
||||||
{
|
{
|
||||||
return make_shared<ProxyRepository>(myKvr, key);
|
return make_shared<ProxyRepository>(myKvr, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CompositeKVRJsonAdapter::has(const string& key)
|
bool CompositeKVRJsonAdapter::has(string_view key)
|
||||||
{
|
{
|
||||||
return myKvr.has(key);
|
return myKvr.has(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CompositeKVRJsonAdapter::remove(const string& key)
|
void CompositeKVRJsonAdapter::remove(string_view key)
|
||||||
{
|
{
|
||||||
return myKvr.remove(key);
|
return myKvr.remove(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,11 @@ class CompositeKVRJsonAdapter : public CompositeKeyValueRepository {
|
||||||
|
|
||||||
explicit CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr);
|
explicit CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr);
|
||||||
|
|
||||||
shared_ptr<KeyValueRepository> get(const string& key) override;
|
shared_ptr<KeyValueRepository> get(string_view key) override;
|
||||||
|
|
||||||
bool has(const string& key) override;
|
bool has(string_view key) override;
|
||||||
|
|
||||||
void remove(const string& key) override;
|
void remove(string_view key) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -18,32 +18,34 @@
|
||||||
#include "repository/CompositeKeyValueRepository.hxx"
|
#include "repository/CompositeKeyValueRepository.hxx"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CompositeKeyValueRepositoryAtomic::get(const string& key1, const string& key2, Variant& value)
|
bool CompositeKeyValueRepositoryAtomic::get(string_view key1, string_view key2,
|
||||||
|
Variant& value)
|
||||||
{
|
{
|
||||||
return getAtomic(key1)->get(key2, value);
|
return getAtomic(key1)->get(key2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
shared_ptr<KeyValueRepositoryAtomic> CompositeKeyValueRepositoryAtomic::getAtomic(const string& key)
|
shared_ptr<KeyValueRepositoryAtomic> CompositeKeyValueRepositoryAtomic::getAtomic(string_view key)
|
||||||
{
|
{
|
||||||
auto repo = get(key);
|
auto repo = get(key);
|
||||||
return {repo, repo->atomic()};
|
return {repo, repo->atomic()};
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CompositeKeyValueRepositoryAtomic::save(const string& key1, const string& key2, const Variant& value)
|
bool CompositeKeyValueRepositoryAtomic::save(string_view key1, string_view key2,
|
||||||
|
const Variant& value)
|
||||||
{
|
{
|
||||||
return getAtomic(key1)->save(key2, value);
|
return getAtomic(key1)->save(key2, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CompositeKeyValueRepositoryAtomic::has(const string& key1, const string& key2)
|
bool CompositeKeyValueRepositoryAtomic::has(string_view key1, string_view key2)
|
||||||
{
|
{
|
||||||
return getAtomic(key1)->has(key2);
|
return getAtomic(key1)->has(key2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CompositeKeyValueRepositoryAtomic::remove(const string& key1, const string& key2)
|
void CompositeKeyValueRepositoryAtomic::remove(string_view key1, string_view key2)
|
||||||
{
|
{
|
||||||
getAtomic(key1)->remove(key2);
|
getAtomic(key1)->remove(key2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,11 @@ class CompositeKeyValueRepository
|
||||||
|
|
||||||
virtual ~CompositeKeyValueRepository() = default;
|
virtual ~CompositeKeyValueRepository() = default;
|
||||||
|
|
||||||
virtual shared_ptr<KeyValueRepository> get(const string& key) = 0;
|
virtual shared_ptr<KeyValueRepository> get(string_view key) = 0;
|
||||||
|
|
||||||
virtual bool has(const string& key) = 0;
|
virtual bool has(string_view key) = 0;
|
||||||
|
|
||||||
virtual void remove(const string& key) = 0;
|
virtual void remove(string_view key) = 0;
|
||||||
|
|
||||||
virtual CompositeKeyValueRepositoryAtomic* atomic() { return nullptr; }
|
virtual CompositeKeyValueRepositoryAtomic* atomic() { return nullptr; }
|
||||||
|
|
||||||
|
@ -55,15 +55,15 @@ class CompositeKeyValueRepositoryAtomic : public CompositeKeyValueRepository
|
||||||
using CompositeKeyValueRepository::remove;
|
using CompositeKeyValueRepository::remove;
|
||||||
using CompositeKeyValueRepository::has;
|
using CompositeKeyValueRepository::has;
|
||||||
|
|
||||||
virtual bool get(const string& key1, const string& key2, Variant& value);
|
virtual bool get(string_view key1, string_view key2, Variant& value);
|
||||||
|
|
||||||
virtual shared_ptr<KeyValueRepositoryAtomic> getAtomic(const string& key);
|
virtual shared_ptr<KeyValueRepositoryAtomic> getAtomic(string_view key);
|
||||||
|
|
||||||
virtual bool save(const string& key1, const string& key2, const Variant& value);
|
virtual bool save(string_view key1, string_view key2, const Variant& value);
|
||||||
|
|
||||||
virtual bool has(const string& key1, const string& key2);
|
virtual bool has(string_view key1, string_view key2);
|
||||||
|
|
||||||
virtual void remove(const string& key1, const string& key2);
|
virtual void remove(string_view key1, string_view key2);
|
||||||
|
|
||||||
CompositeKeyValueRepositoryAtomic* atomic() override { return this; }
|
CompositeKeyValueRepositoryAtomic* atomic() override { return this; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,13 +29,13 @@ class CompositeKeyValueRepositoryNoop : public CompositeKeyValueRepositoryAtomic
|
||||||
using CompositeKeyValueRepositoryAtomic::remove;
|
using CompositeKeyValueRepositoryAtomic::remove;
|
||||||
using CompositeKeyValueRepositoryAtomic::get;
|
using CompositeKeyValueRepositoryAtomic::get;
|
||||||
|
|
||||||
shared_ptr<KeyValueRepository> get(const string& key) override {
|
shared_ptr<KeyValueRepository> get(string_view key) override {
|
||||||
return make_shared<KeyValueRepositoryNoop>();
|
return make_shared<KeyValueRepositoryNoop>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has(const string& key) override { return false; }
|
bool has(string_view key) override { return false; }
|
||||||
|
|
||||||
void remove(const string& key) override {}
|
void remove(string_view key) override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMPOSITE_KEY_VALUE_REPOSITORY_NOOP_HXX
|
#endif // COMPOSITE_KEY_VALUE_REPOSITORY_NOOP_HXX
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "Variant.hxx"
|
#include "Variant.hxx"
|
||||||
#include "bspf.hxx"
|
#include "bspf.hxx"
|
||||||
|
|
||||||
|
using KVRMap = std::map<string, Variant, std::less<>>;
|
||||||
|
|
||||||
class KeyValueRepositoryAtomic;
|
class KeyValueRepositoryAtomic;
|
||||||
|
|
||||||
class KeyValueRepository
|
class KeyValueRepository
|
||||||
|
@ -31,9 +33,9 @@ class KeyValueRepository
|
||||||
KeyValueRepository() = default;
|
KeyValueRepository() = default;
|
||||||
virtual ~KeyValueRepository() = default;
|
virtual ~KeyValueRepository() = default;
|
||||||
|
|
||||||
virtual std::map<string, Variant> load() = 0;
|
virtual KVRMap load() = 0;
|
||||||
|
|
||||||
virtual bool save(const std::map<string, Variant>& values) = 0;
|
virtual bool save(const KVRMap& values) = 0;
|
||||||
|
|
||||||
virtual KeyValueRepositoryAtomic* atomic() { return nullptr; }
|
virtual KeyValueRepositoryAtomic* atomic() { return nullptr; }
|
||||||
|
|
||||||
|
@ -49,13 +51,13 @@ class KeyValueRepositoryAtomic : public KeyValueRepository {
|
||||||
public:
|
public:
|
||||||
using KeyValueRepository::save;
|
using KeyValueRepository::save;
|
||||||
|
|
||||||
virtual bool has(const string& key) = 0;
|
virtual bool has(string_view key) = 0;
|
||||||
|
|
||||||
virtual bool get(const string& key, Variant& value) = 0;
|
virtual bool get(string_view key, Variant& value) = 0;
|
||||||
|
|
||||||
virtual bool save(const string& key, const Variant& value) = 0;
|
virtual bool save(string_view key, const Variant& value) = 0;
|
||||||
|
|
||||||
virtual void remove(const string& key) = 0;
|
virtual void remove(string_view key) = 0;
|
||||||
|
|
||||||
KeyValueRepositoryAtomic* atomic() override { return this; }
|
KeyValueRepositoryAtomic* atomic() override { return this; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,9 +25,9 @@ KeyValueRepositoryConfigfile::KeyValueRepositoryConfigfile(const FSNode& file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
std::map<string, Variant> KeyValueRepositoryConfigfile::load(istream& in)
|
KVRMap KeyValueRepositoryConfigfile::load(istream& in)
|
||||||
{
|
{
|
||||||
std::map<string, Variant> values;
|
KVRMap values;
|
||||||
|
|
||||||
string line, key, value;
|
string line, key, value;
|
||||||
string::size_type equalPos = 0, garbage = 0;
|
string::size_type equalPos = 0, garbage = 0;
|
||||||
|
@ -61,7 +61,7 @@ std::map<string, Variant> KeyValueRepositoryConfigfile::load(istream& in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool KeyValueRepositoryConfigfile::save(ostream& out, const std::map<string, Variant>& values)
|
bool KeyValueRepositoryConfigfile::save(ostream& out, const KVRMap& values)
|
||||||
{
|
{
|
||||||
out << "; Stella configuration file" << endl
|
out << "; Stella configuration file" << endl
|
||||||
<< ";" << endl
|
<< ";" << endl
|
||||||
|
|
|
@ -29,9 +29,9 @@ class KeyValueRepositoryConfigfile : public KeyValueRepositoryFile<KeyValueRepos
|
||||||
|
|
||||||
explicit KeyValueRepositoryConfigfile(const FSNode& file);
|
explicit KeyValueRepositoryConfigfile(const FSNode& file);
|
||||||
|
|
||||||
static std::map<string, Variant> load(istream& in);
|
static KVRMap load(istream& in);
|
||||||
|
|
||||||
static bool save(ostream& out, const std::map<string, Variant>& values);
|
static bool save(ostream& out, const KVRMap& values);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEY_VALUE_REPOSITORY_CONFIGFILE_HXX
|
#endif // KEY_VALUE_REPOSITORY_CONFIGFILE_HXX
|
||||||
|
|
|
@ -30,9 +30,9 @@ class KeyValueRepositoryFile : public KeyValueRepository {
|
||||||
public:
|
public:
|
||||||
explicit KeyValueRepositoryFile(const FSNode& node);
|
explicit KeyValueRepositoryFile(const FSNode& node);
|
||||||
|
|
||||||
std::map<string, Variant> load() override;
|
KVRMap load() override;
|
||||||
|
|
||||||
bool save(const std::map<string, Variant>& values) override;
|
bool save(const KVRMap& values) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ KeyValueRepositoryFile<T>::KeyValueRepositoryFile(const FSNode& node)
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
template<class T>
|
template<class T>
|
||||||
std::map<string, Variant> KeyValueRepositoryFile<T>::load()
|
KVRMap KeyValueRepositoryFile<T>::load()
|
||||||
{
|
{
|
||||||
if (!myNode.exists()) return std::map<string, Variant>();
|
if (!myNode.exists()) return KVRMap();
|
||||||
|
|
||||||
stringstream in;
|
stringstream in;
|
||||||
|
|
||||||
|
@ -64,16 +64,16 @@ std::map<string, Variant> KeyValueRepositoryFile<T>::load()
|
||||||
catch (const runtime_error& err) {
|
catch (const runtime_error& err) {
|
||||||
Logger::error(err.what());
|
Logger::error(err.what());
|
||||||
|
|
||||||
return std::map<string, Variant>();
|
return KVRMap();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return std::map<string, Variant>();
|
return KVRMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
template<class T>
|
template<class T>
|
||||||
bool KeyValueRepositoryFile<T>::save(const std::map<string, Variant>& values)
|
bool KeyValueRepositoryFile<T>::save(const KVRMap& values)
|
||||||
{
|
{
|
||||||
if (values.size() == 0) return true;
|
if (values.size() == 0) return true;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
json jsonIfValid(const string& s) {
|
json jsonIfValid(string_view s) {
|
||||||
const json parsed = json::parse(s, nullptr, false);
|
const json parsed = json::parse(s, nullptr, false);
|
||||||
|
|
||||||
return parsed.is_discarded() ? json(s) : parsed;
|
return parsed.is_discarded() ? json(s) : parsed;
|
||||||
|
@ -36,10 +36,10 @@ KeyValueRepositoryJsonFile::KeyValueRepositoryJsonFile(const FSNode& node)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
std::map<string, Variant> KeyValueRepositoryJsonFile::load(istream& in)
|
KVRMap KeyValueRepositoryJsonFile::load(istream& in)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::map<string, Variant> map;
|
KVRMap map;
|
||||||
|
|
||||||
json deserialized = json::parse(in);
|
json deserialized = json::parse(in);
|
||||||
|
|
||||||
|
@ -63,8 +63,7 @@ std::map<string, Variant> KeyValueRepositoryJsonFile::load(istream& in)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool KeyValueRepositoryJsonFile::save(ostream& out,
|
bool KeyValueRepositoryJsonFile::save(ostream& out, const KVRMap& values)
|
||||||
const std::map<string, Variant>& values)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
json serializedJson = json::object();
|
json serializedJson = json::object();
|
||||||
|
|
|
@ -31,9 +31,9 @@ class KeyValueRepositoryJsonFile : public KeyValueRepositoryFile<KeyValueReposit
|
||||||
|
|
||||||
explicit KeyValueRepositoryJsonFile(const FSNode& node);
|
explicit KeyValueRepositoryJsonFile(const FSNode& node);
|
||||||
|
|
||||||
static std::map<string, Variant> load(istream& in);
|
static KVRMap load(istream& in);
|
||||||
|
|
||||||
static bool save(ostream& out, const std::map<string, Variant>& values);
|
static bool save(ostream& out, const KVRMap& values);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEY_VALUE_REPOSITORY_JSON_FILE_HXX
|
#endif // KEY_VALUE_REPOSITORY_JSON_FILE_HXX
|
||||||
|
|
|
@ -24,19 +24,17 @@ class KeyValueRepositoryNoop : public KeyValueRepositoryAtomic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
std::map<string, Variant> load() override {
|
KVRMap load() override { return KVRMap{}; }
|
||||||
return std::map<string, Variant>();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool has(const string& key) override { return false; }
|
bool has(string_view key) override { return false; }
|
||||||
|
|
||||||
bool get(const string& key, Variant& value) override { return false; }
|
bool get(string_view key, Variant& value) override { return false; }
|
||||||
|
|
||||||
bool save(const std::map<string, Variant>& values) override { return false; }
|
bool save(const KVRMap& values) override { return false; }
|
||||||
|
|
||||||
bool save(const string& key, const Variant& value) override { return false; }
|
bool save(string_view key, const Variant& value) override { return false; }
|
||||||
|
|
||||||
void remove(const string& key) override {}
|
void remove(string_view key) override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEY_VALUE_REPOSITORY_NOOP_HXX
|
#endif // KEY_VALUE_REPOSITORY_NOOP_HXX
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeQuotedString(ostream& out, const string& s)
|
void writeQuotedString(ostream& out, string_view s)
|
||||||
{
|
{
|
||||||
out.put('"');
|
out.put('"');
|
||||||
for(auto c: s)
|
for(auto c: s)
|
||||||
|
@ -76,9 +76,9 @@ KeyValueRepositoryPropertyFile::KeyValueRepositoryPropertyFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
std::map<string, Variant> KeyValueRepositoryPropertyFile::load(istream& in)
|
KVRMap KeyValueRepositoryPropertyFile::load(istream& in)
|
||||||
{
|
{
|
||||||
std::map<string, Variant> map;
|
KVRMap map;
|
||||||
|
|
||||||
// Loop reading properties
|
// Loop reading properties
|
||||||
string key, value;
|
string key, value;
|
||||||
|
@ -109,7 +109,7 @@ std::map<string, Variant> KeyValueRepositoryPropertyFile::load(istream& in)
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool KeyValueRepositoryPropertyFile::save(ostream& out,
|
bool KeyValueRepositoryPropertyFile::save(ostream& out,
|
||||||
const std::map<string, Variant>& values)
|
const KVRMap& values)
|
||||||
{
|
{
|
||||||
for (const auto& [key, value]: values) {
|
for (const auto& [key, value]: values) {
|
||||||
writeQuotedString(out, key);
|
writeQuotedString(out, key);
|
||||||
|
|
|
@ -31,9 +31,9 @@ class KeyValueRepositoryPropertyFile : public KeyValueRepositoryFile<KeyValueRep
|
||||||
|
|
||||||
explicit KeyValueRepositoryPropertyFile(const FSNode& node);
|
explicit KeyValueRepositoryPropertyFile(const FSNode& node);
|
||||||
|
|
||||||
static std::map<string, Variant> load(istream& in);
|
static KVRMap load(istream& in);
|
||||||
|
|
||||||
static bool save(ostream& out, const std::map<string, Variant>& values);
|
static bool save(ostream& out, const KVRMap& values);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEY_VALUE_REPOSITORY_PROPERTY_FILE_HXX
|
#endif // KEY_VALUE_REPOSITORY_PROPERTY_FILE_HXX
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#include "SqliteTransaction.hxx"
|
#include "SqliteTransaction.hxx"
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
std::map<string, Variant> AbstractKeyValueRepositorySqlite::load()
|
KVRMap AbstractKeyValueRepositorySqlite::load()
|
||||||
{
|
{
|
||||||
std::map<string, Variant> values;
|
KVRMap values;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SqliteStatement& stmt{stmtSelect()};
|
SqliteStatement& stmt{stmtSelect()};
|
||||||
|
@ -41,7 +41,7 @@ std::map<string, Variant> AbstractKeyValueRepositorySqlite::load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool AbstractKeyValueRepositorySqlite::has(const string& key)
|
bool AbstractKeyValueRepositorySqlite::has(string_view key)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SqliteStatement& stmt{stmtCount(key)};
|
SqliteStatement& stmt{stmtCount(key)};
|
||||||
|
@ -61,7 +61,7 @@ bool AbstractKeyValueRepositorySqlite::has(const string& key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool AbstractKeyValueRepositorySqlite::get(const string& key, Variant& value)
|
bool AbstractKeyValueRepositorySqlite::get(string_view key, Variant& value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SqliteStatement& stmt{stmtSelectOne(key)};
|
SqliteStatement& stmt{stmtSelectOne(key)};
|
||||||
|
@ -81,7 +81,7 @@ bool AbstractKeyValueRepositorySqlite::get(const string& key, Variant& value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool AbstractKeyValueRepositorySqlite::save(const std::map<string, Variant>& values)
|
bool AbstractKeyValueRepositorySqlite::save(const KVRMap& values)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SqliteTransaction tx{database()};
|
SqliteTransaction tx{database()};
|
||||||
|
@ -105,7 +105,7 @@ bool AbstractKeyValueRepositorySqlite::save(const std::map<string, Variant>& val
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool AbstractKeyValueRepositorySqlite::save(const string& key, const Variant& value)
|
bool AbstractKeyValueRepositorySqlite::save(string_view key, const Variant& value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SqliteStatement& stmt{stmtInsert(key, value.toString())};
|
SqliteStatement& stmt{stmtInsert(key, value.toString())};
|
||||||
|
@ -123,7 +123,7 @@ bool AbstractKeyValueRepositorySqlite::save(const string& key, const Variant& va
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void AbstractKeyValueRepositorySqlite::remove(const string& key)
|
void AbstractKeyValueRepositorySqlite::remove(string_view key)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SqliteStatement& stmt{stmtDelete(key)};
|
SqliteStatement& stmt{stmtDelete(key)};
|
||||||
|
|
|
@ -27,25 +27,25 @@ class AbstractKeyValueRepositorySqlite : public KeyValueRepositoryAtomic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool has(const string& key) override;
|
bool has(string_view key) override;
|
||||||
|
|
||||||
bool get(const string& key, Variant& value) override;
|
bool get(string_view key, Variant& value) override;
|
||||||
|
|
||||||
std::map<string, Variant> load() override;
|
KVRMap load() override;
|
||||||
|
|
||||||
bool save(const std::map<string, Variant>& values) override;
|
bool save(const KVRMap& values) override;
|
||||||
|
|
||||||
bool save(const string& key, const Variant& value) override;
|
bool save(string_view key, const Variant& value) override;
|
||||||
|
|
||||||
void remove(const string& key) override;
|
void remove(string_view key) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual SqliteStatement& stmtInsert(const string& key, const string& value) = 0;
|
virtual SqliteStatement& stmtInsert(string_view key, string_view value) = 0;
|
||||||
virtual SqliteStatement& stmtSelect() = 0;
|
virtual SqliteStatement& stmtSelect() = 0;
|
||||||
virtual SqliteStatement& stmtDelete(const string& key) = 0;
|
virtual SqliteStatement& stmtDelete(string_view key) = 0;
|
||||||
virtual SqliteStatement& stmtCount(const string& key) = 0;
|
virtual SqliteStatement& stmtCount(string_view key) = 0;
|
||||||
virtual SqliteStatement& stmtSelectOne(const string& key) = 0;
|
virtual SqliteStatement& stmtSelectOne(string_view key) = 0;
|
||||||
virtual SqliteDatabase& database() = 0;
|
virtual SqliteDatabase& database() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
CompositeKeyValueRepositorySqlite::CompositeKeyValueRepositorySqlite(
|
CompositeKeyValueRepositorySqlite::CompositeKeyValueRepositorySqlite(
|
||||||
SqliteDatabase& db,
|
SqliteDatabase& db,
|
||||||
const string& tableName,
|
string_view tableName,
|
||||||
const string& colKey1,
|
string_view colKey1,
|
||||||
const string& colKey2,
|
string_view colKey2,
|
||||||
const string& colValue
|
string_view colValue
|
||||||
)
|
)
|
||||||
: myDb{db}, myTableName{tableName},
|
: myDb{db}, myTableName{tableName},
|
||||||
myColKey1{colKey1}, myColKey2{colKey2}, myColValue{colValue}
|
myColKey1{colKey1}, myColKey2{colKey2}, myColValue{colValue}
|
||||||
|
@ -34,13 +34,14 @@ CompositeKeyValueRepositorySqlite::CompositeKeyValueRepositorySqlite(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
shared_ptr<KeyValueRepository> CompositeKeyValueRepositorySqlite::get(const string& key)
|
shared_ptr<KeyValueRepository> CompositeKeyValueRepositorySqlite::get(
|
||||||
|
string_view key)
|
||||||
{
|
{
|
||||||
return make_shared<ProxyRepository>(*this, key);
|
return make_shared<ProxyRepository>(*this, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool CompositeKeyValueRepositorySqlite::has(const string& key)
|
bool CompositeKeyValueRepositorySqlite::has(string_view key)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
(*myStmtCountSet)
|
(*myStmtCountSet)
|
||||||
|
@ -63,7 +64,7 @@ bool CompositeKeyValueRepositorySqlite::has(const string& key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void CompositeKeyValueRepositorySqlite::remove(const string& key)
|
void CompositeKeyValueRepositorySqlite::remove(string_view key)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
(*myStmtDeleteSet)
|
(*myStmtDeleteSet)
|
||||||
|
@ -143,13 +144,13 @@ void CompositeKeyValueRepositorySqlite::initialize()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
CompositeKeyValueRepositorySqlite::ProxyRepository::ProxyRepository(
|
CompositeKeyValueRepositorySqlite::ProxyRepository::ProxyRepository(
|
||||||
const CompositeKeyValueRepositorySqlite& repo,
|
const CompositeKeyValueRepositorySqlite& repo,
|
||||||
const string& key
|
string_view key
|
||||||
) : myRepo(repo), myKey(key)
|
) : myRepo(repo), myKey(key)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtInsert(
|
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtInsert(
|
||||||
const string& key, const string& value
|
string_view key, string_view value
|
||||||
) {
|
) {
|
||||||
return (*myRepo.myStmtInsert)
|
return (*myRepo.myStmtInsert)
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -167,7 +168,7 @@ SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtSelect(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtDelete(const string& key)
|
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtDelete(string_view key)
|
||||||
{
|
{
|
||||||
myRepo.myStmtDelete->reset();
|
myRepo.myStmtDelete->reset();
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtDelete(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtSelectOne(const string& key)
|
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtSelectOne(string_view key)
|
||||||
{
|
{
|
||||||
return (*myRepo.myStmtSelectOne)
|
return (*myRepo.myStmtSelectOne)
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -186,7 +187,7 @@ SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtSelectO
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtCount(const string& key)
|
SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtCount(string_view key)
|
||||||
{
|
{
|
||||||
return (*myRepo.myStmtCount)
|
return (*myRepo.myStmtCount)
|
||||||
.reset()
|
.reset()
|
||||||
|
|
|
@ -32,17 +32,17 @@ class CompositeKeyValueRepositorySqlite : public CompositeKeyValueRepositoryAtom
|
||||||
|
|
||||||
CompositeKeyValueRepositorySqlite(
|
CompositeKeyValueRepositorySqlite(
|
||||||
SqliteDatabase& db,
|
SqliteDatabase& db,
|
||||||
const string& tableName,
|
string_view tableName,
|
||||||
const string& colKey1,
|
string_view colKey1,
|
||||||
const string& colKey2,
|
string_view colKey2,
|
||||||
const string& colValue
|
string_view colValue
|
||||||
);
|
);
|
||||||
|
|
||||||
shared_ptr<KeyValueRepository> get(const string& key) override;
|
shared_ptr<KeyValueRepository> get(string_view key) override;
|
||||||
|
|
||||||
bool has(const string& key) override;
|
bool has(string_view key) override;
|
||||||
|
|
||||||
void remove(const string& key) override;
|
void remove(string_view key) override;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
|
@ -51,15 +51,16 @@ class CompositeKeyValueRepositorySqlite : public CompositeKeyValueRepositoryAtom
|
||||||
class ProxyRepository : public AbstractKeyValueRepositorySqlite {
|
class ProxyRepository : public AbstractKeyValueRepositorySqlite {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ProxyRepository(const CompositeKeyValueRepositorySqlite& repo, const string& key);
|
ProxyRepository(const CompositeKeyValueRepositorySqlite& repo,
|
||||||
|
string_view key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
SqliteStatement& stmtInsert(const string& key, const string& value) override;
|
SqliteStatement& stmtInsert(string_view key, string_view value) override;
|
||||||
SqliteStatement& stmtSelect() override;
|
SqliteStatement& stmtSelect() override;
|
||||||
SqliteStatement& stmtDelete(const string& key) override;
|
SqliteStatement& stmtDelete(string_view key) override;
|
||||||
SqliteStatement& stmtCount(const string& key) override;
|
SqliteStatement& stmtCount(string_view key) override;
|
||||||
SqliteStatement& stmtSelectOne(const string& key) override;
|
SqliteStatement& stmtSelectOne(string_view key) override;
|
||||||
SqliteDatabase& database() override;
|
SqliteDatabase& database() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
KeyValueRepositorySqlite::KeyValueRepositorySqlite(
|
KeyValueRepositorySqlite::KeyValueRepositorySqlite(
|
||||||
SqliteDatabase& db, const string& tableName, const string& colKey, const string& colValue
|
SqliteDatabase& db, string_view tableName, string_view colKey,
|
||||||
|
string_view colValue
|
||||||
)
|
)
|
||||||
: myDb{db},
|
: myDb{db},
|
||||||
myTableName{tableName},
|
myTableName{tableName},
|
||||||
|
@ -30,7 +31,8 @@ KeyValueRepositorySqlite::KeyValueRepositorySqlite(
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& KeyValueRepositorySqlite::stmtInsert(const string& key, const string& value)
|
SqliteStatement& KeyValueRepositorySqlite::stmtInsert(string_view key,
|
||||||
|
string_view value)
|
||||||
{
|
{
|
||||||
return (*myStmtInsert)
|
return (*myStmtInsert)
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -46,7 +48,7 @@ SqliteStatement& KeyValueRepositorySqlite::stmtSelect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& KeyValueRepositorySqlite::stmtDelete(const string& key)
|
SqliteStatement& KeyValueRepositorySqlite::stmtDelete(string_view key)
|
||||||
{
|
{
|
||||||
return (*myStmtDelete)
|
return (*myStmtDelete)
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -54,7 +56,7 @@ SqliteStatement& KeyValueRepositorySqlite::stmtDelete(const string& key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& KeyValueRepositorySqlite::stmtCount(const string& key)
|
SqliteStatement& KeyValueRepositorySqlite::stmtCount(string_view key)
|
||||||
{
|
{
|
||||||
return (*myStmtCount)
|
return (*myStmtCount)
|
||||||
.reset()
|
.reset()
|
||||||
|
@ -62,7 +64,7 @@ SqliteStatement& KeyValueRepositorySqlite::stmtCount(const string& key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& KeyValueRepositorySqlite::stmtSelectOne(const string& key)
|
SqliteStatement& KeyValueRepositorySqlite::stmtSelectOne(string_view key)
|
||||||
{
|
{
|
||||||
return (*myStmtSelectOne)
|
return (*myStmtSelectOne)
|
||||||
.reset()
|
.reset()
|
||||||
|
|
|
@ -27,18 +27,19 @@ class KeyValueRepositorySqlite : public AbstractKeyValueRepositorySqlite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
KeyValueRepositorySqlite(SqliteDatabase& db, const string& tableName, const string& colKey, const string& colValue);
|
KeyValueRepositorySqlite(SqliteDatabase& db, string_view tableName,
|
||||||
|
string_view colKey, string_view colValue);
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
SqliteStatement& stmtInsert(const string& key, const string& value) override;
|
SqliteStatement& stmtInsert(string_view key, string_view value) override;
|
||||||
SqliteStatement& stmtSelect() override;
|
SqliteStatement& stmtSelect() override;
|
||||||
SqliteStatement& stmtDelete(const string& key) override;
|
SqliteStatement& stmtDelete(string_view key) override;
|
||||||
SqliteDatabase& database() override;
|
SqliteDatabase& database() override;
|
||||||
SqliteStatement& stmtCount(const string& key) override;
|
SqliteStatement& stmtCount(string_view key) override;
|
||||||
SqliteStatement& stmtSelectOne(const string& key) override;
|
SqliteStatement& stmtSelectOne(string_view key) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,9 @@ void SqliteDatabase::initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SqliteDatabase::exec(const string& sql)
|
void SqliteDatabase::exec(string_view sql)
|
||||||
{
|
{
|
||||||
if (sqlite3_exec(myHandle, sql.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
if (sqlite3_exec(myHandle, string{sql}.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK)
|
||||||
throw SqliteError(myHandle);
|
throw SqliteError(myHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ class SqliteDatabase
|
||||||
|
|
||||||
operator sqlite3*() const { return myHandle; }
|
operator sqlite3*() const { return myHandle; }
|
||||||
|
|
||||||
void exec(const string &sql);
|
void exec(string_view sql);
|
||||||
|
|
||||||
template<class T, class ...Ts>
|
template<class T, class ...Ts>
|
||||||
void exec(const string& sql, T arg1, Ts... args);
|
void exec(string_view sql, T arg1, Ts... args);
|
||||||
|
|
||||||
Int32 getUserVersion() const;
|
Int32 getUserVersion() const;
|
||||||
void setUserVersion(Int32 version) const;
|
void setUserVersion(Int32 version) const;
|
||||||
|
@ -68,11 +68,11 @@ class SqliteDatabase
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class T, class ...Ts>
|
template <class T, class ...Ts>
|
||||||
void SqliteDatabase::exec(const string& sql, T arg1, Ts... args)
|
void SqliteDatabase::exec(string_view sql, T arg1, Ts... args)
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
if (snprintf(buffer, 512, sql.c_str(), arg1, args...) >= 512)
|
if (snprintf(buffer, 512, string{sql}.c_str(), arg1, args...) >= 512)
|
||||||
throw runtime_error("SQL statement too long");
|
throw runtime_error("SQL statement too long");
|
||||||
|
|
||||||
exec(buffer);
|
exec(buffer);
|
||||||
|
|
|
@ -22,16 +22,16 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement::SqliteStatement(sqlite3* handle, const string& sql)
|
SqliteStatement::SqliteStatement(sqlite3* handle, string_view sql)
|
||||||
: myHandle{handle}
|
: myHandle{handle}
|
||||||
{
|
{
|
||||||
initialize(sql);
|
initialize(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void SqliteStatement::initialize(const string& sql)
|
void SqliteStatement::initialize(string_view sql)
|
||||||
{
|
{
|
||||||
if (sqlite3_prepare_v2(myHandle, sql.c_str(), -1, &myStmt, nullptr) != SQLITE_OK)
|
if (sqlite3_prepare_v2(myHandle, string{sql}.c_str(), -1, &myStmt, nullptr) != SQLITE_OK)
|
||||||
throw SqliteError(myHandle);
|
throw SqliteError(myHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ SqliteStatement::~SqliteStatement()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
SqliteStatement& SqliteStatement::bind(int index, const string& value)
|
SqliteStatement& SqliteStatement::bind(int index, string_view value)
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_text(myStmt, index, value.c_str(), -1,
|
if (sqlite3_bind_text(myStmt, index, string{value}.c_str(), -1,
|
||||||
SQLITE_TRANSIENT) != SQLITE_OK) // NOLINT (performance-no-int-to-ptr)
|
SQLITE_TRANSIENT) != SQLITE_OK) // NOLINT (performance-no-int-to-ptr)
|
||||||
throw SqliteError(myHandle);
|
throw SqliteError(myHandle);
|
||||||
|
|
||||||
|
|
|
@ -25,16 +25,16 @@
|
||||||
class SqliteStatement {
|
class SqliteStatement {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SqliteStatement(sqlite3* handle, const string& sql);
|
SqliteStatement(sqlite3* handle, string_view sql);
|
||||||
|
|
||||||
template<class T, class ...Ts>
|
template<class T, class ...Ts>
|
||||||
SqliteStatement(sqlite3* handle, const string& sql, T arg1, Ts... args);
|
SqliteStatement(sqlite3* handle, string_view sql, T arg1, Ts... args);
|
||||||
|
|
||||||
~SqliteStatement();
|
~SqliteStatement();
|
||||||
|
|
||||||
operator sqlite3_stmt*() const { return myStmt; }
|
operator sqlite3_stmt*() const { return myStmt; }
|
||||||
|
|
||||||
SqliteStatement& bind(int index, const string& value);
|
SqliteStatement& bind(int index, string_view value);
|
||||||
SqliteStatement& bind(int index, Int32 value);
|
SqliteStatement& bind(int index, Int32 value);
|
||||||
|
|
||||||
bool step();
|
bool step();
|
||||||
|
@ -47,7 +47,7 @@ class SqliteStatement {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void initialize(const string& sql);
|
void initialize(string_view sql);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -74,12 +74,12 @@ class SqliteStatement {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template<class T, class ...Ts>
|
template<class T, class ...Ts>
|
||||||
SqliteStatement::SqliteStatement(sqlite3* handle, const string& sql, T arg1, Ts... args)
|
SqliteStatement::SqliteStatement(sqlite3* handle, string_view sql, T arg1, Ts... args)
|
||||||
: myHandle{handle}
|
: myHandle{handle}
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
|
|
||||||
if (snprintf(buffer, 512, sql.c_str(), arg1, args...) >= 512)
|
if (snprintf(buffer, 512, string{sql}.c_str(), arg1, args...) >= 512)
|
||||||
throw runtime_error("SQL statement too long");
|
throw runtime_error("SQL statement too long");
|
||||||
|
|
||||||
initialize(buffer);
|
initialize(buffer);
|
||||||
|
|
|
@ -47,7 +47,7 @@ void Properties::load(KeyValueRepository& repo)
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool Properties::save(KeyValueRepository& repo) const
|
bool Properties::save(KeyValueRepository& repo) const
|
||||||
{
|
{
|
||||||
std::map<string, Variant> props;
|
KVRMap props;
|
||||||
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(PropType::NumTypes); i++) {
|
for (size_t i = 0; i < static_cast<size_t>(PropType::NumTypes); i++) {
|
||||||
if (myProperties[i] == ourDefaultProperties[i]) {
|
if (myProperties[i] == ourDefaultProperties[i]) {
|
||||||
|
|
|
@ -804,7 +804,7 @@ void Settings::usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
const Variant& Settings::value(const string& key) const
|
const Variant& Settings::value(string_view key) const
|
||||||
{
|
{
|
||||||
// Try to find the named setting and answer its value
|
// Try to find the named setting and answer its value
|
||||||
auto it = myPermanentSettings.find(key);
|
auto it = myPermanentSettings.find(key);
|
||||||
|
@ -820,7 +820,7 @@ const Variant& Settings::value(const string& key) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setValue(const string& key, const Variant& value, bool persist)
|
void Settings::setValue(string_view key, const Variant& value, bool persist)
|
||||||
{
|
{
|
||||||
const auto it = myPermanentSettings.find(key);
|
const auto it = myPermanentSettings.find(key);
|
||||||
|
|
||||||
|
@ -830,19 +830,19 @@ void Settings::setValue(const string& key, const Variant& value, bool persist)
|
||||||
it->second = value;
|
it->second = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
myTemporarySettings[key] = value;
|
myTemporarySettings[string{key}] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setPermanent(const string& key, const Variant& value)
|
void Settings::setPermanent(string_view key, const Variant& value)
|
||||||
{
|
{
|
||||||
myPermanentSettings[key] = value;
|
myPermanentSettings[string{key}] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Settings::setTemporary(const string& key, const Variant& value)
|
void Settings::setTemporary(string_view key, const Variant& value)
|
||||||
{
|
{
|
||||||
myTemporarySettings[key] = value;
|
myTemporarySettings[string{key}] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Settings
|
||||||
explicit Settings();
|
explicit Settings();
|
||||||
virtual ~Settings() = default;
|
virtual ~Settings() = default;
|
||||||
|
|
||||||
using Options = std::map<string, Variant>;
|
using Options = std::map<string, Variant, std::less<>>;
|
||||||
|
|
||||||
static constexpr int SETTINGS_VERSION = 1;
|
static constexpr int SETTINGS_VERSION = 1;
|
||||||
static constexpr const char* SETTINGS_VERSION_KEY = "settings.version";
|
static constexpr const char* SETTINGS_VERSION_KEY = "settings.version";
|
||||||
|
@ -83,7 +83,7 @@ class Settings
|
||||||
@param key The key of the setting to lookup
|
@param key The key of the setting to lookup
|
||||||
@return The value of the setting; EmptyVariant if none exists
|
@return The value of the setting; EmptyVariant if none exists
|
||||||
*/
|
*/
|
||||||
const Variant& value(const string& key) const;
|
const Variant& value(string_view key) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set the value associated with the specified key.
|
Set the value associated with the specified key.
|
||||||
|
@ -91,7 +91,7 @@ class Settings
|
||||||
@param key The key of the setting
|
@param key The key of the setting
|
||||||
@param value The value to assign to the key
|
@param value The value to assign to the key
|
||||||
*/
|
*/
|
||||||
void setValue(const string& key, const Variant& value, bool persist = true);
|
void setValue(string_view key, const Variant& value, bool persist = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convenience methods to return specific types.
|
Convenience methods to return specific types.
|
||||||
|
@ -99,12 +99,18 @@ class Settings
|
||||||
@param key The key of the setting to lookup
|
@param key The key of the setting to lookup
|
||||||
@return The specific type value of the variant
|
@return The specific type value of the variant
|
||||||
*/
|
*/
|
||||||
int getInt(const string& key) const { return value(key).toInt(); }
|
int getInt(string_view key) const { return value(key).toInt(); }
|
||||||
float getFloat(const string& key) const { return value(key).toFloat(); }
|
float getFloat(string_view key) const { return value(key).toFloat(); }
|
||||||
bool getBool(const string& key) const { return value(key).toBool(); }
|
bool getBool(string_view key) const { return value(key).toBool(); }
|
||||||
const string& getString(const string& key) const { return value(key).toString(); }
|
const string& getString(string_view key) const {
|
||||||
const Common::Size getSize(const string& key) const { return value(key).toSize(); }
|
return value(key).toString();
|
||||||
const Common::Point getPoint(const string& key) const { return value(key).toPoint(); }
|
}
|
||||||
|
const Common::Size getSize(string_view key) const {
|
||||||
|
return value(key).toSize();
|
||||||
|
}
|
||||||
|
const Common::Point getPoint(string_view key) const {
|
||||||
|
return value(key).toPoint();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
|
@ -113,8 +119,8 @@ class Settings
|
||||||
appropriate 'value'. Elsewhere, any derived classes should call 'setValue',
|
appropriate 'value'. Elsewhere, any derived classes should call 'setValue',
|
||||||
and let it decide where the key/value pair will be saved.
|
and let it decide where the key/value pair will be saved.
|
||||||
*/
|
*/
|
||||||
void setPermanent(const string& key, const Variant& value);
|
void setPermanent(string_view key, const Variant& value);
|
||||||
void setTemporary(const string& key, const Variant& value);
|
void setTemporary(string_view key, const Variant& value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue