Back to home page

EIC code displayed by LXR

 
 

    


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_INPUTSTREAM_HPP
0026 #define SFML_INPUTSTREAM_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Config.hpp>
0032 #include <SFML/System/Export.hpp>
0033 
0034 
0035 namespace sf
0036 {
0037 ////////////////////////////////////////////////////////////
0038 /// \brief Abstract class for custom file input streams
0039 ///
0040 ////////////////////////////////////////////////////////////
0041 class SFML_SYSTEM_API InputStream
0042 {
0043 public:
0044 
0045     ////////////////////////////////////////////////////////////
0046     /// \brief Virtual destructor
0047     ///
0048     ////////////////////////////////////////////////////////////
0049     virtual ~InputStream() {}
0050 
0051     ////////////////////////////////////////////////////////////
0052     /// \brief Read data from the stream
0053     ///
0054     /// After reading, the stream's reading position must be
0055     /// advanced by the amount of bytes read.
0056     ///
0057     /// \param data Buffer where to copy the read data
0058     /// \param size Desired number of bytes to read
0059     ///
0060     /// \return The number of bytes actually read, or -1 on error
0061     ///
0062     ////////////////////////////////////////////////////////////
0063     virtual Int64 read(void* data, Int64 size) = 0;
0064 
0065     ////////////////////////////////////////////////////////////
0066     /// \brief Change the current reading position
0067     ///
0068     /// \param position The position to seek to, from the beginning
0069     ///
0070     /// \return The position actually sought to, or -1 on error
0071     ///
0072     ////////////////////////////////////////////////////////////
0073     virtual Int64 seek(Int64 position) = 0;
0074 
0075     ////////////////////////////////////////////////////////////
0076     /// \brief Get the current reading position in the stream
0077     ///
0078     /// \return The current position, or -1 on error.
0079     ///
0080     ////////////////////////////////////////////////////////////
0081     virtual Int64 tell() = 0;
0082 
0083     ////////////////////////////////////////////////////////////
0084     /// \brief Return the size of the stream
0085     ///
0086     /// \return The total number of bytes available in the stream, or -1 on error
0087     ///
0088     ////////////////////////////////////////////////////////////
0089     virtual Int64 getSize() = 0;
0090 };
0091 
0092 } // namespace sf
0093 
0094 
0095 #endif // SFML_INPUTSTREAM_HPP
0096 
0097 
0098 ////////////////////////////////////////////////////////////
0099 /// \class sf::InputStream
0100 /// \ingroup system
0101 ///
0102 /// This class allows users to define their own file input sources
0103 /// from which SFML can load resources.
0104 ///
0105 /// SFML resource classes like sf::Texture and
0106 /// sf::SoundBuffer provide loadFromFile and loadFromMemory functions,
0107 /// which read data from conventional sources. However, if you
0108 /// have data coming from a different source (over a network,
0109 /// embedded, encrypted, compressed, etc) you can derive your
0110 /// own class from sf::InputStream and load SFML resources with
0111 /// their loadFromStream function.
0112 ///
0113 /// Usage example:
0114 /// \code
0115 /// // custom stream class that reads from inside a zip file
0116 /// class ZipStream : public sf::InputStream
0117 /// {
0118 /// public:
0119 ///
0120 ///     ZipStream(std::string archive);
0121 ///
0122 ///     bool open(std::string filename);
0123 ///
0124 ///     Int64 read(void* data, Int64 size);
0125 ///
0126 ///     Int64 seek(Int64 position);
0127 ///
0128 ///     Int64 tell();
0129 ///
0130 ///     Int64 getSize();
0131 ///
0132 /// private:
0133 ///
0134 ///     ...
0135 /// };
0136 ///
0137 /// // now you can load textures...
0138 /// sf::Texture texture;
0139 /// ZipStream stream("resources.zip");
0140 /// stream.open("images/img.png");
0141 /// texture.loadFromStream(stream);
0142 ///
0143 /// // musics...
0144 /// sf::Music music;
0145 /// ZipStream stream("resources.zip");
0146 /// stream.open("musics/msc.ogg");
0147 /// music.openFromStream(stream);
0148 ///
0149 /// // etc.
0150 /// \endcode
0151 ///
0152 ////////////////////////////////////////////////////////////