libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
jsonstreamwriter.cpp
Go to the documentation of this file.
1
/**
2
* \file pappsomspp/processing/cbor/jsonstreamwriter.cpp
3
* \date 19/07/2025
4
* \author Olivier Langella
5
* \brief PAPPSO JSON stream writer
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10
*
11
* This file is part of PAPPSOms-tools.
12
*
13
* PAPPSOms-tools is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
17
*
18
* PAPPSOms-tools is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25
*
26
******************************************************************************/
27
28
#include "
jsonstreamwriter.h
"
29
#include <QJsonDocument>
30
#include <QJsonObject>
31
#include <QJsonArray>
32
#include <qjsonvalue.h>
33
34
35
pappso::cbor::JsonStreamWriter::JsonStreamWriter
(QIODevice *device) : QTextStream(device)
36
{
37
}
38
39
pappso::cbor::JsonStreamWriter::~JsonStreamWriter
()
40
{
41
}
42
43
void
44
pappso::cbor::JsonStreamWriter::endArray
()
45
{
46
*
this
<<
"]"
<< Qt::endl;
47
m_isStart
=
false
;
48
m_nextIsValue
=
false
;
49
}
50
51
void
52
pappso::cbor::JsonStreamWriter::endMap
()
53
{
54
*
this
<<
"}"
<< Qt::endl;
55
m_isStart
=
false
;
56
m_nextIsValue
=
false
;
57
}
58
59
void
60
pappso::cbor::JsonStreamWriter::startArray
()
61
{
62
if
(!
m_nextIsValue
)
63
comma
();
64
*
this
<< Qt::endl <<
"["
;
65
m_isStart
=
true
;
66
}
67
void
68
pappso::cbor::JsonStreamWriter::startMap
()
69
{
70
if
(!
m_nextIsValue
)
71
comma
();
72
*
this
<< Qt::endl <<
"{"
;
73
m_isStart
=
true
;
74
}
75
76
void
77
pappso::cbor::JsonStreamWriter::writeCborMap
(
const
QCborMap &cbor_map)
78
{
79
QJsonDocument doc;
80
doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
81
82
*
this
<< doc.toJson();
83
}
84
85
void
86
pappso::cbor::JsonStreamWriter::writeCborArray
(
const
QCborArray &cbor_array)
87
{
88
QJsonDocument doc;
89
doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
90
91
*
this
<< doc.toJson();
92
}
93
94
95
void
96
pappso::cbor::JsonStreamWriter::appendKey
(
const
QString &key)
97
{
98
if
(!
m_isStart
)
99
comma
();
100
*
this
<<
"\""
<< key <<
"\":"
;
101
m_isStart
=
false
;
102
m_nextIsValue
=
true
;
103
}
104
105
void
106
pappso::cbor::JsonStreamWriter::appendValue
(
const
QString &value)
107
{
108
*
this
<<
"\""
<< value <<
"\""
;
109
m_nextIsValue
=
false
;
110
}
111
112
void
113
pappso::cbor::JsonStreamWriter::appendValue
(std::size_t integer_size_value)
114
{
115
*
this
<< integer_size_value;
116
m_nextIsValue
=
false
;
117
}
118
119
120
void
121
pappso::cbor::JsonStreamWriter::writeArray
(QStringList &str_list)
122
{
123
*
this
<<
"[\""
<< str_list.join(
"\", \""
) <<
"\"]"
<< Qt::endl;
124
}
125
126
void
127
pappso::cbor::JsonStreamWriter::comma
()
128
{
129
*
this
<<
","
<< Qt::endl;
130
m_isStart
=
false
;
131
}
pappso::cbor::JsonStreamWriter::comma
void comma()
Definition
jsonstreamwriter.cpp:127
pappso::cbor::JsonStreamWriter::appendValue
void appendValue(const QString &value)
writes String value to JSON text
Definition
jsonstreamwriter.cpp:106
pappso::cbor::JsonStreamWriter::endArray
void endArray()
ends an array in JSON output simply print "]"
Definition
jsonstreamwriter.cpp:44
pappso::cbor::JsonStreamWriter::m_nextIsValue
bool m_nextIsValue
Definition
jsonstreamwriter.h:115
pappso::cbor::JsonStreamWriter::endMap
void endMap()
ends an object in JSON output simply print "}"
Definition
jsonstreamwriter.cpp:52
pappso::cbor::JsonStreamWriter::writeCborArray
void writeCborArray(const QCborArray &cbor_array)
converts a CBOR array (list) into JSON text in output
Definition
jsonstreamwriter.cpp:86
pappso::cbor::JsonStreamWriter::JsonStreamWriter
JsonStreamWriter(QIODevice *device)
build a QTextStream for JSON writer
Definition
jsonstreamwriter.cpp:35
pappso::cbor::JsonStreamWriter::m_isStart
bool m_isStart
Definition
jsonstreamwriter.h:114
pappso::cbor::JsonStreamWriter::startMap
void startMap()
start an object in JSON output simply print "{"
Definition
jsonstreamwriter.cpp:68
pappso::cbor::JsonStreamWriter::writeArray
void writeArray(QStringList &str_list)
convert a string list to a JSON array
Definition
jsonstreamwriter.cpp:121
pappso::cbor::JsonStreamWriter::appendKey
void appendKey(const QString &key)
writes a key (dictionary entry) to JSON text
Definition
jsonstreamwriter.cpp:96
pappso::cbor::JsonStreamWriter::~JsonStreamWriter
virtual ~JsonStreamWriter()
Definition
jsonstreamwriter.cpp:39
pappso::cbor::JsonStreamWriter::writeCborMap
void writeCborMap(const QCborMap &cbor_map)
converts a CBOR map (object) into JSON text in output
Definition
jsonstreamwriter.cpp:77
pappso::cbor::JsonStreamWriter::startArray
void startArray()
starts an array in JSON output simply print "["
Definition
jsonstreamwriter.cpp:60
jsonstreamwriter.h
pappsomspp
core
processing
cbor
jsonstreamwriter.cpp
Generated on
for libpappsomspp by
1.17.0