libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::mzcbor::CvParam Struct Reference

#include <cvparam.h>

Public Member Functions

void fromCbor (CborStreamReader &reader)
void fromQCborMap (const QCborMap &reader)
void toCbor (CborStreamWriter &writer)
void fromMzml (QXmlStreamReader &reader)
 reads the XML attributes of the cvParam element Inside the cvParam XML element, reads the attributes and go to next XML element
void toMzml (QXmlStreamWriter &writer)
QJsonObject toJsonObject () const
 write the structure to a JSON object
void xmlValueToCbor (CborStreamWriter &writer, const QStringView &value_str)
void setValue (const QString &value_str)
std::uint8_t getExpectedUint8 () const
double getExpectedDouble () const
qint64 getExpectedQint64 () const

Public Attributes

QString cvRef
QString accession
double valueDouble = nan("")
qint64 valueInt = std::numeric_limits<qint64>::max()
QString valueStr
QString name
QString unitAccession
QString unitName
QString unitCvRef
QCborStreamReader::Type cborType = QCborStreamReader::Type::Invalid

Detailed Description

Todo
write docs

Definition at line 46 of file cvparam.h.

Member Function Documentation

◆ fromCbor()

void pappso::cbor::mzcbor::CvParam::fromCbor ( CborStreamReader & reader)

Definition at line 92 of file cvparam.cpp.

93{
94 qDebug();
95 if(!reader.isMap())
96 {
97 throw pappso::PappsoException(QObject::tr("this is not a cvParam : no map"));
98 }
99 reader.enterContainer();
100 QString attribute_cvparam;
101 while(reader.hasNext())
102 {
103 reader.decodeString(attribute_cvparam);
104 qDebug() << attribute_cvparam;
105 if(attribute_cvparam == "cvRef")
106 {
107 reader.decodeString(cvRef);
108 }
109 else if(attribute_cvparam == "accession")
110 {
111 reader.decodeString(accession);
112 }
113 else if(attribute_cvparam == "name")
114 {
115 reader.decodeString(name);
116 }
117 else if(attribute_cvparam == "value")
118 {
119 cborType = reader.type();
120 if(reader.isDouble())
121 {
122 valueDouble = reader.toDouble();
123 reader.next();
124 }
125 else if(reader.isUnsignedInteger())
126 {
127 valueInt = reader.toUnsignedInteger();
128 reader.next();
129 }
130 else if(reader.isInteger())
131 {
132 valueInt = reader.toInteger();
133 reader.next();
134 }
135 else if(reader.type() == QCborStreamReader::Type::String)
136 {
137 if(reader.decodeString(attribute_cvparam))
138 {
139 valueStr = attribute_cvparam;
140 }
141 else
142 {
143 throw pappso::PappsoException(
144 QObject::tr("cvParam value string failed for accession %1").arg(accession));
145 }
146 }
147 else
148 {
149 throw pappso::PappsoException(
150 QObject::tr("cvParam value type not known for accession %1").arg(accession));
151 }
152 }
153 else if(attribute_cvparam == "unitAccession")
154 {
155 reader.decodeString(unitAccession);
156 }
157
158 else if(attribute_cvparam == "unitCvRef")
159 {
160 reader.decodeString(unitCvRef);
161 }
162 else if(attribute_cvparam == "unitName")
163 {
164 reader.decodeString(unitName);
165 }
166 else
167 {
168 reader.next();
169 }
170 }
171
172 reader.leaveContainer();
173 qDebug();
174}
QCborStreamReader::Type cborType
Definition cvparam.h:84

References accession, cborType, cvRef, pappso::cbor::CborStreamReader::decodeString(), name, unitAccession, unitCvRef, unitName, valueDouble, valueInt, and valueStr.

Referenced by pappso::cbor::mzcbor::CvParamMap::fromCbor(), and pappso::cbor::mzcbor::MzcborReaderBase::getCvParamsMap().

◆ fromMzml()

void pappso::cbor::mzcbor::CvParam::fromMzml ( QXmlStreamReader & reader)

reads the XML attributes of the cvParam element Inside the cvParam XML element, reads the attributes and go to next XML element

Parameters
readerXML stream reader

Definition at line 177 of file cvparam.cpp.

178{
179 // qDebug();
180 for(auto &the_attribute : reader.attributes())
181 {
182 if(the_attribute.name() == "cvRef")
183 {
184 cvRef = the_attribute.value().toString();
185 }
186 else if(the_attribute.name() == "accession")
187 {
188 accession = the_attribute.value().toString();
189 }
190 else if(the_attribute.name() == "name")
191 {
192 name = the_attribute.value().toString();
193 }
194 else if(the_attribute.name() == "value")
195 {
196 valueStr = the_attribute.value().toString();
197 }
198 else if(the_attribute.name() == "unitCvRef")
199 {
200 unitCvRef = the_attribute.value().toString();
201 }
202 else if(the_attribute.name() == "unitAccession")
203 {
204 unitAccession = the_attribute.value().toString();
205 }
206 else if(the_attribute.name() == "unitName")
207 {
208 unitName = the_attribute.value().toString();
209 }
210 }
211
212 reader.readNextStartElement();
213 // qDebug();
214}

References accession, cvRef, name, unitAccession, unitCvRef, unitName, and valueStr.

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ fromQCborMap()

void pappso::cbor::mzcbor::CvParam::fromQCborMap ( const QCborMap & reader)

Definition at line 36 of file cvparam.cpp.

37{
38 QString txt_value;
39 for(auto it_binarr = cbor_map.cbegin(); it_binarr != cbor_map.cend(); it_binarr++)
40 {
41 txt_value = it_binarr.key().toString();
42 qDebug() << txt_value;
43
44 if(txt_value == "cvRef")
45 {
46 cvRef = it_binarr.value().toString();
47 }
48 else if(txt_value == "accession")
49 {
50 accession = it_binarr.value().toString();
51 }
52 else if(txt_value == "name")
53 {
54 name = it_binarr.value().toString();
55 }
56 else if(txt_value == "value")
57 {
58 if(it_binarr.value().isDouble())
59 {
60 valueDouble = it_binarr.value().toDouble();
61 }
62 else if(it_binarr.value().isInteger())
63 {
64 valueInt = it_binarr.value().toInteger();
65 }
66 else if(it_binarr.value().isString())
67 {
68 valueStr = it_binarr.value().toString();
69 }
70 else
71 {
72 throw pappso::PappsoException(
73 QObject::tr("cvParam value type not known for accession %1").arg(accession));
74 }
75 }
76 else if(txt_value == "unitAccession")
77 {
78 unitAccession = it_binarr.value().toString();
79 }
80
81 else if(txt_value == "unitCvRef")
82 {
83 unitCvRef = it_binarr.value().toString();
84 }
85 else if(txt_value == "unitName")
86 {
87 unitName = it_binarr.value().toString();
88 }
89 }
90}

References accession, cvRef, name, unitAccession, unitCvRef, unitName, valueDouble, valueInt, and valueStr.

Referenced by pappso::cbor::mzcbor::CvParamMap::fromQCborArray().

◆ getExpectedDouble()

double pappso::cbor::mzcbor::CvParam::getExpectedDouble ( ) const

Definition at line 359 of file cvparam.cpp.

360{
361 bool ok(false);
362 double i = valueStr.toDouble(&ok);
363 if(ok)
364 {
365 return i;
366 }
367 else
368 {
369 throw pappso::PappsoException(
370 QObject::tr("cvParam value string is not a double %1 %2").arg(accession).arg(valueStr));
371 }
372}

References accession, and valueStr.

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ getExpectedQint64()

qint64 pappso::cbor::mzcbor::CvParam::getExpectedQint64 ( ) const

Definition at line 343 of file cvparam.cpp.

344{
345 bool ok(false);
346 qint64 i = valueStr.toLongLong(&ok);
347 if(ok)
348 {
349 return i;
350 }
351 else
352 {
353 throw pappso::PappsoException(
354 QObject::tr("cvParam value string is not an integer %1 %2").arg(accession).arg(valueStr));
355 }
356}

References accession, and valueStr.

◆ getExpectedUint8()

std::uint8_t pappso::cbor::mzcbor::CvParam::getExpectedUint8 ( ) const

Definition at line 327 of file cvparam.cpp.

328{
329 bool ok(false);
330 int i = valueStr.toInt(&ok);
331 if(ok)
332 {
333 return (std::uint8_t)i;
334 }
335 else
336 {
337 throw pappso::PappsoException(
338 QObject::tr("cvParam value string is not an integer %1 %2").arg(accession).arg(valueStr));
339 }
340}

References accession, and valueStr.

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ setValue()

void pappso::cbor::mzcbor::CvParam::setValue ( const QString & value_str)

Definition at line 280 of file cvparam.cpp.

281{
282 valueInt = 0;
283 valueDouble = 0;
284 valueStr = value_str;
285}

References valueDouble, valueInt, and valueStr.

Referenced by pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ toCbor()

void pappso::cbor::mzcbor::CvParam::toCbor ( CborStreamWriter & writer)

Definition at line 217 of file cvparam.cpp.

218{
219
220 writer.startMap();
221 writer.append("cvRef");
222 writer.append(cvRef);
223
224 writer.append("accession");
225 writer.append(accession);
226 writer.append("name");
227 writer.append(name);
228
229 writer.append("value");
230 xmlValueToCbor(writer, valueStr);
231
232 if(!unitAccession.isEmpty())
233 {
234 writer.append("unitCvRef");
235 writer.append(unitCvRef);
236 writer.append("unitAccession");
237 writer.append(unitAccession);
238 writer.append("unitName");
239 writer.append(unitName);
240 }
241 writer.endMap();
242}
void xmlValueToCbor(CborStreamWriter &writer, const QStringView &value_str)
Definition cvparam.cpp:376

References accession, cvRef, name, unitAccession, unitCvRef, unitName, valueStr, and xmlValueToCbor().

Referenced by pappso::cbor::mzcbor::MzmlConvert::insideElement().

◆ toJsonObject()

QJsonObject pappso::cbor::mzcbor::CvParam::toJsonObject ( ) const

write the structure to a JSON object

Returns
QJsonObject

Definition at line 246 of file cvparam.cpp.

247{
248 QJsonObject cv_param;
249 cv_param.insert("cvRef", cvRef);
250 cv_param.insert("accession", accession);
251 cv_param.insert("name", name);
252
253
254 if(std::isnan(valueDouble))
255 {
256 if(valueInt == std::numeric_limits<qint64>::max())
257 {
258 cv_param.insert("value", valueStr);
259 }
260 else
261 {
262 cv_param.insert("value", valueInt);
263 }
264 }
265 else
266 {
267 cv_param.insert("value", valueDouble);
268 }
269
270 if(!unitAccession.isEmpty())
271 {
272 cv_param.insert("unitCvRef", unitCvRef);
273 cv_param.insert("unitAccession", unitAccession);
274 cv_param.insert("unitName", unitName);
275 }
276 return cv_param;
277}

References accession, cvRef, name, unitAccession, unitCvRef, unitName, valueDouble, valueInt, and valueStr.

◆ toMzml()

void pappso::cbor::mzcbor::CvParam::toMzml ( QXmlStreamWriter & writer)

Definition at line 288 of file cvparam.cpp.

289{
290 // <cvParam cvRef="MS" accession="MS:1000514" value="" name="m/z array"
291 writer.writeStartElement("cvParam");
292
293 writer.writeAttribute("cvRef", cvRef);
294 writer.writeAttribute("accession", accession);
295
296
297 if(cborType == QCborStreamReader::Type::Double)
298 {
299 valueStr = QString::number(valueDouble, 'g', 15);
300 }
301 else if(cborType == QCborStreamReader::Type::UnsignedInteger)
302 {
303 valueStr = QString("%1").arg(valueInt);
304 }
305 else if(cborType == QCborStreamReader::Type::NegativeInteger)
306 {
307 valueStr = QString("%1").arg(valueInt);
308 }
309 else if(cborType == QCborStreamReader::Type::String)
310 {
311 }
312 writer.writeAttribute("value", valueStr);
313
314 writer.writeAttribute("name", name);
315 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
316 if(!unitAccession.isEmpty())
317 {
318 writer.writeAttribute("unitAccession", unitAccession);
319 writer.writeAttribute("unitName", unitName);
320 writer.writeAttribute("unitCvRef", unitCvRef);
321 }
322
323 writer.writeEndElement(); // cvParam
324}

References accession, cborType, cvRef, name, unitAccession, unitCvRef, unitName, valueDouble, valueInt, and valueStr.

Referenced by pappso::cbor::mzcbor::BinaryDataArray::toMzml().

◆ xmlValueToCbor()

void pappso::cbor::mzcbor::CvParam::xmlValueToCbor ( CborStreamWriter & writer,
const QStringView & value_str )

Definition at line 376 of file cvparam.cpp.

378{
379 bool ok(false);
380 double d = value_str.toDouble(&ok);
381 if(ok)
382 {
383 if(value_str.contains('.'))
384 {
385 cborType = QCborStreamReader::Type::Double;
386 writer.append(d);
387 }
388 else
389 {
390 qint64 bigint = value_str.toLongLong(&ok);
391 if(ok)
392 {
393 cborType = QCborStreamReader::Type::NegativeInteger;
394 writer.append(bigint);
395 }
396 }
397 }
398 else
399 {
400 cborType = QCborStreamReader::Type::String;
401 writer.append(value_str);
402 }
403}

References cborType.

Referenced by toCbor().

Member Data Documentation

◆ accession

◆ cborType

QCborStreamReader::Type pappso::cbor::mzcbor::CvParam::cborType = QCborStreamReader::Type::Invalid

Definition at line 84 of file cvparam.h.

Referenced by fromCbor(), toMzml(), and xmlValueToCbor().

◆ cvRef

QString pappso::cbor::mzcbor::CvParam::cvRef

◆ name

◆ unitAccession

QString pappso::cbor::mzcbor::CvParam::unitAccession

◆ unitCvRef

QString pappso::cbor::mzcbor::CvParam::unitCvRef

◆ unitName

QString pappso::cbor::mzcbor::CvParam::unitName

◆ valueDouble

double pappso::cbor::mzcbor::CvParam::valueDouble = nan("")

Definition at line 76 of file cvparam.h.

Referenced by fromCbor(), fromQCborMap(), setValue(), toJsonObject(), and toMzml().

◆ valueInt

qint64 pappso::cbor::mzcbor::CvParam::valueInt = std::numeric_limits<qint64>::max()

Definition at line 77 of file cvparam.h.

Referenced by fromCbor(), fromQCborMap(), setValue(), toJsonObject(), and toMzml().

◆ valueStr

QString pappso::cbor::mzcbor::CvParam::valueStr

The documentation for this struct was generated from the following files:
  • pappsomspp/core/processing/cbor/mzcbor/cvparam.h
  • pappsomspp/core/processing/cbor/mzcbor/cvparam.cpp