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 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 37 of file cvparam.cpp.

38{
39 qDebug();
40 if(!reader.isMap())
41 {
42 throw pappso::PappsoException(QObject::tr("this is not a cvParam : no map"));
43 }
44 reader.enterContainer();
45 QString attribute_cvparam;
46 while(reader.hasNext())
47 {
48 reader.decodeString(attribute_cvparam);
49 qDebug() << attribute_cvparam;
50 if(attribute_cvparam == "cvRef")
51 {
52 reader.decodeString(cvRef);
53 }
54 else if(attribute_cvparam == "accession")
55 {
56 reader.decodeString(accession);
57 }
58 else if(attribute_cvparam == "name")
59 {
60 reader.decodeString(name);
61 }
62 else if(attribute_cvparam == "value")
63 {
64 cborType = reader.type();
65 if(reader.isDouble())
66 {
67 valueDouble = reader.toDouble();
68 reader.next();
69 }
70 else if(reader.isUnsignedInteger())
71 {
72 valueInt = reader.toUnsignedInteger();
73 reader.next();
74 }
75 else if(reader.isInteger())
76 {
77 valueInt = reader.toInteger();
78 reader.next();
79 }
80 else if(reader.type() == QCborStreamReader::Type::String)
81 {
82 if(reader.decodeString(attribute_cvparam))
83 {
84 valueStr = attribute_cvparam;
85 }
86 else
87 {
88 throw pappso::PappsoException(
89 QObject::tr("cvParam value string failed for accession %1").arg(accession));
90 }
91 }
92 else
93 {
94 throw pappso::PappsoException(
95 QObject::tr("cvParam value type not known for accession %1").arg(accession));
96 }
97 }
98 else if(attribute_cvparam == "unitAccession")
99 {
100 reader.decodeString(unitAccession);
101 }
102
103 else if(attribute_cvparam == "unitCvRef")
104 {
105 reader.decodeString(unitCvRef);
106 }
107 else if(attribute_cvparam == "unitName")
108 {
109 reader.decodeString(unitName);
110 }
111 else
112 {
113 reader.next();
114 }
115 }
116
117 reader.leaveContainer();
118 qDebug();
119}
QCborStreamReader::Type cborType
Definition cvparam.h:83

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 122 of file cvparam.cpp.

123{
124 // qDebug();
125 for(auto &the_attribute : reader.attributes())
126 {
127 if(the_attribute.name() == "cvRef")
128 {
129 cvRef = the_attribute.value().toString();
130 }
131 else if(the_attribute.name() == "accession")
132 {
133 accession = the_attribute.value().toString();
134 }
135 else if(the_attribute.name() == "name")
136 {
137 name = the_attribute.value().toString();
138 }
139 else if(the_attribute.name() == "value")
140 {
141 valueStr = the_attribute.value().toString();
142 }
143 else if(the_attribute.name() == "unitCvRef")
144 {
145 unitCvRef = the_attribute.value().toString();
146 }
147 else if(the_attribute.name() == "unitAccession")
148 {
149 unitAccession = the_attribute.value().toString();
150 }
151 else if(the_attribute.name() == "unitName")
152 {
153 unitName = the_attribute.value().toString();
154 }
155 }
156
157 reader.readNextStartElement();
158 // qDebug();
159}

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

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

◆ getExpectedDouble()

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

Definition at line 304 of file cvparam.cpp.

305{
306 bool ok(false);
307 double i = valueStr.toDouble(&ok);
308 if(ok)
309 {
310 return i;
311 }
312 else
313 {
314 throw pappso::PappsoException(
315 QObject::tr("cvParam value string is not a double %1 %2").arg(accession).arg(valueStr));
316 }
317}

References accession, and valueStr.

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

◆ getExpectedQint64()

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

Definition at line 288 of file cvparam.cpp.

289{
290 bool ok(false);
291 qint64 i = valueStr.toLongLong(&ok);
292 if(ok)
293 {
294 return i;
295 }
296 else
297 {
298 throw pappso::PappsoException(
299 QObject::tr("cvParam value string is not an integer %1 %2").arg(accession).arg(valueStr));
300 }
301}

References accession, and valueStr.

◆ getExpectedUint8()

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

Definition at line 272 of file cvparam.cpp.

273{
274 bool ok(false);
275 int i = valueStr.toInt(&ok);
276 if(ok)
277 {
278 return (std::uint8_t)i;
279 }
280 else
281 {
282 throw pappso::PappsoException(
283 QObject::tr("cvParam value string is not an integer %1 %2").arg(accession).arg(valueStr));
284 }
285}

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 225 of file cvparam.cpp.

226{
227 valueInt = 0;
228 valueDouble = 0;
229 valueStr = value_str;
230}

References valueDouble, valueInt, and valueStr.

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

◆ toCbor()

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

Definition at line 162 of file cvparam.cpp.

163{
164
165 writer.startMap();
166 writer.append("cvRef");
167 writer.append(cvRef);
168
169 writer.append("accession");
170 writer.append(accession);
171 writer.append("name");
172 writer.append(name);
173
174 writer.append("value");
175 xmlValueToCbor(writer, valueStr);
176
177 if(!unitAccession.isEmpty())
178 {
179 writer.append("unitCvRef");
180 writer.append(unitCvRef);
181 writer.append("unitAccession");
182 writer.append(unitAccession);
183 writer.append("unitName");
184 writer.append(unitName);
185 }
186 writer.endMap();
187}
void xmlValueToCbor(CborStreamWriter &writer, const QStringView &value_str)
Definition cvparam.cpp:321

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 191 of file cvparam.cpp.

192{
193 QJsonObject cv_param;
194 cv_param.insert("cvRef", cvRef);
195 cv_param.insert("accession", accession);
196 cv_param.insert("name", name);
197
198
199 if(std::isnan(valueDouble))
200 {
201 if(valueInt == std::numeric_limits<qint64>::max())
202 {
203 cv_param.insert("value", valueStr);
204 }
205 else
206 {
207 cv_param.insert("value", valueInt);
208 }
209 }
210 else
211 {
212 cv_param.insert("value", valueDouble);
213 }
214
215 if(!unitAccession.isEmpty())
216 {
217 cv_param.insert("unitCvRef", unitCvRef);
218 cv_param.insert("unitAccession", unitAccession);
219 cv_param.insert("unitName", unitName);
220 }
221 return cv_param;
222}

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

◆ toMzml()

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

Definition at line 233 of file cvparam.cpp.

234{
235 // <cvParam cvRef="MS" accession="MS:1000514" value="" name="m/z array"
236 writer.writeStartElement("cvParam");
237
238 writer.writeAttribute("cvRef", cvRef);
239 writer.writeAttribute("accession", accession);
240
241
242 if(cborType == QCborStreamReader::Type::Double)
243 {
244 valueStr = QString::number(valueDouble, 'g', 15);
245 }
246 else if(cborType == QCborStreamReader::Type::UnsignedInteger)
247 {
248 valueStr = QString("%1").arg(valueInt);
249 }
250 else if(cborType == QCborStreamReader::Type::NegativeInteger)
251 {
252 valueStr = QString("%1").arg(valueInt);
253 }
254 else if(cborType == QCborStreamReader::Type::String)
255 {
256 }
257 writer.writeAttribute("value", valueStr);
258
259 writer.writeAttribute("name", name);
260 // unitAccession="MS:1000040" unitName="m/z" unitCvRef="MS" />
261 if(!unitAccession.isEmpty())
262 {
263 writer.writeAttribute("unitAccession", unitAccession);
264 writer.writeAttribute("unitName", unitName);
265 writer.writeAttribute("unitCvRef", unitCvRef);
266 }
267
268 writer.writeEndElement(); // cvParam
269}

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 321 of file cvparam.cpp.

323{
324 bool ok(false);
325 double d = value_str.toDouble(&ok);
326 if(ok)
327 {
328 if(value_str.contains('.'))
329 {
330 cborType = QCborStreamReader::Type::Double;
331 writer.append(d);
332 }
333 else
334 {
335 qint64 bigint = value_str.toLongLong(&ok);
336 if(ok)
337 {
338 cborType = QCborStreamReader::Type::NegativeInteger;
339 writer.append(bigint);
340 }
341 }
342 }
343 else
344 {
345 cborType = QCborStreamReader::Type::String;
346 writer.append(value_str);
347 }
348}

References cborType.

Referenced by toCbor().

Member Data Documentation

◆ accession

◆ cborType

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

Definition at line 83 of file cvparam.h.

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

◆ cvRef

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

◆ name

QString pappso::cbor::mzcbor::CvParam::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 75 of file cvparam.h.

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

◆ valueInt

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

Definition at line 76 of file cvparam.h.

Referenced by fromCbor(), 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