StorageInterface.hxx 2.46 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * 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_STORAGE_INTERFACE_HXX
#define MPD_STORAGE_INTERFACE_HXX

23
#include "util/Compiler.h"
24

25
#include <memory>
26
#include <string>
27
#include <string_view>
28

29
struct StorageFileInfo;
30 31 32 33
class AllocatedPath;

class StorageDirectoryReader {
public:
34 35
	StorageDirectoryReader() = default;
	StorageDirectoryReader(const StorageDirectoryReader &) = delete;
36
	virtual ~StorageDirectoryReader() noexcept {}
37

38
	virtual const char *Read() noexcept = 0;
39 40 41 42 43

	/**
	 * Throws #std::runtime_error on error.
	 */
	virtual StorageFileInfo GetInfo(bool follow) = 0;
44 45 46 47
};

class Storage {
public:
48 49
	Storage() = default;
	Storage(const Storage &) = delete;
50
	virtual ~Storage() noexcept {}
51

52 53 54
	/**
	 * Throws #std::runtime_error on error.
	 */
55
	virtual StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) = 0;
56

57 58 59
	/**
	 * Throws #std::runtime_error on error.
	 */
60
	virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) = 0;
61 62 63 64 65

	/**
	 * Map the given relative URI to an absolute URI.
	 */
	gcc_pure
66
	virtual std::string MapUTF8(std::string_view uri_utf8) const noexcept = 0;
67 68 69

	/**
	 * Map the given relative URI to a local file path.  Returns
70
	 * nullptr on error or if this storage does not
71 72 73
	 * support local files.
	 */
	gcc_pure
74
	virtual AllocatedPath MapFS(std::string_view uri_utf8) const noexcept;
75 76

	gcc_pure
77 78
	AllocatedPath MapChildFS(std::string_view uri_utf8,
				 std::string_view child_utf8) const noexcept;
79 80 81 82 83 84 85

	/**
	 * Check if the given URI points inside this storage.  If yes,
	 * then it returns a relative URI (pointing inside the given
	 * string); if not, returns nullptr.
	 */
	gcc_pure
86
	virtual std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept = 0;
87 88 89
};

#endif