OpenMS  2.8.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
43 
44 #include <xercesc/util/XMLString.hpp>
45 #include <xercesc/sax2/DefaultHandler.hpp>
46 #include <xercesc/sax2/Attributes.hpp>
47 
48 #include <iosfwd>
49 #include <string>
50 #include <memory>
51 
52 
53 namespace OpenMS
54 {
55  class ProteinIdentification;
56  class MetaInfoInterface;
57 
58  namespace Internal
59  {
60 
61  #define CONST_XMLCH(s) reinterpret_cast<const ::XMLCh*>(u ## s)
62 
63  static_assert(sizeof(::XMLCh) == sizeof(char16_t),
64  "XMLCh is not sized correctly for UTF-16.");
65 
66  //Adapted from https://www.codeproject.com/articles/99551/redux-raii-adapter-for-xerces
67  //Copyright 2010 Orjan Westin
68  //Under BSD license
69  //========================================================================================================
70  template<typename T>
71  class OPENMS_DLLAPI shared_xerces_ptr
72  {
73  // Function to release Xerces data type with a release member function
74  template<typename U>
75  static void doRelease_(U* item)
76  {
77  // Only release this if it has no owner
78  if (nullptr == item->getOwnerDocument())
79  item->release();
80  }
81 
82  static void doRelease_(char* item);
83  static void doRelease_(XMLCh* item);
84 
85  // The actual data we're holding
86  std::shared_ptr<T> item_;
87  public:
88  // Default constructor
89  shared_xerces_ptr() = default;
90  // Assignment constructor
92  : item_(item, doRelease_ )
93  {}
94  // Assignment of data to guard
96  {
97  assign(item);
98  return *this;
99  }
100  // Give up hold on data
101  void reset()
102  {
103  item_.reset();
104  }
105  // Release currently held data, if any, to hold another
106  void assign(T* item)
107  {
108  item_.reset(item, doRelease_ );
109  }
110  // Get pointer to the currently held data, if any
111  T* get()
112  {
113  return item_.get();
114  }
115  const T* get() const
116  {
117  return item_.get();
118  }
119  // Return true if no data is held
120  bool is_released() const
121  {
122  return (nullptr == item_.get());
123  }
124  };
125 
126  template <typename T>
127  class OPENMS_DLLAPI unique_xerces_ptr
128  {
129  private:
130 
131  template<typename U>
132  static void doRelease_(U*& item)
133  {
134  // Only release this if it has no parent (otherwise
135  // parent will release it)
136  if (nullptr == item->getOwnerDocument())
137  item->release();
138  }
139 
140  static void doRelease_(char*& item);
141  static void doRelease_(XMLCh*& item);
142 
143  T* item_;
144 
145  public:
146 
147  // Hide copy constructor and assignment operator
150 
152  : item_(nullptr)
153  {}
154 
155  explicit unique_xerces_ptr(T* i)
156  : item_(i)
157  {}
158 
160  {
161  xerces_release();
162  }
163 
165  : item_(nullptr)
166  {
167  this->swap(other);
168  }
169 
170  void swap(unique_xerces_ptr<T>& other) noexcept
171  {
172  std::swap(item_, other.item_);
173  }
174 
175  // Assignment of data to guard (not chainable)
176  void operator=(T* i)
177  {
178  reassign(i);
179  }
180 
181  // Release held data (i.e. delete/free it)
183  {
184  if (!is_released())
185  {
186  // Use type-specific release mechanism
187  doRelease_(item_);
188  item_ = nullptr;
189  }
190  }
191 
192  // Give up held data (i.e. return data without releasing)
193  T* yield()
194  {
195  T* tempItem = item_;
196  item_ = nullptr;
197  return tempItem;
198  }
199 
200  // Release currently held data, if any, to hold another
201  void assign(T* i)
202  {
203  xerces_release();
204  item_ = i;
205  }
206 
207  // Get pointer to the currently held data, if any
208  T* get() const
209  {
210  return item_;
211  }
212 
213  // Return true if no data is held
214  bool is_released() const
215  {
216  return (nullptr == item_);
217  }
218  };
219 
220  //========================================================================================================
221 
222  /*
223  * @brief Helper class for XML parsing that handles the conversions of Xerces strings
224  *
225  * It provides the convert() function which internally calls
226  * XMLString::transcode and ensures that the memory is released properly
227  * through XMLString::release internally. It returns a std::string or
228  * std::basic_string<XMLCh> to the caller who takes ownership of the data.
229  *
230  */
231  class OPENMS_DLLAPI StringManager
232  {
233 
234  typedef std::basic_string<XMLCh> XercesString;
235 
236  // Converts from a narrow-character string to a wide-character string.
237  inline static unique_xerces_ptr<XMLCh> fromNative_(const char* str)
238  {
239  return unique_xerces_ptr<XMLCh>(xercesc::XMLString::transcode(str));
240  }
241 
242  // Converts from a narrow-character string to a wide-character string.
243  inline static unique_xerces_ptr<XMLCh> fromNative_(const String& str)
244  {
245  return fromNative_(str.c_str());
246  }
247 
248  // Converts from a wide-character string to a narrow-character string.
249  inline static String toNative_(const XMLCh* str)
250  {
251  return String(unique_xerces_ptr<char>(xercesc::XMLString::transcode(str)).get());
252  }
253 
254  // Converts from a wide-character string to a narrow-character string.
255  inline static String toNative_(const unique_xerces_ptr<XMLCh>& str)
256  {
257  return toNative_(str.get());
258  }
259 
260 
261 public:
264 
267 
269  inline static XercesString convert(const char * str)
270  {
271  return fromNative_(str).get();
272  }
273 
275  inline static XercesString convert(const std::string & str)
276  {
277  return fromNative_(str.c_str()).get();
278  }
279 
281  inline static XercesString convert(const String & str)
282  {
283  return fromNative_(str.c_str()).get();
284  }
285 
287  inline static unique_xerces_ptr<XMLCh> convertPtr(const char * str)
288  {
289  return fromNative_(str);
290  }
291 
293  inline static unique_xerces_ptr<XMLCh> convertPtr(const std::string & str)
294  {
295  return fromNative_(str.c_str());
296  }
297 
299  inline static unique_xerces_ptr<XMLCh> convertPtr(const String & str)
300  {
301  return fromNative_(str.c_str());
302  }
303 
305  inline static String convert(const XMLCh * str)
306  {
307  return toNative_(str);
308  }
309 
316  static void appendASCII(const XMLCh * str, const XMLSize_t length, String & result);
317 
318  };
319 
323  class OPENMS_DLLAPI XMLHandler :
324  public xercesc::DefaultHandler
325  {
326 public:
327 
329  class OPENMS_DLLAPI EndParsingSoftly :
331  {
332  public:
333  EndParsingSoftly(const char * file, int line, const char * function) :
334  Exception::BaseException(file, line, function)
335  {
336  }
337 
338  };
339 
342  {
344  STORE
345  };
346 
348  {
349  LD_ALLDATA, // default; load all data
350  LD_RAWCOUNTS, // only count the total number of spectra and chromatograms (usually very fast)
351  LD_COUNTS_WITHOPTIONS // count the number of spectra, while respecting PeakFileOptions (msLevel and RTRange) and chromatograms (fast)
352  };
353 
354 
356  XMLHandler(const String & filename, const String & version);
358  ~XMLHandler() override;
359 
361  void reset();
362 
363 
370  void fatalError(const xercesc::SAXParseException & exception) override;
371  void error(const xercesc::SAXParseException & exception) override;
372  void warning(const xercesc::SAXParseException & exception) override;
374 
376  void fatalError(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
378  void error(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
380  void warning(ActionMode mode, const String & msg, UInt line = 0, UInt column = 0) const;
381 
383  void characters(const XMLCh * const chars, const XMLSize_t length) override;
385  void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const xercesc::Attributes & attrs) override;
387  void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override;
388 
390  virtual void writeTo(std::ostream & /*os*/);
391 
394 
396  virtual LOADDETAIL getLoadDetail() const;
397 
399  virtual void setLoadDetail(const LOADDETAIL d);
400 
408  static String writeXMLEscape(const String& to_escape)
409  {
410  String _copy = to_escape;
411  // has() is cheap, so check before calling substitute(), since substitute() will usually happen rarely
412  if (_copy.has('&')) _copy.substitute("&","&amp;");
413  if (_copy.has('>')) _copy.substitute(">","&gt;");
414  if (_copy.has('"')) _copy.substitute("\"","&quot;");
415  if (_copy.has('<')) _copy.substitute("<","&lt;");
416  if (_copy.has('\'')) _copy.substitute("'","&apos;");
417 
418  return _copy;
419  }
420 
423  void checkUniqueIdentifiers_(const std::vector<ProteinIdentification>& prot_ids) const;
424 
425 protected:
428 
431 
434 
437 
443  std::vector<String> open_tags_;
444 
447 
448 
450  inline bool equal_(const XMLCh * a, const XMLCh * b) const
451  {
452  return xercesc::XMLString::compareString(a, b) == 0;
453  }
454 
456 
457 
459  void writeUserParam_(const String & tag_name, std::ostream & os, const MetaInfoInterface & meta, UInt indent) const;
460 
462 
464 
465 
467  std::vector<std::vector<String> > cv_terms_;
468 
471  SignedSize cvStringToEnum_(const Size section, const String & term, const char * message, const SignedSize result_on_error = 0);
472 
474 
476 
477 
479  inline Int asInt_(const String & in) const
480  {
481  Int res = 0;
482  try
483  {
484  res = in.toInt();
485  }
487  {
488  error(LOAD, String("Int conversion error of \"") + in + "\"");
489  }
490  return res;
491  }
492 
494  inline Int asInt_(const XMLCh * in) const
495  {
496  return xercesc::XMLString::parseInt(in);
497  }
498 
500  inline UInt asUInt_(const String & in) const
501  {
502  UInt res = 0;
503  try
504  {
505  Int tmp = in.toInt();
506  if (tmp < 0)
507  {
508  throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "");
509  }
510  res = UInt(tmp);
511  }
513  {
514  error(LOAD, String("UInt conversion error of \"") + in + "\"");
515  }
516  return res;
517  }
518 
520  inline double asDouble_(const String & in) const
521  {
522  double res = 0.0;
523  try
524  {
525  res = in.toDouble();
526  }
528  {
529  error(LOAD, String("Double conversion error of \"") + in + "\"");
530  }
531  return res;
532  }
533 
535  inline float asFloat_(const String & in) const
536  {
537  float res = 0.0;
538  try
539  {
540  res = in.toFloat();
541  }
543  {
544  error(LOAD, String("Float conversion error of \"") + in + "\"");
545  }
546  return res;
547  }
548 
556  inline bool asBool_(const String & in) const
557  {
558  if (in == "true" || in == "TRUE" || in == "True" || in == "1")
559  {
560  return true;
561  }
562  else if (in == "false" || in == "FALSE" || in == "False" || in == "0")
563  {
564  return false;
565  }
566  else
567  {
568  error(LOAD, String("Boolean conversion error of \"") + in + "\"");
569  }
570  return false;
571  }
572 
574  inline DateTime asDateTime_(String date_string) const
575  {
576  DateTime date_time;
577  if (!date_string.empty())
578  {
579  try
580  {
581  //strip away milliseconds
582  date_string.trim();
583  date_string = date_string.substr(0, 19);
584  date_time.set(date_string);
585  }
586  catch (Exception::ParseError& /*err*/ )
587  {
588  error(LOAD, String("DateTime conversion error of \"") + date_string + "\"");
589  }
590  }
591  return date_time;
592  }
593 
595 
597 
598 
600  inline String attributeAsString_(const xercesc::Attributes & a, const char * name) const
601  {
602  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
603  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
604  return sm_.convert(val);
605  }
606 
608  inline Int attributeAsInt_(const xercesc::Attributes & a, const char * name) const
609  {
610  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
611  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + name + "' not present!");
612  return xercesc::XMLString::parseInt(val);
613  }
614 
616  inline double attributeAsDouble_(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 String(sm_.convert(val)).toDouble();
621  }
622 
624  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const char * name) const
625  {
626  String tmp(expectList_(attributeAsString_(a, name)));
627  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
628  }
629 
631  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const char * name) const
632  {
633  String tmp(expectList_(attributeAsString_(a, name)));
634  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
635  }
636 
638  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const char * name) const
639  {
640  String tmp(expectList_(attributeAsString_(a, name)));
641  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
642 
643  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
644  {
645  for (String& s : tmp_list)
646  {
647  s.substitute("\\|", ",");
648  }
649  }
650  return tmp_list;
651  }
652 
658  inline bool optionalAttributeAsString_(String & value, const xercesc::Attributes & a, const char * name) const
659  {
660  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
661  if (val != nullptr)
662  {
663  value = sm_.convert(val);
664  return true;
665  }
666  return false;
667  }
668 
674  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const char * name) const
675  {
676  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
677  if (val != nullptr)
678  {
679  value = xercesc::XMLString::parseInt(val);
680  return true;
681  }
682  return false;
683  }
684 
690  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const char * name) const
691  {
692  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
693  if (val != nullptr)
694  {
695  value = xercesc::XMLString::parseInt(val);
696  return true;
697  }
698  return false;
699  }
700 
706  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const char * name) const
707  {
708  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
709  if (val != nullptr)
710  {
711  value = String(sm_.convert(val)).toDouble();
712  return true;
713  }
714  return false;
715  }
716 
722  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const char * name) const
723  {
724  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
725  if (val != nullptr)
726  {
727  value = attributeAsDoubleList_(a, name);
728  return true;
729  }
730  return false;
731  }
732 
738  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const char * name) const
739  {
740  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
741  if (val != nullptr)
742  {
743  value = attributeAsStringList_(a, name);
744  return true;
745  }
746  return false;
747  }
748 
754  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const char * name) const
755  {
756  const XMLCh * val = a.getValue(sm_.convertPtr(name).get());
757  if (val != nullptr)
758  {
759  value = attributeAsIntList_(a, name);
760  return true;
761  }
762  return false;
763  }
764 
766  inline String attributeAsString_(const xercesc::Attributes & a, const XMLCh * name) const
767  {
768  const XMLCh * val = a.getValue(name);
769  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
770  return sm_.convert(val);
771  }
772 
774  inline Int attributeAsInt_(const xercesc::Attributes & a, const XMLCh * name) const
775  {
776  const XMLCh * val = a.getValue(name);
777  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
778  return xercesc::XMLString::parseInt(val);
779  }
780 
782  inline double attributeAsDouble_(const xercesc::Attributes & a, const XMLCh * name) const
783  {
784  const XMLCh * val = a.getValue(name);
785  if (val == nullptr) fatalError(LOAD, String("Required attribute '") + sm_.convert(name) + "' not present!");
786  return sm_.convert(val).toDouble();
787  }
788 
790  inline DoubleList attributeAsDoubleList_(const xercesc::Attributes & a, const XMLCh * name) const
791  {
792  String tmp(expectList_(attributeAsString_(a, name)));
793  return ListUtils::create<double>(tmp.substr(1, tmp.size() - 2));
794  }
795 
797  inline IntList attributeAsIntList_(const xercesc::Attributes & a, const XMLCh * name) const
798  {
799  String tmp(expectList_(attributeAsString_(a, name)));
800  return ListUtils::create<Int>(tmp.substr(1, tmp.size() - 2));
801  }
802 
804  inline StringList attributeAsStringList_(const xercesc::Attributes & a, const XMLCh * name) const
805  {
806  String tmp(expectList_(attributeAsString_(a, name)));
807  StringList tmp_list = ListUtils::create<String>(tmp.substr(1, tmp.size() - 2)); // between [ and ]
808 
809  if (tmp.hasSubstring("\\|")) // check full string for escaped comma
810  {
811  for (String& s : tmp_list)
812  {
813  s.substitute("\\|", ",");
814  }
815  }
816  return tmp_list;
817  }
818 
820  inline bool optionalAttributeAsString_(String& value, const xercesc::Attributes & a, const XMLCh * name) const
821  {
822  const XMLCh * val = a.getValue(name);
823  if (val != nullptr)
824  {
825  value = sm_.convert(val);
826  return !value.empty();
827  }
828  return false;
829  }
830 
832  inline bool optionalAttributeAsInt_(Int & value, const xercesc::Attributes & a, const XMLCh * name) const
833  {
834  const XMLCh * val = a.getValue(name);
835  if (val != nullptr)
836  {
837  value = xercesc::XMLString::parseInt(val);
838  return true;
839  }
840  return false;
841  }
842 
844  inline bool optionalAttributeAsUInt_(UInt & value, const xercesc::Attributes & a, const XMLCh * name) const
845  {
846  const XMLCh * val = a.getValue(name);
847  if (val != nullptr)
848  {
849  value = xercesc::XMLString::parseInt(val);
850  return true;
851  }
852  return false;
853  }
854 
856  inline bool optionalAttributeAsDouble_(double & value, const xercesc::Attributes & a, const XMLCh * name) const
857  {
858  const XMLCh * val = a.getValue(name);
859  if (val != nullptr)
860  {
861  value = sm_.convert(val).toDouble();
862  return true;
863  }
864  return false;
865  }
866 
872  inline bool optionalAttributeAsDoubleList_(DoubleList & value, const xercesc::Attributes & a, const XMLCh * name) const
873  {
874  const XMLCh * val = a.getValue(name);
875  if (val != nullptr)
876  {
877  value = attributeAsDoubleList_(a, name);
878  return true;
879  }
880  return false;
881  }
882 
888  inline bool optionalAttributeAsIntList_(IntList & value, const xercesc::Attributes & a, const XMLCh * name) const
889  {
890  const XMLCh * val = a.getValue(name);
891  if (val != nullptr)
892  {
893  value = attributeAsIntList_(a, name);
894  return true;
895  }
896  return false;
897  }
898 
904  inline bool optionalAttributeAsStringList_(StringList & value, const xercesc::Attributes & a, const XMLCh * name) const
905  {
906  const XMLCh * val = a.getValue(name);
907  if (val != nullptr)
908  {
909  value = attributeAsStringList_(a, name);
910  return true;
911  }
912  return false;
913  }
914 
916 
917 private:
920 
921  inline const String& expectList_(const String& str) const
922  {
923  if (!(str.hasPrefix('[') && str.hasSuffix(']')))
924  {
925  fatalError(LOAD, String("List argument is not a string representation of a list!"));
926  }
927  return str;
928  }
929 
930  };
931 
932  } // namespace Internal
933 } // namespace OpenMS
934 
935 
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:91
Invalid conversion exception.
Definition: Exception.h:356
Parse Error exception.
Definition: Exception.h:624
Definition: XMLHandler.h:232
static unique_xerces_ptr< XMLCh > convertPtr(const String &str)
Transcode the supplied OpenMS string to a xerces string pointer.
Definition: XMLHandler.h:299
static XercesString convert(const String &str)
Transcode the supplied OpenMS string to a xerces string.
Definition: XMLHandler.h:281
static unique_xerces_ptr< XMLCh > convertPtr(const char *str)
Transcode the supplied C string to a xerces string pointer.
Definition: XMLHandler.h:287
static unique_xerces_ptr< XMLCh > fromNative_(const String &str)
Definition: XMLHandler.h:243
static String convert(const XMLCh *str)
Transcode the supplied XMLCh* to a String.
Definition: XMLHandler.h:305
static String toNative_(const XMLCh *str)
Definition: XMLHandler.h:249
std::basic_string< XMLCh > XercesString
Definition: XMLHandler.h:234
static unique_xerces_ptr< XMLCh > fromNative_(const char *str)
Definition: XMLHandler.h:237
static XercesString convert(const std::string &str)
Transcode the supplied C++ string to a xerces string.
Definition: XMLHandler.h:275
static XercesString convert(const char *str)
Transcode the supplied C string to a xerces string.
Definition: XMLHandler.h:269
static String toNative_(const unique_xerces_ptr< XMLCh > &str)
Definition: XMLHandler.h:255
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:293
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:331
EndParsingSoftly(const char *file, int line, const char *function)
Definition: XMLHandler.h:333
Base class for XML handlers.
Definition: XMLHandler.h:325
IntList attributeAsIntList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a IntList.
Definition: XMLHandler.h:797
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:443
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:832
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:738
LOADDETAIL load_detail_
parse only until total number of scans and chroms have been determined from attributes
Definition: XMLHandler.h:446
Int asInt_(const String &in) const
Conversion of a String to an integer value.
Definition: XMLHandler.h:479
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:820
StringList attributeAsStringList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a StringList.
Definition: XMLHandler.h:804
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:790
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:690
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:556
String file_
File name.
Definition: XMLHandler.h:430
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:888
String version_
Schema version.
Definition: XMLHandler.h:433
LOADDETAIL
Definition: XMLHandler.h:348
@ LD_RAWCOUNTS
Definition: XMLHandler.h:350
@ LD_ALLDATA
Definition: XMLHandler.h:349
bool equal_(const XMLCh *a, const XMLCh *b) const
Returns if two Xerces strings are equal.
Definition: XMLHandler.h:450
String error_message_
Error message of the last error.
Definition: XMLHandler.h:427
UInt asUInt_(const String &in) const
Conversion of a String to an unsigned integer value.
Definition: XMLHandler.h:500
String attributeAsString_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:600
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:904
StringList attributeAsStringList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an StringList.
Definition: XMLHandler.h:638
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:467
ActionMode
Action to set the current mode (for error messages)
Definition: XMLHandler.h:342
@ LOAD
Loading a file.
Definition: XMLHandler.h:343
DoubleList attributeAsDoubleList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a DoubleList.
Definition: XMLHandler.h:624
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:856
Int attributeAsInt_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:774
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:494
Int attributeAsInt_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a Int.
Definition: XMLHandler.h:608
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:844
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:872
IntList attributeAsIntList_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to an IntList.
Definition: XMLHandler.h:631
StringManager sm_
Helper class for string conversion.
Definition: XMLHandler.h:436
void fatalError(const xercesc::SAXParseException &exception) override
static String writeXMLEscape(const String &to_escape)
Escapes a string and returns the escaped string.
Definition: XMLHandler.h:408
double attributeAsDouble_(const xercesc::Attributes &a, const char *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:616
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:706
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:722
String attributeAsString_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a String.
Definition: XMLHandler.h:766
void reset()
Release internal memory used for parsing (call.
const String & expectList_(const String &str) const
Definition: XMLHandler.h:921
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:574
double attributeAsDouble_(const xercesc::Attributes &a, const XMLCh *name) const
Converts an attribute to a double.
Definition: XMLHandler.h:782
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:658
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:754
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:674
double asDouble_(const String &in) const
Conversion of a String to a double value.
Definition: XMLHandler.h:520
void error(const xercesc::SAXParseException &exception) override
float asFloat_(const String &in) const
Conversion of a String to a float value.
Definition: XMLHandler.h:535
Definition: XMLHandler.h:72
std::shared_ptr< T > item_
Definition: XMLHandler.h:86
static void doRelease_(char *item)
shared_xerces_ptr(T *item)
Definition: XMLHandler.h:91
static void doRelease_(XMLCh *item)
bool is_released() const
Definition: XMLHandler.h:120
static void doRelease_(U *item)
Definition: XMLHandler.h:75
T * get()
Definition: XMLHandler.h:111
const T * get() const
Definition: XMLHandler.h:115
void assign(T *item)
Definition: XMLHandler.h:106
void reset()
Definition: XMLHandler.h:101
shared_xerces_ptr & operator=(T *item)
Definition: XMLHandler.h:95
Definition: XMLHandler.h:128
T * item_
Definition: XMLHandler.h:143
unique_xerces_ptr & operator=(const unique_xerces_ptr< T > &)=delete
void operator=(T *i)
Definition: XMLHandler.h:176
void xerces_release()
Definition: XMLHandler.h:182
unique_xerces_ptr(T *i)
Definition: XMLHandler.h:155
void swap(unique_xerces_ptr< T > &other) noexcept
Definition: XMLHandler.h:170
void assign(T *i)
Definition: XMLHandler.h:201
static void doRelease_(XMLCh *&item)
bool is_released() const
Definition: XMLHandler.h:214
T * get() const
Definition: XMLHandler.h:208
unique_xerces_ptr()
Definition: XMLHandler.h:151
unique_xerces_ptr(unique_xerces_ptr< T > &&other) noexcept
Definition: XMLHandler.h:164
unique_xerces_ptr(const unique_xerces_ptr< T > &)=delete
static void doRelease_(char *&item)
~unique_xerces_ptr()
Definition: XMLHandler.h:159
T * yield()
Definition: XMLHandler.h:193
static void doRelease_(U *&item)
Definition: XMLHandler.h:132
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
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
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