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

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

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

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

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

References accession, and valueStr.

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

◆ getExpectedQint64()

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

Definition at line 287 of file cvparam.cpp.

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

References accession, and valueStr.

◆ getExpectedUint8()

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

Definition at line 271 of file cvparam.cpp.

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

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

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

References valueDouble, valueInt, and valueStr.

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

◆ toCbor()

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

Definition at line 161 of file cvparam.cpp.

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

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

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

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

◆ toMzml()

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

Definition at line 232 of file cvparam.cpp.

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

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

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

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