27 class ControlledVocabulary;
29 class MetaInfoInterface;
30 class ProteinIdentification;
51 Exception::BaseException(file, line, function)
73 XMLHandler(
const std::string & filename,
const std::string & version);
122 std::string _copy = to_escape;
124 if (StringUtils::has(_copy,
'&')) StringUtils::substitute(_copy,
"&",
"&");
125 if (StringUtils::has(_copy,
'>')) StringUtils::substitute(_copy,
">",
">");
126 if (StringUtils::has(_copy,
'"')) StringUtils::substitute(_copy,
"\"",
""");
127 if (StringUtils::has(_copy,
'<')) StringUtils::substitute(_copy,
"<",
"<");
128 if (StringUtils::has(_copy,
'\'')) StringUtils::substitute(_copy,
"'",
"'");
150 if (type ==
"xsd:double" || type ==
"xsd:float" || type ==
"xsd:decimal")
152 data_value =
DataValue(StringUtils::toDouble(value));
155 else if (type ==
"xsd:byte" ||
157 type ==
"xsd:unsignedShort" ||
158 type ==
"xsd:short" ||
159 type ==
"xsd:unsignedByte" || type ==
"xsd:unsignedInt")
161 data_value =
DataValue(StringUtils::toInt32(value));
164 else if (type ==
"xsd:long" || type ==
"xsd:unsignedLong" ||
165 type ==
"xsd:integer" || type ==
"xsd:negativeInteger" ||
166 type ==
"xsd:nonNegativeInteger" || type ==
"xsd:nonPositiveInteger" || type ==
"xsd:positiveInteger")
168 data_value =
DataValue(StringUtils::toInt64(value));
192 const std::string& accession,
const std::string& name,
const std::string& value,
193 const std::string& unit_accession)
const;
231 inline bool equal_(
const char16_t * a,
const char16_t * b)
const
236 if (a ==
nullptr || b ==
nullptr)
return a == b;
237 return std::u16string_view(a) == std::u16string_view(b);
269 res = StringUtils::toInt32(in);
273 error(LOAD,std::string(
"Int conversion error of \"") + in +
"\"");
290 Int tmp = StringUtils::toInt32(in);
299 error(LOAD,std::string(
"UInt conversion error of \"") + in +
"\"");
310 res = StringUtils::toDouble(in);
314 error(LOAD,std::string(
"Double conversion error of \"") + in +
"\"");
320 inline float asFloat_(
const std::string & in)
const
325 res = StringUtils::toFloat(in);
329 error(LOAD,std::string(
"Float conversion error of \"") + in +
"\"");
341 inline bool asBool_(
const std::string & in)
const
343 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
347 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
353 error(LOAD,std::string(
"Boolean conversion error of \"") + in +
"\"");
362 if (!date_string.empty())
367 StringUtils::trim(date_string);
368 date_string = StringUtils::substr(date_string, 0, 19);
369 date_time.
set(date_string);
373 error(LOAD,std::string(
"DateTime conversion error of \"") + date_string +
"\"");
387 const char16_t * val = a.
value(name);
388 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
395 const char16_t * val = a.
value(name);
396 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
403 const char16_t * val = a.
value(name);
404 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
405 return StringUtils::toDouble(sm_.
convert(val));
424 const char16_t * val = a.
value(name);
440 const char16_t * val = a.
value(name);
456 const char16_t * val = a.
value(name);
472 const char16_t * val = a.
value(name);
475 value =StringUtils::toDouble(sm_.
convert(val));
488 const char16_t * val = a.
value(name);
491 value = attributeAsDoubleList_(a, name);
504 const char16_t * val = a.
value(name);
507 value = attributeAsStringList_(a, name);
520 const char16_t * val = a.
value(name);
523 value = attributeAsIntList_(a, name);
532 const char16_t * val = a.
value(name);
533 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
540 const char16_t * val = a.
value(name);
541 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
548 const char16_t * val = a.
value(name);
549 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
550 return StringUtils::toDouble(sm_.
convert(val));
565 const char16_t * val = a.
value(name);
569 return !value.empty();
577 const char16_t * val = a.
value(name);
589 const char16_t * val = a.
value(name);
601 const char16_t * val = a.
value(name);
604 value = StringUtils::toDouble(sm_.
convert(val));
617 const char16_t * val = a.
value(name);
620 value = attributeAsDoubleList_(a, name);
633 const char16_t * val = a.
value(name);
636 value = attributeAsIntList_(a, name);
649 const char16_t * val = a.
value(name);
652 value = attributeAsStringList_(a, name);
664 inline const std::string&
expectList_(
const std::string& str)
const
666 if (!(StringUtils::hasPrefix(str,
'[') && StringUtils::hasSuffix(str,
']')))
668 fatalError(LOAD,std::string(
"List argument is not a string representation of a list!"));
Representation of controlled vocabulary term.
Definition CVTerm.h:28
Definition ControlledVocabulary.h:29
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition DataValue.h:33
DateTime Class.
Definition DateTime.h:31
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
Exception base class.
Definition Exception.h:63
Invalid conversion exception.
Definition Exception.h:331
Parse Error exception.
Definition Exception.h:596
Helper class for XML parsing that handles the conversions of Xerces strings.
Definition StringManager.h:190
static XercesString convert(const char *str)
Transcode the supplied C string to a UTF-16 string.
static Int parseInt(const char16_t *str)
Parse an integer from a UTF-16 numeric string (as Xerces' XMLString::parseInt would).
Xerces-free, lightweight view over the attribute list of an XML element.
Definition XMLAttributes.h:32
const char16_t * value(const char16_t *qname) const
Value of the attribute named qname (UTF-16 code units), or nullptr if absent.
Exception that is thrown if the parsing is ended by some event (e.g. if only a prefix of the XML file...
Definition XMLHandler.h:48
EndParsingSoftly(const char *file, int line, const char *function)
Definition XMLHandler.h:50
Base class for XML handlers.
Definition XMLHandler.h:42
float asFloat_(const std::string &in) const
Conversion of a std::string to a float value.
Definition XMLHandler.h:320
SignedSize cvStringToEnum_(const Size section, const std::string &term, const char *message, const SignedSize result_on_error=0)
UInt asUInt_(const std::string &in) const
Conversion of a std::string to an unsigned integer value.
Definition XMLHandler.h:285
virtual LOADDETAIL getLoadDetail() const
handler which support partial loading, implement this method
bool optionalAttributeAsDouble_(double &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition XMLHandler.h:599
bool optionalAttributeAsString_(std::string &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition XMLHandler.h:563
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition XMLHandler.h:227
bool optionalAttributeAsIntList_(IntList &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition XMLHandler.h:518
virtual void setLoadDetail(const LOADDETAIL d)
handler which support partial loading, implement this method
Int asInt_(const std::string &in) const
Conversion of a std::string to an integer value.
Definition XMLHandler.h:264
void checkUniqueIdentifiers_(const std::vector< ProteinIdentification > &prot_ids) const
void warning(ActionMode mode, const std::string &msg, UInt line=0, UInt column=0) const
Warning handler.
static std::string writeXMLEscape(const std::string &to_escape)
Escapes a string and returns the escaped string.
Definition XMLHandler.h:120
StringList attributeAsStringList_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a StringList.
XMLHandler()
Not implemented.
Int attributeAsInt_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:538
StringList attributeAsStringList_(const XMLAttributes &a, const char *name) const
Converts an attribute to an StringList.
Int asInt_(const char16_t *in) const
Conversion of a Xerces string to an integer value.
Definition XMLHandler.h:279
double attributeAsDouble_(const XMLAttributes &a, const char *name) const
Converts an attribute to a double.
Definition XMLHandler.h:401
DataValue cvParamToValue(const ControlledVocabulary &cv, const std::string &parent_tag, const std::string &accession, const std::string &name, const std::string &value, const std::string &unit_accession) const
Convert the value of a <cvParam value=.> (as commonly found in PSI schemata) to the DataValue with th...
bool optionalAttributeAsStringList_(StringList &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition XMLHandler.h:502
std::string attributeAsString_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a String.
Definition XMLHandler.h:530
bool optionalAttributeAsDoubleList_(DoubleList &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition XMLHandler.h:486
LOADDETAIL
Definition XMLHandler.h:65
@ LD_RAWCOUNTS
Definition XMLHandler.h:67
@ LD_ALLDATA
Definition XMLHandler.h:66
virtual void onCharacters(const char16_t *chars, Size length)
Parsing method for character data.
std::string version_
Schema version.
Definition XMLHandler.h:214
Int attributeAsInt_(const XMLAttributes &a, const char *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:393
void fatalError(ActionMode mode, const std::string &msg, UInt line=0, UInt column=0) const
Fatal error handler. Throws a ParseError exception.
std::string attributeAsString_(const XMLAttributes &a, const char *name) const
Converts an attribute to a String.
Definition XMLHandler.h:385
ActionMode
Action to set the current mode (for error messages)
Definition XMLHandler.h:59
@ LOAD
Loading a file.
Definition XMLHandler.h:60
virtual void onStartElement(const char16_t *qname, const XMLAttributes &attributes)
Parsing method for opening tags.
void writeUserParam_(const std::string &tag_name, std::ostream &os, const MetaInfoInterface &meta, UInt indent) const
Writes the content of MetaInfoInterface to the file.
bool asBool_(const std::string &in) const
Conversion of a string to a boolean value.
Definition XMLHandler.h:341
bool optionalAttributeAsUInt_(UInt &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition XMLHandler.h:454
DoubleList attributeAsDoubleList_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a DoubleList.
bool optionalAttributeAsUInt_(UInt &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition XMLHandler.h:587
static DataValue fromXSDString(const std::string &type, const std::string &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition XMLHandler.h:146
bool equal_(const char16_t *a, const char16_t *b) const
Returns if two Xerces strings are equal.
Definition XMLHandler.h:231
StringManager sm_
Helper class for string conversion.
Definition XMLHandler.h:217
const std::string & expectList_(const std::string &str) const
Definition XMLHandler.h:664
void error(ActionMode mode, const std::string &msg, UInt line=0, UInt column=0) const
Error handler for recoverable errors.
XMLHandler(const std::string &filename, const std::string &version)
Default constructor.
double asDouble_(const std::string &in) const
Conversion of a std::string to a double value.
Definition XMLHandler.h:305
bool optionalAttributeAsStringList_(StringList &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition XMLHandler.h:647
DataValue cvParamToValue(const ControlledVocabulary &cv, const CVTerm &raw_term) const
Convert the value of a <cvParam value=.> (as commonly found in PSI schemata) to the DataValue with th...
IntList attributeAsIntList_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a IntList.
std::string file_
File name.
Definition XMLHandler.h:211
double attributeAsDouble_(const XMLAttributes &a, const char16_t *name) const
Converts an attribute to a double.
Definition XMLHandler.h:546
bool optionalAttributeAsDouble_(double &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition XMLHandler.h:470
bool optionalAttributeAsInt_(Int &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition XMLHandler.h:575
virtual void writeTo(std::ostream &)
Writes the contents to a stream.
bool optionalAttributeAsIntList_(IntList &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition XMLHandler.h:631
std::vector< std::vector< std::string > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children)
Definition XMLHandler.h:252
IntList attributeAsIntList_(const XMLAttributes &a, const char *name) const
Converts an attribute to an IntList.
DateTime asDateTime_(std::string date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition XMLHandler.h:359
bool optionalAttributeAsDoubleList_(DoubleList &value, const XMLAttributes &a, const char16_t *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition XMLHandler.h:615
void reset()
Release internal memory used for parsing (call.
std::vector< std::string > open_tags_
Stack of open XML tags.
Definition XMLHandler.h:224
bool optionalAttributeAsString_(std::string &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition XMLHandler.h:422
DoubleList attributeAsDoubleList_(const XMLAttributes &a, const char *name) const
Converts an attribute to a DoubleList.
virtual ~XMLHandler()
Destructor.
bool optionalAttributeAsInt_(Int &value, const XMLAttributes &a, const char *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition XMLHandler.h:438
virtual void onEndElement(const char16_t *qname)
Parsing method for closing tags.
int Int
Signed integer type.
Definition Types.h:72
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< Int > IntList
Vector of signed integers.
Definition TypeAliases.h:24
std::vector< double > DoubleList
Vector of double precision real types.
Definition TypeAliases.h:31
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19