]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mstream.h | |
31de2596 | 3 | // Purpose: interface of wxMemoryOutputStream, wxMemoryInputStream |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
8 | /** | |
9 | @class wxMemoryOutputStream | |
7c913512 | 10 | |
31de2596 FM |
11 | This class allows to use all methods taking a wxOutputStream reference to write |
12 | to in-memory data. | |
13 | ||
14 | Example: | |
15 | @code | |
16 | wxMemoryOutputStream stream; | |
17 | if (!my_wxImage.SaveFile(stream)) | |
18 | return; | |
19 | ||
20 | // now we can access the saved image bytes: | |
21 | wxStreamBuffer* theBuffer = stream.GetOutputStreamBuffer(); | |
22 | unsigned char byte; | |
23 | if (theBuffer->Read(byte, 1) != 1) | |
24 | return; | |
25 | ||
26 | // ... do something with 'byte'... | |
27 | ||
28 | // remember that ~wxMemoryOutputStream will destroy the internal | |
29 | // buffer since we didn't provide our own when constructing it | |
30 | @endcode | |
7c913512 | 31 | |
23324ae1 FM |
32 | @library{wxbase} |
33 | @category{streams} | |
7c913512 | 34 | |
e54c96f1 | 35 | @see wxStreamBuffer |
23324ae1 FM |
36 | */ |
37 | class wxMemoryOutputStream : public wxOutputStream | |
38 | { | |
39 | public: | |
40 | /** | |
4cc4bfaf | 41 | If @a data is @NULL, then it will initialize a new empty buffer which will |
23324ae1 | 42 | grow if required. |
ba1d7a6c FM |
43 | |
44 | @warning | |
31de2596 FM |
45 | If the buffer is created by wxMemoryOutputStream, it will be destroyed |
46 | at the destruction of the stream. | |
23324ae1 | 47 | */ |
8067ee11 | 48 | wxMemoryOutputStream(void* data = NULL, size_t length = 0); |
23324ae1 FM |
49 | |
50 | /** | |
51 | Destructor. | |
31de2596 FM |
52 | |
53 | If the buffer wasn't provided by the user, it will be deleted here. | |
23324ae1 | 54 | */ |
adaaa686 | 55 | virtual ~wxMemoryOutputStream(); |
23324ae1 FM |
56 | |
57 | /** | |
ba1d7a6c FM |
58 | Allows you to transfer data from the internal buffer of wxMemoryOutputStream |
59 | to an external buffer. @a len specifies the size of the buffer. | |
23324ae1 | 60 | */ |
5267aefd | 61 | size_t CopyTo(void* buffer, size_t len) const; |
23324ae1 FM |
62 | |
63 | /** | |
64 | Returns the pointer to the stream object used as an internal buffer | |
31de2596 | 65 | for this stream. |
23324ae1 | 66 | */ |
328f5751 | 67 | wxStreamBuffer* GetOutputStreamBuffer() const; |
23324ae1 FM |
68 | }; |
69 | ||
70 | ||
e54c96f1 | 71 | |
23324ae1 FM |
72 | /** |
73 | @class wxMemoryInputStream | |
7c913512 | 74 | |
31de2596 FM |
75 | This class allows to use all methods taking a wxInputStream reference to read |
76 | in-memory data. | |
77 | ||
78 | Example: | |
79 | @code | |
80 | // we've got a block of memory containing a BMP image and we want | |
81 | // to use wxImage to load it: | |
82 | wxMemoryInputStream stream(my_memory_block, size); | |
83 | ||
84 | wxImage theBitmap; | |
85 | if (!theBitmap.LoadFile(stream, wxBITMAP_TYPE_BMP)) | |
86 | return; | |
87 | ||
88 | // we can now safely delete the original memory buffer as the data | |
89 | // has been decoded by wxImage: | |
90 | delete [] my_memory_block; | |
91 | @endcode | |
7c913512 | 92 | |
23324ae1 FM |
93 | @library{wxbase} |
94 | @category{streams} | |
7c913512 | 95 | |
e54c96f1 | 96 | @see wxStreamBuffer, wxMemoryOutputStream |
23324ae1 FM |
97 | */ |
98 | class wxMemoryInputStream : public wxInputStream | |
99 | { | |
100 | public: | |
23324ae1 | 101 | /** |
ba1d7a6c FM |
102 | Initializes a new read-only memory stream which will use the specified |
103 | buffer data of length len. The stream does not take ownership of the buffer, | |
104 | i.e. the buffer will not be deleted in its destructor. | |
23324ae1 | 105 | */ |
0a98423e | 106 | wxMemoryInputStream(const void* data, size_t len); |
ba1d7a6c FM |
107 | |
108 | /** | |
109 | Creates a new read-only memory stream, initializing it with the data from | |
110 | the given output stream @a stream. | |
111 | */ | |
7c913512 | 112 | wxMemoryInputStream(const wxMemoryOutputStream& stream); |
ba1d7a6c FM |
113 | |
114 | /** | |
115 | Creates a new read-only memory stream, initializing it with the | |
116 | data from the given input stream @a stream. | |
117 | ||
118 | The @a len argument specifies the amount of data to read from the | |
acdad9db | 119 | @a stream. Setting it to ::wxInvalidOffset means that the @a stream |
ba1d7a6c FM |
120 | is to be read entirely (i.e. till the EOF is reached). |
121 | */ | |
7c913512 FM |
122 | wxMemoryInputStream(wxInputStream& stream, |
123 | wxFileOffset len = wxInvalidOffset); | |
23324ae1 FM |
124 | |
125 | /** | |
31de2596 | 126 | Destructor. Does NOT free the buffer provided in the ctor. |
23324ae1 | 127 | */ |
adaaa686 | 128 | virtual ~wxMemoryInputStream(); |
23324ae1 FM |
129 | |
130 | /** | |
131 | Returns the pointer to the stream object used as an internal buffer | |
132 | for that stream. | |
133 | */ | |
328f5751 | 134 | wxStreamBuffer* GetInputStreamBuffer() const; |
23324ae1 | 135 | }; |
e54c96f1 | 136 |