Coverage Report

Created: 2026-09-20 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wxwidgets/include/wx/mstream.h
Line
Count
Source
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/mstream.h
3
// Purpose:     Memory stream classes
4
// Author:      Guilhem Lavaux
5
// Created:     11/07/98
6
// Copyright:   (c) Guilhem Lavaux
7
// Licence:     wxWindows licence
8
/////////////////////////////////////////////////////////////////////////////
9
10
#ifndef _WX_WXMMSTREAM_H__
11
#define _WX_WXMMSTREAM_H__
12
13
#include "wx/defs.h"
14
15
#if wxUSE_STREAMS
16
17
#include "wx/stream.h"
18
19
class WXDLLIMPEXP_FWD_BASE wxMemoryOutputStream;
20
21
class WXDLLIMPEXP_BASE wxMemoryInputStream : public wxInputStream
22
{
23
public:
24
    wxMemoryInputStream(const void *data, size_t length);
25
    wxMemoryInputStream(const wxMemoryOutputStream& stream);
26
    wxMemoryInputStream(wxInputStream& stream,
27
                        wxFileOffset lenFile = wxInvalidOffset)
28
0
    {
29
0
        InitFromStream(stream, lenFile);
30
0
    }
31
    wxMemoryInputStream(wxMemoryInputStream& stream)
32
        : wxInputStream()
33
0
    {
34
0
        InitFromStream(stream, wxInvalidOffset);
35
0
    }
36
37
    virtual ~wxMemoryInputStream();
38
0
    virtual wxFileOffset GetLength() const override { return m_length; }
39
52.3k
    virtual bool IsSeekable() const override { return true; }
40
41
    virtual char Peek() override;
42
    virtual bool CanRead() const override;
43
44
0
    wxStreamBuffer *GetInputStreamBuffer() const { return m_i_streambuf; }
45
46
protected:
47
    wxStreamBuffer *m_i_streambuf;
48
49
    size_t OnSysRead(void *buffer, size_t nbytes) override;
50
    wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) override;
51
    wxFileOffset OnSysTell() const override;
52
53
private:
54
    // common part of ctors taking wxInputStream
55
    void InitFromStream(wxInputStream& stream, wxFileOffset lenFile);
56
57
    size_t m_length;
58
59
    // copy ctor is implemented above: it copies the other stream in this one
60
    wxDECLARE_ABSTRACT_CLASS(wxMemoryInputStream);
61
    wxDECLARE_NO_ASSIGN_CLASS(wxMemoryInputStream);
62
};
63
64
class WXDLLIMPEXP_BASE wxMemoryOutputStream : public wxOutputStream
65
{
66
public:
67
    // if data is not null it must be allocated with malloc()
68
    wxMemoryOutputStream(void *data = nullptr, size_t length = 0);
69
    virtual ~wxMemoryOutputStream();
70
0
    virtual wxFileOffset GetLength() const override { return m_o_streambuf->GetLastAccess(); }
71
0
    virtual bool IsSeekable() const override { return true; }
72
73
    size_t CopyTo(void *buffer, size_t len) const;
74
75
0
    wxStreamBuffer *GetOutputStreamBuffer() const { return m_o_streambuf; }
76
77
protected:
78
    wxStreamBuffer *m_o_streambuf;
79
80
protected:
81
    size_t OnSysWrite(const void *buffer, size_t nbytes) override;
82
    wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode) override;
83
    wxFileOffset OnSysTell() const override;
84
85
    wxDECLARE_DYNAMIC_CLASS(wxMemoryOutputStream);
86
    wxDECLARE_NO_COPY_CLASS(wxMemoryOutputStream);
87
};
88
89
#endif
90
  // wxUSE_STREAMS
91
92
#endif
93
  // _WX_WXMMSTREAM_H__