Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:07:20

0001 // Copyright (C) 2018 Intel Corporation.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QCBORSTREAMWRITER_H
0005 #define QCBORSTREAMWRITER_H
0006 
0007 #include <QtCore/qbytearray.h>
0008 #include <QtCore/qcborcommon.h>
0009 #include <QtCore/qscopedpointer.h>
0010 #include <QtCore/qstring.h>
0011 #include <QtCore/qstringview.h>
0012 #ifndef QT_BOOTSTRAPPED
0013 #include <QtCore/qfloat16.h>
0014 #endif
0015 
0016 #include <memory>
0017 
0018 QT_REQUIRE_CONFIG(cborstreamwriter);
0019 
0020 /* X11 headers use these values too, but as defines */
0021 #if defined(False) && defined(True)
0022 #  undef True
0023 #  undef False
0024 #endif
0025 
0026 QT_BEGIN_NAMESPACE
0027 
0028 class QIODevice;
0029 
0030 class QCborStreamWriterPrivate;
0031 class Q_CORE_EXPORT QCborStreamWriter
0032 {
0033 public:
0034     explicit QCborStreamWriter(QIODevice *device);
0035     explicit QCborStreamWriter(QByteArray *data);
0036     ~QCborStreamWriter();
0037     Q_DISABLE_COPY(QCborStreamWriter)
0038 
0039     void setDevice(QIODevice *device);
0040     QIODevice *device() const;
0041 
0042     void append(quint64 u);
0043     void append(qint64 i);
0044     void append(QCborNegativeInteger n);
0045     void append(const QByteArray &ba)       { appendByteString(ba.constData(), ba.size()); }
0046     void append(QLatin1StringView str);
0047     void append(QStringView str);
0048     void append(QCborTag tag);
0049     void append(QCborKnownTags tag)         { append(QCborTag(tag)); }
0050     void append(QCborSimpleType st);
0051     void append(std::nullptr_t)             { append(QCborSimpleType::Null); }
0052 #ifndef QT_BOOTSTRAPPED
0053     void append(qfloat16 f);
0054 #endif
0055     void append(float f);
0056     void append(double d);
0057 
0058     void appendByteString(const char *data, qsizetype len);
0059     void appendTextString(const char *utf8, qsizetype len);
0060 
0061     // convenience
0062     void append(bool b)     { append(b ? QCborSimpleType::True : QCborSimpleType::False); }
0063     void appendNull()       { append(QCborSimpleType::Null); }
0064     void appendUndefined()  { append(QCborSimpleType::Undefined); }
0065 
0066 #ifndef Q_QDOC
0067     // overloads to make normal code not complain
0068     void append(int i)      { append(qint64(i)); }
0069     void append(uint u)     { append(quint64(u)); }
0070 #endif
0071 #ifndef QT_NO_CAST_FROM_ASCII
0072     void append(const char *str, qsizetype size = -1)
0073     { appendTextString(str, (str && size == -1)  ? int(strlen(str)) : size); }
0074 #endif
0075 
0076     void startArray();
0077     void startArray(quint64 count);
0078     bool endArray();
0079     void startMap();
0080     void startMap(quint64 count);
0081     bool endMap();
0082 
0083     // no API for encoding chunked strings
0084 
0085 private:
0086     std::unique_ptr<QCborStreamWriterPrivate> d;
0087 };
0088 
0089 QT_END_NAMESPACE
0090 
0091 #endif // QCBORSTREAMWRITER_H