OpenMS  2.7.0
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-2021.
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/sax/Locator.hpp>
48 #include <xercesc/sax2/Attributes.hpp>
49 
50 #include <algorithm>
51 #include <iosfwd>
52 #include <string>
53 #include <memory>
54 
55 namespace OpenMS
56 {
57  class ProteinIdentification;
58 
59 
60  namespace Internal
61  {
62 
63  #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
64 
65  static_assert(sizeof(::XMLCh) == sizeof(char16_t),
66  "XMLCh is not sized correctly for UTF-16.");
67 
68  //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
69  //Copyright 2010 Orjan Westin
70  //Under BSD license
71  //========================================================================================================
72  template<typename T>
73  class OPENMS_DLLAPI shared_xerces_ptr
74  {
75  // Function to release Xerces data type with a release member function
76  template<typename U>
77  static void doRelease_(U* item)
78  {
79  // Only release this if it has no owner
80  if (nullptr == item->getOwnerDocument())
81  item->release();
82  }
83 
84  static void doRelease_(char* item);
85  static void doRelease_(XMLCh* item);
86 
87  // The actual data we're holding
88  std::shared_ptr<T> item_;
89  public:
90  // Default constructor
91  shared_xerces_ptr() = default;
92  // Assignment constructor
94  : item_(item, doRelease_ )
95  {}
96  // Assignment of data to guard
98  {
99  assign(item);
100  return *this;
101  }
102  // Give up hold on data
103  void reset()
104  {
105  item_.reset();
106  }
107  // Release currently held data, if any, to hold another
108  void assign(T* item)
109  {
110  item_.reset(item, doRelease_ );
111  }
112  // Get pointer to the currently held data, if any
113  T* get()
114  {
115  return item_.get();
116  }
117  const T* get() const
118  {
119  return item_.get();
120  }
121  // Return true if no data is held
122  bool is_released() const
123  {
124  return (nullptr == item_.get());
125  }
126  };
127 
128  template <typename T>
129  class OPENMS_DLLAPI unique_xerces_ptr
130  {
131  private:
132 
133  template<typename U>
134  static void doRelease_(U*& item)
135  {
136  // Only release this if it has no parent (otherwise
137  // parent will release it)
138  if (nullptr == item->getOwnerDocument())
139  item->release();
140  }
141 
142  static void doRelease_(char*& item);
143  static void doRelease_(XMLCh*& item);
144 
145  T* item_;
146 
147  public:
148 
149  // Hide copy constructor and assignment operator
152 
154  : item_(nullptr)
155  {}
156 
157  explicit unique_xerces_ptr(T* i)
158  : item_(i)
159  {}
160 
162  {
163  xerces_release();
164  }
165 
167  : item_(nullptr)
168  {
169  this->swap(other);
170  }
171 
172  void swap(unique_xerces_ptr<T>& other) noexcept
173  {
174  std::swap(item_, other.item_);
175  }
176 
177  // Assignment of data to guard (not chainable)
178  void operator=(T* i)
179  {
180  reassign(i);
181  }
182 
183  // Release held data (i.e. delete/free it)
185  {
186  if (!is_released())
187  {
188  // Use type-specific release mechanism
189  doRelease_(item_);
190  item_ = nullptr;
191  }
192  }
193 
194  // Give up held data (i.e. return data without releasing)
195  T* yield()
196  {
197  T* tempItem = item_;
198  item_ = nullptr;
199  return tempItem;
200  }
201 
202  // Release currently held data, if any, to hold another
203  void assign(T* i)
204  {
205  xerces_release();
206  item_ = i;
207  }
208 
209  // Get pointer to the currently held data, if any
210  T* get() const
211  {
212  return item_;
213  }
214 
215  // Return true if no data is held
216  bool is_released() const
217  {
218  return (nullptr == item_);
219  }
220  };
221 
222  //========================================================================================================
223 
224  /*
225  * @brief Helper class for XML parsing that handles the conversions of Xerces strings
226  *
227  * It provides the convert() function which internally calls
228  * XMLString::transcode and ensures that the memory is released properly
229  * through XMLString::release internally. It returns a std::string or
230  * std::basic_string<XMLCh> to the caller who takes ownership of the data.
231  *
232  */
233  class OPENMS_DLLAPI StringManager
234  {
235 
236  typedef std::basic_string<XMLCh> XercesString;
237 
238  // Converts from a narrow-character string to a wide-character string.
239  inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
240  {
241  return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
242  }
243 
244  // Converts from a narrow-character string to a wide-character string.
245  inline static unique_xerces_ptr<XMLCh> fromNative_(const String& str)
246  {
247  return fromNative_(str.c_str());
248  }
249 
250  // Converts from a wide-character string to a narrow-character string.
251  inline static String toNative_(const XMLCh* str)
252  {
253  return String(unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
254  }
255 
256  // Converts from a wide-character string to a narrow-character string.
257  inline static String toNative_(const unique_xerces_ptr<XMLCh>& str)
258  {
259  return toNative_(str.get());
260  }
261 
262 
263 public:
266 
269 
271  inline static XercesString convert(const char * str)
272  {
273  return fromNative_(str).get();
274  }
275 
277  inline static XercesString convert(const std::string & str)
278  {
279  return fromNative_(str.c_str()).get();
280  }
281 
283  inline static XercesString convert(const String & str)
284  {
285  return fromNative_(str.c_str()).get();
286  }
287 
289  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
290  {
291  return fromNative_(str);
292  }
293 
295  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
296  {
297  return fromNative_(str.c_str());
298  }
299 
301  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
302  {
303  return fromNative_(str.c_str());
304  }
305 
307  inline static String convert(const XMLCh * str)
308  {
309  return toNative_(str);
310  }
311 
318  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
319 
320  };
321 
325  class OPENMS_DLLAPI XMLHandler :
326  public xercesc::DefaultHandler
327  {
328 public:
329 
331  class OPENMS_DLLAPI EndParsingSoftly :
333  {
334  public:
335  EndParsingSoftly(const char * file, int line, const char * function) :
336  Exception::BaseException(file, line, function)
337  {
338  }
339 
340  };
341 
344  {
346  STORE
347  };
348 
350  {
351  LD_ALLDATA, // default; load all data
352  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
353  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
354  };
355 
356 
358  XMLHandler(const String & filename, const String & version);
360  ~XMLHandler() override;
361 
363  void reset();
364 
365 
372  void fatalError(const xercesc::SAXParseException & exception) override;
373  void error(const xercesc::SAXParseException & exception) override;
374  void warning(const xercesc::SAXParseException & exception) override;
376 
378  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
380  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
382  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
383 
385  void characters(const XMLCh * const chars, const XMLSize_t length) override;
387  void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
389  void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
390 
392  virtual void writeTo(std::ostream & /*os*/);
393 
396 
398  virtual LOADDETAIL getLoadDetail() const;
399 
401  virtual void setLoadDetail(const LOADDETAIL d);
402 
410  static String writeXMLEscape(const String& to_escape)
411  {
412  String _copy = to_escape;
413  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
414  if (_copy.has('&')) _copy.substitute("&","&amp;");
415  if (_copy.has('>')) _copy.substitute(">","&gt;");
416  if (_copy.has('"')) _copy.substitute("\"","&quot;");
417  if (_copy.has('<')) _copy.substitute("<","&lt;");
418  if (_copy.has('\'')) _copy.substitute("'","&apos;");
419 
420  return _copy;
421  }
422 
425  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids);
426 
427 protected:
430 
433 
436 
439 
445  std::vector<String> open_tags_;
446 
449 
450 
452  inline bool equal_(const XMLCh * a, const XMLCh * b) const
453  {
454  return xercesc::XMLString::compareString(a, b) == 0;
455  }
456 
458 
459 
461  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
462 
464 
466 
467 
469  std::vector<std::vector<String> > cv_terms_;
470 
473  inline SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0)
474  {
475  OPENMS_PRECONDITION(section < cv_terms_.size(), "cvStringToEnum_: Index overflow (section number too large)");
476 
477  std::vector<String>::const_iterator it = std::find(cv_terms_[section].begin(), cv_terms_[section].end(), term);
478  if (it != cv_terms_[section].end())
479  {
480  return it - cv_terms_[section].begin();
481  }
482  else
483  {
484  warning(LOAD, String("Unexpected CV entry '") + message + "'='" + term + "'");
485  return result_on_error;
486  }
487  }
488 
490 
492 
493 
495  inline Int asInt_(const String & in) const
496  {
497  Int res = 0;
498  try
499  {
500  res = in.toInt();
501  }
503  {
504  error(LOAD, String("Int conversion error of \"") + in + "\"");
505  }
506  return res;
507  }
508 
510  inline Int asInt_(const XMLCh * in) const
511  {
512  return xercesc::XMLString::parseInt(in);
513  }
514 
516  inline UInt asUInt_(const String & in) const
517  {
518  UInt res = 0;
519  try
520  {
521  Int tmp = in.toInt();
522  if (tmp < 0)
523  {
524  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
525  }
526  res = UInt(tmp);
527  }
529  {
530  error(LOAD, String("UInt conversion error of \"") + in + "\"");
531  }
532  return res;
533  }
534 
536  inline double asDouble_(const String & in) const
537  {
538  double res = 0.0;
539  try
540  {
541  res = in.toDouble();
542  }
544  {
545  error(LOAD, String("Double conversion error of \"") + in + "\"");
546  }
547  return res;
548  }
549 
551  inline float asFloat_(const String & in) const
552  {
553  float res = 0.0;
554  try
555  {
556  res = in.toFloat();
557  }
559  {
560  error(LOAD, String("Float conversion error of \"") + in + "\"");
561  }
562  return res;
563  }
564 
572  inline bool asBool_(const String & in) const
573  {
574  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
575  {
576  return true;
577  }
578  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
579  {
580  return false;
581  }
582  else
583  {
584  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
585  }
586  return false;
587  }
588 
590  inline DateTime asDateTime_(String date_string) const
591  {
592  DateTime date_time;
593  if (date_string != "")
594  {
595  try
596  {
597  //strip away milliseconds
598  date_string.trim();
599  date_string = date_string.substr(0, 19);
600  date_time.set(date_string);
601  }
602  catch (Exception::ParseError& /*err*/ )
603  {
604  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
605  }
606  }
607  return date_time;
608  }
609 
611 
613 
614 
616  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
617  {
618  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
619  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
620  return sm_.convert(val);
621  }
622 
624  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
625  {
626  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
627  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
628  return xercesc::XMLString::parseInt(val);
629  }
630 
632  inline double attributeAsDouble_(const xercesc::Attributes & a, const char * name) const
633  {
634  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
635  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
636  return String(sm_.convert(val)).toDouble();
637  }
638 
640  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
641  {
642  String tmp(expectList_(attributeAsString_(a, name)));
643  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
644  }
645 
647  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
648  {
649  String tmp(expectList_(attributeAsString_(a, name)));
650  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
651  }
652 
654  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
655  {
656  String tmp(expectList_(attributeAsString_(a, name)));
657  return ListUtils::create<String>(tmp.substr(1, tmp.size() - 2));
658  }
659 
665  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
666  {
667  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
668  if (val != nullptr)
669  {
670  value = sm_.convert(val);
671  return true;
672  }
673  return false;
674  }
675 
681  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
682  {
683  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
684  if (val != nullptr)
685  {
686  value = xercesc::XMLString::parseInt(val);
687  return true;
688  }
689  return false;
690  }
691 
697  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
698  {
699  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
700  if (val != nullptr)
701  {
702  value = xercesc::XMLString::parseInt(val);
703  return true;
704  }
705  return false;
706  }
707 
713  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
714  {
715  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
716  if (val != nullptr)
717  {
718  value = String(sm_.convert(val)).toDouble();
719  return true;
720  }
721  return false;
722  }
723 
729  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
730  {
731  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
732  if (val != nullptr)
733  {
734  value = attributeAsDoubleList_(a, name);
735  return true;
736  }
737  return false;
738  }
739 
745  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
746  {
747  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
748  if (val != nullptr)
749  {
750  value = attributeAsStringList_(a, name);
751  return true;
752  }
753  return false;
754  }
755 
761  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
762  {
763  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
764  if (val != nullptr)
765  {
766  value = attributeAsIntList_(a, name);
767  return true;
768  }
769  return false;
770  }
771 
773  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
774  {
775  const XMLCh * val = a.getValue(name);
776  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
777  return sm_.convert(val);
778  }
779 
781  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
782  {
783  const XMLCh * val = a.getValue(name);
784  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
785  return xercesc::XMLString::parseInt(val);
786  }
787 
789  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
790  {
791  const XMLCh * val = a.getValue(name);
792  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
793  return sm_.convert(val).toDouble();
794  }
795 
797  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
798  {
799  String tmp(expectList_(attributeAsString_(a, name)));
800  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
801  }
802 
804  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
805  {
806  String tmp(expectList_(attributeAsString_(a, name)));
807  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
808  }
809 
811  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
812  {
813  String tmp(expectList_(attributeAsString_(a, name)));
814  return ListUtils::create<String>(tmp.substr(1, tmp.size() - 2));
815  }
816 
818  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
819  {
820  const XMLCh * val = a.getValue(name);
821  if (val != nullptr)
822  {
823  value = sm_.convert(val);
824  return !value.empty();
825  }
826  return false;
827  }
828 
830  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
831  {
832  const XMLCh * val = a.getValue(name);
833  if (val != nullptr)
834  {
835  value = xercesc::XMLString::parseInt(val);
836  return true;
837  }
838  return false;
839  }
840 
842  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
843  {
844  const XMLCh * val = a.getValue(name);
845  if (val != nullptr)
846  {
847  value = xercesc::XMLString::parseInt(val);
848  return true;
849  }
850  return false;
851  }
852 
854  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
855  {
856  const XMLCh * val = a.getValue(name);
857  if (val != nullptr)
858  {
859  value = sm_.convert(val).toDouble();
860  return true;
861  }
862  return false;
863  }
864 
870  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
871  {
872  const XMLCh * val = a.getValue(name);
873  if (val != nullptr)
874  {
875  value = attributeAsDoubleList_(a, name);
876  return true;
877  }
878  return false;
879  }
880 
886  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
887  {
888  const XMLCh * val = a.getValue(name);
889  if (val != nullptr)
890  {
891  value = attributeAsIntList_(a, name);
892  return true;
893  }
894  return false;
895  }
896 
902  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
903  {
904  const XMLCh * val = a.getValue(name);
905  if (val != nullptr)
906  {
907  value = attributeAsStringList_(a, name);
908  return true;
909  }
910  return false;
911  }
912 
914 
915 private:
918 
919  inline const String& expectList_(const String& str) const
920  {
921  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
922  {
923  fatalError(LOAD, String("List argument is not a string representation of a list!"));
924  }
925  return str;
926  }
927 
928  };
929 
930  } // namespace Internal
931 } // namespace OpenMS
932 
933 
DateTime Class.
Definition: DateTime.h:55
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:92
Invalid conversion exception.
Definition: Exception.h:356
Parse Error exception.
Definition: Exception.h:630
Definition: XMLHandler.h:234
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:301
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:283
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:289
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:245
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:307
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:251
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:236
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:239
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:277
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:271
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:257
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:295
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:333
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:335
Base class for XML handlers.
Definition: XMLHandler.h:327
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:804
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:445
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:830
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:745
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:448
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:495
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:818
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:811
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:797
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:697
virtual void setLoadDetail(const LOADDETAIL d)
handler which support partial loading, implement this method
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:572
String file_
File name.
Definition: XMLHandler.h:432
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:886
String version_
Schema version.
Definition: XMLHandler.h:435
LOADDETAIL
Definition: XMLHandler.h:350
@ LD_RAWCOUNTS
Definition: XMLHandler.h:352
@ LD_ALLDATA
Definition: XMLHandler.h:351
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:452
String error_message_
Error message of the last error.
Definition: XMLHandler.h:429
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:516
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:616
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:902
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:654
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:469
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:344
@ LOAD
Loading a file.
Definition: XMLHandler.h:345
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:640
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:854
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:781
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:510
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:624
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:842
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:870
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:647
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:438
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:410
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:632
SignedSize cvStringToEnum_(const Size section, const String &term, const char *message, const SignedSize result_on_error=0)
Definition: XMLHandler.h:473
~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:713
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:729
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:773
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:919
void characters(const XMLCh *const chars, const XMLSize_t length) override
Parsing method for character data.
void checkUniqueIdentifiers_(const std::vector< ProteinIdentification > &prot_ids)
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:590
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:789
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:665
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:761
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:681
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:536
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:551
Definition: XMLHandler.h:74
std::shared_ptr< T > item_
Definition: XMLHandler.h:88
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:93
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:122
static void doRelease_(U *item)
Definition: XMLHandler.h:77
T * get()
Definition: XMLHandler.h:113
const T * get() const
Definition: XMLHandler.h:117
void assign(T *item)
Definition: XMLHandler.h:108
void reset()
Definition: XMLHandler.h:103
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:97
Definition: XMLHandler.h:130
T * item_
Definition: XMLHandler.h:145
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:178
void xerces_release()
Definition: XMLHandler.h:184
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:157
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:172
void assign(T *i)
Definition: XMLHandler.h:203
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:216
T * get() const
Definition: XMLHandler.h:210
unique_xerces_ptr()
Definition: XMLHandler.h:153
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:166
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:161
T * yield()
Definition: XMLHandler.h:195
static void doRelease_(U *&item)
Definition: XMLHandler.h:134
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:61
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 has(Byte byte) const
true if String contains the byte, false otherwise
Int toInt() const
Conversion to int.
double toDouble() const
Conversion to double.
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
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition: openms/include/OpenMS/CONCEPT/Macros.h:120
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:47
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:886
void assign(char &c_target, AAcid const &source)
Definition: AhoCorasickAmbiguous.h:179