All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
11 #include <OpenMS/CONCEPT/Types.h>
12 #include <OpenMS/CONCEPT/Macros.h>
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 
28 namespace 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 
120  T* item_;
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 String& str)
221  {
222  return fromNative_(str.c_str());
223  }
224 
226  inline static String toNative_(const XMLCh* str)
227  {
228  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 String toNative_(const unique_xerces_ptr<XMLCh>& str)
243  {
244  return toNative_(str.get());
245  }
246 
247 protected:
249  static void compress64_ (const XMLCh * input_it, char* output_it);
250 
251 public:
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 XercesString convert(const String & str)
281  {
282  return fromNative_(str.c_str()).get();
283  }
284 
286  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
287  {
288  return fromNative_(str);
289  }
290 
292  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
293  {
294  return fromNative_(str.c_str());
295  }
296 
298  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
299  {
300  return fromNative_(str.c_str());
301  }
302 
304  inline static String convert(const XMLCh * str)
305  {
306  return toNative_(str);
307  }
309  static bool isASCII(const XMLCh * chars, const XMLSize_t length);
310 
311 
312 
319  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
320 
321  };
322 
326  class OPENMS_DLLAPI XMLHandler :
327  public xercesc::DefaultHandler
328  {
329 public:
330 
332  class OPENMS_DLLAPI EndParsingSoftly :
334  {
335  public:
336  EndParsingSoftly(const char * file, int line, const char * function) :
337  Exception::BaseException(file, line, function)
338  {
339  }
340 
341  };
342 
345  {
347  STORE
348  };
349 
351  {
352  LD_ALLDATA, // default; load all data
353  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
354  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
355  };
356 
357 
359  XMLHandler(const String & filename, const String & version);
361  ~XMLHandler() override;
362 
364  void reset();
365 
366 
373  void fatalError(const xercesc::SAXParseException & exception) override;
374  void error(const xercesc::SAXParseException & exception) override;
375  void warning(const xercesc::SAXParseException & exception) override;
377 
379  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
381  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
383  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
384 
386  void characters(const XMLCh * const chars, const XMLSize_t length) override;
388  void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
390  void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
391 
393  virtual void writeTo(std::ostream & /*os*/);
394 
396  virtual LOADDETAIL getLoadDetail() const;
397 
399  virtual void setLoadDetail(const LOADDETAIL d);
400 
408  static String writeXMLEscape(const String& to_escape)
409  {
410  String _copy = to_escape;
411  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
412  if (_copy.has('&')) _copy.substitute("&","&amp;");
413  if (_copy.has('>')) _copy.substitute(">","&gt;");
414  if (_copy.has('"')) _copy.substitute("\"","&quot;");
415  if (_copy.has('<')) _copy.substitute("<","&lt;");
416  if (_copy.has('\'')) _copy.substitute("'","&apos;");
417 
418  return _copy;
419  }
420 
434  static DataValue fromXSDString(const String& type, const String& value)
435  {
436  DataValue data_value;
437  // float type
438  if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
439  {
440  data_value = DataValue(value.toDouble());
441  }
442  // <=32 bit integer types
443  else if (type == "xsd:byte" || // 8bit signed
444  type == "xsd:int" || // 32bit signed
445  type == "xsd:unsignedShort" || // 16bit unsigned
446  type == "xsd:short" || // 16bit signed
447  type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
448  {
449  data_value = DataValue(value.toInt32());
450  }
451  // 64 bit integer types
452  else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
453  type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
454  type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
455  {
456  data_value = DataValue(value.toInt64()); // internally a signed 64-bit integer. So if someone uses 2^64-1 as value, toInt64() will raise an exception...
457  }
458  // everything else is treated as a string
459  else
460  {
461  data_value = DataValue(value);
462  }
463  return data_value;
464  }
465 
466 
479  DataValue cvParamToValue(const ControlledVocabulary& cv, const String& parent_tag,
480  const String& accession, const String& name, const String& value,
481  const String& unit_accession) const;
482 
491  DataValue cvParamToValue(const ControlledVocabulary& cv, const CVTerm& raw_term) const;
492 
495  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
496 
497 protected:
500 
503 
506 
512  std::vector<String> open_tags_;
513 
516 
517 
519  inline bool equal_(const XMLCh * a, const XMLCh * b) const
520  {
521  return xercesc::XMLString::compareString(a, b) == 0;
522  }
523 
525 
526 
528  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
529 
531 
533 
534 
536  std::vector<std::vector<String> > cv_terms_;
537 
540  SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0);
541 
543 
545 
546 
548  inline Int asInt_(const String & in) const
549  {
550  Int res = 0;
551  try
552  {
553  res = in.toInt();
554  }
556  {
557  error(LOAD, String("Int conversion error of \"") + in + "\"");
558  }
559  return res;
560  }
561 
563  inline Int asInt_(const XMLCh * in) const
564  {
565  return xercesc::XMLString::parseInt(in);
566  }
567 
569  inline UInt asUInt_(const String & in) const
570  {
571  UInt res = 0;
572  try
573  {
574  Int tmp = in.toInt();
575  if (tmp < 0)
576  {
577  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
578  }
579  res = UInt(tmp);
580  }
582  {
583  error(LOAD, String("UInt conversion error of \"") + in + "\"");
584  }
585  return res;
586  }
587 
589  inline double asDouble_(const String & in) const
590  {
591  double res = 0.0;
592  try
593  {
594  res = in.toDouble();
595  }
597  {
598  error(LOAD, String("Double conversion error of \"") + in + "\"");
599  }
600  return res;
601  }
602 
604  inline float asFloat_(const String & in) const
605  {
606  float res = 0.0;
607  try
608  {
609  res = in.toFloat();
610  }
612  {
613  error(LOAD, String("Float conversion error of \"") + in + "\"");
614  }
615  return res;
616  }
617 
625  inline bool asBool_(const String & in) const
626  {
627  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
628  {
629  return true;
630  }
631  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
632  {
633  return false;
634  }
635  else
636  {
637  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
638  }
639  return false;
640  }
641 
643  inline DateTime asDateTime_(String date_string) const
644  {
645  DateTime date_time;
646  if (!date_string.empty())
647  {
648  try
649  {
650  //strip away milliseconds
651  date_string.trim();
652  date_string = date_string.substr(0, 19);
653  date_time.set(date_string);
654  }
655  catch (Exception::ParseError& /*err*/ )
656  {
657  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
658  }
659  }
660  return date_time;
661  }
662 
664 
666 
667 
669  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
670  {
671  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
672  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
673  return sm_.convert(val);
674  }
675 
677  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
678  {
679  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
680  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
681  return xercesc::XMLString::parseInt(val);
682  }
683 
685  inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
686  {
687  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
688  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
689  return String(sm_.convert(val)).toDouble();
690  }
691 
693  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
694  {
695  String tmp(expectList_(attributeAsString_(a, name)));
696  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
697  }
698 
700  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
701  {
702  String tmp(expectList_(attributeAsString_(a, name)));
703  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
704  }
705 
707  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
708  {
709  String tmp(expectList_(attributeAsString_(a, name)));
710  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
711 
712  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
713  {
714  for (String& s : tmp_list)
715  {
716  s.substitute("\\|", ",");
717  }
718  }
719  return tmp_list;
720  }
721 
727  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
728  {
729  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
730  if (val != nullptr)
731  {
732  value = sm_.convert(val);
733  return true;
734  }
735  return false;
736  }
737 
743  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
744  {
745  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
746  if (val != nullptr)
747  {
748  value = xercesc::XMLString::parseInt(val);
749  return true;
750  }
751  return false;
752  }
753 
759  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
760  {
761  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
762  if (val != nullptr)
763  {
764  value = xercesc::XMLString::parseInt(val);
765  return true;
766  }
767  return false;
768  }
769 
775  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
776  {
777  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
778  if (val != nullptr)
779  {
780  value = String(sm_.convert(val)).toDouble();
781  return true;
782  }
783  return false;
784  }
785 
791  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
792  {
793  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
794  if (val != nullptr)
795  {
796  value = attributeAsDoubleList_(a, name);
797  return true;
798  }
799  return false;
800  }
801 
807  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
808  {
809  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
810  if (val != nullptr)
811  {
812  value = attributeAsStringList_(a, name);
813  return true;
814  }
815  return false;
816  }
817 
823  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
824  {
825  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
826  if (val != nullptr)
827  {
828  value = attributeAsIntList_(a, name);
829  return true;
830  }
831  return false;
832  }
833 
835  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
836  {
837  const XMLCh * val = a.getValue(name);
838  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
839  return sm_.convert(val);
840  }
841 
843  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
844  {
845  const XMLCh * val = a.getValue(name);
846  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
847  return xercesc::XMLString::parseInt(val);
848  }
849 
851  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
852  {
853  const XMLCh * val = a.getValue(name);
854  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
855  return sm_.convert(val).toDouble();
856  }
857 
859  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
860  {
861  String tmp(expectList_(attributeAsString_(a, name)));
862  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
863  }
864 
866  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
867  {
868  String tmp(expectList_(attributeAsString_(a, name)));
869  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
870  }
871 
873  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
874  {
875  String tmp(expectList_(attributeAsString_(a, name)));
876  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
877 
878  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
879  {
880  for (String& s : tmp_list)
881  {
882  s.substitute("\\|", ",");
883  }
884  }
885  return tmp_list;
886  }
887 
889  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
890  {
891  const XMLCh * val = a.getValue(name);
892  if (val != nullptr)
893  {
894  value = sm_.convert(val);
895  return !value.empty();
896  }
897  return false;
898  }
899 
901  inline bool optionalAttributeAsInt_(Int & 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 optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
914  {
915  const XMLCh * val = a.getValue(name);
916  if (val != nullptr)
917  {
918  value = xercesc::XMLString::parseInt(val);
919  return true;
920  }
921  return false;
922  }
923 
925  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
926  {
927  const XMLCh * val = a.getValue(name);
928  if (val != nullptr)
929  {
930  value = sm_.convert(val).toDouble();
931  return true;
932  }
933  return false;
934  }
935 
941  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
942  {
943  const XMLCh * val = a.getValue(name);
944  if (val != nullptr)
945  {
946  value = attributeAsDoubleList_(a, name);
947  return true;
948  }
949  return false;
950  }
951 
957  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
958  {
959  const XMLCh * val = a.getValue(name);
960  if (val != nullptr)
961  {
962  value = attributeAsIntList_(a, name);
963  return true;
964  }
965  return false;
966  }
967 
973  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
974  {
975  const XMLCh * val = a.getValue(name);
976  if (val != nullptr)
977  {
978  value = attributeAsStringList_(a, name);
979  return true;
980  }
981  return false;
982  }
983 
985 
986 private:
989 
990  inline const String& expectList_(const String& str) const
991  {
992  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
993  {
994  fatalError(LOAD, String("List argument is not a string representation of a list!"));
995  }
996  return str;
997  }
998 
999  };
1000 
1001  } // namespace Internal
1002 } // namespace OpenMS
1003 
1004 
char16_t XMLCh
Definition: ClassTest.h:28
Representation of controlled vocabulary term.
Definition: CVTerm.h:27
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:33
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:330
Parse Error exception.
Definition: Exception.h:592
Definition: XMLHandler.h:209
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:298
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)
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:280
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:286
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Converts from a narrow-character string to a wide-character string.
Definition: XMLHandler.h:220
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:304
static String toNative_(const XMLCh *str)
Converts from a wide-character string to a narrow-character string.
Definition: XMLHandler.h:226
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:211
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 XMLSize_t strLength(const XMLCh *input_ptr)
Calculates the length of a XMLCh* string using SIMDe.
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 String toNative_(const unique_xerces_ptr< XMLCh > &str)
Converts from a wide-character string to a narrow-character string.
Definition: XMLHandler.h:242
static void compress64_(const XMLCh *input_it, char *output_it)
Compresses eight 8x16bit Chars in XMLCh* to 8x8bit Chars by cutting upper byte.
static void appendASCII(const XMLCh *str, const XMLSize_t length, String &result)
Transcodes the supplied XMLCh* and appends it to the OpenMS String.
static unique_xerces_ptr< XMLCh > convertPtr(const std::string &str)
Transcode the supplied C++ string to a xerces string pointer.
Definition: XMLHandler.h:292
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:334
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:336
Base class for XML handlers.
Definition: XMLHandler.h:328
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:866
virtual LOADDETAIL getLoadDetail() const
handler which support partial loading, implement this method
std::vector< String > open_tags_
Stack of open XML tags.
Definition: XMLHandler.h:512
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:901
XMLHandler(const String &filename, const String &version)
Default constructor.
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:807
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:515
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:548
bool optionalAttributeAsString_(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:889
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:873
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:859
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:759
virtual void setLoadDetail(const LOADDETAIL d)
handler which support partial loading, implement this method
void checkUniqueIdentifiers_(const std::vector< ProteinIdentification > &prot_ids) const
XMLHandler()
Not implemented.
void endElement(const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
Parsing method for closing tags.
bool asBool_(const String &in) const
Conversion of a string to a boolean value.
Definition: XMLHandler.h:625
String file_
File name.
Definition: XMLHandler.h:499
static DataValue fromXSDString(const String &type, const String &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition: XMLHandler.h:434
void fatalError(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Fatal error handler. Throws a ParseError exception.
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:957
String version_
Schema version.
Definition: XMLHandler.h:502
LOADDETAIL
Definition: XMLHandler.h:351
@ LD_RAWCOUNTS
Definition: XMLHandler.h:353
@ LD_ALLDATA
Definition: XMLHandler.h:352
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:519
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:569
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:669
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:973
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:707
void warning(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Warning handler.
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it's children)
Definition: XMLHandler.h:536
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:345
@ LOAD
Loading a file.
Definition: XMLHandler.h:346
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:693
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:925
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:843
void writeUserParam_(const String &tag_name, std::ostream &os, const MetaInfoInterface &meta, UInt indent) const
Writes the content of MetaInfoInterface to the file.
Int asInt_(const XMLCh *in) const
Conversion of a Xerces string to an integer value.
Definition: XMLHandler.h:563
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:677
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:913
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:941
DataValue cvParamToValue(const ControlledVocabulary &cv, const String &parent_tag, const String &accession, const String &name, const String &value, const String &unit_accession) const
Convert the value of a <cvParam value=.> (as commonly found in PSI schemata) to the DataValue with th...
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:700
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:505
void fatalError(const xercesc::SAXParseException &exception) override
static String writeXMLEscape(const String &to_escape)
Escapes a string and returns the escaped string.
Definition: XMLHandler.h:408
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:685
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
~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:775
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...
virtual void writeTo(std::ostream &)
Writes the contents to a stream.
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:791
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:835
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:990
void characters(const XMLCh *const chars, const XMLSize_t length) override
Parsing method for character data.
void error(ActionMode mode, const String &msg, UInt line=0, UInt column=0) const
Error handler for recoverable errors.
DateTime asDateTime_(String date_string) const
Conversion of a xs:datetime string to a DateTime value.
Definition: XMLHandler.h:643
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:851
bool optionalAttributeAsString_(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:727
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:823
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:743
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:589
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:604
Definition: XMLHandler.h:49
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
T * get()
Definition: XMLHandler.h:88
const T * get() const
Definition: XMLHandler.h:92
void assign(T *item)
Definition: XMLHandler.h:83
void reset()
Definition: XMLHandler.h:78
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:72
Definition: XMLHandler.h:105
T * item_
Definition: XMLHandler.h:120
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:153
void xerces_release()
Definition: XMLHandler.h:159
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:132
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
T * get() const
Definition: XMLHandler.h:185
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
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:136
T * yield()
Definition: XMLHandler.h:170
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
A more convenient string class.
Definition: String.h:34
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
Int64 toInt64() const
Conversion to Int64.
bool has(Byte byte) const
true if String contains the byte, false otherwise
Int toInt() const
Conversion to Int.
double toDouble() const
Conversion to double.
Int32 toInt32() const
Conversion to Int32.
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
float toFloat() const
Conversion to float.
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< String > StringList
Vector of String.
Definition: ListUtils.h:44
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:36
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19