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<int> &positions)
91{
92 enterContainer();
93 while(!lastError() && hasNext())
94 {
95 if(isInteger())
96 {
97 positions.push_back(toInteger());
98 }
99 else
100 {
101 return false;
102 }
103 next();
104 //}
105 }
106 leaveContainer();
107 return true;
108}
109
110bool
111CborStreamReader::readArray(std::vector<std::size_t> &int_list)
112{
113 enterContainer();
114 while(!lastError() && hasNext())
115 {
116 if(isUnsignedInteger())
117 {
118 int_list.push_back(toUnsignedInteger());
119 }
120 else
121 {
122 return false;
123 }
124 next();
125 //}
126 }
127 leaveContainer();
128 return true;
129}
130
131bool
132CborStreamReader::readArray(std::vector<qint64> &int_list)
133{
134 enterContainer();
135 while(!lastError() && hasNext())
136 {
137 if(isUnsignedInteger())
138 {
139 int_list.push_back(toUnsignedInteger());
140 }
141 else
142 {
143 return false;
144 }
145 next();
146 //}
147 }
148 leaveContainer();
149 return true;
150}
151
152
153bool
154CborStreamReader::readArray(QStringList &str_list)
155{
156 enterContainer();
157 QString the_str;
158 while(!lastError() && hasNext())
159 {
160 if(decodeString(the_str))
161 {
162 str_list << the_str;
163 }
164 else
165 {
166 return false;
167 }
168 }
169 leaveContainer();
170 return true;
171}
172bool
173CborStreamReader::readArray(std::vector<QString> &str_list)
174{
175 str_list.clear();
176 str_list.reserve(length());
177 enterContainer();
178 QString the_str;
179 while(!lastError() && hasNext())
180 {
181 if(decodeString(the_str))
182 {
183 str_list.push_back(the_str);
184 }
185 else
186 {
187 return false;
188 }
189 }
190 leaveContainer();
191 return true;
192}
193
194bool
196{
197 cbor_map = QCborValue::fromCbor(*this).toMap();
198 if(!lastError())
199 {
200 return true;
201 }
202 else
203 {
204 qDebug() << lastError().toString();
205 }
206
207 return false;
208}
209
210bool
211CborStreamReader::readCborArray(QCborArray &cbor_array)
212{
213 cbor_array = QCborValue::fromCbor(*this).toArray();
214 if(!lastError())
215 {
216 return true;
217 }
218 else
219 {
220 qDebug() << lastError().toString();
221 }
222
223 return false;
224}
225
226} // namespace cbor
227} // namespace pappso
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...
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39