b79436a0c603534dfb3cdfa507fd0b6f01a420aa
[TDDC76_proj.git] /
1 ////////////////////////////////////////////////////////////
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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 //
23 ////////////////////////////////////////////////////////////
24
25 #ifndef SFML_INPUTSTREAM_HPP
26 #define SFML_INPUTSTREAM_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Config.hpp>
32
33
34 namespace sf
35 {
36 ////////////////////////////////////////////////////////////
37 /// \brief Abstract class for custom file input streams
38 ///
39 ////////////////////////////////////////////////////////////
40 class InputStream
41 {
42 public :
43
44 ////////////////////////////////////////////////////////////
45 /// \brief Virtual destructor
46 ///
47 ////////////////////////////////////////////////////////////
48 virtual ~InputStream() {}
49
50 ////////////////////////////////////////////////////////////
51 /// \brief Read data from the stream
52 ///
53 /// After reading, the stream's reading position must be
54 /// advanced by the amount of bytes read.
55 ///
56 /// \param data Buffer where to copy the read data
57 /// \param size Desired number of bytes to read
58 ///
59 /// \return The number of bytes actually read, or -1 on error
60 ///
61 ////////////////////////////////////////////////////////////
62 virtual Int64 read(void* data, Int64 size) = 0;
63
64 ////////////////////////////////////////////////////////////
65 /// \brief Change the current reading position
66 ///
67 /// \param position The position to seek to, from the beginning
68 ///
69 /// \return The position actually sought to, or -1 on error
70 ///
71 ////////////////////////////////////////////////////////////
72 virtual Int64 seek(Int64 position) = 0;
73
74 ////////////////////////////////////////////////////////////
75 /// \brief Get the current reading position in the stream
76 ///
77 /// \return The current position, or -1 on error.
78 ///
79 ////////////////////////////////////////////////////////////
80 virtual Int64 tell() = 0;
81
82 ////////////////////////////////////////////////////////////
83 /// \brief Return the size of the stream
84 ///
85 /// \return The total number of bytes available in the stream, or -1 on error
86 ///
87 ////////////////////////////////////////////////////////////
88 virtual Int64 getSize() = 0;
89 };
90
91 } // namespace sf
92
93
94 #endif // SFML_INPUTSTREAM_HPP
95
96
97 ////////////////////////////////////////////////////////////
98 /// \class sf::InputStream
99 /// \ingroup system
100 ///
101 /// This class allows users to define their own file input sources
102 /// from which SFML can load resources.
103 ///
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.
111 ///
112 /// Usage example:
113 /// \code
114 /// // custom stream class that reads from inside a zip file
115 /// class ZipStream : public sf::InputStream
116 /// {
117 /// public :
118 ///
119 /// ZipStream(std::string archive);
120 ///
121 /// bool open(std::string filename);
122 ///
123 /// Int64 read(void* data, Int64 size);
124 ///
125 /// Int64 seek(Int64 position);
126 ///
127 /// Int64 tell();
128 ///
129 /// Int64 getSize();
130 ///
131 /// private :
132 ///
133 /// ...
134 /// };
135 ///
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);
141 ///
142 /// // musics...
143 /// sf::Music music;
144 /// ZipStream stream("resources.zip");
145 /// stream.open("musics/msc.ogg");
146 /// music.openFromStream(stream);
147 ///
148 /// // etc.
149 /// \endcode
150 ///
151 ////////////////////////////////////////////////////////////