Loading...
Searching...
No Matches
FileInputStream.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Config.hpp>
31
33
35
36#include <filesystem>
37#include <memory>
38
39#include <cstdint>
40#include <cstdio>
41
42#ifdef SFML_SYSTEM_ANDROID
43namespace sf::priv
44{
45class SFML_SYSTEM_API ResourceStream;
46}
47#endif
48
49
50namespace sf
51{
57{
58public:
67
72 ~FileInputStream() override;
73
79
85
91
96 FileInputStream& operator=(FileInputStream&&) noexcept;
97
106 explicit FileInputStream(const std::filesystem::path& filename);
107
116 [[nodiscard]] bool open(const std::filesystem::path& filename);
117
130 [[nodiscard]] std::optional<std::size_t> read(void* data, std::size_t size) override;
131
140 [[nodiscard]] std::optional<std::size_t> seek(std::size_t position) override;
141
148 [[nodiscard]] std::optional<std::size_t> tell() override;
149
156 std::optional<std::size_t> getSize() override;
157
158private:
163 struct FileCloser
164 {
165 void operator()(std::FILE* file);
166 };
167
169 // Member data
171#ifdef SFML_SYSTEM_ANDROID
172 std::unique_ptr<priv::ResourceStream> m_androidFile;
173#endif
174
175 std::unique_ptr<std::FILE, FileCloser> m_file;
176};
177
178} // namespace sf
179
180
#define SFML_SYSTEM_API
Implementation of input stream based on a file.
FileInputStream(const FileInputStream &)=delete
Deleted copy constructor.
FileInputStream()
Default constructor.
FileInputStream(FileInputStream &&) noexcept
Move constructor.
~FileInputStream() override
Default destructor.
FileInputStream & operator=(const FileInputStream &)=delete
Deleted copy assignment.
Abstract class for custom file input streams.