1/****************************************************************************
2**
3** Copyright (C) 2018 Intel Corporation.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QCBORSTREAMWRITER_H
41#define QCBORSTREAMWRITER_H
42
43#include <QtCore/qbytearray.h>
44#include <QtCore/qcborcommon.h>
45#include <QtCore/qscopedpointer.h>
46#include <QtCore/qstring.h>
47#include <QtCore/qstringview.h>
48#ifndef QT_BOOTSTRAPPED
49#include <QtCore/qfloat16.h>
50#endif
51
52QT_REQUIRE_CONFIG(cborstreamwriter);
53
54// See qcborcommon.h for why we check
55#if defined(QT_X11_DEFINES_FOUND)
56# undef True
57# undef False
58#endif
59
60QT_BEGIN_NAMESPACE
61
62class QIODevice;
63
64class QCborStreamWriterPrivate;
65class Q_CORE_EXPORT QCborStreamWriter
66{
67public:
68 explicit QCborStreamWriter(QIODevice *device);
69 explicit QCborStreamWriter(QByteArray *data);
70 ~QCborStreamWriter();
71 Q_DISABLE_COPY(QCborStreamWriter)
72
73 void setDevice(QIODevice *device);
74 QIODevice *device() const;
75
76 void append(quint64 u);
77 void append(qint64 i);
78 void append(QCborNegativeInteger n);
79 void append(const QByteArray &ba) { appendByteString(data: ba.constData(), len: ba.size()); }
80 void append(QLatin1String str);
81 void append(QStringView str);
82 void append(QCborTag tag);
83 void append(QCborKnownTags tag) { append(tag: QCborTag(tag)); }
84 void append(QCborSimpleType st);
85 void append(std::nullptr_t) { append(st: QCborSimpleType::Null); }
86#ifndef QT_BOOTSTRAPPED
87 void append(qfloat16 f);
88#endif
89 void append(float f);
90 void append(double d);
91
92 void appendByteString(const char *data, qsizetype len);
93 void appendTextString(const char *utf8, qsizetype len);
94
95 // convenience
96 void append(bool b) { append(st: b ? QCborSimpleType::True : QCborSimpleType::False); }
97 void appendNull() { append(st: QCborSimpleType::Null); }
98 void appendUndefined() { append(st: QCborSimpleType::Undefined); }
99
100#ifndef Q_QDOC
101 // overloads to make normal code not complain
102 void append(int i) { append(i: qint64(i)); }
103 void append(uint u) { append(u: quint64(u)); }
104#endif
105#ifndef QT_NO_CAST_FROM_ASCII
106 void append(const char *str, qsizetype size = -1)
107 { appendTextString(utf8: str, len: (str && size == -1) ? int(strlen(s: str)) : size); }
108#endif
109
110 void startArray();
111 void startArray(quint64 count);
112 bool endArray();
113 void startMap();
114 void startMap(quint64 count);
115 bool endMap();
116
117 // no API for encoding chunked strings
118
119private:
120 QScopedPointer<QCborStreamWriterPrivate> d;
121};
122
123QT_END_NAMESPACE
124
125#if defined(QT_X11_DEFINES_FOUND)
126# define True 1
127# define False 0
128#endif
129
130#endif // QCBORSTREAMWRITER_H
131

source code of qtbase/src/corelib/serialization/qcborstreamwriter.h