libpappsomspp
Library for mass spectrometry
cborstreamreader.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/cborstreamwriter.h
3 * \date 08/07/2025
4 * \author Olivier Langella
5 * \brief PAPPSO CBOR stream reader
6 *
7 * QCborStreamReader overloaded with convenient functions
8 */
9
10/*******************************************************************************
11 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
12 *
13 * This file is part of PAPPSOms-tools.
14 *
15 * PAPPSOms-tools is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * PAPPSOms-tools is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
27 *
28 ******************************************************************************/
29
30#include "cborstreamreader.h"
31
33{
34}
35
36pappso::cbor::CborStreamReader::CborStreamReader(QIODevice *device) : QCborStreamReader(device)
37{
38}
40{
41}
42
43bool
45{
46 the_str.clear();
47 auto r = readString();
48 while(r.status == QCborStreamReader::Ok)
49 {
50 the_str += r.data;
51 r = readString();
52 }
53
54 if(r.status == QCborStreamReader::Error)
55 {
56 // handle error condition
57 the_str.clear();
58 return false;
59 }
60 return true;
61}
62
63
64bool
65pappso::cbor::CborStreamReader::readArray(std::vector<double> &double_list)
66{
67 enterContainer();
68 while(!lastError() && hasNext())
69 {
70 if(isDouble())
71 {
72 double_list.push_back(toDouble());
73 }
74 else
75 {
76 return false;
77 }
78 next();
79 //}
80 }
81 leaveContainer();
82 return true;
83}
84
85bool
87{
88 enterContainer();
89 while(!lastError() && hasNext())
90 {
91 if(isInteger())
92 {
93 positions.push_back(toInteger());
94 }
95 else
96 {
97 return false;
98 }
99 next();
100 //}
101 }
102 leaveContainer();
103 return true;
104}
105
106bool
107pappso::cbor::CborStreamReader::readArray(std::vector<std::size_t> &int_list)
108{
109 enterContainer();
110 while(!lastError() && hasNext())
111 {
112 if(isUnsignedInteger())
113 {
114 int_list.push_back(toUnsignedInteger());
115 }
116 else
117 {
118 return false;
119 }
120 next();
121 //}
122 }
123 leaveContainer();
124 return true;
125}
126
127
128bool
130{
131 enterContainer();
132 QString the_str;
133 while(!lastError() && hasNext())
134 {
135 if(decodeString(the_str))
136 {
137 str_list << the_str;
138 }
139 else
140 {
141 return false;
142 }
143 }
144 leaveContainer();
145 return true;
146}
147
148bool
150{
151 cbor_map = QCborValue::fromCbor(*this).toMap();
152 if(!lastError())
153 {
154 return true;
155 }
156 else
157 {
158 qDebug() << lastError().toString();
159 }
160
161 return false;
162}
163
164bool
166{
167 cbor_array = QCborValue::fromCbor(*this).toArray();
168 if(!lastError())
169 {
170 return true;
171 }
172 else
173 {
174 qDebug() << lastError().toString();
175 }
176
177 return false;
178}
bool readCborMap(QCborMap &cbor_map)
bool readCborArray(QCborArray &cbor_array)
bool readArray(std::vector< std::size_t > &int_list)
bool decodeString(QString &the_str)
decode the current cbor value as a string the point to the next value the current value is decoded as...