OpenMS
XMLHandler.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Marc Sturm, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/CONCEPT/Types.h>
38 #include <OpenMS/CONCEPT/Macros.h>
39 
40 #include <OpenMS/DATASTRUCTURES/ListUtils.h> // StringList
44 
45 #include <xercesc/util/XMLString.hpp>
46 #include <xercesc/sax2/DefaultHandler.hpp>
47 #include <xercesc/sax2/Attributes.hpp>
48 
49 #include <iosfwd>
50 #include <string>
51 #include <memory>
52 
53 
54 namespace OpenMS
55 {
56  class ProteinIdentification;
57  class MetaInfoInterface;
58 
59  namespace Internal
60  {
61 
62  #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
63 
64  static_assert(sizeof(::XMLCh) == sizeof(char16_t),
65  "XMLCh is not sized correctly for UTF-16.");
66 
67  //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
68  //Copyright 2010 Orjan Westin
69  //Under BSD license
70  //========================================================================================================
71  template<typename T>
72  class OPENMS_DLLAPI shared_xerces_ptr
73  {
74  // Function to release Xerces data type with a release member function
75  template<typename U>
76  static void doRelease_(U* item)
77  {
78  // Only release this if it has no owner
79  if (nullptr == item->getOwnerDocument())
80  item->release();
81  }
82 
83  static void doRelease_(char* item);
84  static void doRelease_(XMLCh* item);
85 
86  // The actual data we're holding
87  std::shared_ptr<T> item_;
88  public:
89  // Default constructor
90  shared_xerces_ptr() = default;
91  // Assignment constructor
93  : item_(item, doRelease_ )
94  {}
95  // Assignment of data to guard
97  {
98  assign(item);
99  return *this;
100  }
101  // Give up hold on data
102  void reset()
103  {
104  item_.reset();
105  }
106  // Release currently held data, if any, to hold another
107  void assign(T* item)
108  {
109  item_.reset(item, doRelease_ );
110  }
111  // Get pointer to the currently held data, if any
112  T* get()
113  {
114  return item_.get();
115  }
116  const T* get() const
117  {
118  return item_.get();
119  }
120  // Return true if no data is held
121  bool is_released() const
122  {
123  return (nullptr == item_.get());
124  }
125  };
126 
127  template <typename T>
128  class OPENMS_DLLAPI unique_xerces_ptr
129  {
130  private:
131 
132  template<typename U>
133  static void doRelease_(U*& item)
134  {
135  // Only release this if it has no parent (otherwise
136  // parent will release it)
137  if (nullptr == item->getOwnerDocument())
138  item->release();
139  }
140 
141  static void doRelease_(char*& item);
142  static void doRelease_(XMLCh*& item);
143 
144  T* item_;
145 
146  public:
147 
148  // Hide copy constructor and assignment operator
151 
153  : item_(nullptr)
154  {}
155 
156  explicit unique_xerces_ptr(T* i)
157  : item_(i)
158  {}
159 
161  {
162  xerces_release();
163  }
164 
166  : item_(nullptr)
167  {
168  this->swap(other);
169  }
170 
171  void swap(unique_xerces_ptr<T>& other) noexcept
172  {
173  std::swap(item_, other.item_);
174  }
175 
176  // Assignment of data to guard (not chainable)
177  void operator=(T* i)
178  {
179  reassign(i);
180  }
181 
182  // Release held data (i.e. delete/free it)
184  {
185  if (!is_released())
186  {
187  // Use type-specific release mechanism
188  doRelease_(item_);
189  item_ = nullptr;
190  }
191  }
192 
193  // Give up held data (i.e. return data without releasing)
194  T* yield()
195  {
196  T* tempItem = item_;
197  item_ = nullptr;
198  return tempItem;
199  }
200 
201  // Release currently held data, if any, to hold another
202  void assign(T* i)
203  {
204  xerces_release();
205  item_ = i;
206  }
207 
208  // Get pointer to the currently held data, if any
209  T* get() const
210  {
211  return item_;
212  }
213 
214  // Return true if no data is held
215  bool is_released() const
216  {
217  return (nullptr == item_);
218  }
219  };
220 
221  //========================================================================================================
222 
223  /*
224  * @brief Helper class for XML parsing that handles the conversions of Xerces strings
225  *
226  * It provides the convert() function which internally calls
227  * XMLString::transcode and ensures that the memory is released properly
228  * through XMLString::release internally. It returns a std::string or
229  * std::basic_string<XMLCh> to the caller who takes ownership of the data.
230  *
231  */
232  class OPENMS_DLLAPI StringManager
233  {
234 
235  typedef std::basic_string<XMLCh> XercesString;
236 
237  // Converts from a narrow-character string to a wide-character string.
238  inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
239  {
240  return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
241  }
242 
243  // Converts from a narrow-character string to a wide-character string.
244  inline static unique_xerces_ptr<XMLCh> fromNative_(const String& str)
245  {
246  return fromNative_(str.c_str());
247  }
248 
249  // Converts from a wide-character string to a narrow-character string.
250  inline static String toNative_(const XMLCh* str)
251  {
252  return String(unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
253  }
254 
255  // Converts from a wide-character string to a narrow-character string.
256  inline static String toNative_(const unique_xerces_ptr<XMLCh>& str)
257  {
258  return toNative_(str.get());
259  }
260 
261 
262 public:
265 
268 
270  inline static XercesString convert(const char * str)
271  {
272  return fromNative_(str).get();
273  }
274 
276  inline static XercesString convert(const std::string & str)
277  {
278  return fromNative_(str.c_str()).get();
279  }
280 
282  inline static XercesString convert(const String & str)
283  {
284  return fromNative_(str.c_str()).get();
285  }
286 
288  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
289  {
290  return fromNative_(str);
291  }
292 
294  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
295  {
296  return fromNative_(str.c_str());
297  }
298 
300  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
301  {
302  return fromNative_(str.c_str());
303  }
304 
306  inline static String convert(const XMLCh * str)
307  {
308  return toNative_(str);
309  }
310 
317  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
318 
319  };
320 
324  class OPENMS_DLLAPI XMLHandler :
325  public xercesc::DefaultHandler
326  {
327 public:
328 
330  class OPENMS_DLLAPI EndParsingSoftly :
332  {
333  public:
334  EndParsingSoftly(const char * file, int line, const char * function) :
335  Exception::BaseException(file, line, function)
336  {
337  }
338 
339  };
340 
343  {
345  STORE
346  };
347 
349  {
350  LD_ALLDATA, // default; load all data
351  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
352  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
353  };
354 
355 
357  XMLHandler(const String & filename, const String & version);
359  ~XMLHandler() override;
360 
362  void reset();
363 
364 
371  void fatalError(const xercesc::SAXParseException & exception) override;
372  void error(const xercesc::SAXParseException & exception) override;
373  void warning(const xercesc::SAXParseException & exception) override;
375 
377  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
379  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
381  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
382 
384  void characters(const XMLCh * const chars, const XMLSize_t length) override;
386  void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
388  void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
389 
391  virtual void writeTo(std::ostream & /*os*/);
392 
395 
397  virtual LOADDETAIL getLoadDetail() const;
398 
400  virtual void setLoadDetail(const LOADDETAIL d);
401 
409  static String writeXMLEscape(const String& to_escape)
410  {
411  String _copy = to_escape;
412  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
413  if (_copy.has('&')) _copy.substitute("&","&amp;");
414  if (_copy.has('>')) _copy.substitute(">","&gt;");
415  if (_copy.has('"')) _copy.substitute("\"","&quot;");
416  if (_copy.has('<')) _copy.substitute("<","&lt;");
417  if (_copy.has('\'')) _copy.substitute("'","&apos;");
418 
419  return _copy;
420  }
421 
435  static DataValue fromXSDString(const String& type, const String& value)
436  {
437  DataValue data_value;
438  // float type
439  if (type == "xsd:double" || type == "xsd:float" || type == "xsd:decimal")
440  {
441  data_value = DataValue(value.toDouble());
442  }
443  // <=32 bit integer types
444  else if (type == "xsd:byte" || // 8bit signed
445  type == "xsd:int" || // 32bit signed
446  type == "xsd:unsignedShort" || // 16bit unsigned
447  type == "xsd:short" || // 16bit signed
448  type == "xsd:unsignedByte" || type == "xsd:unsignedInt")
449  {
450  data_value = DataValue(value.toInt32());
451  }
452  // 64 bit integer types
453  else if (type == "xsd:long" || type == "xsd:unsignedLong" || // 64bit signed or unsigned respectively
454  type == "xsd:integer" || type == "xsd:negativeInteger" || // any 'integer' has arbitrary size... but we have to cope with 64bit for now.
455  type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger")
456  {
457  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...
458  }
459  // everything else is treated as a string
460  else
461  {
462  data_value = DataValue(value);
463  }
464  return data_value;
465  }
466 
469  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
470 
471 protected:
474 
477 
480 
483 
489  std::vector<String> open_tags_;
490 
493 
494 
496  inline bool equal_(const XMLCh * a, const XMLCh * b) const
497  {
498  return xercesc::XMLString::compareString(a, b) == 0;
499  }
500 
502 
503 
505  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
506 
508 
510 
511 
513  std::vector<std::vector<String> > cv_terms_;
514 
517  SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0);
518 
520 
522 
523 
525  inline Int asInt_(const String & in) const
526  {
527  Int res = 0;
528  try
529  {
530  res = in.toInt();
531  }
533  {
534  error(LOAD, String("Int conversion error of \"") + in + "\"");
535  }
536  return res;
537  }
538 
540  inline Int asInt_(const XMLCh * in) const
541  {
542  return xercesc::XMLString::parseInt(in);
543  }
544 
546  inline UInt asUInt_(const String & in) const
547  {
548  UInt res = 0;
549  try
550  {
551  Int tmp = in.toInt();
552  if (tmp < 0)
553  {
554  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
555  }
556  res = UInt(tmp);
557  }
559  {
560  error(LOAD, String("UInt conversion error of \"") + in + "\"");
561  }
562  return res;
563  }
564 
566  inline double asDouble_(const String & in) const
567  {
568  double res = 0.0;
569  try
570  {
571  res = in.toDouble();
572  }
574  {
575  error(LOAD, String("Double conversion error of \"") + in + "\"");
576  }
577  return res;
578  }
579 
581  inline float asFloat_(const String & in) const
582  {
583  float res = 0.0;
584  try
585  {
586  res = in.toFloat();
587  }
589  {
590  error(LOAD, String("Float conversion error of \"") + in + "\"");
591  }
592  return res;
593  }
594 
602  inline bool asBool_(const String & in) const
603  {
604  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
605  {
606  return true;
607  }
608  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
609  {
610  return false;
611  }
612  else
613  {
614  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
615  }
616  return false;
617  }
618 
620  inline DateTime asDateTime_(String date_string) const
621  {
622  DateTime date_time;
623  if (!date_string.empty())
624  {
625  try
626  {
627  //strip away milliseconds
628  date_string.trim();
629  date_string = date_string.substr(0, 19);
630  date_time.set(date_string);
631  }
632  catch (Exception::ParseError& /*err*/ )
633  {
634  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
635  }
636  }
637  return date_time;
638  }
639 
641 
643 
644 
646  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
647  {
648  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
649  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
650  return sm_.convert(val);
651  }
652 
654  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
655  {
656  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
657  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
658  return xercesc::XMLString::parseInt(val);
659  }
660 
662  inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
663  {
664  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
665  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
666  return String(sm_.convert(val)).toDouble();
667  }
668 
670  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
671  {
672  String tmp(expectList_(attributeAsString_(a, name)));
673  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
674  }
675 
677  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
678  {
679  String tmp(expectList_(attributeAsString_(a, name)));
680  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
681  }
682 
684  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
685  {
686  String tmp(expectList_(attributeAsString_(a, name)));
687  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
688 
689  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
690  {
691  for (String& s : tmp_list)
692  {
693  s.substitute("\\|", ",");
694  }
695  }
696  return tmp_list;
697  }
698 
704  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
705  {
706  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
707  if (val != nullptr)
708  {
709  value = sm_.convert(val);
710  return true;
711  }
712  return false;
713  }
714 
720  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
721  {
722  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
723  if (val != nullptr)
724  {
725  value = xercesc::XMLString::parseInt(val);
726  return true;
727  }
728  return false;
729  }
730 
736  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
737  {
738  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
739  if (val != nullptr)
740  {
741  value = xercesc::XMLString::parseInt(val);
742  return true;
743  }
744  return false;
745  }
746 
752  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
753  {
754  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
755  if (val != nullptr)
756  {
757  value = String(sm_.convert(val)).toDouble();
758  return true;
759  }
760  return false;
761  }
762 
768  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
769  {
770  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
771  if (val != nullptr)
772  {
773  value = attributeAsDoubleList_(a, name);
774  return true;
775  }
776  return false;
777  }
778 
784  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
785  {
786  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
787  if (val != nullptr)
788  {
789  value = attributeAsStringList_(a, name);
790  return true;
791  }
792  return false;
793  }
794 
800  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
801  {
802  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
803  if (val != nullptr)
804  {
805  value = attributeAsIntList_(a, name);
806  return true;
807  }
808  return false;
809  }
810 
812  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
813  {
814  const XMLCh * val = a.getValue(name);
815  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
816  return sm_.convert(val);
817  }
818 
820  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
821  {
822  const XMLCh * val = a.getValue(name);
823  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
824  return xercesc::XMLString::parseInt(val);
825  }
826 
828  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
829  {
830  const XMLCh * val = a.getValue(name);
831  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
832  return sm_.convert(val).toDouble();
833  }
834 
836  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
837  {
838  String tmp(expectList_(attributeAsString_(a, name)));
839  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
840  }
841 
843  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
844  {
845  String tmp(expectList_(attributeAsString_(a, name)));
846  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
847  }
848 
850  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
851  {
852  String tmp(expectList_(attributeAsString_(a, name)));
853  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
854 
855  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
856  {
857  for (String& s : tmp_list)
858  {
859  s.substitute("\\|", ",");
860  }
861  }
862  return tmp_list;
863  }
864 
866  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
867  {
868  const XMLCh * val = a.getValue(name);
869  if (val != nullptr)
870  {
871  value = sm_.convert(val);
872  return !value.empty();
873  }
874  return false;
875  }
876 
878  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
879  {
880  const XMLCh * val = a.getValue(name);
881  if (val != nullptr)
882  {
883  value = xercesc::XMLString::parseInt(val);
884  return true;
885  }
886  return false;
887  }
888 
890  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
891  {
892  const XMLCh * val = a.getValue(name);
893  if (val != nullptr)
894  {
895  value = xercesc::XMLString::parseInt(val);
896  return true;
897  }
898  return false;
899  }
900 
902  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
903  {
904  const XMLCh * val = a.getValue(name);
905  if (val != nullptr)
906  {
907  value = sm_.convert(val).toDouble();
908  return true;
909  }
910  return false;
911  }
912 
918  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
919  {
920  const XMLCh * val = a.getValue(name);
921  if (val != nullptr)
922  {
923  value = attributeAsDoubleList_(a, name);
924  return true;
925  }
926  return false;
927  }
928 
934  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
935  {
936  const XMLCh * val = a.getValue(name);
937  if (val != nullptr)
938  {
939  value = attributeAsIntList_(a, name);
940  return true;
941  }
942  return false;
943  }
944 
950  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
951  {
952  const XMLCh * val = a.getValue(name);
953  if (val != nullptr)
954  {
955  value = attributeAsStringList_(a, name);
956  return true;
957  }
958  return false;
959  }
960 
962 
963 private:
966 
967  inline const String& expectList_(const String& str) const
968  {
969  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
970  {
971  fatalError(LOAD, String("List argument is not a string representation of a list!"));
972  }
973  return str;
974  }
975 
976  };
977 
978  } // namespace Internal
979 } // namespace OpenMS
980 
981 
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
DateTime Class.
Definition: DateTime.h:59
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:91
Invalid conversion exception.
Definition: Exception.h:356
Parse Error exception.
Definition: Exception.h:624
Definition: XMLHandler.h:233
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:300
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:282
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:288
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:244
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:306
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:250
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:235
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:238
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:276
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:270
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:256
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:294
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:332
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:334
Base class for XML handlers.
Definition: XMLHandler.h:326
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:843
String errorString()
Returns the last error description.
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:489
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:878
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:784
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:492
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:525
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:866
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:850
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:836
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:736
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:602
String file_
File name.
Definition: XMLHandler.h:476
static DataValue fromXSDString(const String &type, const String &value)
Convert an XSD type (e.g. 'xsd:double') to a DataValue.
Definition: XMLHandler.h:435
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:934
String version_
Schema version.
Definition: XMLHandler.h:479
LOADDETAIL
Definition: XMLHandler.h:349
@ LD_RAWCOUNTS
Definition: XMLHandler.h:351
@ LD_ALLDATA
Definition: XMLHandler.h:350
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:496
String error_message_
Error message of the last error.
Definition: XMLHandler.h:473
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:546
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:646
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:950
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:684
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:513
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:343
@ LOAD
Loading a file.
Definition: XMLHandler.h:344
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:670
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:902
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:820
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:540
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:654
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:890
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:918
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:677
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:482
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:409
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:662
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:752
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:768
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:812
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:967
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:620
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:828
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:704
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:800
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:720
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:566
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:581
Definition: XMLHandler.h:73
std::shared_ptr< T > item_
Definition: XMLHandler.h:87
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:92
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:121
static void doRelease_(U *item)
Definition: XMLHandler.h:76
T * get()
Definition: XMLHandler.h:112
const T * get() const
Definition: XMLHandler.h:116
void assign(T *item)
Definition: XMLHandler.h:107
void reset()
Definition: XMLHandler.h:102
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:96
Definition: XMLHandler.h:129
T * item_
Definition: XMLHandler.h:144
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:177
void xerces_release()
Definition: XMLHandler.h:183
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:156
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:171
void assign(T *i)
Definition: XMLHandler.h:202
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:215
T * get() const
Definition: XMLHandler.h:209
unique_xerces_ptr()
Definition: XMLHandler.h:152
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:165
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:160
T * yield()
Definition: XMLHandler.h:194
static void doRelease_(U *&item)
Definition: XMLHandler.h:133
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
A more convenient string class.
Definition: String.h:60
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:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:62
int exception
(Used by various macros. Indicates a rough category of the exception being caught....
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48