OpenMS
XMLHandler.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- 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 #include <OpenMS/DATASTRUCTURES/ListUtils.h> // StringList
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 
213  // Converts from a narrow-character string to a wide-character string.
214  inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
215  {
216  return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
217  }
218 
219  // Converts from a narrow-character string to a wide-character string.
220  inline static unique_xerces_ptr<XMLCh> fromNative_(const String& str)
221  {
222  return fromNative_(str.c_str());
223  }
224 
225  // Converts from a wide-character string to a narrow-character string.
226  inline static String toNative_(const XMLCh* str)
227  {
228  return String(unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
229  }
230 
231  // Converts from a wide-character string to a narrow-character string.
232  inline static String toNative_(const unique_xerces_ptr<XMLCh>& str)
233  {
234  return toNative_(str.get());
235  }
236 
237 
238 public:
241 
244 
246  inline static XercesString convert(const char * str)
247  {
248  return fromNative_(str).get();
249  }
250 
252  inline static XercesString convert(const std::string & str)
253  {
254  return fromNative_(str.c_str()).get();
255  }
256 
258  inline static XercesString convert(const String & str)
259  {
260  return fromNative_(str.c_str()).get();
261  }
262 
264  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
265  {
266  return fromNative_(str);
267  }
268 
270  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
271  {
272  return fromNative_(str.c_str());
273  }
274 
276  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
277  {
278  return fromNative_(str.c_str());
279  }
280 
282  inline static String convert(const XMLCh * str)
283  {
284  return toNative_(str);
285  }
286 
293  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
294 
295  };
296 
300  class OPENMS_DLLAPI XMLHandler :
301  public xercesc::DefaultHandler
302  {
303 public:
304 
306  class OPENMS_DLLAPI EndParsingSoftly :
308  {
309  public:
310  EndParsingSoftly(const char * file, int line, const char * function) :
311  Exception::BaseException(file, line, function)
312  {
313  }
314 
315  };
316 
319  {
321  STORE
322  };
323 
325  {
326  LD_ALLDATA, // default; load all data
327  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
328  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
329  };
330 
331 
333  XMLHandler(const String & filename, const String & version);
335  ~XMLHandler() override;
336 
338  void reset();
339 
340 
347  void fatalError(const xercesc::SAXParseException & exception) override;
348  void error(const xercesc::SAXParseException & exception) override;
349  void warning(const xercesc::SAXParseException & exception) override;
351 
353  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
355  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
357  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
358 
360  void characters(const XMLCh * const chars, const XMLSize_t length) override;
362  void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
364  void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
365 
367  virtual void writeTo(std::ostream & /*os*/);
368 
370  virtual LOADDETAIL getLoadDetail() const;
371 
373  virtual void setLoadDetail(const LOADDETAIL d);
374 
382  static String writeXMLEscape(const String& to_escape)
383  {
384  String _copy = to_escape;
385  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
386  if (_copy.has('&')) _copy.substitute("&","&amp;");
387  if (_copy.has('>')) _copy.substitute(">","&gt;");
388  if (_copy.has('"')) _copy.substitute("\"","&quot;");
389  if (_copy.has('<')) _copy.substitute("<","&lt;");
390  if (_copy.has('\'')) _copy.substitute("'","&apos;");
391 
392  return _copy;
393  }
394 
408  static DataValue fromXSDString(const String& type, const String& value)
409  {
410  DataValue data_value;
411  // float type
412  if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
413  {
414  data_value = DataValue(value.toDouble());
415  }
416  // <=32 bit integer types
417  else if (type == "xsd:byte" || // 8bit signed
418  type == "xsd:int" || // 32bit signed
419  type == "xsd:unsignedShort" || // 16bit unsigned
420  type == "xsd:short" || // 16bit signed
421  type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
422  {
423  data_value = DataValue(value.toInt32());
424  }
425  // 64 bit integer types
426  else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
427  type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
428  type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
429  {
430  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...
431  }
432  // everything else is treated as a string
433  else
434  {
435  data_value = DataValue(value);
436  }
437  return data_value;
438  }
439 
440 
454  DataValue cvParamToValue(const ControlledVocabulary& cv, const String& parent_tag,
455  const String& accession, const String& name, const String& value,
456  const String& unit_accession) const;
457 
466  DataValue cvParamToValue(const ControlledVocabulary& cv, const CVTerm& raw_term) const;
467 
470  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
471 
472 protected:
475 
478 
481 
487  std::vector<String> open_tags_;
488 
491 
492 
494  inline bool equal_(const XMLCh * a, const XMLCh * b) const
495  {
496  return xercesc::XMLString::compareString(a, b) == 0;
497  }
498 
500 
501 
503  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
504 
506 
508 
509 
511  std::vector<std::vector<String> > cv_terms_;
512 
515  SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0);
516 
518 
520 
521 
523  inline Int asInt_(const String & in) const
524  {
525  Int res = 0;
526  try
527  {
528  res = in.toInt();
529  }
531  {
532  error(LOAD, String("Int conversion error of \"") + in + "\"");
533  }
534  return res;
535  }
536 
538  inline Int asInt_(const XMLCh * in) const
539  {
540  return xercesc::XMLString::parseInt(in);
541  }
542 
544  inline UInt asUInt_(const String & in) const
545  {
546  UInt res = 0;
547  try
548  {
549  Int tmp = in.toInt();
550  if (tmp < 0)
551  {
552  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
553  }
554  res = UInt(tmp);
555  }
557  {
558  error(LOAD, String("UInt conversion error of \"") + in + "\"");
559  }
560  return res;
561  }
562 
564  inline double asDouble_(const String & in) const
565  {
566  double res = 0.0;
567  try
568  {
569  res = in.toDouble();
570  }
572  {
573  error(LOAD, String("Double conversion error of \"") + in + "\"");
574  }
575  return res;
576  }
577 
579  inline float asFloat_(const String & in) const
580  {
581  float res = 0.0;
582  try
583  {
584  res = in.toFloat();
585  }
587  {
588  error(LOAD, String("Float conversion error of \"") + in + "\"");
589  }
590  return res;
591  }
592 
600  inline bool asBool_(const String & in) const
601  {
602  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
603  {
604  return true;
605  }
606  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
607  {
608  return false;
609  }
610  else
611  {
612  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
613  }
614  return false;
615  }
616 
618  inline DateTime asDateTime_(String date_string) const
619  {
620  DateTime date_time;
621  if (!date_string.empty())
622  {
623  try
624  {
625  //strip away milliseconds
626  date_string.trim();
627  date_string = date_string.substr(0, 19);
628  date_time.set(date_string);
629  }
630  catch (Exception::ParseError& /*err*/ )
631  {
632  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
633  }
634  }
635  return date_time;
636  }
637 
639 
641 
642 
644  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
645  {
646  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
647  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
648  return sm_.convert(val);
649  }
650 
652  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
653  {
654  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
655  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
656  return xercesc::XMLString::parseInt(val);
657  }
658 
660  inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
661  {
662  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
663  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
664  return String(sm_.convert(val)).toDouble();
665  }
666 
668  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
669  {
670  String tmp(expectList_(attributeAsString_(a, name)));
671  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
672  }
673 
675  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
676  {
677  String tmp(expectList_(attributeAsString_(a, name)));
678  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
679  }
680 
682  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
683  {
684  String tmp(expectList_(attributeAsString_(a, name)));
685  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
686 
687  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
688  {
689  for (String& s : tmp_list)
690  {
691  s.substitute("\\|", ",");
692  }
693  }
694  return tmp_list;
695  }
696 
702  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
703  {
704  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
705  if (val != nullptr)
706  {
707  value = sm_.convert(val);
708  return true;
709  }
710  return false;
711  }
712 
718  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
719  {
720  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
721  if (val != nullptr)
722  {
723  value = xercesc::XMLString::parseInt(val);
724  return true;
725  }
726  return false;
727  }
728 
734  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
735  {
736  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
737  if (val != nullptr)
738  {
739  value = xercesc::XMLString::parseInt(val);
740  return true;
741  }
742  return false;
743  }
744 
750  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
751  {
752  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
753  if (val != nullptr)
754  {
755  value = String(sm_.convert(val)).toDouble();
756  return true;
757  }
758  return false;
759  }
760 
766  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
767  {
768  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
769  if (val != nullptr)
770  {
771  value = attributeAsDoubleList_(a, name);
772  return true;
773  }
774  return false;
775  }
776 
782  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
783  {
784  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
785  if (val != nullptr)
786  {
787  value = attributeAsStringList_(a, name);
788  return true;
789  }
790  return false;
791  }
792 
798  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
799  {
800  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
801  if (val != nullptr)
802  {
803  value = attributeAsIntList_(a, name);
804  return true;
805  }
806  return false;
807  }
808 
810  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
811  {
812  const XMLCh * val = a.getValue(name);
813  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
814  return sm_.convert(val);
815  }
816 
818  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
819  {
820  const XMLCh * val = a.getValue(name);
821  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
822  return xercesc::XMLString::parseInt(val);
823  }
824 
826  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
827  {
828  const XMLCh * val = a.getValue(name);
829  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
830  return sm_.convert(val).toDouble();
831  }
832 
834  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
835  {
836  String tmp(expectList_(attributeAsString_(a, name)));
837  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
838  }
839 
841  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
842  {
843  String tmp(expectList_(attributeAsString_(a, name)));
844  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
845  }
846 
848  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
849  {
850  String tmp(expectList_(attributeAsString_(a, name)));
851  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
852 
853  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
854  {
855  for (String& s : tmp_list)
856  {
857  s.substitute("\\|", ",");
858  }
859  }
860  return tmp_list;
861  }
862 
864  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
865  {
866  const XMLCh * val = a.getValue(name);
867  if (val != nullptr)
868  {
869  value = sm_.convert(val);
870  return !value.empty();
871  }
872  return false;
873  }
874 
876  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
877  {
878  const XMLCh * val = a.getValue(name);
879  if (val != nullptr)
880  {
881  value = xercesc::XMLString::parseInt(val);
882  return true;
883  }
884  return false;
885  }
886 
888  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
889  {
890  const XMLCh * val = a.getValue(name);
891  if (val != nullptr)
892  {
893  value = xercesc::XMLString::parseInt(val);
894  return true;
895  }
896  return false;
897  }
898 
900  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
901  {
902  const XMLCh * val = a.getValue(name);
903  if (val != nullptr)
904  {
905  value = sm_.convert(val).toDouble();
906  return true;
907  }
908  return false;
909  }
910 
916  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
917  {
918  const XMLCh * val = a.getValue(name);
919  if (val != nullptr)
920  {
921  value = attributeAsDoubleList_(a, name);
922  return true;
923  }
924  return false;
925  }
926 
932  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
933  {
934  const XMLCh * val = a.getValue(name);
935  if (val != nullptr)
936  {
937  value = attributeAsIntList_(a, name);
938  return true;
939  }
940  return false;
941  }
942 
948  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
949  {
950  const XMLCh * val = a.getValue(name);
951  if (val != nullptr)
952  {
953  value = attributeAsStringList_(a, name);
954  return true;
955  }
956  return false;
957  }
958 
960 
961 private:
964 
965  inline const String& expectList_(const String& str) const
966  {
967  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
968  {
969  fatalError(LOAD, String("List argument is not a string representation of a list!"));
970  }
971  return str;
972  }
973 
974  };
975 
976  } // namespace Internal
977 } // namespace OpenMS
978 
979 
Representation of controlled vocabulary term.
Definition: CVTerm.h:27
Representation of a controlled vocabulary.
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:313
Parse Error exception.
Definition: Exception.h:562
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:276
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:258
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:264
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:220
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:282
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:226
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:211
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:214
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:252
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:246
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:232
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:270
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:308
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:310
Base class for XML handlers.
Definition: XMLHandler.h:302
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:841
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:487
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:876
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:782
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:490
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:523
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:864
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:848
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:834
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:734
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:600
String file_
File name.
Definition: XMLHandler.h:474
static DataValue fromXSDString(const String &type, const String &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition: XMLHandler.h:408
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:932
String version_
Schema version.
Definition: XMLHandler.h:477
LOADDETAIL
Definition: XMLHandler.h:325
@ LD_RAWCOUNTS
Definition: XMLHandler.h:327
@ LD_ALLDATA
Definition: XMLHandler.h:326
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:494
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:544
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:644
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:948
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:682
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:511
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:319
@ LOAD
Loading a file.
Definition: XMLHandler.h:320
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:668
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:900
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:818
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:538
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:652
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:888
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:916
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 t...
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:675
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:480
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:382
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:660
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:750
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 t...
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:766
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:810
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:965
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:618
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:826
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:702
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:798
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:718
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:564
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:579
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:76
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:108
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
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: FeatureDeconvolution.h:22