libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
32namespace pappso
33{
34namespace cbor
35{
37{
38}
39
40CborStreamReader::CborStreamReader(QIODevice *device) : QCborStreamReader(device)
41{
42}
46
47bool
49{
50 the_str.clear();
51 auto r = readString();
52 while(r.status == QCborStreamReader::Ok)
53 {
54 the_str += r.data;
55 r = readString();
56 }
57
58 if(r.status == QCborStreamReader::Error)
59 {
60 // handle error condition
61 the_str.clear();
62 return false;
63 }
64 return true;
65}
66
67
68bool
69CborStreamReader::readArray(std::vector<double> &double_list)
70{
71 enterContainer();
72 while(!lastError() && hasNext())
73 {
74 if(isDouble())
75 {
76 double_list.push_back(toDouble());
77 }
78 else
79 {
80 return false;
81 }
82 next();
83 //}
84 }
85 leaveContainer();
86 return true;
87}
88
89bool
90CborStreamReader::readArray(std::vector<std::uint8_t> &small_int_list)
91{
92
93 enterContainer();
94 while(!lastError() && hasNext())
95 {
96 if(isInteger())
97 {
98 small_int_list.push_back(toInteger());
99 }
100 else
101 {
102 return false;
103 }
104 next();
105 //}
106 }
107 leaveContainer();
108 return true;
109}
110
111bool
112CborStreamReader::readArray(std::vector<int> &positions)
113{
114 enterContainer();
115 while(!lastError() && hasNext())
116 {
117 if(isInteger())
118 {
119 positions.push_back(toInteger());
120 }
121 else
122 {
123 return false;
124 }
125 next();
126 //}
127 }
128 leaveContainer();
129 return true;
130}
131
132bool
133CborStreamReader::readArray(std::vector<std::size_t> &int_list)
134{
135 enterContainer();
136 while(!lastError() && hasNext())
137 {
138 if(isUnsignedInteger())
139 {
140 int_list.push_back(toUnsignedInteger());
141 }
142 else
143 {
144 return false;
145 }
146 next();
147 //}
148 }
149 leaveContainer();
150 return true;
151}
152
153bool
154CborStreamReader::readArray(std::vector<qint64> &int_list)
155{
156 enterContainer();
157 while(!lastError() && hasNext())
158 {
159 if(isUnsignedInteger())
160 {
161 int_list.push_back(toUnsignedInteger());
162 }
163 else
164 {
165 return false;
166 }
167 next();
168 //}
169 }
170 leaveContainer();
171 return true;
172}
173
174
175bool
176CborStreamReader::readArray(QStringList &str_list)
177{
178 enterContainer();
179 QString the_str;
180 while(!lastError() && hasNext())
181 {
182 if(decodeString(the_str))
183 {
184 str_list << the_str;
185 }
186 else
187 {
188 return false;
189 }
190 }
191 leaveContainer();
192 return true;
193}
194bool
195CborStreamReader::readArray(std::vector<QString> &str_list)
196{
197 str_list.clear();
198 str_list.reserve(length());
199 enterContainer();
200 QString the_str;
201 while(!lastError() && hasNext())
202 {
203 if(decodeString(the_str))
204 {
205 str_list.push_back(the_str);
206 }
207 else
208 {
209 return false;
210 }
211 }
212 leaveContainer();
213 return true;
214}
215
216bool
218{
219 cbor_map = QCborValue::fromCbor(*this).toMap();
220 if(!lastError())
221 {
222 return true;
223 }
224 else
225 {
226 qDebug() << lastError().toString();
227 }
228
229 return false;
230}
231
232bool
233CborStreamReader::readCborArray(QCborArray &cbor_array)
234{
235 cbor_array = QCborValue::fromCbor(*this).toArray();
236 if(!lastError())
237 {
238 return true;
239 }
240 else
241 {
242 qDebug() << lastError().toString();
243 }
244
245 return false;
246}
247
248} // namespace cbor
249} // namespace pappso
bool readCborMap(QCborMap &cbor_map)
transfer the entire current CBOR map to a QCborMap object
bool readCborArray(QCborArray &cbor_array)
transfer the entire current CBOR array to a QCborMap object
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...
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39