summaryrefslogtreecommitdiff
path: root/src/db/VHelper.hxx
blob: 1951a8f119ea6bd0691f04812e05b165e6bd56e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright 2003-2020 The Music Player Daemon Project
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef MPD_DATABASE_VISITOR_HELPER_HXX
#define MPD_DATABASE_VISITOR_HELPER_HXX

#include "Visitor.hxx"
#include "Selection.hxx"

#include <vector>

class DetachedSong;

/**
 * This class helps implementing Database::Visit() by emulating
 * #DatabaseSelection features that the #Database implementation
 * doesn't have, e.g. filtering, sorting and window.
 *
 * To use this class, construct it, passing unsupported features and
 * the visitor callback to the constructor; before leaving Visit(),
 * call Commit() (unless an error has occurred).
 */
class DatabaseVisitorHelper {
	const DatabaseSelection selection;

	/**
	 * If the plugin can't sort, then this container will collect
	 * all songs, sort them and report them to the visitor in
	 * Commit().
	 */
	std::vector<DetachedSong> songs;

	VisitSong original_visit_song;

	/**
	 * Used to emulate the "window".
	 */
	unsigned counter = 0;

public:
	/**
	 * @param selection a #DatabaseSelection instance with only
	 * features enabled which shall be emulated by this class
	 * @param visit_song the callback function passed to
	 * Database::Visit(); may be replaced by this class
	 */
	DatabaseVisitorHelper(DatabaseSelection selection,
			      VisitSong &visit_song) noexcept;
	~DatabaseVisitorHelper() noexcept;

	void Commit();
};

#endif