30#include <catch2/internal/catch_polyfills.hpp>
32#include <qjsonobject.h>
44 reader.enterContainer();
45 QString attribute_cvparam;
46 while(reader.hasNext())
49 qDebug() << attribute_cvparam;
50 if(attribute_cvparam ==
"cvRef")
54 else if(attribute_cvparam ==
"accession")
58 else if(attribute_cvparam ==
"name")
62 else if(attribute_cvparam ==
"value")
70 else if(reader.isUnsignedInteger())
72 valueInt = reader.toUnsignedInteger();
75 else if(reader.isInteger())
80 else if(reader.type() == QCborStreamReader::Type::String)
89 QObject::tr(
"cvParam value string failed for accession %1").arg(
accession));
95 QObject::tr(
"cvParam value type not known for accession %1").arg(
accession));
98 else if(attribute_cvparam ==
"unitAccession")
103 else if(attribute_cvparam ==
"unitCvRef")
107 else if(attribute_cvparam ==
"unitName")
117 reader.leaveContainer();
125 for(
auto &the_attribute : reader.attributes())
127 if(the_attribute.name() ==
"cvRef")
129 cvRef = the_attribute.value().toString();
131 else if(the_attribute.name() ==
"accession")
133 accession = the_attribute.value().toString();
135 else if(the_attribute.name() ==
"name")
137 name = the_attribute.value().toString();
139 else if(the_attribute.name() ==
"value")
141 valueStr = the_attribute.value().toString();
143 else if(the_attribute.name() ==
"unitCvRef")
145 unitCvRef = the_attribute.value().toString();
147 else if(the_attribute.name() ==
"unitAccession")
151 else if(the_attribute.name() ==
"unitName")
153 unitName = the_attribute.value().toString();
157 reader.readNextStartElement();
166 writer.append(
"cvRef");
167 writer.append(
cvRef);
169 writer.append(
"accession");
171 writer.append(
"name");
174 writer.append(
"value");
179 writer.append(
"unitCvRef");
181 writer.append(
"unitAccession");
183 writer.append(
"unitName");
193 QJsonObject cv_param;
194 cv_param.insert(
"cvRef",
cvRef);
196 cv_param.insert(
"name",
name);
201 if(
valueInt == std::numeric_limits<qint64>::max())
219 cv_param.insert(
"unitName",
unitName);
236 writer.writeStartElement(
"cvParam");
238 writer.writeAttribute(
"cvRef",
cvRef);
239 writer.writeAttribute(
"accession",
accession);
242 if(
cborType == QCborStreamReader::Type::Double)
246 else if(
cborType == QCborStreamReader::Type::UnsignedInteger)
250 else if(
cborType == QCborStreamReader::Type::NegativeInteger)
254 else if(
cborType == QCborStreamReader::Type::String)
257 writer.writeAttribute(
"value",
valueStr);
259 writer.writeAttribute(
"name",
name);
264 writer.writeAttribute(
"unitName",
unitName);
265 writer.writeAttribute(
"unitCvRef",
unitCvRef);
268 writer.writeEndElement();
278 return (std::uint8_t)i;
283 QObject::tr(
"cvParam value string is not an integer %1 %2").arg(
accession).arg(
valueStr));
291 qint64 i =
valueStr.toLongLong(&ok);
299 QObject::tr(
"cvParam value string is not an integer %1 %2").arg(
accession).arg(
valueStr));
315 QObject::tr(
"cvParam value string is not a double %1 %2").arg(
accession).arg(
valueStr));
322 const QStringView &value_str)
325 double d = value_str.toDouble(&ok);
328 if(value_str.contains(
'.'))
330 cborType = QCborStreamReader::Type::Double;
335 qint64 bigint = value_str.toLongLong(&ok);
338 cborType = QCborStreamReader::Type::NegativeInteger;
339 writer.append(bigint);
345 cborType = QCborStreamReader::Type::String;
346 writer.append(value_str);
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...
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...
overrides QCborStreamWriter base class to provide convenient functions
PSI cvParam object for mzML/mzCBOR.
void fromCbor(CborStreamReader &reader)
QJsonObject toJsonObject() const
write the structure to a JSON object
QCborStreamReader::Type cborType
void setValue(const QString &value_str)
void xmlValueToCbor(CborStreamWriter &writer, const QStringView &value_str)
void fromMzml(QXmlStreamReader &reader)
reads the XML attributes of the cvParam element Inside the cvParam XML element, reads the attributes ...
void toCbor(CborStreamWriter &writer)
qint64 getExpectedQint64() const
void toMzml(QXmlStreamWriter &writer)
std::uint8_t getExpectedUint8() const
double getExpectedDouble() const