Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:28

0001 // -*- C++ -*-
0002 //
0003 // ElementIO.hpp is a part of myXML
0004 // Copyright (C) 2012-2019 Simon Platzer, The Herwig Collaboration
0005 //
0006 // myXML is licenced under version 3 of the GPL, see COPYING for details.
0007 //
0008 
0009 #ifndef MYXML_ElementIO_hpp_included
0010 #define MYXML_ElementIO_hpp_included
0011 
0012 #include <iostream>
0013 
0014 #include "Element.h"
0015 
0016 namespace XML {
0017 
0018   /**
0019    * \brief ElementIO handles in/output of XML elements
0020    * \author Simon Platzer
0021    */
0022   class ElementIO {
0023 
0024   public:
0025 
0026     /**
0027      * Write a tree to an ostream
0028      */
0029     template<class OStream>
0030     static void put(Element, OStream&);
0031 
0032     /**
0033      * Get the next element from a stream
0034      */
0035     static Element get(std::istream&);
0036 
0037     /**
0038      * Parse the entire stream
0039      */
0040     static Element getAll(std::istream&);
0041 
0042   private:
0043 
0044     /**
0045      * Strip whitespaces from a string
0046      */
0047     static void strip(std::string&, const std::string& skip = "\n\t ");
0048 
0049     /**
0050      * Read from istream until occurence of the given pattern
0051      */
0052     static std::istream& getline(std::istream&, std::string&, const std::string&);
0053 
0054     /**
0055      * Skip charecters encountered on the given istream
0056      */
0057     static void skip(std::istream&, const std::string& skip_chars = "\n\t ");
0058 
0059     /**
0060      * Helper struct representing a single tag or parsed content
0061      */
0062     struct Tag {
0063 
0064       /**
0065        * The tag type enumeration
0066        */
0067       enum EnumerateTagTypes {
0068 
0069     Unknown = -1,
0070     /** Tag type unknown */
0071     EmptyElement = 1,
0072     /** An empty element tag */
0073     ElementBegin = 2,
0074     /** An element begin tag */
0075     ProcessingInstruction = 3,
0076     /** A processing instruction tag */
0077     CharacterData = 4,
0078     /** Character data tag */
0079     ParsedCharacterData = 5,
0080     /** Parsed character data */
0081     Comment = 6,
0082     /** A comment tag */
0083     ElementEnd = 20
0084     /** An element end tag */
0085       };
0086 
0087       /**
0088        * The type of the tag
0089        */
0090       int type;
0091 
0092       /**
0093        * The content or name of the tag
0094        */
0095       std::string content;
0096 
0097       /**
0098        * A lis of attributes, if present
0099        */
0100       std::map<std::string,std::string> attributes;
0101 
0102       /**
0103        * Produce an element
0104        */
0105       Element produce() const;
0106 
0107     };
0108 
0109     /**
0110      * Get a single tag or parsed content from an istream 
0111      */
0112     static void getTag(Tag&, std::istream&);
0113 
0114     /**
0115      * Produce element tree from parsed stack of tags
0116      */
0117     static Element produce(std::list<Tag>&);
0118 
0119     /**
0120      * Produce element tree from parsed stack of tags
0121      */
0122     static void produce(std::list<Tag>&, Element&);
0123 
0124     /**
0125      * Throw an unexpected end of file exception
0126      */
0127     static void unexpectedEOF(const std::string& what = "");
0128 
0129     /**
0130      * Throw a parse error exception
0131      */
0132     static void parseError(const std::string& what = "");
0133 
0134   };
0135 
0136 }
0137 
0138 #include "ElementIO.tcc"
0139 
0140 #endif // MYXML_ElementIO_hpp_included