19#include <xercesc/sax2/Attributes.hpp>
20#include <xercesc/sax2/DefaultHandler.hpp>
21#include <xercesc/util/XMLString.hpp>
30 class ControlledVocabulary;
32 class MetaInfoInterface;
33 class ProteinIdentification;
38 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
40 static_assert(
sizeof(
::XMLCh) ==
sizeof(
char16_t),
41 "XMLCh is not sized correctly for UTF-16.");
55 if (
nullptr == item->getOwnerDocument())
69 : item_(item, doRelease_ )
85 item_.reset(item, doRelease_ );
99 return (
nullptr == item_.get());
103 template <
typename T>
113 if (
nullptr == item->getOwnerDocument())
149 std::swap(item_, other.item_);
193 return (
nullptr == item_);
222 return fromNative_(str.c_str());
229 XMLSize_t l = strLength(str);
232 appendASCII(str,l,r);
244 return toNative_(str.
get());
260 #if defined(__GNUC__)
261 __attribute__((no_sanitize(
"address")))
262 #elif defined(_MSC_VER)
263 __declspec(no_sanitize_address)
270 return fromNative_(str).get();
276 return fromNative_(str.c_str()).get();
282 return fromNative_(str);
288 return fromNative_(str.c_str());
294 return toNative_(str);
315 public xercesc::DefaultHandler
325 Exception::BaseException(file, line, function)
342 LD_COUNTS_WITHOPTIONS
347 XMLHandler(
const std::string & filename,
const std::string & version);
361 void fatalError(
const xercesc::SAXParseException & exception)
override;
362 void error(
const xercesc::SAXParseException & exception)
override;
363 void warning(
const xercesc::SAXParseException & exception)
override;
398 std::string _copy = to_escape;
400 if (StringUtils::has(_copy,
'&')) StringUtils::substitute(_copy,
"&",
"&");
401 if (StringUtils::has(_copy,
'>')) StringUtils::substitute(_copy,
">",
">");
402 if (StringUtils::has(_copy,
'"')) StringUtils::substitute(_copy,
"\"",
""");
403 if (StringUtils::has(_copy,
'<')) StringUtils::substitute(_copy,
"<",
"<");
404 if (StringUtils::has(_copy,
'\'')) StringUtils::substitute(_copy,
"'",
"'");
426 if (type ==
"xsd:double" || type ==
"xsd:float" || type ==
"xsd:decimal")
428 data_value =
DataValue(StringUtils::toDouble(value));
431 else if (type ==
"xsd:byte" ||
433 type ==
"xsd:unsignedShort" ||
434 type ==
"xsd:short" ||
435 type ==
"xsd:unsignedByte" || type ==
"xsd:unsignedInt")
437 data_value =
DataValue(StringUtils::toInt32(value));
440 else if (type ==
"xsd:long" || type ==
"xsd:unsignedLong" ||
441 type ==
"xsd:integer" || type ==
"xsd:negativeInteger" ||
442 type ==
"xsd:nonNegativeInteger" || type ==
"xsd:nonPositiveInteger" || type ==
"xsd:positiveInteger")
444 data_value =
DataValue(StringUtils::toInt64(value));
468 const std::string& accession,
const std::string& name,
const std::string& value,
469 const std::string& unit_accession)
const;
509 return xercesc::XMLString::compareString(a, b) == 0;
541 res = StringUtils::toInt32(in);
545 error(LOAD,std::string(
"Int conversion error of \"") + in +
"\"");
553 return xercesc::XMLString::parseInt(in);
562 Int tmp = StringUtils::toInt32(in);
571 error(LOAD,std::string(
"UInt conversion error of \"") + in +
"\"");
582 res = StringUtils::toDouble(in);
586 error(LOAD,std::string(
"Double conversion error of \"") + in +
"\"");
592 inline float asFloat_(
const std::string & in)
const
597 res = StringUtils::toFloat(in);
601 error(LOAD,std::string(
"Float conversion error of \"") + in +
"\"");
613 inline bool asBool_(
const std::string & in)
const
615 if (in ==
"true" || in ==
"TRUE" || in ==
"True" || in ==
"1")
619 else if (in ==
"false" || in ==
"FALSE" || in ==
"False" || in ==
"0")
625 error(LOAD,std::string(
"Boolean conversion error of \"") + in +
"\"");
634 if (!date_string.empty())
639 StringUtils::trim(date_string);
640 date_string = StringUtils::substr(date_string, 0, 19);
641 date_time.
set(date_string);
645 error(LOAD,std::string(
"DateTime conversion error of \"") + date_string +
"\"");
660 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
668 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
669 return xercesc::XMLString::parseInt(val);
676 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + name +
"' not present!");
677 return StringUtils::toDouble(sm_.
convert(val));
683 std::string tmp(expectList_(attributeAsString_(a, name)));
684 return ListUtils::create<double>(StringUtils::substr(tmp, 1, tmp.size() - 2));
690 std::string tmp(expectList_(attributeAsString_(a, name)));
691 return ListUtils::create<Int>(StringUtils::substr(tmp, 1, tmp.size() - 2));
697 std::string tmp(expectList_(attributeAsString_(a, name)));
698 StringList tmp_list = ListUtils::create<std::string>(StringUtils::substr(tmp, 1, tmp.size() - 2));
700 if (StringUtils::hasSubstring(tmp,
"\\|"))
702 for (std::string& s : tmp_list)
704 StringUtils::substitute(s,
"\\|",
",");
736 value = xercesc::XMLString::parseInt(val);
752 value = xercesc::XMLString::parseInt(val);
768 value =StringUtils::toDouble(sm_.
convert(val));
784 value = attributeAsDoubleList_(a, name);
800 value = attributeAsStringList_(a, name);
816 value = attributeAsIntList_(a, name);
825 const XMLCh * val = a.getValue(name);
826 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
833 const XMLCh * val = a.getValue(name);
834 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
835 return xercesc::XMLString::parseInt(val);
841 const XMLCh * val = a.getValue(name);
842 if (val ==
nullptr) fatalError(LOAD,std::string(
"Required attribute '") + sm_.
convert(name) +
"' not present!");
843 return StringUtils::toDouble(sm_.
convert(val));
849 std::string tmp(expectList_(attributeAsString_(a, name)));
850 return ListUtils::create<double>(StringUtils::substr(tmp, 1, tmp.size() - 2));
856 std::string tmp(expectList_(attributeAsString_(a, name)));
857 return ListUtils::create<Int>(StringUtils::substr(tmp, 1, tmp.size() - 2));
863 std::string tmp(expectList_(attributeAsString_(a, name)));
864 StringList tmp_list = ListUtils::create<std::string>(StringUtils::substr(tmp, 1, tmp.size() - 2));
866 if (StringUtils::hasSubstring(tmp,
"\\|"))
868 for (std::string& s : tmp_list)
870 StringUtils::substitute(s,
"\\|",
",");
879 const XMLCh * val = a.getValue(name);
883 return !value.empty();
891 const XMLCh * val = a.getValue(name);
894 value = xercesc::XMLString::parseInt(val);
903 const XMLCh * val = a.getValue(name);
906 value = xercesc::XMLString::parseInt(val);
915 const XMLCh * val = a.getValue(name);
918 value = StringUtils::toDouble(sm_.
convert(val));
931 const XMLCh * val = a.getValue(name);
934 value = attributeAsDoubleList_(a, name);
947 const XMLCh * val = a.getValue(name);
950 value = attributeAsIntList_(a, name);
963 const XMLCh * val = a.getValue(name);
966 value = attributeAsStringList_(a, name);
978 inline const std::string&
expectList_(
const std::string& str)
const
980 if (!(StringUtils::hasPrefix(str,
'[') && StringUtils::hasSuffix(str,
']')))
982 fatalError(LOAD,std::string(
"List argument is not a string representation of a list!"));
char16_t XMLCh
Definition ClassTest.h:30
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:32
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:593
Definition XMLHandler.h:209
static void appendASCII(const XMLCh *str, const XMLSize_t length, std::string &result)
Transcodes the supplied XMLCh* and appends it to the OpenMS String.
static std::string toNative_(const XMLCh *str)
Converts from a wide-character string to a narrow-character string.
Definition XMLHandler.h:226
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition XMLHandler.h:280
static bool isASCII(const XMLCh *chars, const XMLSize_t length)
Checks if supplied chars in XMLCh* can be encoded with ASCII (i.e. the upper byte of each char is 0)
std::basic_string< XMLCh > XercesString
Definition XMLHandler.h:211
static std::string convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition XMLHandler.h:292
~StringManager()
Destructor.
static unique_xerces_ptr< XMLCh > convertPtr(const std::string &str)
Transcode the supplied C++ string to a xerces string pointer.
Definition XMLHandler.h:286
static XMLSize_t strLength(const XMLCh *input_ptr)
Calculates the length of a XMLCh* string using SIMDe.
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Converts from a narrow-character string to a wide-character string.
Definition XMLHandler.h:214
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition XMLHandler.h:274
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition XMLHandler.h:268
static void compress64_(const XMLCh *input_it, char *output_it)
Compresses eight 8x16bit Chars in XMLCh* to 8x8bit Chars by cutting upper byte.
StringManager()
Constructor.
static std::string toNative_(const unique_xerces_ptr< XMLCh > &str)
Converts from a wide-character string to a narrow-character string.
Definition XMLHandler.h:242
static unique_xerces_ptr< XMLCh > fromNative_(const std::string &str)
Converts from a narrow-character string to a wide-character string.
Definition XMLHandler.h:220
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:322
EndParsingSoftly(const char *file, int line, const char *function)
Definition XMLHandler.h:324
Base class for XML handlers.
Definition XMLHandler.h:316
float asFloat_(const std::string &in) const
Conversion of a std::string to a float value.
Definition XMLHandler.h:592
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:557
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition XMLHandler.h:854
virtual LOADDETAIL getLoadDetail() const
handler which support partial loading, implement this method
void startElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const xercesc::Attributes &attrs) override
Parsing method for opening tags.
void warning(const xercesc::SAXParseException &exception) override
bool optionalAttributeAsInt_(Int &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition XMLHandler.h:889
bool optionalAttributeAsStringList_(StringList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition XMLHandler.h:795
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition XMLHandler.h:503
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition XMLHandler.h:861
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition XMLHandler.h:847
bool optionalAttributeAsUInt_(UInt &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition XMLHandler.h:747
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:536
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:396
XMLHandler()
Not implemented.
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
Parsing method for closing tags.
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 optionalAttributeAsIntList_(IntList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition XMLHandler.h:945
LOADDETAIL
Definition XMLHandler.h:339
@ LD_RAWCOUNTS
Definition XMLHandler.h:341
@ LD_ALLDATA
Definition XMLHandler.h:340
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition XMLHandler.h:507
std::string version_
Schema version.
Definition XMLHandler.h:490
bool optionalAttributeAsStringList_(StringList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the StringList value if the attribute is present.
Definition XMLHandler.h:961
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition XMLHandler.h:695
bool optionalAttributeAsString_(std::string &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition XMLHandler.h:877
void fatalError(ActionMode mode, const std::string &msg, UInt line=0, UInt column=0) const
Fatal error handler. Throws a ParseError exception.
ActionMode
Action to set the current mode (for error messages)
Definition XMLHandler.h:333
@ LOAD
Loading a file.
Definition XMLHandler.h:334
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition XMLHandler.h:681
bool optionalAttributeAsDouble_(double &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition XMLHandler.h:913
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:613
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:831
Int asInt_(const XMLCh *in) const
Conversion of a Xerces string to an integer value.
Definition XMLHandler.h:551
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:665
bool optionalAttributeAsUInt_(UInt &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the UInt value if the attribute is present.
Definition XMLHandler.h:901
bool optionalAttributeAsDoubleList_(DoubleList &value, const xercesc::Attributes &a, const XMLCh *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition XMLHandler.h:929
bool optionalAttributeAsString_(std::string &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the String value if the attribute is present.
Definition XMLHandler.h:715
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:422
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition XMLHandler.h:688
StringManager sm_
Helper class for string conversion.
Definition XMLHandler.h:493
const std::string & expectList_(const std::string &str) const
Definition XMLHandler.h:978
void fatalError(const xercesc::SAXParseException &exception) override
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:577
std::string attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition XMLHandler.h:823
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition XMLHandler.h:673
std::string attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition XMLHandler.h:657
~XMLHandler() override
Destructor.
bool optionalAttributeAsDouble_(double &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the double value if the attribute is present.
Definition XMLHandler.h:763
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...
std::string file_
File name.
Definition XMLHandler.h:487
virtual void writeTo(std::ostream &)
Writes the contents to a stream.
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:524
bool optionalAttributeAsDoubleList_(DoubleList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the DoubleList value if the attribute is present.
Definition XMLHandler.h:779
DateTime asDateTime_(std::string date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition XMLHandler.h:631
void reset()
Release internal memory used for parsing (call.
void characters(const XMLCh *const chars, const XMLSize_t length) override
Parsing method for character data.
std::vector< std::string > open_tags_
Stack of open XML tags.
Definition XMLHandler.h:500
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition XMLHandler.h:839
bool optionalAttributeAsIntList_(IntList &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the IntList value if the attribute is present.
Definition XMLHandler.h:811
bool optionalAttributeAsInt_(Int &value, const xercesc::Attributes &a, const char *name) const
Assigns the attribute content to the Int value if the attribute is present.
Definition XMLHandler.h:731
void error(const xercesc::SAXParseException &exception) override
Definition XMLHandler.h:49
T * get()
Definition XMLHandler.h:88
std::shared_ptr< T > item_
Definition XMLHandler.h:63
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition XMLHandler.h:68
static void doRelease_(XMLCh *item)
bool is_released() const
Definition XMLHandler.h:97
static void doRelease_(U *item)
Definition XMLHandler.h:52
void assign(T *item)
Definition XMLHandler.h:83
shared_xerces_ptr()=default
void reset()
Definition XMLHandler.h:78
shared_xerces_ptr & operator=(T *item)
Definition XMLHandler.h:72
const T * get() const
Definition XMLHandler.h:92
Definition XMLHandler.h:105
T * item_
Definition XMLHandler.h:120
void operator=(T *i)
Definition XMLHandler.h:153
void xerces_release()
Definition XMLHandler.h:159
unique_xerces_ptr(T *i)
Definition XMLHandler.h:132
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void swap(unique_xerces_ptr< T > &other) noexcept
Definition XMLHandler.h:147
void assign(T *i)
Definition XMLHandler.h:178
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition XMLHandler.h:191
unique_xerces_ptr()
Definition XMLHandler.h:128
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition XMLHandler.h:141
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
T * yield()
Definition XMLHandler.h:170
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition XMLHandler.h:136
T * get() const
Definition XMLHandler.h:185
static void doRelease_(U *&item)
Definition XMLHandler.h:109
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 ListUtils.h:29
std::vector< double > DoubleList
Vector of double precision real types.
Definition ListUtils.h:36
std::vector< std::string > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19