tiny_xml.hpp 1.9 KB

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