|
|
|||
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_MEMORYINPUTSTREAM_HPP 0026 #define SFML_MEMORYINPUTSTREAM_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Config.hpp> 0032 #include <SFML/System/InputStream.hpp> 0033 #include <SFML/System/Export.hpp> 0034 #include <cstdlib> 0035 0036 0037 namespace sf 0038 { 0039 //////////////////////////////////////////////////////////// 0040 /// \brief Implementation of input stream based on a memory chunk 0041 /// 0042 //////////////////////////////////////////////////////////// 0043 class SFML_SYSTEM_API MemoryInputStream : public InputStream 0044 { 0045 public: 0046 0047 //////////////////////////////////////////////////////////// 0048 /// \brief Default constructor 0049 /// 0050 //////////////////////////////////////////////////////////// 0051 MemoryInputStream(); 0052 0053 //////////////////////////////////////////////////////////// 0054 /// \brief Open the stream from its data 0055 /// 0056 /// \param data Pointer to the data in memory 0057 /// \param sizeInBytes Size of the data, in bytes 0058 /// 0059 //////////////////////////////////////////////////////////// 0060 void open(const void* data, std::size_t sizeInBytes); 0061 0062 //////////////////////////////////////////////////////////// 0063 /// \brief Read data from the stream 0064 /// 0065 /// After reading, the stream's reading position must be 0066 /// advanced by the amount of bytes read. 0067 /// 0068 /// \param data Buffer where to copy the read data 0069 /// \param size Desired number of bytes to read 0070 /// 0071 /// \return The number of bytes actually read, or -1 on error 0072 /// 0073 //////////////////////////////////////////////////////////// 0074 virtual Int64 read(void* data, Int64 size); 0075 0076 //////////////////////////////////////////////////////////// 0077 /// \brief Change the current reading position 0078 /// 0079 /// \param position The position to seek to, from the beginning 0080 /// 0081 /// \return The position actually sought to, or -1 on error 0082 /// 0083 //////////////////////////////////////////////////////////// 0084 virtual Int64 seek(Int64 position); 0085 0086 //////////////////////////////////////////////////////////// 0087 /// \brief Get the current reading position in the stream 0088 /// 0089 /// \return The current position, or -1 on error. 0090 /// 0091 //////////////////////////////////////////////////////////// 0092 virtual Int64 tell(); 0093 0094 //////////////////////////////////////////////////////////// 0095 /// \brief Return the size of the stream 0096 /// 0097 /// \return The total number of bytes available in the stream, or -1 on error 0098 /// 0099 //////////////////////////////////////////////////////////// 0100 virtual Int64 getSize(); 0101 0102 private: 0103 0104 //////////////////////////////////////////////////////////// 0105 // Member data 0106 //////////////////////////////////////////////////////////// 0107 const char* m_data; //!< Pointer to the data in memory 0108 Int64 m_size; //!< Total size of the data 0109 Int64 m_offset; //!< Current reading position 0110 }; 0111 0112 } // namespace sf 0113 0114 0115 #endif // SFML_MEMORYINPUTSTREAM_HPP 0116 0117 0118 //////////////////////////////////////////////////////////// 0119 /// \class sf::MemoryInputStream 0120 /// \ingroup system 0121 /// 0122 /// This class is a specialization of InputStream that 0123 /// reads from data in memory. 0124 /// 0125 /// It wraps a memory chunk in the common InputStream interface 0126 /// and therefore allows to use generic classes or functions 0127 /// that accept such a stream, with content already loaded in memory. 0128 /// 0129 /// In addition to the virtual functions inherited from 0130 /// InputStream, MemoryInputStream adds a function to 0131 /// specify the pointer and size of the data in memory. 0132 /// 0133 /// SFML resource classes can usually be loaded directly from 0134 /// memory, so this class shouldn't be useful to you unless 0135 /// you create your own algorithms that operate on an InputStream. 0136 /// 0137 /// Usage example: 0138 /// \code 0139 /// void process(InputStream& stream); 0140 /// 0141 /// MemoryInputStream stream; 0142 /// stream.open(thePtr, theSize); 0143 /// process(stream); 0144 /// \endcode 0145 /// 0146 /// InputStream, FileInputStream 0147 /// 0148 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|