libpappsomspp
Library for mass spectrometry
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
33
34
pappso::cbor::JsonStreamWriter::JsonStreamWriter
(QIODevice *device) : QTextStream(device)
35
{
36
}
37
38
pappso::cbor::JsonStreamWriter::~JsonStreamWriter
()
39
{
40
}
41
42
void
43
pappso::cbor::JsonStreamWriter::endArray
()
44
{
45
*
this
<<
"]"
<< Qt::endl;
46
m_isStart
=
false
;
47
m_nextIsValue
=
false
;
48
}
49
50
void
51
pappso::cbor::JsonStreamWriter::endMap
()
52
{
53
*
this
<<
"}"
<< Qt::endl;
54
m_isStart
=
false
;
55
m_nextIsValue
=
false
;
56
}
57
58
void
59
pappso::cbor::JsonStreamWriter::startArray
()
60
{
61
if
(!
m_nextIsValue
)
62
comma
();
63
*
this
<< Qt::endl <<
"["
;
64
m_isStart
=
true
;
65
}
66
void
67
pappso::cbor::JsonStreamWriter::startMap
()
68
{
69
if
(!
m_nextIsValue
)
70
comma
();
71
*
this
<< Qt::endl <<
"{"
;
72
m_isStart
=
true
;
73
}
74
75
void
76
pappso::cbor::JsonStreamWriter::writeCborMap
(
const
QCborMap &cbor_map)
77
{
78
QJsonDocument doc;
79
doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
80
81
*
this
<< doc.toJson();
82
}
83
84
void
85
pappso::cbor::JsonStreamWriter::writeCborArray
(
const
QCborArray &cbor_array)
86
{
87
QJsonDocument doc;
88
doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
89
90
*
this
<< doc.toJson();
91
}
92
93
94
void
95
pappso::cbor::JsonStreamWriter::appendKey
(
const
QString &key)
96
{
97
if
(!
m_isStart
)
98
comma
();
99
*
this
<<
"\""
<< key <<
"\":"
;
100
m_isStart
=
false
;
101
m_nextIsValue
=
true
;
102
}
103
104
void
105
pappso::cbor::JsonStreamWriter::appendValue
(
const
QString &value)
106
{
107
*
this
<<
"\""
<< value <<
"\""
;
108
m_nextIsValue
=
false
;
109
}
110
111
void
112
pappso::cbor::JsonStreamWriter::writeArray
(QStringList &str_list)
113
{
114
*
this
<<
"[\""
<< str_list.join(
"\", \""
) <<
"\"]"
<< Qt::endl;
115
}
116
117
void
118
pappso::cbor::JsonStreamWriter::comma
()
119
{
120
*
this
<<
","
<< Qt::endl;
121
m_isStart
=
false
;
122
}
pappso::cbor::JsonStreamWriter::comma
void comma()
Definition
jsonstreamwriter.cpp:118
pappso::cbor::JsonStreamWriter::appendValue
void appendValue(const QString &value)
Definition
jsonstreamwriter.cpp:105
pappso::cbor::JsonStreamWriter::endArray
void endArray()
Definition
jsonstreamwriter.cpp:43
pappso::cbor::JsonStreamWriter::m_nextIsValue
bool m_nextIsValue
Definition
jsonstreamwriter.h:68
pappso::cbor::JsonStreamWriter::endMap
void endMap()
Definition
jsonstreamwriter.cpp:51
pappso::cbor::JsonStreamWriter::writeCborArray
void writeCborArray(const QCborArray &cbor_array)
Definition
jsonstreamwriter.cpp:85
pappso::cbor::JsonStreamWriter::JsonStreamWriter
JsonStreamWriter(QIODevice *device)
Definition
jsonstreamwriter.cpp:34
pappso::cbor::JsonStreamWriter::m_isStart
bool m_isStart
Definition
jsonstreamwriter.h:67
pappso::cbor::JsonStreamWriter::startMap
void startMap()
Definition
jsonstreamwriter.cpp:67
pappso::cbor::JsonStreamWriter::writeArray
void writeArray(QStringList &str_list)
Definition
jsonstreamwriter.cpp:112
pappso::cbor::JsonStreamWriter::appendKey
void appendKey(const QString &key)
Definition
jsonstreamwriter.cpp:95
pappso::cbor::JsonStreamWriter::~JsonStreamWriter
virtual ~JsonStreamWriter()
Definition
jsonstreamwriter.cpp:38
pappso::cbor::JsonStreamWriter::writeCborMap
void writeCborMap(const QCborMap &cbor_map)
Definition
jsonstreamwriter.cpp:76
pappso::cbor::JsonStreamWriter::startArray
void startArray()
Definition
jsonstreamwriter.cpp:59
jsonstreamwriter.h
pappsomspp
core
processing
cbor
jsonstreamwriter.cpp
Generated on Tue Sep 23 2025 09:36:35 for libpappsomspp by
1.13.2