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