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
34pappso::cbor::JsonStreamWriter::JsonStreamWriter(QIODevice *device) : QTextStream(device)
35{
36}
37
41
42void
44{
45 *this << "]" << Qt::endl;
46 m_isStart = false;
47 m_nextIsValue = false;
48}
49
50void
52{
53 *this << "}" << Qt::endl;
54 m_isStart = false;
55 m_nextIsValue = false;
56}
57
58void
60{
61 if(!m_nextIsValue)
62 comma();
63 *this << Qt::endl << "[";
64 m_isStart = true;
65}
66void
68{
69 if(!m_nextIsValue)
70 comma();
71 *this << Qt::endl << "{";
72 m_isStart = true;
73}
74
75void
77{
78 QJsonDocument doc;
79 doc.setObject(QCborValue(cbor_map).toJsonValue().toObject());
80
81 *this << doc.toJson();
82}
83
84void
86{
87 QJsonDocument doc;
88 doc.setArray(QCborValue(cbor_array).toJsonValue().toArray());
89
90 *this << doc.toJson();
91}
92
93
94void
96{
97 if(!m_isStart)
98 comma();
99 *this << "\"" << key << "\":";
100 m_isStart = false;
101 m_nextIsValue = true;
102}
103
104void
106{
107 *this << "\"" << value << "\"";
108 m_nextIsValue = false;
109}
110
111void
113{
114 *this << "[\"" << str_list.join("\", \"") << "\"]" << Qt::endl;
115}
116
117void
119{
120 *this << "," << Qt::endl;
121 m_isStart = false;
122}
void appendValue(const QString &value)
void writeCborArray(const QCborArray &cbor_array)
void writeArray(QStringList &str_list)
void appendKey(const QString &key)
void writeCborMap(const QCborMap &cbor_map)