|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_FILEINPUTSTREAM_HPP 0026 #define SFML_FILEINPUTSTREAM_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Config.hpp> 0032 #include <SFML/System/Export.hpp> 0033 #include <SFML/System/InputStream.hpp> 0034 #include <SFML/System/NonCopyable.hpp> 0035 #include <cstdio> 0036 #include <string> 0037 0038 #ifdef SFML_SYSTEM_ANDROID 0039 namespace sf 0040 { 0041 namespace priv 0042 { 0043 class SFML_SYSTEM_API ResourceStream; 0044 } 0045 } 0046 #endif 0047 0048 0049 namespace sf 0050 { 0051 //////////////////////////////////////////////////////////// 0052 /// \brief Implementation of input stream based on a file 0053 /// 0054 //////////////////////////////////////////////////////////// 0055 class SFML_SYSTEM_API FileInputStream : public InputStream, NonCopyable 0056 { 0057 public: 0058 //////////////////////////////////////////////////////////// 0059 /// \brief Default constructor 0060 /// 0061 //////////////////////////////////////////////////////////// 0062 FileInputStream(); 0063 0064 //////////////////////////////////////////////////////////// 0065 /// \brief Default destructor 0066 /// 0067 //////////////////////////////////////////////////////////// 0068 virtual ~FileInputStream(); 0069 0070 //////////////////////////////////////////////////////////// 0071 /// \brief Open the stream from a file path 0072 /// 0073 /// \param filename Name of the file to open 0074 /// 0075 /// \return True on success, false on error 0076 /// 0077 //////////////////////////////////////////////////////////// 0078 bool open(const std::string& filename); 0079 0080 //////////////////////////////////////////////////////////// 0081 /// \brief Read data from the stream 0082 /// 0083 /// After reading, the stream's reading position must be 0084 /// advanced by the amount of bytes read. 0085 /// 0086 /// \param data Buffer where to copy the read data 0087 /// \param size Desired number of bytes to read 0088 /// 0089 /// \return The number of bytes actually read, or -1 on error 0090 /// 0091 //////////////////////////////////////////////////////////// 0092 virtual Int64 read(void* data, Int64 size); 0093 0094 //////////////////////////////////////////////////////////// 0095 /// \brief Change the current reading position 0096 /// 0097 /// \param position The position to seek to, from the beginning 0098 /// 0099 /// \return The position actually sought to, or -1 on error 0100 /// 0101 //////////////////////////////////////////////////////////// 0102 virtual Int64 seek(Int64 position); 0103 0104 //////////////////////////////////////////////////////////// 0105 /// \brief Get the current reading position in the stream 0106 /// 0107 /// \return The current position, or -1 on error. 0108 /// 0109 //////////////////////////////////////////////////////////// 0110 virtual Int64 tell(); 0111 0112 //////////////////////////////////////////////////////////// 0113 /// \brief Return the size of the stream 0114 /// 0115 /// \return The total number of bytes available in the stream, or -1 on error 0116 /// 0117 //////////////////////////////////////////////////////////// 0118 virtual Int64 getSize(); 0119 0120 private: 0121 0122 //////////////////////////////////////////////////////////// 0123 // Member data 0124 //////////////////////////////////////////////////////////// 0125 #ifdef SFML_SYSTEM_ANDROID 0126 priv::ResourceStream* m_file; 0127 #else 0128 std::FILE* m_file; //!< stdio file stream 0129 #endif 0130 }; 0131 0132 } // namespace sf 0133 0134 0135 #endif // SFML_FILEINPUTSTREAM_HPP 0136 0137 0138 //////////////////////////////////////////////////////////// 0139 /// \class sf::FileInputStream 0140 /// \ingroup system 0141 /// 0142 /// This class is a specialization of InputStream that 0143 /// reads from a file on disk. 0144 /// 0145 /// It wraps a file in the common InputStream interface 0146 /// and therefore allows to use generic classes or functions 0147 /// that accept such a stream, with a file on disk as the data 0148 /// source. 0149 /// 0150 /// In addition to the virtual functions inherited from 0151 /// InputStream, FileInputStream adds a function to 0152 /// specify the file to open. 0153 /// 0154 /// SFML resource classes can usually be loaded directly from 0155 /// a filename, so this class shouldn't be useful to you unless 0156 /// you create your own algorithms that operate on an InputStream. 0157 /// 0158 /// Usage example: 0159 /// \code 0160 /// void process(InputStream& stream); 0161 /// 0162 /// FileInputStream stream; 0163 /// if (stream.open("some_file.dat")) 0164 /// process(stream); 0165 /// \endcode 0166 /// 0167 /// InputStream, MemoryInputStream 0168 /// 0169 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|