Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
cbordevice.h
Go to the documentation of this file.
1// Copyright (C) 2018 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef CBORDEVICE_H
5#define CBORDEVICE_H
6
7#include <QtCore/qtypes.h>
8
9#include <memory>
10#include <stdio.h>
11
12#define CBOR_API inline
13#define CBOR_PRIVATE_API inline
14#define CBOR_NO_PARSER_API 1
15#include <cbor.h>
16
18{
19public:
20 CborDevice(FILE *out) : out(out) {}
21
22 void nextItem(const char *comment = nullptr)
23 {
24 i = 0;
25 if (comment)
26 fprintf(out, "\n // %s", comment);
27 }
28
29 static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
30 {
31 auto that = static_cast<CborDevice *>(self);
32 auto data = static_cast<const char *>(ptr);
33 if (t == CborEncoderAppendCborData) {
34 while (len--)
35 that->putByte(*data++);
36 } else {
37 while (len--)
38 that->putChar(*data++);
39 }
40 return CborNoError;
41 }
42
43private:
44 FILE *out;
45 int i = 0;
46
47 void putNewline()
48 {
49 if ((i++ % 8) == 0)
50 fputs("\n ", out);
51 }
52
53 void putByte(uint8_t c)
54 {
55 putNewline();
56 fprintf(out, " 0x%02x, ", c);
57 }
58
59 void putChar(char c)
60 {
61 putNewline();
62 if (uchar(c) < 0x20)
63 fprintf(out, " '\\x%x',", uint8_t(c));
64 else if (uchar(c) >= 0x7f)
65 fprintf(out, " uchar('\\x%x'),", uint8_t(c));
66 else if (c == '\'' || c == '\\')
67 fprintf(out, " '\\%c',", c);
68 else
69 fprintf(out, " '%c', ", c);
70 }
71};
72
73#endif // CBORDEVICE_H
static CborError callback(void *self, const void *ptr, size_t len, CborEncoderAppendType t)
Definition cbordevice.h:29
void nextItem(const char *comment=nullptr)
Definition cbordevice.h:22
CborDevice(FILE *out)
Definition cbordevice.h:20
static ControlElement< T > * ptr(QWidget *widget)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLenum GLsizei len
unsigned char uchar
Definition qtypes.h:32
QTextStream out(stdout)
[7]