libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::CborStreamReader Class Reference

simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++ structures More...

#include <cborstreamreader.h>

Inheritance diagram for pappso::cbor::CborStreamReader:

Public Member Functions

 CborStreamReader ()
 CborStreamReader (QIODevice *device)
virtual ~CborStreamReader ()
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 a string, beware that using this function, the cbor stream will point to the next cbor value
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 readArray (std::vector< qint64 > &int_list)
bool readArray (std::vector< double > &double_list)
bool readArray (std::vector< int > &positions)
bool readArray (std::vector< std::uint8_t > &small_int_list)
bool readArray (QStringList &str_list)
bool readArray (std::vector< QString > &str_list)

Detailed Description

simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++ structures

Definition at line 45 of file cborstreamreader.h.

Constructor & Destructor Documentation

◆ CborStreamReader() [1/2]

pappso::cbor::CborStreamReader::CborStreamReader ( )

Default constructor

Definition at line 36 of file cborstreamreader.cpp.

36 : QCborStreamReader()
37{
38}

◆ CborStreamReader() [2/2]

pappso::cbor::CborStreamReader::CborStreamReader ( QIODevice * device)

Definition at line 40 of file cborstreamreader.cpp.

40 : QCborStreamReader(device)
41{
42}

◆ ~CborStreamReader()

pappso::cbor::CborStreamReader::~CborStreamReader ( )
virtual

Destructor

Definition at line 43 of file cborstreamreader.cpp.

44{
45}

Member Function Documentation

◆ decodeString()

bool pappso::cbor::CborStreamReader::decodeString ( QString & the_str)

decode the current cbor value as a string the point to the next value the current value is decoded as a string, beware that using this function, the cbor stream will point to the next cbor value

Parameters
the_strreference to the string
Returns
true if OK

Definition at line 48 of file cborstreamreader.cpp.

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}

Referenced by pappso::cbor::mzcbor::BinaryDataArray::fromCbor(), pappso::cbor::mzcbor::CvParam::fromCbor(), pappso::cbor::mzcbor::IsolationWindow::fromCbor(), pappso::cbor::mzcbor::Precursor::fromCbor(), pappso::cbor::mzcbor::Scan::fromCbor(), pappso::cbor::mzcbor::SelectedIon::fromCbor(), pappso::cbor::mzcbor::Spectrum::fromCbor(), readArray(), readArray(), pappso::cbor::psm::PsmProteinMap::readMap(), and pappso::cbor::mzcbor::Spectrum::readScanCvParams().

◆ readArray() [1/7]

bool pappso::cbor::CborStreamReader::readArray ( QStringList & str_list)

Definition at line 176 of file cborstreamreader.cpp.

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}
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...

References decodeString().

◆ readArray() [2/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< double > & double_list)

Definition at line 69 of file cborstreamreader.cpp.

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}

◆ readArray() [3/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< int > & positions)

Definition at line 112 of file cborstreamreader.cpp.

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}

◆ readArray() [4/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< qint64 > & int_list)

Definition at line 154 of file cborstreamreader.cpp.

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}

◆ readArray() [5/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< QString > & str_list)

Definition at line 195 of file cborstreamreader.cpp.

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}

References decodeString().

◆ readArray() [6/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< std::size_t > & int_list)

Definition at line 133 of file cborstreamreader.cpp.

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}

◆ readArray() [7/7]

bool pappso::cbor::CborStreamReader::readArray ( std::vector< std::uint8_t > & small_int_list)

Definition at line 90 of file cborstreamreader.cpp.

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}

◆ readCborArray()

bool pappso::cbor::CborStreamReader::readCborArray ( QCborArray & cbor_array)

transfer the entire current CBOR array to a QCborMap object

Parameters
cbor_mapQCborMap reference to use
Returns
true if OK

Definition at line 233 of file cborstreamreader.cpp.

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}

◆ readCborMap()

bool pappso::cbor::CborStreamReader::readCborMap ( QCborMap & cbor_map)

transfer the entire current CBOR map to a QCborMap object

Parameters
cbor_mapQCborMap reference to use
Returns
true if OK

Definition at line 217 of file cborstreamreader.cpp.

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}

Referenced by pappso::cbor::psm::PsmFileAppend::close(), and pappso::cbor::psm::PsmProteinMap::readMap().


The documentation for this class was generated from the following files: