1 | // tiny XML sub-set tools --------------------------------------------------// |
---|
2 | |
---|
3 | // (C) Copyright Beman Dawes 2002. Distributed under the Boost |
---|
4 | // Software License, Version 1.0. (See accompanying file |
---|
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | // Provides self-contained tools for this XML sub-set: |
---|
8 | // |
---|
9 | // element ::= { "<" name { name "=" "\"" value "\"" } ">" |
---|
10 | // {element} [contents] "</" name ">" } |
---|
11 | // |
---|
12 | // The point of "self-contained" is to minimize tool-chain dependencies. |
---|
13 | |
---|
14 | #ifndef BOOST_TINY_XML_H |
---|
15 | #define BOOST_TINY_XML_H |
---|
16 | |
---|
17 | #include "boost/smart_ptr.hpp" // for shared_ptr |
---|
18 | #include "boost/utility.hpp" // for noncopyable |
---|
19 | #include <list> |
---|
20 | #include <iostream> |
---|
21 | #include <string> |
---|
22 | |
---|
23 | namespace boost |
---|
24 | { |
---|
25 | namespace tiny_xml |
---|
26 | { |
---|
27 | class element; |
---|
28 | struct attribute |
---|
29 | { |
---|
30 | std::string name; |
---|
31 | std::string value; |
---|
32 | |
---|
33 | attribute(){} |
---|
34 | attribute( const std::string & name, const std::string & value ) |
---|
35 | : name(name), value(value) {} |
---|
36 | }; |
---|
37 | typedef boost::shared_ptr< element > element_ptr; |
---|
38 | typedef std::list< element_ptr > element_list; |
---|
39 | typedef std::list< attribute > attribute_list; |
---|
40 | |
---|
41 | class element |
---|
42 | : private boost::noncopyable // because deep copy sematics would be required |
---|
43 | { |
---|
44 | public: |
---|
45 | std::string name; |
---|
46 | attribute_list attributes; |
---|
47 | element_list elements; |
---|
48 | std::string content; |
---|
49 | |
---|
50 | element() {} |
---|
51 | explicit element( const std::string & name ) : name(name) {} |
---|
52 | }; |
---|
53 | |
---|
54 | element_ptr parse( std::istream & in, const std::string & msg ); |
---|
55 | // Precondition: stream positioned at either the initial "<" |
---|
56 | // or the first character after the initial "<". |
---|
57 | // Postcondition: stream positioned at the first character after final |
---|
58 | // ">" (or eof). |
---|
59 | // Returns: an element_ptr to an element representing the parsed stream. |
---|
60 | // Throws: std::string on syntax error. msg appended to what() string. |
---|
61 | |
---|
62 | void write( const element & e, std::ostream & out ); |
---|
63 | |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | #endif // BOOST_TINY_XML_H |
---|
68 | |
---|
69 | |
---|
70 | |
---|