SFML 3.0.1
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-2025 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
32#include <SFML/System/Export.hpp>
33
34#include <SFML/System/InputStream.hpp>
35
36#include <filesystem>
37#include <memory>
38
39#include <cstdint>
40#include <cstdio>
41
42#ifdef SFML_SYSTEM_ANDROID
43 namespace sf::priv
44{
45 class SFML_SYSTEM_API ResourceStream;
46}
47#endif
48
49
50 namespace sf
51{
56 class SFML_SYSTEM_API FileInputStream : public InputStream
57{
58 public:
66 FileInputStream();
67
72 ~FileInputStream() override;
73
78 FileInputStream(const FileInputStream&) = delete;
79
84 FileInputStream& operator=(const FileInputStream&) = delete;
85
90 FileInputStream(FileInputStream&&) noexcept;
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
Config.hpp
InputStream.hpp
Export.hpp
SFML_SYSTEM_API
#define SFML_SYSTEM_API
Definition System/Export.hpp:42
sf::FileInputStream::getSize
std::optional< std::size_t > getSize() override
Return the size of the stream.
sf::FileInputStream::read
std::optional< std::size_t > read(void *data, std::size_t size) override
Read data from the stream.
sf::FileInputStream::seek
std::optional< std::size_t > seek(std::size_t position) override
Change the current reading position.
sf::FileInputStream::tell
std::optional< std::size_t > tell() override
Get the current reading position in the stream.
sf::FileInputStream::FileInputStream
FileInputStream(const FileInputStream &)=delete
Deleted copy constructor.
sf::FileInputStream::FileInputStream
FileInputStream()
Default constructor.
sf::FileInputStream::FileInputStream
FileInputStream(FileInputStream &&) noexcept
Move constructor.
sf::FileInputStream::open
bool open(const std::filesystem::path &filename)
Open the stream from a file path.
sf::FileInputStream::~FileInputStream
~FileInputStream() override
Default destructor.
sf::FileInputStream::operator=
FileInputStream & operator=(const FileInputStream &)=delete
Deleted copy assignment.
sf::InputStream
Abstract class for custom file input streams.
Definition InputStream.hpp:46
sf
Definition AudioResource.hpp:36