storage/Interface: add [[nodiscard]]

This commit is contained in:
Max Kellermann 2024-05-10 19:08:15 +02:00
parent 48ce8e9fb7
commit 4800f1d8f2

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#ifndef MPD_STORAGE_INTERFACE_HXX #pragma once
#define MPD_STORAGE_INTERFACE_HXX
#include <memory> #include <memory>
#include <string> #include <string>
@ -17,11 +16,13 @@ public:
StorageDirectoryReader(const StorageDirectoryReader &) = delete; StorageDirectoryReader(const StorageDirectoryReader &) = delete;
virtual ~StorageDirectoryReader() noexcept = default; virtual ~StorageDirectoryReader() noexcept = default;
[[nodiscard]]
virtual const char *Read() noexcept = 0; virtual const char *Read() noexcept = 0;
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
[[nodiscard]]
virtual StorageFileInfo GetInfo(bool follow) = 0; virtual StorageFileInfo GetInfo(bool follow) = 0;
}; };
@ -34,17 +35,19 @@ public:
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
[[nodiscard]]
virtual StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) = 0; virtual StorageFileInfo GetInfo(std::string_view uri_utf8, bool follow) = 0;
/** /**
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
[[nodiscard]]
virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) = 0; virtual std::unique_ptr<StorageDirectoryReader> OpenDirectory(std::string_view uri_utf8) = 0;
/** /**
* Map the given relative URI to an absolute URI. * Map the given relative URI to an absolute URI.
*/ */
[[gnu::pure]] [[nodiscard]] [[gnu::pure]]
virtual std::string MapUTF8(std::string_view uri_utf8) const noexcept = 0; virtual std::string MapUTF8(std::string_view uri_utf8) const noexcept = 0;
/** /**
@ -52,10 +55,10 @@ public:
* nullptr on error or if this storage does not * nullptr on error or if this storage does not
* support local files. * support local files.
*/ */
[[gnu::pure]] [[nodiscard]] [[gnu::pure]]
virtual AllocatedPath MapFS(std::string_view uri_utf8) const noexcept; virtual AllocatedPath MapFS(std::string_view uri_utf8) const noexcept;
[[gnu::pure]] [[nodiscard]] [[gnu::pure]]
AllocatedPath MapChildFS(std::string_view uri_utf8, AllocatedPath MapChildFS(std::string_view uri_utf8,
std::string_view child_utf8) const noexcept; std::string_view child_utf8) const noexcept;
@ -64,8 +67,6 @@ public:
* then it returns a relative URI (pointing inside the given * then it returns a relative URI (pointing inside the given
* string); if not, returns nullptr. * string); if not, returns nullptr.
*/ */
[[gnu::pure]] [[nodiscard]] [[gnu::pure]]
virtual std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept = 0; virtual std::string_view MapToRelativeUTF8(std::string_view uri_utf8) const noexcept = 0;
}; };
#endif