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 --- xml/content.hxx | 35 +++++++++++++++++++++++++++++++++++ xml/parser.cxx | 18 +++++++++--------- xml/parser.hxx | 14 ++++---------- xml/parser.ixx | 2 +- 4 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 xml/content.hxx (limited to 'xml') 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