herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
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
16namespace 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,
83 ElementEnd = 20
85 };
86
90 int type;
91
95 std::string content;
96
100 std::map<std::string,std::string> attributes;
101
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
ElementIO handles in/output of XML elements.
Definition: ElementIO.h:22
static void produce(std::list< Tag > &, Element &)
Produce element tree from parsed stack of tags.
static void getTag(Tag &, std::istream &)
Get a single tag or parsed content from an istream.
static Element getAll(std::istream &)
Parse the entire stream.
static void unexpectedEOF(const std::string &what="")
Throw an unexpected end of file exception.
static void put(Element, OStream &)
Write a tree to an ostream.
static void strip(std::string &, const std::string &skip="\n\t ")
Strip whitespaces from a string.
static std::istream & getline(std::istream &, std::string &, const std::string &)
Read from istream until occurence of the given pattern.
static void parseError(const std::string &what="")
Throw a parse error exception.
static void skip(std::istream &, const std::string &skip_chars="\n\t ")
Skip charecters encountered on the given istream.
static Element get(std::istream &)
Get the next element from a stream.
static Element produce(std::list< Tag > &)
Produce element tree from parsed stack of tags.
Element represents a (tree of) XML elements.
Definition: Element.h:56
Helper struct representing a single tag or parsed content.
Definition: ElementIO.h:62
std::string content
The content or name of the tag.
Definition: ElementIO.h:95
EnumerateTagTypes
The tag type enumeration.
Definition: ElementIO.h:67
@ CharacterData
A processing instruction tag.
Definition: ElementIO.h:77
@ ElementEnd
A comment tag.
Definition: ElementIO.h:83
@ ParsedCharacterData
Character data tag.
Definition: ElementIO.h:79
@ ElementBegin
An empty element tag.
Definition: ElementIO.h:73
@ Comment
Parsed character data.
Definition: ElementIO.h:81
@ EmptyElement
Tag type unknown.
Definition: ElementIO.h:71
@ ProcessingInstruction
An element begin tag.
Definition: ElementIO.h:75
Element produce() const
Produce an element.
int type
The type of the tag.
Definition: ElementIO.h:90
std::map< std::string, std::string > attributes
A lis of attributes, if present.
Definition: ElementIO.h:100