basic_xml_grammar.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP
  2. #define BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // basic_xml_grammar.hpp
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. // this module is derived from simplexml.cpp - an example shipped as part of
  15. // the spirit parser. This example contains the following notice:
  16. /*=============================================================================
  17. simplexml.cpp
  18. Spirit V1.3
  19. URL: http://spirit.sourceforge.net/
  20. Copyright (c) 2001, Daniel C. Nuffer
  21. This software is provided 'as-is', without any express or implied
  22. warranty. In no event will the copyright holder be held liable for
  23. any damages arising from the use of this software.
  24. Permission is granted to anyone to use this software for any purpose,
  25. including commercial applications, and to alter it and redistribute
  26. it freely, subject to the following restrictions:
  27. 1. The origin of this software must not be misrepresented; you must
  28. not claim that you wrote the original software. If you use this
  29. software in a product, an acknowledgment in the product documentation
  30. would be appreciated but is not required.
  31. 2. Altered source versions must be plainly marked as such, and must
  32. not be misrepresented as being the original software.
  33. 3. This notice may not be removed or altered from any source
  34. distribution.
  35. =============================================================================*/
  36. #include <string>
  37. #include <boost/config.hpp>
  38. #include <boost/detail/workaround.hpp>
  39. #include <boost/spirit/include/classic_rule.hpp>
  40. #include <boost/spirit/include/classic_chset.hpp>
  41. #include <boost/archive/basic_archive.hpp>
  42. #include <boost/serialization/tracking.hpp>
  43. #include <boost/serialization/version.hpp>
  44. namespace boost {
  45. namespace archive {
  46. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  47. // XML grammar parsing
  48. template<class CharType>
  49. class BOOST_SYMBOL_VISIBLE basic_xml_grammar {
  50. public:
  51. // The following is not necessary according to DR45, but at least
  52. // one compiler (Compaq C++ 6.5 in strict_ansi mode) chokes otherwise.
  53. struct return_values;
  54. friend struct return_values;
  55. private:
  56. typedef typename std::basic_istream<CharType> IStream;
  57. typedef typename std::basic_string<CharType> StringType;
  58. typedef typename boost::spirit::classic::chset<CharType> chset_t;
  59. typedef typename boost::spirit::classic::chlit<CharType> chlit_t;
  60. typedef typename boost::spirit::classic::scanner<
  61. typename std::basic_string<CharType>::iterator
  62. > scanner_t;
  63. typedef typename boost::spirit::classic::rule<scanner_t> rule_t;
  64. // Start grammar definition
  65. rule_t
  66. Reference,
  67. Eq,
  68. STag,
  69. ETag,
  70. LetterOrUnderscoreOrColon,
  71. AttValue,
  72. CharRef1,
  73. CharRef2,
  74. CharRef,
  75. AmpRef,
  76. LTRef,
  77. GTRef,
  78. AposRef,
  79. QuoteRef,
  80. CharData,
  81. CharDataChars,
  82. content,
  83. AmpName,
  84. LTName,
  85. GTName,
  86. ClassNameChar,
  87. ClassName,
  88. Name,
  89. XMLDecl,
  90. XMLDeclChars,
  91. DocTypeDecl,
  92. DocTypeDeclChars,
  93. ClassIDAttribute,
  94. ObjectIDAttribute,
  95. ClassNameAttribute,
  96. TrackingAttribute,
  97. VersionAttribute,
  98. UnusedAttribute,
  99. Attribute,
  100. SignatureAttribute,
  101. SerializationWrapper,
  102. NameHead,
  103. NameTail,
  104. AttributeList,
  105. S;
  106. // XML Character classes
  107. chset_t
  108. BaseChar,
  109. Ideographic,
  110. Char,
  111. Letter,
  112. Digit,
  113. CombiningChar,
  114. Extender,
  115. Sch,
  116. NameChar;
  117. void init_chset();
  118. bool my_parse(
  119. IStream & is,
  120. const rule_t &rule_,
  121. const CharType delimiter = L'>'
  122. ) const ;
  123. public:
  124. struct return_values {
  125. StringType object_name;
  126. StringType contents;
  127. //class_id_type class_id;
  128. int_least16_t class_id;
  129. //object_id_type object_id;
  130. uint_least32_t object_id;
  131. //version_type version;
  132. unsigned int version;
  133. tracking_type tracking_level;
  134. StringType class_name;
  135. return_values() :
  136. version(0),
  137. tracking_level(false)
  138. {}
  139. } rv;
  140. bool parse_start_tag(IStream & is) /*const*/;
  141. bool parse_end_tag(IStream & is) const;
  142. bool parse_string(IStream & is, StringType & s) /*const*/;
  143. void init(IStream & is);
  144. bool windup(IStream & is);
  145. basic_xml_grammar();
  146. };
  147. } // namespace archive
  148. } // namespace boost
  149. #endif // BOOST_ARCHIVE_BASIC_XML_GRAMMAR_HPP