diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp index ebd5559a..7af484aa 100644 --- a/src/app_console/app_console.cpp +++ b/src/app_console/app_console.cpp @@ -194,7 +194,7 @@ int CmdDbTracks(int argc, char** argv) { } if (res->next_page()) { auto continuation = res->next_page().value(); - res.reset(db->GetPage(&continuation).get()); + res.reset(db->GetPage(&continuation).get()); } else { break; } diff --git a/src/database/database.cpp b/src/database/database.cpp index ad81cfcf..9d29aea8 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -355,23 +355,23 @@ auto Database::GetTracksByIndex(const IndexInfo& index, std::size_t page_size) .components_hash = 0, }; OwningSlice prefix = EncodeIndexPrefix(header); - Continuation c{.prefix = prefix.data, - .start_key = prefix.data, - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = prefix.data, + .start_key = prefix.data, + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } auto Database::GetTracks(std::size_t page_size) -> std::future*> { return worker_task_->Dispatch*>([=, this]() -> Result* { - Continuation c{.prefix = EncodeDataPrefix().data, - .start_key = EncodeDataPrefix().data, - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = EncodeDataPrefix().data, + .start_key = EncodeDataPrefix().data, + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } @@ -379,28 +379,27 @@ auto Database::GetDump(std::size_t page_size) -> std::future*> { return worker_task_->Dispatch*>( [=, this]() -> Result* { - Continuation c{.prefix = "", - .start_key = "", - .forward = true, - .was_prev_forward = true, - .page_size = page_size}; - return dbGetPage(c); + Continuation c{.prefix = "", + .start_key = "", + .forward = true, + .was_prev_forward = true, + .page_size = page_size}; + return dbGetPage(c); }); } template -auto Database::GetPage(Continuation* c) -> std::future*> { - Continuation copy = *c; +auto Database::GetPage(Continuation* c) -> std::future*> { + Continuation copy = *c; return worker_task_->Dispatch*>( - [=, this]() -> Result* { return dbGetPage(copy); }); + [=, this]() -> Result* { return dbGetPage(copy); }); } -template auto Database::GetPage(Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; -template auto Database::GetPage(Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; -template auto Database::GetPage( - Continuation* c) +template auto Database::GetPage(Continuation* c) -> std::future*>; auto Database::dbMintNewTrackId() -> TrackId { @@ -477,7 +476,7 @@ auto Database::dbCreateIndexesForTrack(const Track& track) -> void { } template -auto Database::dbGetPage(const Continuation& c) -> Result* { +auto Database::dbGetPage(const Continuation& c) -> Result* { // Work out our starting point. Sometimes this will already done. std::unique_ptr it{ db_->NewIterator(leveldb::ReadOptions{})}; @@ -524,13 +523,13 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { } // Work out the new continuations. - std::optional> next_page; + std::optional next_page; if (c.forward) { if (it != nullptr) { // We were going forward, and now we want the next page. std::pmr::string key{it->key().data(), it->key().size(), &memory::kSpiRamResource}; - next_page = Continuation{ + next_page = Continuation{ .prefix = c.prefix, .start_key = key, .forward = true, @@ -543,7 +542,7 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { // We were going backwards, and now we want the next page. This is a // reversal, to set the start key to the first record we saw and mark that // it's off by one. - next_page = Continuation{ + next_page = Continuation{ .prefix = c.prefix, .start_key = *first_key, .forward = true, @@ -552,11 +551,11 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { }; } - std::optional> prev_page; + std::optional prev_page; if (c.forward) { // We were going forwards, and now we want the previous page. Set the search // key to the first result we saw, and mark that it's off by one. - prev_page = Continuation{ + prev_page = Continuation{ .prefix = c.prefix, .start_key = *first_key, .forward = false, @@ -568,7 +567,7 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { // We were going backwards, and we still want to go backwards. std::pmr::string key{it->key().data(), it->key().size(), &memory::kSpiRamResource}; - prev_page = Continuation{ + prev_page = Continuation{ .prefix = c.prefix, .start_key = key, .forward = false, @@ -582,10 +581,10 @@ auto Database::dbGetPage(const Continuation& c) -> Result* { return new Result(std::move(records), next_page, prev_page); } -template auto Database::dbGetPage(const Continuation& c) +template auto Database::dbGetPage(const Continuation& c) -> Result*; -template auto Database::dbGetPage( - const Continuation& c) -> Result*; +template auto Database::dbGetPage(const Continuation& c) + -> Result*; template <> auto Database::ParseRecord(const leveldb::Slice& key, @@ -668,13 +667,13 @@ auto IndexRecord::track() const -> std::optional { } auto IndexRecord::Expand(std::size_t page_size) const - -> std::optional> { + -> std::optional { if (track_) { return {}; } IndexKey::Header new_header = ExpandHeader(key_.header, key_.item); OwningSlice new_prefix = EncodeIndexPrefix(new_header); - return Continuation{ + return Continuation{ .prefix = new_prefix.data, .start_key = new_prefix.data, .forward = true, diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 6ad8d318..7cb1d09c 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -31,7 +31,6 @@ namespace database { -template struct Continuation { std::pmr::string prefix; std::pmr::string start_key; @@ -52,12 +51,12 @@ class Result { return values_; } - auto next_page() -> std::optional>& { return next_page_; } - auto prev_page() -> std::optional>& { return prev_page_; } + auto next_page() -> std::optional& { return next_page_; } + auto prev_page() -> std::optional& { return prev_page_; } Result(const std::vector>&& values, - std::optional> next, - std::optional> prev) + std::optional next, + std::optional prev) : values_(values), next_page_(next), prev_page_(prev) {} Result(const Result&) = delete; @@ -65,8 +64,8 @@ class Result { private: std::vector> values_; - std::optional> next_page_; - std::optional> prev_page_; + std::optional next_page_; + std::optional prev_page_; }; class IndexRecord { @@ -78,7 +77,7 @@ class IndexRecord { auto text() const -> std::optional; auto track() const -> std::optional; - auto Expand(std::size_t) const -> std::optional>; + auto Expand(std::size_t) const -> std::optional; private: IndexKey key_; @@ -120,7 +119,7 @@ class Database { auto GetDump(std::size_t page_size) -> std::future*>; template - auto GetPage(Continuation* c) -> std::future*>; + auto GetPage(Continuation* c) -> std::future*>; Database(const Database&) = delete; Database& operator=(const Database&) = delete; @@ -153,7 +152,7 @@ class Database { auto dbCreateIndexesForTrack(const Track& track) -> void; template - auto dbGetPage(const Continuation& c) -> Result*; + auto dbGetPage(const Continuation& c) -> Result*; template auto ParseRecord(const leveldb::Slice& key, const leveldb::Slice& val) diff --git a/src/playlist/source.cpp b/src/playlist/source.cpp index cf60b1c1..18a7887b 100644 --- a/src/playlist/source.cpp +++ b/src/playlist/source.cpp @@ -68,7 +68,7 @@ auto IndexRecordSource::Advance() -> std::optional { return {}; } - current_page_.reset(db->GetPage(&*next_page).get()); + current_page_.reset(db->GetPage(&*next_page).get()); current_item_ = 0; } @@ -92,7 +92,7 @@ auto IndexRecordSource::Previous() -> std::optional { return {}; } - current_page_.reset(db->GetPage(&*prev_page).get()); + current_page_.reset(db->GetPage(&*prev_page).get()); current_item_ = current_page_->values().size() - 1; } @@ -124,7 +124,7 @@ auto IndexRecordSource::Peek(std::size_t n, std::vector* out) } // TODO(jacqueline): It would probably be a good idea to hold onto these // peeked pages, to avoid needing to look them up again later. - working_page.reset(db->GetPage(&*next_page).get()); + working_page.reset(db->GetPage(&*next_page).get()); working_item = 0; } diff --git a/src/ui/screen_track_browser.cpp b/src/ui/screen_track_browser.cpp index ba27ad5e..58cd2946 100644 --- a/src/ui/screen_track_browser.cpp +++ b/src/ui/screen_track_browser.cpp @@ -262,7 +262,7 @@ auto TrackBrowser::FetchNewPage(Position pos) -> void { return; } - std::optional> cont; + std::optional cont; switch (pos) { case START: cont = current_pages_.front()->prev_page(); @@ -294,7 +294,7 @@ auto TrackBrowser::FetchNewPage(Position pos) -> void { } loading_pos_ = pos; - loading_page_ = db->GetPage(&cont.value()); + loading_page_ = db->GetPage(&cont.value()); } auto TrackBrowser::GetNumRecords() -> std::size_t { diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index b5a0fa34..145bcbcc 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -299,7 +299,7 @@ void Browse::react(const internal::RecordSelected& ev) { if (!cont) { return; } - auto query = db->GetPage(&cont.value()); + auto query = db->GetPage(&cont.value()); std::pmr::string title = record->text().value_or("TODO"); PushScreen(std::make_shared( sTopBarModel, sServices->database(), title, std::move(query)));