From 50a2823da6f13d0cc09630516531b8cf84c0d0a6 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 19 Dec 2022 17:21:36 -0330 Subject: [PATCH] More conversion of 'const string&' to 'string_view'. --- .../repository/CompositeKVRJsonAdapter.cxx | 14 +++++----- .../repository/CompositeKVRJsonAdapter.hxx | 6 ++-- .../CompositeKeyValueRepository.cxx | 12 ++++---- .../CompositeKeyValueRepository.hxx | 16 +++++------ .../CompositeKeyValueRepositoryNoop.hxx | 6 ++-- src/common/repository/KeyValueRepository.hxx | 14 ++++++---- .../KeyValueRepositoryConfigfile.cxx | 6 ++-- .../KeyValueRepositoryConfigfile.hxx | 4 +-- .../repository/KeyValueRepositoryFile.hxx | 14 +++++----- .../repository/KeyValueRepositoryJsonFile.cxx | 9 +++--- .../repository/KeyValueRepositoryJsonFile.hxx | 4 +-- .../repository/KeyValueRepositoryNoop.hxx | 14 ++++------ .../KeyValueRepositoryPropertyFile.cxx | 8 +++--- .../KeyValueRepositoryPropertyFile.hxx | 4 +-- .../AbstractKeyValueRepositorySqlite.cxx | 14 +++++----- .../AbstractKeyValueRepositorySqlite.hxx | 20 ++++++------- .../CompositeKeyValueRepositorySqlite.cxx | 25 +++++++++-------- .../CompositeKeyValueRepositorySqlite.hxx | 25 +++++++++-------- .../sqlite/KeyValueRepositorySqlite.cxx | 12 ++++---- .../sqlite/KeyValueRepositorySqlite.hxx | 11 ++++---- .../repository/sqlite/SqliteDatabase.cxx | 4 +-- .../repository/sqlite/SqliteDatabase.hxx | 8 +++--- .../repository/sqlite/SqliteStatement.cxx | 10 +++---- .../repository/sqlite/SqliteStatement.hxx | 12 ++++---- src/emucore/Props.cxx | 2 +- src/emucore/Settings.cxx | 14 +++++----- src/emucore/Settings.hxx | 28 +++++++++++-------- 27 files changed, 164 insertions(+), 152 deletions(-) diff --git a/src/common/repository/CompositeKVRJsonAdapter.cxx b/src/common/repository/CompositeKVRJsonAdapter.cxx index a9b3672eb..593ad72be 100644 --- a/src/common/repository/CompositeKVRJsonAdapter.cxx +++ b/src/common/repository/CompositeKVRJsonAdapter.cxx @@ -23,11 +23,11 @@ namespace { class ProxyRepository : public KeyValueRepository { public: - ProxyRepository(KeyValueRepositoryAtomic& kvr, const string& key) + ProxyRepository(KeyValueRepositoryAtomic& kvr, string_view key) : myKvr{kvr}, myKey{key} {} - std::map load() override { + KVRMap load() override { if (!myKvr.has(myKey)) return {}; Variant serialized; @@ -38,7 +38,7 @@ namespace { return KeyValueRepositoryJsonFile::load(in); } - bool save(const std::map& values) override { + bool save(const KVRMap& values) override { stringstream out; if (!KeyValueRepositoryJsonFile::save(out, values)) return false; @@ -50,7 +50,7 @@ namespace { // NOLINT: cppcoreguidelines-avoid-const-or-ref-data-members KeyValueRepositoryAtomic& myKvr; // NOLINT - const string& myKey; // NOLINT + string myKey; }; } // namespace @@ -61,19 +61,19 @@ CompositeKVRJsonAdapter::CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr CompositeKVRJsonAdapter::get(const string& key) +shared_ptr CompositeKVRJsonAdapter::get(string_view key) { return make_shared(myKvr, key); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CompositeKVRJsonAdapter::has(const string& key) +bool CompositeKVRJsonAdapter::has(string_view key) { return myKvr.has(key); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CompositeKVRJsonAdapter::remove(const string& key) +void CompositeKVRJsonAdapter::remove(string_view key) { return myKvr.remove(key); } diff --git a/src/common/repository/CompositeKVRJsonAdapter.hxx b/src/common/repository/CompositeKVRJsonAdapter.hxx index f78098dd4..8a266072f 100644 --- a/src/common/repository/CompositeKVRJsonAdapter.hxx +++ b/src/common/repository/CompositeKVRJsonAdapter.hxx @@ -27,11 +27,11 @@ class CompositeKVRJsonAdapter : public CompositeKeyValueRepository { explicit CompositeKVRJsonAdapter(KeyValueRepositoryAtomic& kvr); - shared_ptr get(const string& key) override; + shared_ptr 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: diff --git a/src/common/repository/CompositeKeyValueRepository.cxx b/src/common/repository/CompositeKeyValueRepository.cxx index dd63b5360..8c8df52fc 100644 --- a/src/common/repository/CompositeKeyValueRepository.cxx +++ b/src/common/repository/CompositeKeyValueRepository.cxx @@ -18,32 +18,34 @@ #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); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr CompositeKeyValueRepositoryAtomic::getAtomic(const string& key) +shared_ptr CompositeKeyValueRepositoryAtomic::getAtomic(string_view key) { auto repo = get(key); 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); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CompositeKeyValueRepositoryAtomic::has(const string& key1, const string& key2) +bool CompositeKeyValueRepositoryAtomic::has(string_view key1, string_view 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); } diff --git a/src/common/repository/CompositeKeyValueRepository.hxx b/src/common/repository/CompositeKeyValueRepository.hxx index 76e797059..f45cd1a10 100644 --- a/src/common/repository/CompositeKeyValueRepository.hxx +++ b/src/common/repository/CompositeKeyValueRepository.hxx @@ -32,11 +32,11 @@ class CompositeKeyValueRepository virtual ~CompositeKeyValueRepository() = default; - virtual shared_ptr get(const string& key) = 0; + virtual shared_ptr 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; } @@ -55,15 +55,15 @@ class CompositeKeyValueRepositoryAtomic : public CompositeKeyValueRepository using CompositeKeyValueRepository::remove; 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 getAtomic(const string& key); + virtual shared_ptr 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; } }; diff --git a/src/common/repository/CompositeKeyValueRepositoryNoop.hxx b/src/common/repository/CompositeKeyValueRepositoryNoop.hxx index 7badb6e8f..d216a89bf 100644 --- a/src/common/repository/CompositeKeyValueRepositoryNoop.hxx +++ b/src/common/repository/CompositeKeyValueRepositoryNoop.hxx @@ -29,13 +29,13 @@ class CompositeKeyValueRepositoryNoop : public CompositeKeyValueRepositoryAtomic using CompositeKeyValueRepositoryAtomic::remove; using CompositeKeyValueRepositoryAtomic::get; - shared_ptr get(const string& key) override { + shared_ptr get(string_view key) override { return make_shared(); } - 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 diff --git a/src/common/repository/KeyValueRepository.hxx b/src/common/repository/KeyValueRepository.hxx index 9aa52ada6..a85f09124 100644 --- a/src/common/repository/KeyValueRepository.hxx +++ b/src/common/repository/KeyValueRepository.hxx @@ -23,6 +23,8 @@ #include "Variant.hxx" #include "bspf.hxx" +using KVRMap = std::map>; + class KeyValueRepositoryAtomic; class KeyValueRepository @@ -31,9 +33,9 @@ class KeyValueRepository KeyValueRepository() = default; virtual ~KeyValueRepository() = default; - virtual std::map load() = 0; + virtual KVRMap load() = 0; - virtual bool save(const std::map& values) = 0; + virtual bool save(const KVRMap& values) = 0; virtual KeyValueRepositoryAtomic* atomic() { return nullptr; } @@ -49,13 +51,13 @@ class KeyValueRepositoryAtomic : public KeyValueRepository { public: 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; } }; diff --git a/src/common/repository/KeyValueRepositoryConfigfile.cxx b/src/common/repository/KeyValueRepositoryConfigfile.cxx index a538aa123..856f96b00 100644 --- a/src/common/repository/KeyValueRepositoryConfigfile.cxx +++ b/src/common/repository/KeyValueRepositoryConfigfile.cxx @@ -25,9 +25,9 @@ KeyValueRepositoryConfigfile::KeyValueRepositoryConfigfile(const FSNode& file) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::map KeyValueRepositoryConfigfile::load(istream& in) +KVRMap KeyValueRepositoryConfigfile::load(istream& in) { - std::map values; + KVRMap values; string line, key, value; string::size_type equalPos = 0, garbage = 0; @@ -61,7 +61,7 @@ std::map KeyValueRepositoryConfigfile::load(istream& in) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool KeyValueRepositoryConfigfile::save(ostream& out, const std::map& values) +bool KeyValueRepositoryConfigfile::save(ostream& out, const KVRMap& values) { out << "; Stella configuration file" << endl << ";" << endl diff --git a/src/common/repository/KeyValueRepositoryConfigfile.hxx b/src/common/repository/KeyValueRepositoryConfigfile.hxx index a787f66ef..1cdc7270c 100644 --- a/src/common/repository/KeyValueRepositoryConfigfile.hxx +++ b/src/common/repository/KeyValueRepositoryConfigfile.hxx @@ -29,9 +29,9 @@ class KeyValueRepositoryConfigfile : public KeyValueRepositoryFile load(istream& in); + static KVRMap load(istream& in); - static bool save(ostream& out, const std::map& values); + static bool save(ostream& out, const KVRMap& values); }; #endif // KEY_VALUE_REPOSITORY_CONFIGFILE_HXX diff --git a/src/common/repository/KeyValueRepositoryFile.hxx b/src/common/repository/KeyValueRepositoryFile.hxx index a59818ba0..60bbf2f5c 100644 --- a/src/common/repository/KeyValueRepositoryFile.hxx +++ b/src/common/repository/KeyValueRepositoryFile.hxx @@ -30,9 +30,9 @@ class KeyValueRepositoryFile : public KeyValueRepository { public: explicit KeyValueRepositoryFile(const FSNode& node); - std::map load() override; + KVRMap load() override; - bool save(const std::map& values) override; + bool save(const KVRMap& values) override; protected: @@ -51,9 +51,9 @@ KeyValueRepositoryFile::KeyValueRepositoryFile(const FSNode& node) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -std::map KeyValueRepositoryFile::load() +KVRMap KeyValueRepositoryFile::load() { - if (!myNode.exists()) return std::map(); + if (!myNode.exists()) return KVRMap(); stringstream in; @@ -64,16 +64,16 @@ std::map KeyValueRepositoryFile::load() catch (const runtime_error& err) { Logger::error(err.what()); - return std::map(); + return KVRMap(); } catch (...) { - return std::map(); + return KVRMap(); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template -bool KeyValueRepositoryFile::save(const std::map& values) +bool KeyValueRepositoryFile::save(const KVRMap& values) { if (values.size() == 0) return true; diff --git a/src/common/repository/KeyValueRepositoryJsonFile.cxx b/src/common/repository/KeyValueRepositoryJsonFile.cxx index a72486c2b..1f2d406e1 100644 --- a/src/common/repository/KeyValueRepositoryJsonFile.cxx +++ b/src/common/repository/KeyValueRepositoryJsonFile.cxx @@ -22,7 +22,7 @@ using nlohmann::json; namespace { - json jsonIfValid(const string& s) { + json jsonIfValid(string_view s) { const json parsed = json::parse(s, nullptr, false); return parsed.is_discarded() ? json(s) : parsed; @@ -36,10 +36,10 @@ KeyValueRepositoryJsonFile::KeyValueRepositoryJsonFile(const FSNode& node) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::map KeyValueRepositoryJsonFile::load(istream& in) +KVRMap KeyValueRepositoryJsonFile::load(istream& in) { try { - std::map map; + KVRMap map; json deserialized = json::parse(in); @@ -63,8 +63,7 @@ std::map KeyValueRepositoryJsonFile::load(istream& in) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool KeyValueRepositoryJsonFile::save(ostream& out, - const std::map& values) +bool KeyValueRepositoryJsonFile::save(ostream& out, const KVRMap& values) { try { json serializedJson = json::object(); diff --git a/src/common/repository/KeyValueRepositoryJsonFile.hxx b/src/common/repository/KeyValueRepositoryJsonFile.hxx index 547560fff..18734dbb5 100644 --- a/src/common/repository/KeyValueRepositoryJsonFile.hxx +++ b/src/common/repository/KeyValueRepositoryJsonFile.hxx @@ -31,9 +31,9 @@ class KeyValueRepositoryJsonFile : public KeyValueRepositoryFile load(istream& in); + static KVRMap load(istream& in); - static bool save(ostream& out, const std::map& values); + static bool save(ostream& out, const KVRMap& values); }; #endif // KEY_VALUE_REPOSITORY_JSON_FILE_HXX diff --git a/src/common/repository/KeyValueRepositoryNoop.hxx b/src/common/repository/KeyValueRepositoryNoop.hxx index 1ec8f3001..b7c23915d 100644 --- a/src/common/repository/KeyValueRepositoryNoop.hxx +++ b/src/common/repository/KeyValueRepositoryNoop.hxx @@ -24,19 +24,17 @@ class KeyValueRepositoryNoop : public KeyValueRepositoryAtomic { public: - std::map load() override { - return std::map(); - } + KVRMap load() override { return KVRMap{}; } - 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& 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 diff --git a/src/common/repository/KeyValueRepositoryPropertyFile.cxx b/src/common/repository/KeyValueRepositoryPropertyFile.cxx index ff582663d..1e991304f 100644 --- a/src/common/repository/KeyValueRepositoryPropertyFile.cxx +++ b/src/common/repository/KeyValueRepositoryPropertyFile.cxx @@ -46,7 +46,7 @@ namespace { return s; } - void writeQuotedString(ostream& out, const string& s) + void writeQuotedString(ostream& out, string_view s) { out.put('"'); for(auto c: s) @@ -76,9 +76,9 @@ KeyValueRepositoryPropertyFile::KeyValueRepositoryPropertyFile( } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::map KeyValueRepositoryPropertyFile::load(istream& in) +KVRMap KeyValueRepositoryPropertyFile::load(istream& in) { - std::map map; + KVRMap map; // Loop reading properties string key, value; @@ -109,7 +109,7 @@ std::map KeyValueRepositoryPropertyFile::load(istream& in) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool KeyValueRepositoryPropertyFile::save(ostream& out, - const std::map& values) + const KVRMap& values) { for (const auto& [key, value]: values) { writeQuotedString(out, key); diff --git a/src/common/repository/KeyValueRepositoryPropertyFile.hxx b/src/common/repository/KeyValueRepositoryPropertyFile.hxx index 41d32a0f1..13fccf7fd 100644 --- a/src/common/repository/KeyValueRepositoryPropertyFile.hxx +++ b/src/common/repository/KeyValueRepositoryPropertyFile.hxx @@ -31,9 +31,9 @@ class KeyValueRepositoryPropertyFile : public KeyValueRepositoryFile load(istream& in); + static KVRMap load(istream& in); - static bool save(ostream& out, const std::map& values); + static bool save(ostream& out, const KVRMap& values); }; #endif // KEY_VALUE_REPOSITORY_PROPERTY_FILE_HXX diff --git a/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.cxx b/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.cxx index 59a007e3b..85d90d8ff 100644 --- a/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.cxx +++ b/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.cxx @@ -21,9 +21,9 @@ #include "SqliteTransaction.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -std::map AbstractKeyValueRepositorySqlite::load() +KVRMap AbstractKeyValueRepositorySqlite::load() { - std::map values; + KVRMap values; try { SqliteStatement& stmt{stmtSelect()}; @@ -41,7 +41,7 @@ std::map AbstractKeyValueRepositorySqlite::load() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool AbstractKeyValueRepositorySqlite::has(const string& key) +bool AbstractKeyValueRepositorySqlite::has(string_view key) { try { 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 { SqliteStatement& stmt{stmtSelectOne(key)}; @@ -81,7 +81,7 @@ bool AbstractKeyValueRepositorySqlite::get(const string& key, Variant& value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool AbstractKeyValueRepositorySqlite::save(const std::map& values) +bool AbstractKeyValueRepositorySqlite::save(const KVRMap& values) { try { SqliteTransaction tx{database()}; @@ -105,7 +105,7 @@ bool AbstractKeyValueRepositorySqlite::save(const std::map& val } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool AbstractKeyValueRepositorySqlite::save(const string& key, const Variant& value) +bool AbstractKeyValueRepositorySqlite::save(string_view key, const Variant& value) { try { 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 { SqliteStatement& stmt{stmtDelete(key)}; diff --git a/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.hxx b/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.hxx index a4a981d17..71b57b772 100644 --- a/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.hxx +++ b/src/common/repository/sqlite/AbstractKeyValueRepositorySqlite.hxx @@ -27,25 +27,25 @@ class AbstractKeyValueRepositorySqlite : public KeyValueRepositoryAtomic { 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 load() override; + KVRMap load() override; - bool save(const std::map& 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: - 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& stmtDelete(const string& key) = 0; - virtual SqliteStatement& stmtCount(const string& key) = 0; - virtual SqliteStatement& stmtSelectOne(const string& key) = 0; + virtual SqliteStatement& stmtDelete(string_view key) = 0; + virtual SqliteStatement& stmtCount(string_view key) = 0; + virtual SqliteStatement& stmtSelectOne(string_view key) = 0; virtual SqliteDatabase& database() = 0; }; diff --git a/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.cxx b/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.cxx index cd668541a..6dcb65d0b 100644 --- a/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.cxx +++ b/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.cxx @@ -23,10 +23,10 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CompositeKeyValueRepositorySqlite::CompositeKeyValueRepositorySqlite( SqliteDatabase& db, - const string& tableName, - const string& colKey1, - const string& colKey2, - const string& colValue + string_view tableName, + string_view colKey1, + string_view colKey2, + string_view colValue ) : myDb{db}, myTableName{tableName}, myColKey1{colKey1}, myColKey2{colKey2}, myColValue{colValue} @@ -34,13 +34,14 @@ CompositeKeyValueRepositorySqlite::CompositeKeyValueRepositorySqlite( } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -shared_ptr CompositeKeyValueRepositorySqlite::get(const string& key) +shared_ptr CompositeKeyValueRepositorySqlite::get( + string_view key) { return make_shared(*this, key); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool CompositeKeyValueRepositorySqlite::has(const string& key) +bool CompositeKeyValueRepositorySqlite::has(string_view key) { try { (*myStmtCountSet) @@ -63,7 +64,7 @@ bool CompositeKeyValueRepositorySqlite::has(const string& key) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void CompositeKeyValueRepositorySqlite::remove(const string& key) +void CompositeKeyValueRepositorySqlite::remove(string_view key) { try { (*myStmtDeleteSet) @@ -143,13 +144,13 @@ void CompositeKeyValueRepositorySqlite::initialize() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CompositeKeyValueRepositorySqlite::ProxyRepository::ProxyRepository( const CompositeKeyValueRepositorySqlite& repo, - const string& key + string_view key ) : myRepo(repo), myKey(key) {} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SqliteStatement& CompositeKeyValueRepositorySqlite::ProxyRepository::stmtInsert( - const string& key, const string& value + string_view key, string_view value ) { return (*myRepo.myStmtInsert) .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(); @@ -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) .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) .reset() diff --git a/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.hxx b/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.hxx index 84381a5c7..e3e61bcf4 100644 --- a/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.hxx +++ b/src/common/repository/sqlite/CompositeKeyValueRepositorySqlite.hxx @@ -32,17 +32,17 @@ class CompositeKeyValueRepositorySqlite : public CompositeKeyValueRepositoryAtom CompositeKeyValueRepositorySqlite( SqliteDatabase& db, - const string& tableName, - const string& colKey1, - const string& colKey2, - const string& colValue + string_view tableName, + string_view colKey1, + string_view colKey2, + string_view colValue ); - shared_ptr get(const string& key) override; + shared_ptr 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(); @@ -51,15 +51,16 @@ class CompositeKeyValueRepositorySqlite : public CompositeKeyValueRepositoryAtom class ProxyRepository : public AbstractKeyValueRepositorySqlite { public: - ProxyRepository(const CompositeKeyValueRepositorySqlite& repo, const string& key); + ProxyRepository(const CompositeKeyValueRepositorySqlite& repo, + string_view key); protected: - SqliteStatement& stmtInsert(const string& key, const string& value) override; + SqliteStatement& stmtInsert(string_view key, string_view value) override; SqliteStatement& stmtSelect() override; - SqliteStatement& stmtDelete(const string& key) override; - SqliteStatement& stmtCount(const string& key) override; - SqliteStatement& stmtSelectOne(const string& key) override; + SqliteStatement& stmtDelete(string_view key) override; + SqliteStatement& stmtCount(string_view key) override; + SqliteStatement& stmtSelectOne(string_view key) override; SqliteDatabase& database() override; private: diff --git a/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx b/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx index 43c570a4e..9050ac764 100644 --- a/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx +++ b/src/common/repository/sqlite/KeyValueRepositorySqlite.cxx @@ -20,7 +20,8 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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}, 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) .reset() @@ -46,7 +48,7 @@ SqliteStatement& KeyValueRepositorySqlite::stmtSelect() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SqliteStatement& KeyValueRepositorySqlite::stmtDelete(const string& key) +SqliteStatement& KeyValueRepositorySqlite::stmtDelete(string_view key) { return (*myStmtDelete) .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) .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) .reset() diff --git a/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx b/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx index dc6bc5217..b1e6f25aa 100644 --- a/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx +++ b/src/common/repository/sqlite/KeyValueRepositorySqlite.hxx @@ -27,18 +27,19 @@ class KeyValueRepositorySqlite : public AbstractKeyValueRepositorySqlite { 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(); protected: - SqliteStatement& stmtInsert(const string& key, const string& value) override; + SqliteStatement& stmtInsert(string_view key, string_view value) override; SqliteStatement& stmtSelect() override; - SqliteStatement& stmtDelete(const string& key) override; + SqliteStatement& stmtDelete(string_view key) override; SqliteDatabase& database() override; - SqliteStatement& stmtCount(const string& key) override; - SqliteStatement& stmtSelectOne(const string& key) override; + SqliteStatement& stmtCount(string_view key) override; + SqliteStatement& stmtSelectOne(string_view key) override; private: diff --git a/src/common/repository/sqlite/SqliteDatabase.cxx b/src/common/repository/sqlite/SqliteDatabase.cxx index 28e47cc34..1fd0f283d 100644 --- a/src/common/repository/sqlite/SqliteDatabase.cxx +++ b/src/common/repository/sqlite/SqliteDatabase.cxx @@ -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); } diff --git a/src/common/repository/sqlite/SqliteDatabase.hxx b/src/common/repository/sqlite/SqliteDatabase.hxx index 607a378bd..cf79febcf 100644 --- a/src/common/repository/sqlite/SqliteDatabase.hxx +++ b/src/common/repository/sqlite/SqliteDatabase.hxx @@ -36,10 +36,10 @@ class SqliteDatabase operator sqlite3*() const { return myHandle; } - void exec(const string &sql); + void exec(string_view sql); template - void exec(const string& sql, T arg1, Ts... args); + void exec(string_view sql, T arg1, Ts... args); Int32 getUserVersion() const; void setUserVersion(Int32 version) const; @@ -68,11 +68,11 @@ class SqliteDatabase #endif template -void SqliteDatabase::exec(const string& sql, T arg1, Ts... args) +void SqliteDatabase::exec(string_view sql, T arg1, Ts... args) { 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"); exec(buffer); diff --git a/src/common/repository/sqlite/SqliteStatement.cxx b/src/common/repository/sqlite/SqliteStatement.cxx index 30aa630ac..306306bc3 100644 --- a/src/common/repository/sqlite/SqliteStatement.cxx +++ b/src/common/repository/sqlite/SqliteStatement.cxx @@ -22,16 +22,16 @@ #endif // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -SqliteStatement::SqliteStatement(sqlite3* handle, const string& sql) +SqliteStatement::SqliteStatement(sqlite3* handle, string_view sql) : myHandle{handle} { 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); } @@ -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) throw SqliteError(myHandle); diff --git a/src/common/repository/sqlite/SqliteStatement.hxx b/src/common/repository/sqlite/SqliteStatement.hxx index f37cded58..73f2d131a 100644 --- a/src/common/repository/sqlite/SqliteStatement.hxx +++ b/src/common/repository/sqlite/SqliteStatement.hxx @@ -25,16 +25,16 @@ class SqliteStatement { public: - SqliteStatement(sqlite3* handle, const string& sql); + SqliteStatement(sqlite3* handle, string_view sql); template - SqliteStatement(sqlite3* handle, const string& sql, T arg1, Ts... args); + SqliteStatement(sqlite3* handle, string_view sql, T arg1, Ts... args); ~SqliteStatement(); 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); bool step(); @@ -47,7 +47,7 @@ class SqliteStatement { private: - void initialize(const string& sql); + void initialize(string_view sql); private: @@ -74,12 +74,12 @@ class SqliteStatement { #endif template -SqliteStatement::SqliteStatement(sqlite3* handle, const string& sql, T arg1, Ts... args) +SqliteStatement::SqliteStatement(sqlite3* handle, string_view sql, T arg1, Ts... args) : myHandle{handle} { 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"); initialize(buffer); diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index db981b05d..54aa085f0 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -47,7 +47,7 @@ void Properties::load(KeyValueRepository& repo) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Properties::save(KeyValueRepository& repo) const { - std::map props; + KVRMap props; for (size_t i = 0; i < static_cast(PropType::NumTypes); i++) { if (myProperties[i] == ourDefaultProperties[i]) { diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index fc9797ebc..e3114e1f4 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -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 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); @@ -830,19 +830,19 @@ void Settings::setValue(const string& key, const Variant& value, bool persist) it->second = value; } 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; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Settings.hxx b/src/emucore/Settings.hxx index 55258794b..55cb0d97b 100644 --- a/src/emucore/Settings.hxx +++ b/src/emucore/Settings.hxx @@ -49,7 +49,7 @@ class Settings explicit Settings(); virtual ~Settings() = default; - using Options = std::map; + using Options = std::map>; static constexpr int SETTINGS_VERSION = 1; static constexpr const char* SETTINGS_VERSION_KEY = "settings.version"; @@ -83,7 +83,7 @@ class Settings @param key The key of the setting to lookup @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. @@ -91,7 +91,7 @@ class Settings @param key The key of the setting @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. @@ -99,12 +99,18 @@ class Settings @param key The key of the setting to lookup @return The specific type value of the variant */ - int getInt(const string& key) const { return value(key).toInt(); } - float getFloat(const string& key) const { return value(key).toFloat(); } - bool getBool(const string& key) const { return value(key).toBool(); } - const string& getString(const string& key) const { return value(key).toString(); } - const Common::Size getSize(const string& key) const { return value(key).toSize(); } - const Common::Point getPoint(const string& key) const { return value(key).toPoint(); } + int getInt(string_view key) const { return value(key).toInt(); } + float getFloat(string_view key) const { return value(key).toFloat(); } + bool getBool(string_view key) const { return value(key).toBool(); } + const string& getString(string_view key) const { + return value(key).toString(); + } + 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: /** @@ -113,8 +119,8 @@ class Settings appropriate 'value'. Elsewhere, any derived classes should call 'setValue', and let it decide where the key/value pair will be saved. */ - void setPermanent(const string& key, const Variant& value); - void setTemporary(const string& key, const Variant& value); + void setPermanent(string_view key, const Variant& value); + void setTemporary(string_view key, const Variant& value); private: /**