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
18
19#include <xercesc/sax2/Attributes.hpp>
20#include <xercesc/sax2/DefaultHandler.hpp>
21#include <xercesc/util/XMLString.hpp>
22
23#include <iosfwd>
24#include <string>
25#include <memory>
26
27
28namespace OpenMS
29{
30 class ControlledVocabulary;
31 class CVTerm;
32 class MetaInfoInterface;
33 class ProteinIdentification;
34
35 namespace Internal
36 {
37
38 #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
39
40 static_assert(sizeof(::XMLCh) == sizeof(char16_t),
41 "XMLCh is not sized correctly for UTF-16.");
42
43 //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
44 //Copyright 2010 Orjan Westin
45 //Under BSD license
46 //========================================================================================================
47 template<typename T>
48 class OPENMS_DLLAPI shared_xerces_ptr
49 {
50 // Function to release Xerces data type with a release member function
51 template<typename U>
52 static void doRelease_(U* item)
53 {
54 // Only release this if it has no owner
55 if (nullptr == item->getOwnerDocument())
56 item->release();
57 }
58
59 static void doRelease_(char* item);
60 static void doRelease_(XMLCh* item);
61
62 // The actual data we're holding
63 std::shared_ptr<T> item_;
64 public:
65 // Default constructor
66 shared_xerces_ptr() = default;
67 // Assignment constructor
69 : item_(item, doRelease_ )
70 {}
71 // Assignment of data to guard
73 {
74 assign(item);
75 return *this;
76 }
77 // Give up hold on data
78 void reset()
79 {
80 item_.reset();
81 }
82 // Release currently held data, if any, to hold another
83 void assign(T* item)
84 {
85 item_.reset(item, doRelease_ );
86 }
87 // Get pointer to the currently held data, if any
88 T* get()
89 {
90 return item_.get();
91 }
92 const T* get() const
93 {
94 return item_.get();
95 }
96 // Return true if no data is held
97 bool is_released() const
98 {
99 return (nullptr == item_.get());
100 }
101 };
102
103 template <typename T>
104 class OPENMS_DLLAPI unique_xerces_ptr
105 {
106 private:
107
108 template<typename U>
109 static void doRelease_(U*& item)
110 {
111 // Only release this if it has no parent (otherwise
112 // parent will release it)
113 if (nullptr == item->getOwnerDocument())
114 item->release();
115 }
116
117 static void doRelease_(char*& item);
118 static void doRelease_(XMLCh*& item);
119
121
122 public:
123
124 // Hide copy constructor and assignment operator
127
129 : item_(nullptr)
130 {}
131
132 explicit unique_xerces_ptr(T* i)
133 : item_(i)
134 {}
135
137 {
138 xerces_release();
139 }
140
142 : item_(nullptr)
143 {
144 this->swap(other);
145 }
146
147 void swap(unique_xerces_ptr<T>& other) noexcept
148 {
149 std::swap(item_, other.item_);
150 }
151
152 // Assignment of data to guard (not chainable)
153 void operator=(T* i)
154 {
155 reassign(i);
156 }
157
158 // Release held data (i.e. delete/free it)
160 {
161 if (!is_released())
162 {
163 // Use type-specific release mechanism
164 doRelease_(item_);
165 item_ = nullptr;
166 }
167 }
168
169 // Give up held data (i.e. return data without releasing)
170 T* yield()
171 {
172 T* tempItem = item_;
173 item_ = nullptr;
174 return tempItem;
175 }
176
177 // Release currently held data, if any, to hold another
178 void assign(T* i)
179 {
180 xerces_release();
181 item_ = i;
182 }
183
184 // Get pointer to the currently held data, if any
185 T* get() const
186 {
187 return item_;
188 }
189
190 // Return true if no data is held
191 bool is_released() const
192 {
193 return (nullptr == item_);
194 }
195 };
196
197 //========================================================================================================
198
199 /*
200 * @brief Helper class for XML parsing that handles the conversions of Xerces strings
201 *
202 * It provides the convert() function which internally calls
203 * XMLString::transcode and ensures that the memory is released properly
204 * through XMLString::release internally. It returns a std::string or
205 * std::basic_string<XMLCh> to the caller who takes ownership of the data.
206 *
207 */
208 class OPENMS_DLLAPI StringManager
209 {
210
211 typedef std::basic_string<XMLCh> XercesString;
212
214 inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
215 {
216 return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
217 }
218
220 inline static unique_xerces_ptr<XMLCh> fromNative_(const std::string& str)
221 {
222 return fromNative_(str.c_str());
223 }
224
226 inline static std::string toNative_(const XMLCh* str)
227 {
228 std::string r;
229 XMLSize_t l = strLength(str);
230 if(isASCII(str, l))
231 {
232 appendASCII(str,l,r);
233 }
234 else
235 {
236 r = (unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
237 }
238 return r;
239 }
240
242 inline static std::string toNative_(const unique_xerces_ptr<XMLCh>& str)
243 {
244 return toNative_(str.get());
245 }
246
247protected:
249 static void compress64_ (const XMLCh * input_it, char* output_it);
250
251public:
254
257
259 // https://github.com/OpenMS/OpenMS/issues/8122
260 #if defined(__GNUC__)
261 __attribute__((no_sanitize("address")))
262 #elif defined(_MSC_VER)
263 __declspec(no_sanitize_address)
264 #endif
265 static XMLSize_t strLength(const XMLCh* input_ptr);
266
268 inline static XercesString convert(const char * str)
269 {
270 return fromNative_(str).get();
271 }
272
274 inline static XercesString convert(const std::string & str)
275 {
276 return fromNative_(str.c_str()).get();
277 }
278
280 inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
281 {
282 return fromNative_(str);
283 }
284
286 inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
287 {
288 return fromNative_(str.c_str());
289 }
290
292 inline static std::string convert(const XMLCh * str)
293 {
294 return toNative_(str);
295 }
297 static bool isASCII(const XMLCh * chars, const XMLSize_t length);
298
299
300
307 static void appendASCII(const XMLCh * str, const XMLSize_t length, std::string & result);
308
309 };
310
314 class OPENMS_DLLAPI XMLHandler :
315 public xercesc::DefaultHandler
316 {
317public:
318
320 class OPENMS_DLLAPI EndParsingSoftly :
322 {
323 public:
324 EndParsingSoftly(const char * file, int line, const char * function) :
325 Exception::BaseException(file, line, function)
326 {
327 }
328
329 };
330
333 {
335 STORE
336 };
337
339 {
340 LD_ALLDATA, // default; load all data
341 LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
342 LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
343 };
344
345
347 XMLHandler(const std::string & filename, const std::string & version);
349 ~XMLHandler() override;
350
352 void reset();
353
354
361 void fatalError(const xercesc::SAXParseException & exception) override;
362 void error(const xercesc::SAXParseException & exception) override;
363 void warning(const xercesc::SAXParseException & exception) override;
365
367 void fatalError(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
369 void error(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
371 void warning(ActionMode mode, const std::string & msg, UInt line = 0, UInt column = 0) const;
372
374 void characters(const XMLCh * const chars, const XMLSize_t length) override;
376 void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
378 void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
379
381 virtual void writeTo(std::ostream & /*os*/);
382
384 virtual LOADDETAIL getLoadDetail() const;
385
387 virtual void setLoadDetail(const LOADDETAIL d);
388
396 static std::string writeXMLEscape(const std::string& to_escape)
397 {
398 std::string _copy = to_escape;
399 // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
400 if (StringUtils::has(_copy, '&')) StringUtils::substitute(_copy, "&","&amp;");
401 if (StringUtils::has(_copy, '>')) StringUtils::substitute(_copy, ">","&gt;");
402 if (StringUtils::has(_copy, '"')) StringUtils::substitute(_copy, "\"","&quot;");
403 if (StringUtils::has(_copy, '<')) StringUtils::substitute(_copy, "<","&lt;");
404 if (StringUtils::has(_copy, '\'')) StringUtils::substitute(_copy, "'","&apos;");
405
406 return _copy;
407 }
408
422 static DataValue fromXSDString(const std::string& type, const std::string& value)
423 {
424 DataValue data_value;
425 // float type
426 if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
427 {
428 data_value = DataValue(StringUtils::toDouble(value));
429 }
430 // <=32 bit integer types
431 else if (type == "xsd:byte" || // 8bit signed
432 type == "xsd:int" || // 32bit signed
433 type == "xsd:unsignedShort" || // 16bit unsigned
434 type == "xsd:short" || // 16bit signed
435 type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
436 {
437 data_value = DataValue(StringUtils::toInt32(value));
438 }
439 // 64 bit integer types
440 else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
441 type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
442 type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
443 {
444 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...
445 }
446 // everything else is treated as a string
447 else
448 {
449 data_value = DataValue(value);
450 }
451 return data_value;
452 }
453
454
467 DataValue cvParamToValue(const ControlledVocabulary& cv, const std::string& parent_tag,
468 const std::string& accession, const std::string& name, const std::string& value,
469 const std::string& unit_accession) const;
470
479 DataValue cvParamToValue(const ControlledVocabulary& cv, const CVTerm& raw_term) const;
480
483 void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
484
485protected:
487 std::string file_;
488
490 std::string version_;
491
494
500 std::vector<std::string> open_tags_;
501
504
505
507 inline bool equal_(const XMLCh * a, const XMLCh * b) const
508 {
509 return xercesc::XMLString::compareString(a, b) == 0;
510 }
511
513
514
516 void writeUserParam_(const std::string & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
517
519
521
522
524 std::vector<std::vector<std::string> > cv_terms_;
525
528 SignedSize cvStringToEnum_(const Size section, const std::string & term, const char * message, const SignedSize result_on_error = 0);
529
531
533
534
536 inline Int asInt_(const std::string & in) const
537 {
538 Int res = 0;
539 try
540 {
541 res = StringUtils::toInt32(in);
542 }
544 {
545 error(LOAD,std::string("Int conversion error of \"") + in + "\"");
546 }
547 return res;
548 }
549
551 inline Int asInt_(const XMLCh * in) const
552 {
553 return xercesc::XMLString::parseInt(in);
554 }
555
557 inline UInt asUInt_(const std::string & in) const
558 {
559 UInt res = 0;
560 try
561 {
562 Int tmp = StringUtils::toInt32(in);
563 if (tmp < 0)
564 {
565 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
566 }
567 res = UInt(tmp);
568 }
570 {
571 error(LOAD,std::string("UInt conversion error of \"") + in + "\"");
572 }
573 return res;
574 }
575
577 inline double asDouble_(const std::string & in) const
578 {
579 double res = 0.0;
580 try
581 {
582 res = StringUtils::toDouble(in);
583 }
585 {
586 error(LOAD,std::string("Double conversion error of \"") + in + "\"");
587 }
588 return res;
589 }
590
592 inline float asFloat_(const std::string & in) const
593 {
594 float res = 0.0;
595 try
596 {
597 res = StringUtils::toFloat(in);
598 }
600 {
601 error(LOAD,std::string("Float conversion error of \"") + in + "\"");
602 }
603 return res;
604 }
605
613 inline bool asBool_(const std::string & in) const
614 {
615 if (in == "true" || in == "TRUE" || in == "True" || in == "1")
616 {
617 return true;
618 }
619 else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
620 {
621 return false;
622 }
623 else
624 {
625 error(LOAD,std::string("Boolean conversion error of \"") + in + "\"");
626 }
627 return false;
628 }
629
631 inline DateTime asDateTime_(std::string date_string) const
632 {
633 DateTime date_time;
634 if (!date_string.empty())
635 {
636 try
637 {
638 //strip away milliseconds
639 StringUtils::trim(date_string);
640 date_string = StringUtils::substr(date_string, 0, 19);
641 date_time.set(date_string);
642 }
643 catch (Exception::ParseError& /*err*/ )
644 {
645 error(LOAD,std::string("DateTime conversion error of \"") + date_string + "\"");
646 }
647 }
648 return date_time;
649 }
650
652
654
655
657 inline std::string attributeAsString_(const xercesc::Attributes & a, const char * name) const
658 {
659 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
660 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
661 return sm_.convert(val);
662 }
663
665 inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
666 {
667 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
668 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
669 return xercesc::XMLString::parseInt(val);
670 }
671
673 inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
674 {
675 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
676 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + name + "' not present!");
677 return StringUtils::toDouble(sm_.convert(val));
678 }
679
681 inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
682 {
683 std::string tmp(expectList_(attributeAsString_(a, name)));
684 return ListUtils::create<double>(StringUtils::substr(tmp, 1, tmp.size() - 2));
685 }
686
688 inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
689 {
690 std::string tmp(expectList_(attributeAsString_(a, name)));
691 return ListUtils::create<Int>(StringUtils::substr(tmp, 1, tmp.size() - 2));
692 }
693
695 inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
696 {
697 std::string tmp(expectList_(attributeAsString_(a, name)));
698 StringList tmp_list = ListUtils::create<std::string>(StringUtils::substr(tmp, 1, tmp.size() - 2)); // between [ and ]
699
700 if (StringUtils::hasSubstring(tmp, "\\|")) // check full string for escaped comma
701 {
702 for (std::string& s : tmp_list)
703 {
704 StringUtils::substitute(s, "\\|", ",");
705 }
706 }
707 return tmp_list;
708 }
709
715 inline bool optionalAttributeAsString_(std::string & value, const xercesc::Attributes & a, const char * name) const
716 {
717 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
718 if (val != nullptr)
719 {
720 value = sm_.convert(val);
721 return true;
722 }
723 return false;
724 }
725
731 inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
732 {
733 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
734 if (val != nullptr)
735 {
736 value = xercesc::XMLString::parseInt(val);
737 return true;
738 }
739 return false;
740 }
741
747 inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
748 {
749 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
750 if (val != nullptr)
751 {
752 value = xercesc::XMLString::parseInt(val);
753 return true;
754 }
755 return false;
756 }
757
763 inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
764 {
765 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
766 if (val != nullptr)
767 {
768 value =StringUtils::toDouble(sm_.convert(val));
769 return true;
770 }
771 return false;
772 }
773
779 inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
780 {
781 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
782 if (val != nullptr)
783 {
784 value = attributeAsDoubleList_(a, name);
785 return true;
786 }
787 return false;
788 }
789
795 inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
796 {
797 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
798 if (val != nullptr)
799 {
800 value = attributeAsStringList_(a, name);
801 return true;
802 }
803 return false;
804 }
805
811 inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
812 {
813 const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
814 if (val != nullptr)
815 {
816 value = attributeAsIntList_(a, name);
817 return true;
818 }
819 return false;
820 }
821
823 inline std::string attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
824 {
825 const XMLCh * val = a.getValue(name);
826 if (val == nullptr) fatalError(LOAD,std::string("Required attribute '") + sm_.convert(name) + "' not present!");
827 return sm_.convert(val);
828 }
829
831 inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
832 {
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);
836 }
837
839 inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
840 {
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));
844 }
845
847 inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
848 {
849 std::string tmp(expectList_(attributeAsString_(a, name)));
850 return ListUtils::create<double>(StringUtils::substr(tmp, 1, tmp.size() - 2));
851 }
852
854 inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
855 {
856 std::string tmp(expectList_(attributeAsString_(a, name)));
857 return ListUtils::create<Int>(StringUtils::substr(tmp, 1, tmp.size() - 2));
858 }
859
861 inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
862 {
863 std::string tmp(expectList_(attributeAsString_(a, name)));
864 StringList tmp_list = ListUtils::create<std::string>(StringUtils::substr(tmp, 1, tmp.size() - 2)); // between [ and ]
865
866 if (StringUtils::hasSubstring(tmp, "\\|")) // check full string for escaped comma
867 {
868 for (std::string& s : tmp_list)
869 {
870 StringUtils::substitute(s, "\\|", ",");
871 }
872 }
873 return tmp_list;
874 }
875
877 inline bool optionalAttributeAsString_(std::string& value, const xercesc::Attributes & a, const XMLCh * name) const
878 {
879 const XMLCh * val = a.getValue(name);
880 if (val != nullptr)
881 {
882 value = sm_.convert(val);
883 return !value.empty();
884 }
885 return false;
886 }
887
889 inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
890 {
891 const XMLCh * val = a.getValue(name);
892 if (val != nullptr)
893 {
894 value = xercesc::XMLString::parseInt(val);
895 return true;
896 }
897 return false;
898 }
899
901 inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
902 {
903 const XMLCh * val = a.getValue(name);
904 if (val != nullptr)
905 {
906 value = xercesc::XMLString::parseInt(val);
907 return true;
908 }
909 return false;
910 }
911
913 inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
914 {
915 const XMLCh * val = a.getValue(name);
916 if (val != nullptr)
917 {
918 value = StringUtils::toDouble(sm_.convert(val));
919 return true;
920 }
921 return false;
922 }
923
929 inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
930 {
931 const XMLCh * val = a.getValue(name);
932 if (val != nullptr)
933 {
934 value = attributeAsDoubleList_(a, name);
935 return true;
936 }
937 return false;
938 }
939
945 inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
946 {
947 const XMLCh * val = a.getValue(name);
948 if (val != nullptr)
949 {
950 value = attributeAsIntList_(a, name);
951 return true;
952 }
953 return false;
954 }
955
961 inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
962 {
963 const XMLCh * val = a.getValue(name);
964 if (val != nullptr)
965 {
966 value = attributeAsStringList_(a, name);
967 return true;
968 }
969 return false;
970 }
971
973
974private:
977
978 inline const std::string& expectList_(const std::string& str) const
979 {
980 if (!(StringUtils::hasPrefix(str, '[') && StringUtils::hasSuffix(str, ']')))
981 {
982 fatalError(LOAD,std::string("List argument is not a string representation of a list!"));
983 }
984 return str;
985 }
986
987 };
988
989 } // namespace Internal
990} // namespace OpenMS
991
992
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
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.
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
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
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 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