File: mstream.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (136 lines) | stat: -rw-r--r-- 4,019 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/////////////////////////////////////////////////////////////////////////////
// Name:        mstream.h
// Purpose:     interface of wxMemoryOutputStream, wxMemoryInputStream
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @class wxMemoryOutputStream

    This class allows to use all methods taking a wxOutputStream reference to write
    to in-memory data.

    Example:
    @code
        wxMemoryOutputStream stream;
        if (!my_wxImage.SaveFile(stream))
            return;

        // now we can access the saved image bytes:
        wxStreamBuffer* theBuffer = stream.GetOutputStreamBuffer();
        unsigned char byte;
        if (theBuffer->Read(byte, 1) != 1)
            return;

        // ... do something with 'byte'...

        // remember that ~wxMemoryOutputStream will destroy the internal
        // buffer since we didn't provide our own when constructing it
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxStreamBuffer
*/
class wxMemoryOutputStream : public wxOutputStream
{
public:
    /**
        If @a data is @NULL, then it will initialize a new empty buffer which will
        grow if required.

        @warning
        If the buffer is created by wxMemoryOutputStream, it will be destroyed
        at the destruction of the stream.
    */
    wxMemoryOutputStream(void* data = NULL, size_t length = 0);

    /**
        Destructor.

        If the buffer wasn't provided by the user, it will be deleted here.
    */
    virtual ~wxMemoryOutputStream();

    /**
        Allows you to transfer data from the internal buffer of wxMemoryOutputStream
        to an external buffer. @a len specifies the size of the buffer.
    */
    size_t CopyTo(void* buffer, size_t len) const;

    /**
        Returns the pointer to the stream object used as an internal buffer
        for this stream.
    */
    wxStreamBuffer* GetOutputStreamBuffer() const;
};



/**
    @class wxMemoryInputStream

    This class allows to use all methods taking a wxInputStream reference to read
    in-memory data.

    Example:
    @code
        // we've got a block of memory containing a BMP image and we want
        // to use wxImage to load it:
        wxMemoryInputStream stream(my_memory_block, size);

        wxImage theBitmap;
        if (!theBitmap.LoadFile(stream, wxBITMAP_TYPE_BMP))
            return;

        // we can now safely delete the original memory buffer as the data
        // has been decoded by wxImage:
        delete [] my_memory_block;
    @endcode

    @library{wxbase}
    @category{streams}

    @see wxStreamBuffer, wxMemoryOutputStream
*/
class wxMemoryInputStream : public wxInputStream
{
public:
    /**
        Initializes a new read-only memory stream which will use the specified
        buffer data of length len. The stream does not take ownership of the buffer,
        i.e. the buffer will not be deleted in its destructor.
    */
    wxMemoryInputStream(const void* data, size_t len);

    /**
        Creates a new read-only memory stream, initializing it with the data from
        the given output stream @a stream.
    */
    wxMemoryInputStream(const wxMemoryOutputStream& stream);

    /**
        Creates a new read-only memory stream, initializing it with the
        data from the given input stream @a stream.

        The @a len argument specifies the amount of data to read from the
        @a stream. Setting it to ::wxInvalidOffset means that the @a stream
        is to be read entirely (i.e. till the EOF is reached).
    */
    wxMemoryInputStream(wxInputStream& stream,
                        wxFileOffset len = wxInvalidOffset);

    /**
        Destructor. Does NOT free the buffer provided in the ctor.
    */
    virtual ~wxMemoryInputStream();

    /**
        Returns the pointer to the stream object used as an internal buffer
        for that stream.
    */
    wxStreamBuffer* GetInputStreamBuffer() const;
};