From 3f7f199cb940c8d5f6d48f77fd59971adffe49ef Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 7 Dec 2023 16:57:05 +1100 Subject: Remove pre-iterator concepts - No more IndexRecord/Result/dbGetPage nonsense - Queue is just track ids - i am so tired and have so much to do --- src/playlist/include/source.hpp | 157 ---------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 src/playlist/include/source.hpp (limited to 'src/playlist/include/source.hpp') diff --git a/src/playlist/include/source.hpp b/src/playlist/include/source.hpp deleted file mode 100644 index ce12faf3..00000000 --- a/src/playlist/include/source.hpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "bloom_filter.hpp" -#include "database.hpp" -#include "future_fetcher.hpp" -#include "random.hpp" -#include "track.hpp" - -namespace playlist { - -/* - * Stateful interface for iterating over a collection of tracks by id. - */ -class ISource { - public: - virtual ~ISource() {} - - virtual auto Current() -> std::optional = 0; - - /* - * Discards the current track id and continues to the next in this source. - * Returns the new current track id. - */ - virtual auto Advance() -> std::optional = 0; - - /* - * Repeatedly advances until a track with the given id is the current track. - * Returns false if this source ran out of tracks before the requested id - * was encounted, true otherwise. - */ - virtual auto AdvanceTo(database::TrackId id) -> bool { - for (auto t = Current(); t.has_value(); t = Advance()) { - if (*t == id) { - return true; - } - } - return false; - } - - /* - * Places the next n tracks into the given vector, in order. Does not change - * the value returned by Current(). - */ - virtual auto Peek(std::size_t n, std::vector*) - -> std::size_t = 0; -}; - -/* - * A Source that supports restarting iteration from its original initial - * value. - */ -class IResetableSource : public ISource { - public: - virtual ~IResetableSource() {} - - virtual auto Previous() -> std::optional = 0; - - /* - * Restarts iteration from this source's initial value. - */ - virtual auto Reset() -> void = 0; -}; - -class IteratorSource : public IResetableSource { - public: - IteratorSource(const database::Iterator&); - - auto Current() -> std::optional override; - auto Advance() -> std::optional override; - auto Peek(std::size_t n, std::vector*) - -> std::size_t override; - - auto Previous() -> std::optional override; - auto Reset() -> void override; - - private: - const database::Iterator& start_; - std::optional current_; - std::stack> next_; -}; - -auto CreateSourceFromResults( - std::weak_ptr, - std::shared_ptr>) - -> std::shared_ptr; - -class IndexRecordSource : public IResetableSource { - public: - IndexRecordSource(std::weak_ptr db, - std::shared_ptr>); - - IndexRecordSource(std::weak_ptr db, - std::shared_ptr>, - std::size_t, - std::shared_ptr>, - std::size_t); - - auto Current() -> std::optional override; - auto Advance() -> std::optional override; - auto Peek(std::size_t n, std::vector*) - -> std::size_t override; - - auto Previous() -> std::optional override; - auto Reset() -> void override; - - private: - std::weak_ptr db_; - - std::shared_ptr> initial_page_; - ssize_t initial_item_; - - std::shared_ptr> current_page_; - ssize_t current_item_; -}; - -class NestedSource : public IResetableSource { - public: - NestedSource(std::weak_ptr db, - std::shared_ptr>); - - auto Current() -> std::optional override; - auto Advance() -> std::optional override; - auto Peek(std::size_t n, std::vector*) - -> std::size_t override; - - auto Previous() -> std::optional override; - auto Reset() -> void override; - - private: - auto CreateChild(std::shared_ptr page) - -> std::shared_ptr; - - std::weak_ptr db_; - - std::shared_ptr> initial_page_; - ssize_t initial_item_; - - std::shared_ptr> current_page_; - ssize_t current_item_; - - std::shared_ptr current_child_; -}; - -} // namespace playlist -- cgit v1.2.3