OpenMS
Loading...
Searching...
No Matches
XMLHandler.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Marc Sturm, Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13
14
17
18#include <xercesc/sax2/Attributes.hpp>
19#include <xercesc/sax2/DefaultHandler.hpp>
20#include <xercesc/util/XMLString.hpp>
21
22#include <iosfwd>
23#include <string>
24#include <memory>
25
26
27namespace OpenMS
28{
29 class ControlledVocabulary;
30 class CVTerm;
31 class MetaInfoInterface;
32 class ProteinIdentification;
33
34 namespace Internal
35 {
36
37 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
38
39 static_assert(sizeof(::XMLCh) == sizeof(char16_t),
40 "XMLCh is not sized correctly for UTF-16.");
41
42 //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
43 //Copyright 2010 Orjan Westin
44 //Under BSD license
45 //========================================================================================================
46 template<typename T>
47 class OPENMS_DLLAPI shared_xerces_ptr
48 {
49 // Function to release Xerces data type with a release member function
50 template<typename U>
51 static void doRelease_(U* item)
52 {
53 // Only release this if it has no owner
54 if (nullptr == item->getOwnerDocument())
55 item->release();
56 }
57
58 static void doRelease_(char* item);
59 static void doRelease_(XMLCh* item);
60
61 // The actual data we're holding
62 std::shared_ptr<T> item_;
63 public:
64 // Default constructor
65 shared_xerces_ptr() = default;
66 // Assignment constructor
68 : item_(item, doRelease_ )
69 {}
70 // Assignment of data to guard
72 {
73 assign(item);
74 return *this;
75 }
76 // Give up hold on data
77 void reset()
78 {
79 item_.reset();
80 }
81 // Release currently held data, if any, to hold another
82 void assign(T* item)
83 {
84 item_.reset(item, doRelease_ );
85 }
86 // Get pointer to the currently held data, if any
87 T* get()
88 {
89 return item_.get();
90 }
91 const T* get() const
92 {
93 return item_.get();
94 }
95 // Return true if no data is held
96 bool is_released() const
97 {
98 return (nullptr == item_.get());
99 }
100 };
101
102 template <typename T>
103 class OPENMS_DLLAPI unique_xerces_ptr
104 {
105 private:
106
107 template<typename U>
108 static void doRelease_(U*& item)
109 {
110 // Only release this if it has no parent (otherwise
111 // parent will release it)
112 if (nullptr == item->getOwnerDocument())
113 item->release();
114 }
115
116 static void doRelease_(char*& item);
117 static void doRelease_(XMLCh*& item);
118
120
121 public:
122
123 // Hide copy constructor and assignment operator
126
128 : item_(nullptr)
129 {}
130
131 explicit unique_xerces_ptr(T* i)
132 : item_(i)
133 {}
134
136 {
137 xerces_release();
138 }
139
141 : item_(nullptr)
142 {
143 this->swap(other);
144 }
145
146 void swap(unique_xerces_ptr<T>& other) noexcept
147 {
148 std::swap(item_, other.item_);
149 }
150
151 // Assignment of data to guard (not chainable)
152 void operator=(T* i)
153 {
154 reassign(i);
155 }
156
157 // Release held data (i.e. delete/free it)
159 {
160 if (!is_released())
161 {
162 // Use type-specific release mechanism
163 doRelease_(item_);
164 item_ = nullptr;
165 }
166 }
167
168 // Give up held data (i.e. return data without releasing)
169 T* yield()
170 {
171 T* tempItem = item_;
172 item_ = nullptr;
173 return tempItem;
174 }
175
176 // Release currently held data, if any, to hold another
177 void assign(T* i)
178 {
179 xerces_release();
180 item_ = i;
181 }
182
183 // Get pointer to the currently held data, if any
184 T* get() const
185 {
186 return item_;
187 }
188
189 // Return true if no data is held
190 bool is_released() const
191 {
192 return (nullptr == item_);
193 }
194 };
195
196 //========================================================================================================
197
198 /*
199 * @brief Helper class for XML parsing that handles the conversions of Xerces strings
200 *
201 * It provides the convert() function which internally calls
202 * XMLString::transcode and ensures that the memory is released properly
203 * through XMLString::release internally. It returns a std::string or
204 * std::basic_string<XMLCh> to the caller who takes ownership of the data.
205 *
206 */
207 class OPENMS_DLLAPI StringManager
208 {
209
210 typedef std::basic_string<XMLCh> XercesString;
211
213 inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
214 {
215 return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
216 }
217
219 inline static unique_xerces_ptr<XMLCh> fromNative_(const std::string& str)
220 {
221 return fromNative_(str.c_str());
222 }
223
225 inline static std::string toNative_(const XMLCh* str)
226 {
227 std::string r;
228 XMLSize_t l = strLength(str);
229 if(isASCII(str, l))
230 {
231 appendASCII(str,l,r);
232 }
233 else
234 {
235 r = (unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
236 }
237 return r;
238 }
239
241 inline static std::string toNative_(const unique_xerces_ptr<XMLCh>& str)
242 {
243 return toNative_(str.get());
244 }
245
246protected:
248 static void compress64_ (const XMLCh * input_it, char* output_it);
249
250public:
253
256
258 // https://github.com/OpenMS/OpenMS/issues/8122
259 #if defined(__GNUC__)
260 __attribute__((no_sanitize("address")))
261 #elif defined(_MSC_VER)
262 __declspec(no_sanitize_address)
263 #endif
264 static XMLSize_t strLength(const XMLCh* input_ptr);
265
267 inline static XercesString convert(const char * str)
268 {
269 return fromNative_(str).get();
270 }
271
273 inline static XercesString convert(const std::string & str)
274 {
275 return fromNative_(str.c_str()).get();
276 }
277
279 inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
280 {
281 return fromNative_(str);
282 }
283
285 inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
286 {
287 return fromNative_(str.c_str());
288 }
289
291 inline static std::string convert(const XMLCh * str)
292 {
293 return toNative_(str);
294 }
296 static bool isASCII(const XMLCh * chars, const XMLSize_t length);
297
298
299
306 static void appendASCII(const XMLCh * str, const XMLSize_t length, std::string & result);
307
308 };
309
313 class OPENMS_DLLAPI XMLHandler :
314 public xercesc::DefaultHandler
315 {
316public:
317
319 class OPENMS_DLLAPI EndParsingSoftly :
321 {
322 public:
323 EndParsingSoftly(const char * file, int line, const char * function) :
324 Exception::BaseException(file, line, function)
325 {
326 }
327
328 };
329
332 {
334 STORE
335 };
336
338 {
339 LD_ALLDATA, // default; load all data
340 LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
341 LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
342 };
343
344
346 XMLHandler(const std::string & filename, const std::string & version);
348 ~XMLHandler() override;
349
351 void reset();
352
353
360 void fatalError(const xercesc::SAXParseException & exception) override;
361 void error(const xercesc::SAXParseException & exception) override;
362 void warning(const xercesc::SAXParseException & exception) override;
364
366 void fatalError(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
368 void error(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
370 void warning(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
371
373 void characters(const XMLCh * const chars, const XMLSize_t length) override;
375 void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
377 void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
378
380 virtual void writeTo(std::ostream & /*os*/);
381
383 virtual LOADDETAIL getLoadDetail() const;
384
386 virtual void setLoadDetail(const LOADDETAIL d);
387
395 static std::string writeXMLEscape(const std::string& to_escape)
396 {
397 std::string _copy = to_escape;
398 // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
399 if (StringUtils::has(_copy, '&')) StringUtils::substitute(_copy, "&","&amp;");
400 if (StringUtils::has(_copy, '>')) StringUtils::substitute(_copy, ">","&gt;");
401 if (StringUtils::has(_copy, '"')) StringUtils::substitute(_copy, "\"","&quot;");
402 if (StringUtils::has(_copy, '<')) StringUtils::substitute(_copy, "<","&lt;");
403 if (StringUtils::has(_copy, '\'')) StringUtils::substitute(_copy, "'","&apos;");
404
405 return _copy;
406 }
407
421 static DataValue fromXSDString(const std::string& type, const std::string& value)
422 {
423 DataValue data_value;
424 // float type
425 if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
426 {
427 data_value = DataValue(StringUtils::toDouble(value));
428 }
429 // <=32 bit integer types
430 else if (type == "xsd:byte" || // 8bit signed
431 type == "xsd:int" || // 32bit signed
432 type == "xsd:unsignedShort" || // 16bit unsigned
433 type == "xsd:short" || // 16bit signed
434 type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
435 {
436 data_value = DataValue(StringUtils::toInt32(value));
437 }
438 // 64 bit integer types
439 else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
440 type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
441 type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
442 {
443 data_value = DataValue(StringUtils::toInt64(value)); // internally a signed 64-bit integer. So if someone uses 2^64-1 as value, toInt64() will raise an exception...
444 }
445 // everything else is treated as a string
446 else
447 {
448 data_value = DataValue(value);
449 }
450 return data_value;
451 }
452
453
466 DataValue cvParamToValue(const ControlledVocabulary& cv, const std::string& parent_tag,
467 const std::string& accession, const std::string& name, const std::string& value,
468 const std::string& unit_accession) const;
469
478 DataValue cvParamToValue(const ControlledVocabulary& cv, const CVTerm& raw_term) const;
479
482 void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
483
484protected:
486 std::string file_;
487
489 std::string version_;
490
493
499 std::vector<std::string> open_tags_;
500
503
504
506 inline bool equal_(const XMLCh * a, const XMLCh * b) const
507 {
508 return xercesc::XMLString::compareString(a, b) == 0;
509 }
510
512
513
515 void writeUserParam_(const std::string & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
516
518
520
521
523 std::vector<std::vector<std::string> > cv_terms_;
524
527 SignedSize cvStringToEnum_(const Size section, const std::string & term, const char * message, const SignedSize result_on_error = 0);
528
530
532
533
535 inline Int asInt_(const std::string & in) const
536 {
537 Int res = 0;
538 try
539 {
540 res = StringUtils::toInt32(in);
541 }
543 {
544 error(LOAD,std::string("Int conversion error of \"") + in + "\"");
545 }
546 return res;
547 }
548
550 inline Int asInt_(const XMLCh * in) const
551 {
552 return xercesc::XMLString::parseInt(in);
553 }
554
556 inline UInt asUInt_(const std::string & in) const
557 {
558 UInt res = 0;
559 try
560 {
561 Int tmp = StringUtils::toInt32(in);
562 if (tmp < 0)
563 {
564 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
565 }
566 res = UInt(tmp);
567 }
569 {
570 error(LOAD,std::string("UInt conversion error of \"") + in + "\"");
571 }
572 return res;
573 }
574
576 inline double asDouble_(const std::string & in) const
577 {
578 double res = 0.0;
579 try
580 {
581 res = StringUtils::toDouble(in);
582 }
584 {
585 error(LOAD,std::string("Double conversion error of \"") + in + "\"");
586 }
587 return res;
588 }
589
591 inline float asFloat_(const std::string & in) const
592 {
593 float res = 0.0;
594 try
595 {
596 res = StringUtils::toFloat(in);
597 }
599 {
600 error(LOAD,std::string("Float conversion error of \"") + in + "\"");
601 }
602 return res;
603 }
604
612 inline bool asBool_(const std::string & in) const
613 {
614 if (in == "true" || in == "TRUE" || in == "True" || in == "1")
615 {
616 return true;
617 }
618 else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
619 {
620 return false;
621 }
622 else
623 {
624 error(LOAD,std::string("Boolean conversion error of \"") + in + "\"");
625 }
626 return false;
627 }
628
630 inline DateTime asDateTime_(std::string date_string) const
631 {
632 DateTime date_time;
633 if (!date_string.empty())
634 {
635 try
636 {
637 //strip away milliseconds
638 StringUtils::trim(date_string);
639 date_string = StringUtils::substr(date_string, 0, 19);
640 date_time.set(date_string);
641 }
642 catch (Exception::ParseError& /*err*/ )
643 {
644 error(LOAD,std::string("DateTime conversion error of \"") + date_string + "\"");
645 }
646 }
647 return date_time;
648 }
649
651
653
654
656 inline std::string attributeAsString_(const xercesc::Attributes & a, const char * name) const
657 {
658 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
659 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
660 return sm_.convert(val);
661 }
662
664 inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
665 {
666 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
667 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
668 return xercesc::XMLString::parseInt(val);
669 }
670
672 inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
673 {
674 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
675 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
676 return StringUtils::toDouble(sm_.convert(val));
677 }
678
680 DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const;
681
683 IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const;
684
686 StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const;
687
693 inline bool optionalAttributeAsString_(std::string & value, const xercesc::Attributes & a, const char * name) const
694 {
695 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
696 if (val != nullptr)
697 {
698 value = sm_.convert(val);
699 return true;
700 }
701 return false;
702 }
703
709 inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
710 {
711 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
712 if (val != nullptr)
713 {
714 value = xercesc::XMLString::parseInt(val);
715 return true;
716 }
717 return false;
718 }
719
725 inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
726 {
727 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
728 if (val != nullptr)
729 {
730 value = xercesc::XMLString::parseInt(val);
731 return true;
732 }
733 return false;
734 }
735
741 inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
742 {
743 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
744 if (val != nullptr)
745 {
746 value =StringUtils::toDouble(sm_.convert(val));
747 return true;
748 }
749 return false;
750 }
751
757 inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
758 {
759 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
760 if (val != nullptr)
761 {
762 value = attributeAsDoubleList_(a, name);
763 return true;
764 }
765 return false;
766 }
767
773 inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
774 {
775 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
776 if (val != nullptr)
777 {
778 value = attributeAsStringList_(a, name);
779 return true;
780 }
781 return false;
782 }
783
789 inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
790 {
791 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
792 if (val != nullptr)
793 {
794 value = attributeAsIntList_(a, name);
795 return true;
796 }
797 return false;
798 }
799
801 inline std::string attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
802 {
803 const XMLCh * val = a.getValue(name);
804 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + sm_.convert(name) + "' not present!");
805 return sm_.convert(val);
806 }
807
809 inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
810 {
811 const XMLCh * val = a.getValue(name);
812 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + sm_.convert(name) + "' not present!");
813 return xercesc::XMLString::parseInt(val);
814 }
815
817 inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
818 {
819 const XMLCh * val = a.getValue(name);
820 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + sm_.convert(name) + "' not present!");
821 return StringUtils::toDouble(sm_.convert(val));
822 }
823
825 DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const;
826
828 IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const;
829
831 StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const;
832
834 inline bool optionalAttributeAsString_(std::string& value, const xercesc::Attributes & a, const XMLCh * name) const
835 {
836 const XMLCh * val = a.getValue(name);
837 if (val != nullptr)
838 {
839 value = sm_.convert(val);
840 return !value.empty();
841 }
842 return false;
843 }
844
846 inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
847 {
848 const XMLCh * val = a.getValue(name);
849 if (val != nullptr)
850 {
851 value = xercesc::XMLString::parseInt(val);
852 return true;
853 }
854 return false;
855 }
856
858 inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
859 {
860 const XMLCh * val = a.getValue(name);
861 if (val != nullptr)
862 {
863 value = xercesc::XMLString::parseInt(val);
864 return true;
865 }
866 return false;
867 }
868
870 inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
871 {
872 const XMLCh * val = a.getValue(name);
873 if (val != nullptr)
874 {
875 value = StringUtils::toDouble(sm_.convert(val));
876 return true;
877 }
878 return false;
879 }
880
886 inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
887 {
888 const XMLCh * val = a.getValue(name);
889 if (val != nullptr)
890 {
891 value = attributeAsDoubleList_(a, name);
892 return true;
893 }
894 return false;
895 }
896
902 inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
903 {
904 const XMLCh * val = a.getValue(name);
905 if (val != nullptr)
906 {
907 value = attributeAsIntList_(a, name);
908 return true;
909 }
910 return false;
911 }
912
918 inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
919 {
920 const XMLCh * val = a.getValue(name);
921 if (val != nullptr)
922 {
923 value = attributeAsStringList_(a, name);
924 return true;
925 }
926 return false;
927 }
928
930
931private:
934
935 inline const std::string& expectList_(const std::string& str) const
936 {
937 if (!(StringUtils::hasPrefix(str, '[') && StringUtils::hasSuffix(str, ']')))
938 {
939 fatalError(LOAD,std::string("List argument is not a string representation of a list!"));
940 }
941 return str;
942 }
943
944 };
945
946 } // namespace Internal
947} // namespace OpenMS
948
949
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: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
Definition XMLHandler.h:208
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:225
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition XMLHandler.h:279
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:210
static std::string convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition XMLHandler.h:291
static unique_xerces_ptr< XMLCh > convertPtr(const std::string &str)
Transcode the supplied C++ string to a xerces string pointer.
Definition XMLHandler.h:285
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:213
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition XMLHandler.h:273
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition XMLHandler.h:267
static void compress64_(const XMLCh *input_it, char *output_it)
Compresses eight 8x16bit Chars in XMLCh* to 8x8bit Chars by cutting upper byte.
static std::string toNative_(const unique_xerces_ptr< XMLCh > &str)
Converts from a wide-character string to a narrow-character string.
Definition XMLHandler.h:241
static unique_xerces_ptr< XMLCh > fromNative_(const std::string &str)
Converts from a narrow-character string to a wide-character string.
Definition XMLHandler.h:219
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:321
EndParsingSoftly(const char *file, int line, const char *function)
Definition XMLHandler.h:323
Base class for XML handlers.
Definition XMLHandler.h:315
float asFloat_(const std::string &in) const
Conversion of a std::string to a float value.
Definition XMLHandler.h:591
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:556
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
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:846
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:773
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition XMLHandler.h:502
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
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:725
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:535
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:395
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:902
LOADDETAIL
Definition XMLHandler.h:338
@ LD_RAWCOUNTS
Definition XMLHandler.h:340
@ LD_ALLDATA
Definition XMLHandler.h:339
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition XMLHandler.h:506
std::string version_
Schema version.
Definition XMLHandler.h:489
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:918
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
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:834
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:332
@ LOAD
Loading a file.
Definition XMLHandler.h:333
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
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:870
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:612
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:809
Int asInt_(const XMLCh *in) const
Conversion of a Xerces string to an integer value.
Definition XMLHandler.h:550
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition XMLHandler.h:664
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:858
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:886
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:693
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:421
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
StringManager sm_
Helper class for string conversion.
Definition XMLHandler.h:492
const std::string & expectList_(const std::string &str) const
Definition XMLHandler.h:935
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:576
std::string attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition XMLHandler.h:801
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition XMLHandler.h:672
std::string attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition XMLHandler.h:656
~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:741
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:486
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:523
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:757
DateTime asDateTime_(std::string date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition XMLHandler.h:630
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:499
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition XMLHandler.h:817
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:789
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:709
void error(const xercesc::SAXParseException &exception) override
Definition XMLHandler.h:48
T * get()
Definition XMLHandler.h:87
std::shared_ptr< T > item_
Definition XMLHandler.h:62
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition XMLHandler.h:67
static void doRelease_(XMLCh *item)
bool is_released() const
Definition XMLHandler.h:96
static void doRelease_(U *item)
Definition XMLHandler.h:51
void assign(T *item)
Definition XMLHandler.h:82
void reset()
Definition XMLHandler.h:77
shared_xerces_ptr & operator=(T *item)
Definition XMLHandler.h:71
const T * get() const
Definition XMLHandler.h:91
Definition XMLHandler.h:104
T * item_
Definition XMLHandler.h:119
void operator=(T *i)
Definition XMLHandler.h:152
void xerces_release()
Definition XMLHandler.h:158
unique_xerces_ptr(T *i)
Definition XMLHandler.h:131
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void swap(unique_xerces_ptr< T > &other) noexcept
Definition XMLHandler.h:146
void assign(T *i)
Definition XMLHandler.h:177
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition XMLHandler.h:190
unique_xerces_ptr()
Definition XMLHandler.h:127
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition XMLHandler.h:140
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
T * yield()
Definition XMLHandler.h:169
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition XMLHandler.h:135
T * get() const
Definition XMLHandler.h:184
static void doRelease_(U *&item)
Definition XMLHandler.h:108
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
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