From 41569646f9b5e70e53769e24d5e8efe45c2d24b4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 9 May 2014 16:24:44 -0700 Subject: Move content model enum out of parser and into xml namespace --- tests/parser/driver.cxx | 26 +++++++++++++------------- xml/content.hxx | 35 +++++++++++++++++++++++++++++++++++ xml/parser.cxx | 18 +++++++++--------- xml/parser.hxx | 14 ++++---------- xml/parser.ixx | 2 +- 5 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 xml/content.hxx diff --git a/tests/parser/driver.cxx b/tests/parser/driver.cxx index 84ab2fa..2afe522 100644 --- a/tests/parser/driver.cxx +++ b/tests/parser/driver.cxx @@ -91,7 +91,7 @@ main () istringstream is (" "); parser p (is, "empty"); - p.next_expect (parser::start_element, "root", parser::empty); + p.next_expect (parser::start_element, "root", content::empty); p.next_expect (parser::end_element); p.next_expect (parser::eof); } @@ -247,7 +247,7 @@ main () parser::receive_default | parser::receive_attributes_event); assert (p.next () == parser::start_element); - p.content (parser::empty); + p.content (content::empty); assert (p.next () == parser::start_attribute); assert (p.next () == parser::characters && p.value () == " x "); assert (p.next () == parser::end_attribute); @@ -261,7 +261,7 @@ main () parser p (is, "empty"); assert (p.next () == parser::start_element); - p.content (parser::empty); + p.content (content::empty); p.next (); assert (false); } @@ -277,7 +277,7 @@ main () parser p (is, "simple"); assert (p.next () == parser::start_element); - p.content (parser::simple); + p.content (content::simple); assert (p.next () == parser::characters && p.value () == " X "); assert (p.next () == parser::end_element); assert (p.next () == parser::eof); @@ -289,7 +289,7 @@ main () parser p (is, "simple"); assert (p.next () == parser::start_element); - p.content (parser::simple); + p.content (content::simple); assert (p.next () == parser::characters && p.value () == " ? "); p.next (); assert (false); @@ -310,7 +310,7 @@ main () assert (p.next () == parser::start_element); p.next_expect (parser::start_namespace_decl); - p.content (parser::simple); + p.content (content::simple); assert (p.next () == parser::characters && p.value () == "123"); p.next_expect (parser::end_namespace_decl); assert (p.next () == parser::end_element); @@ -329,7 +329,7 @@ main () assert (p.next () == parser::start_element); p.next_expect (parser::start_namespace_decl); - p.content (parser::simple); + p.content (content::simple); p.next (); assert (false); } @@ -351,21 +351,21 @@ main () parser::receive_default | parser::receive_attributes_event); assert (p.next () == parser::start_element); // root - p.content (parser::complex); + p.content (content::complex); assert (p.next () == parser::start_attribute); assert (p.next () == parser::characters && p.value () == " x "); assert (p.next () == parser::end_attribute); assert (p.next () == parser::start_element); // nested - p.content (parser::complex); + p.content (content::complex); assert (p.next () == parser::start_element); // inner - p.content (parser::empty); + p.content (content::empty); assert (p.next () == parser::end_element); // inner assert (p.next () == parser::start_element); // inner - p.content (parser::simple); + p.content (content::simple); assert (p.next () == parser::characters && p.value () == " X "); assert (p.next () == parser::end_element); // inner @@ -380,7 +380,7 @@ main () parser p (is, "complex"); assert (p.next () == parser::start_element); - p.content (parser::complex); + p.content (content::complex); assert (p.next () == parser::start_element); assert (p.next () == parser::end_element); p.next (); @@ -413,7 +413,7 @@ main () ""); parser p (is, "element"); - p.next_expect (parser::start_element, "root", parser::complex); + p.next_expect (parser::start_element, "root", content::complex); p.next_expect (parser::start_element, "nested"); assert (p.element () == "X"); diff --git a/xml/content.hxx b/xml/content.hxx new file mode 100644 index 0000000..575ef1d --- /dev/null +++ b/xml/content.hxx @@ -0,0 +1,35 @@ +// file : xml/content.hxx +// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef XML_CONTENT_HXX +#define XML_CONTENT_HXX + +#include + +namespace xml +{ + // XML content model. C++11 enum class emulated for C++98. + // + struct content + { + enum value + { + // element characters whitespaces notes + empty, // no no ignored + simple, // no yes preserved content accumulated + complex, // yes no ignored + mixed // yes yes preserved + }; + + content (value v): v_ (v) {}; + operator value () const {return v_;} + + private: + value v_; + }; +} + +#include + +#endif // XML_CONTENT_HXX diff --git a/xml/parser.cxx b/xml/parser.cxx index ef5683f..28a17ce 100644 --- a/xml/parser.cxx +++ b/xml/parser.cxx @@ -147,11 +147,11 @@ namespace xml // switch (content ()) { - case empty: + case content_type::empty: throw parsing (*this, "character in empty content"); - case simple: + case content_type::simple: throw parsing (*this, "element in simple content"); - case complex: + case content_type::complex: throw parsing (*this, "character in complex content"); default: assert (false); @@ -321,7 +321,7 @@ namespace xml string parser:: element () { - content (simple); + content (content_type::simple); string r; // The content of the element can be empty in which case there @@ -435,9 +435,9 @@ namespace xml { switch (e->content) { - case empty: + case content_type::empty: throw parsing (*this, "element in empty content"); - case simple: + case content_type::simple: throw parsing (*this, "element in simple content"); default: break; @@ -865,8 +865,8 @@ namespace xml // switch (cont) { - case empty: - case complex: + case content_type::empty: + case content_type::complex: { for (int i (0); i != n; ++i) { @@ -909,7 +909,7 @@ namespace xml // into a single event. To do this we will let the parser run // until we reach the end of the element. // - if (cont == simple) + if (cont == content_type::simple) p.accumulate_ = true; else XML_StopParser (p.p_, true); diff --git a/xml/parser.hxx b/xml/parser.hxx index cd33588..1d45e8c 100644 --- a/xml/parser.hxx +++ b/xml/parser.hxx @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -80,6 +81,8 @@ namespace xml { public: typedef xml::qname qname_type; + typedef xml::content content_type; + typedef unsigned short feature_type; // If both receive_attributes_event and receive_attributes_map are @@ -246,15 +249,6 @@ namespace xml // Optional content processing. // public: - enum content_type - { - // element characters whitespaces notes - empty, // no no ignored - simple, // no yes preserved content accumulated - complex, // yes no ignored - mixed // yes yes preserved - }; - // Note that you cannot get/set content while peeking. // void @@ -434,7 +428,7 @@ namespace xml // struct element_entry { - element_entry (std::size_t d, content_type c = mixed) + element_entry (std::size_t d, content_type c = content_type::mixed) : depth (d), content (c), attr_unhandled_ (0) {} std::size_t depth; diff --git a/xml/parser.ixx b/xml/parser.ixx index 49d9c89..e5656d4 100644 --- a/xml/parser.ixx +++ b/xml/parser.ixx @@ -205,7 +205,7 @@ namespace xml return !element_state_.empty () && element_state_.back ().depth == depth_ ? element_state_.back ().content - : mixed; + : content_type (content_type::mixed); } inline const parser::element_entry* parser:: -- cgit v1.1