1 ////////////////////////////////////////////////////////////
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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.
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:
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.
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
21 // 3. This notice may not be removed or altered from any source distribution.
23 ////////////////////////////////////////////////////////////
25 #ifndef SFML_INPUTSTREAM_HPP
26 #define SFML_INPUTSTREAM_HPP
28 ////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Config.hpp>
36 ////////////////////////////////////////////////////////////
37 /// \brief Abstract class for custom file input streams
39 ////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////
45 /// \brief Virtual destructor
47 ////////////////////////////////////////////////////////////
48 virtual ~InputStream() {}
50 ////////////////////////////////////////////////////////////
51 /// \brief Read data from the stream
53 /// After reading, the stream's reading position must be
54 /// advanced by the amount of bytes read.
56 /// \param data Buffer where to copy the read data
57 /// \param size Desired number of bytes to read
59 /// \return The number of bytes actually read, or -1 on error
61 ////////////////////////////////////////////////////////////
62 virtual Int64 read(void* data, Int64 size) = 0;
64 ////////////////////////////////////////////////////////////
65 /// \brief Change the current reading position
67 /// \param position The position to seek to, from the beginning
69 /// \return The position actually sought to, or -1 on error
71 ////////////////////////////////////////////////////////////
72 virtual Int64 seek(Int64 position) = 0;
74 ////////////////////////////////////////////////////////////
75 /// \brief Get the current reading position in the stream
77 /// \return The current position, or -1 on error.
79 ////////////////////////////////////////////////////////////
80 virtual Int64 tell() = 0;
82 ////////////////////////////////////////////////////////////
83 /// \brief Return the size of the stream
85 /// \return The total number of bytes available in the stream, or -1 on error
87 ////////////////////////////////////////////////////////////
88 virtual Int64 getSize() = 0;
94 #endif // SFML_INPUTSTREAM_HPP
97 ////////////////////////////////////////////////////////////
98 /// \class sf::InputStream
101 /// This class allows users to define their own file input sources
102 /// from which SFML can load resources.
104 /// SFML resource classes like sf::Texture and
105 /// sf::SoundBuffer provide loadFromFile and loadFromMemory functions,
106 /// which read data from conventional sources. However, if you
107 /// have data coming from a different source (over a network,
108 /// embedded, encrypted, compressed, etc) you can derive your
109 /// own class from sf::InputStream and load SFML resources with
110 /// their loadFromStream function.
114 /// // custom stream class that reads from inside a zip file
115 /// class ZipStream : public sf::InputStream
119 /// ZipStream(std::string archive);
121 /// bool open(std::string filename);
123 /// Int64 read(void* data, Int64 size);
125 /// Int64 seek(Int64 position);
136 /// // now you can load textures...
137 /// sf::Texture texture;
138 /// ZipStream stream("resources.zip");
139 /// stream.open("images/img.png");
140 /// texture.loadFromStream(stream);
144 /// ZipStream stream("resources.zip");
145 /// stream.open("musics/msc.ogg");
146 /// music.openFromStream(stream);
151 ////////////////////////////////////////////////////////////