tiny_xml.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // tiny XML sub-set tools --------------------------------------------------//
  2. // (C) Copyright Beman Dawes 2002. Permission to copy,
  3. // use, modify, sell and distribute this software is granted provided this
  4. // copyright notice appears in all copies. This software is provided "as is"
  5. // without express or implied warranty, and with no claim as to its
  6. // suitability for any purpose.
  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. #ifndef BOOST_TINY_XML_H
  14. #define BOOST_TINY_XML_H
  15. #include "boost/smart_ptr.hpp" // for shared_ptr
  16. #include "boost/utility.hpp" // for noncopyable
  17. #include <list>
  18. #include <iostream>
  19. #include <string>
  20. namespace boost
  21. {
  22. namespace tiny_xml
  23. {
  24. class element;
  25. struct attribute
  26. {
  27. std::string name;
  28. std::string value;
  29. attribute(){}
  30. attribute( const std::string & name, const std::string & value )
  31. : name(name), value(value) {}
  32. };
  33. typedef boost::shared_ptr< element > element_ptr;
  34. typedef std::list< element_ptr > element_list;
  35. typedef std::list< attribute > attribute_list;
  36. struct element
  37. : boost::noncopyable // because of shared_ptr use
  38. {
  39. std::string name;
  40. attribute_list attributes;
  41. element_list elements;
  42. std::string content;
  43. element() {}
  44. explicit element( const std::string & name ) : name(name) {}
  45. };
  46. element_ptr parse( std::istream & in );
  47. // Precondition: stream positioned at either the initial "<"
  48. // or the first character after the initial "<".
  49. // Postcondition: stream positioned at the first character after final
  50. // ">" (or eof).
  51. // Returns: an element_ptr to an element representing the parsed stream.
  52. // Throws: std::string on syntax error.
  53. void write( const element & e, std::ostream & out );
  54. }
  55. }
  56. #endif // BOOST_TINY_XML_H
粤ICP备19079148号