herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
ElementIO.h
1 // -*- C++ -*-
2 //
3 // ElementIO.hpp is a part of myXML
4 // Copyright (C) 2012-2019 Simon Platzer, The Herwig Collaboration
5 //
6 // myXML is licenced under version 3 of the GPL, see COPYING for details.
7 //
8 
9 #ifndef MYXML_ElementIO_hpp_included
10 #define MYXML_ElementIO_hpp_included
11 
12 #include <iostream>
13 
14 #include "Element.h"
15 
16 namespace XML {
17 
22  class ElementIO {
23 
24  public:
25 
29  template<class OStream>
30  static void put(Element, OStream&);
31 
35  static Element get(std::istream&);
36 
40  static Element getAll(std::istream&);
41 
42  private:
43 
47  static void strip(std::string&, const std::string& skip = "\n\t ");
48 
52  static std::istream& getline(std::istream&, std::string&, const std::string&);
53 
57  static void skip(std::istream&, const std::string& skip_chars = "\n\t ");
58 
62  struct Tag {
63 
68 
69  Unknown = -1,
81  Comment = 6,
85  };
86 
90  int type;
91 
95  std::string content;
96 
100  std::map<std::string,std::string> attributes;
101 
105  Element produce() const;
106 
107  };
108 
112  static void getTag(Tag&, std::istream&);
113 
117  static Element produce(std::list<Tag>&);
118 
122  static void produce(std::list<Tag>&, Element&);
123 
127  static void unexpectedEOF(const std::string& what = "");
128 
132  static void parseError(const std::string& what = "");
133 
134  };
135 
136 }
137 
138 #include "ElementIO.tcc"
139 
140 #endif // MYXML_ElementIO_hpp_included
A processing instruction tag.
Definition: ElementIO.h:77
EnumerateTagTypes
The tag type enumeration.
Definition: ElementIO.h:67
std::map< std::string, std::string > attributes
A lis of attributes, if present.
Definition: ElementIO.h:100
static void put(Element, OStream &)
Write a tree to an ostream.
static void unexpectedEOF(const std::string &what="")
Throw an unexpected end of file exception.
int type
The type of the tag.
Definition: ElementIO.h:90
static Element getAll(std::istream &)
Parse the entire stream.
std::string content
The content or name of the tag.
Definition: ElementIO.h:95
An empty element tag.
Definition: ElementIO.h:73
ElementIO handles in/output of XML elements.
Definition: ElementIO.h:22
Definition: Element.h:18
static std::istream & getline(std::istream &, std::string &, const std::string &)
Read from istream until occurence of the given pattern.
static void getTag(Tag &, std::istream &)
Get a single tag or parsed content from an istream.
static void skip(std::istream &, const std::string &skip_chars="\ ")
Skip charecters encountered on the given istream.
Element produce() const
Produce an element.
Element represents a (tree of) XML elements.
Definition: Element.h:56
static void strip(std::string &, const std::string &skip="\ ")
Strip whitespaces from a string.
Helper struct representing a single tag or parsed content.
Definition: ElementIO.h:62
Parsed character data.
Definition: ElementIO.h:81
static void parseError(const std::string &what="")
Throw a parse error exception.