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
131
132bool
133CborStreamReader::readArray(QStringList &str_list)
134{
135 enterContainer();
136 QString the_str;
137 while(!lastError() && hasNext())
138 {
139 if(decodeString(the_str))
140 {
141 str_list << the_str;
142 }
143 else
144 {
145 return false;
146 }
147 }
148 leaveContainer();
149 return true;
150}
151
152bool
154{
155 cbor_map = QCborValue::fromCbor(*this).toMap();
156 if(!lastError())
157 {
158 return true;
159 }
160 else
161 {
162 qDebug() << lastError().toString();
163 }
164
165 return false;
166}
167
168bool
169CborStreamReader::readCborArray(QCborArray &cbor_array)
170{
171 cbor_array = QCborValue::fromCbor(*this).toArray();
172 if(!lastError())
173 {
174 return true;
175 }
176 else
177 {
178 qDebug() << lastError().toString();
179 }
180
181 return false;
182}
183
184} // namespace cbor
185} // 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