1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBUFFER_H
5#define QBUFFER_H
6
7#include <QtCore/qiodevice.h>
8#include <QtCore/qbytearray.h>
9
10QT_BEGIN_NAMESPACE
11
12class QObject;
13class QBufferPrivate;
14
15class Q_CORE_EXPORT QBuffer : public QIODevice
16{
17#ifndef QT_NO_QOBJECT
18 Q_OBJECT
19#endif
20
21public:
22#ifndef QT_NO_QOBJECT
23 explicit QBuffer(QObject *parent = nullptr);
24 QBuffer(QByteArray *buf, QObject *parent = nullptr);
25#else
26 QBuffer();
27 explicit QBuffer(QByteArray *buf);
28#endif
29 ~QBuffer();
30
31 QByteArray &buffer();
32 const QByteArray &buffer() const;
33 void setBuffer(QByteArray *a);
34
35 void setData(const QByteArray &data);
36#if QT_CORE_REMOVED_SINCE(6, 5) && QT_POINTER_SIZE != 4
37 void setData(const char *data, int len) { setData(data, qsizetype(len)); }
38#endif
39 void setData(const char *data, qsizetype len);
40 const QByteArray &data() const;
41
42 bool open(OpenMode openMode) override;
43
44 void close() override;
45 qint64 size() const override;
46 qint64 pos() const override;
47 bool seek(qint64 off) override;
48 bool atEnd() const override;
49 bool canReadLine() const override;
50
51protected:
52#ifndef QT_NO_QOBJECT
53 void connectNotify(const QMetaMethod &) override;
54 void disconnectNotify(const QMetaMethod &) override;
55#endif
56 qint64 readData(char *data, qint64 maxlen) override;
57 qint64 writeData(const char *data, qint64 len) override;
58
59private:
60 Q_DECLARE_PRIVATE(QBuffer)
61 Q_DISABLE_COPY(QBuffer)
62
63 Q_PRIVATE_SLOT(d_func(), void _q_emitSignals())
64};
65
66QT_END_NAMESPACE
67
68#endif // QBUFFER_H
69

source code of qtbase/src/corelib/io/qbuffer.h