summaryrefslogtreecommitdiffstats
path: root/src/io/stream/bufferstream.h
blob: 811ab0d574e2fdd469981bf95d5360ee74f327f8 (plain)
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
// SPDX-License-Identifier: LGPL-2.1-or-later
/**
 * @file
 * Phoebe DOM Implementation.
 *
 * This is a C++ approximation of the W3C DOM model, which follows
 * fairly closely the specifications in the various .idl files, copies of
 * which are provided for reference.  Most important is this one:
 *
 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
 *//*
 * Authors:
 * see git history
 *   Bob Jamison
 *
 * Copyright (C) 2018 Authors
 * Released under GNU LGPL v2.1+, read the file 'COPYING' for more information.
 */
#ifndef SEEN_BUFFERSTREAM_H
#define SEEN_BUFFERSTREAM_H


#include <vector>
#include "inkscapestream.h"


namespace Inkscape
{
namespace IO
{

//#########################################################################
//# S T R I N G    I N P U T    S T R E A M
//#########################################################################

/**
 * This class is for reading character from a DOMString
 *
 */
class BufferInputStream : public InputStream
{

public:

    BufferInputStream(const std::vector<unsigned char> &sourceBuffer);
    ~BufferInputStream() override;
    int available() override;
    void close() override;
    int get() override;

private:
    const std::vector<unsigned char> &buffer;
    long position;
    bool closed;

}; // class BufferInputStream




//#########################################################################
//# B U F F E R     O U T P U T    S T R E A M
//#########################################################################

/**
 * This class is for sending a stream to a character buffer
 *
 */
class BufferOutputStream : public OutputStream
{

public:

    BufferOutputStream();
    ~BufferOutputStream() override;
    void close() override;
    void flush() override;
    int put(char ch) override;
    virtual std::vector<unsigned char> &getBuffer()
        { return buffer; }

    virtual void clear()
        { buffer.clear(); }

private:
    std::vector<unsigned char> buffer;
    bool closed;

}; // class BufferOutputStream



}  //namespace IO
}  //namespace Inkscape



#endif // SEEN_BUFFERSTREAM_H