diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-08 15:35:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-08 15:35:23 +0200 |
commit | 7db026e8056914d113ac0bbfd9bdc4908a9e7874 (patch) | |
tree | 0ab15cb8b0ee160a10cca21edaf0aca1e97e8921 /xsde/cxx | |
parent | 4f38adc11ab1a3a1ab2dd3f958c917182be7d71f (diff) |
Add support for the whiteSpace facet
Use the same mechanism to handle whitespace processing for build-in types
and enumerations.
Diffstat (limited to 'xsde/cxx')
-rw-r--r-- | xsde/cxx/hybrid/parser-header.cxx | 10 | ||||
-rw-r--r-- | xsde/cxx/hybrid/parser-source.cxx | 78 | ||||
-rw-r--r-- | xsde/cxx/parser/elements.cxx | 43 | ||||
-rw-r--r-- | xsde/cxx/parser/elements.hxx | 5 | ||||
-rw-r--r-- | xsde/cxx/parser/parser-header.cxx | 38 | ||||
-rw-r--r-- | xsde/cxx/parser/parser-inline.cxx | 162 | ||||
-rw-r--r-- | xsde/cxx/serializer/serializer-header.cxx | 3 | ||||
-rw-r--r-- | xsde/cxx/serializer/serializer-inline.cxx | 3 |
8 files changed, 195 insertions, 147 deletions
diff --git a/xsde/cxx/hybrid/parser-header.cxx b/xsde/cxx/hybrid/parser-header.cxx index d67cdca..e64ac63 100644 --- a/xsde/cxx/hybrid/parser-header.cxx +++ b/xsde/cxx/hybrid/parser-header.cxx @@ -135,13 +135,9 @@ namespace CXX // _post // - if (!options.value<CLI::suppress_validation> () && - !options.value<CLI::suppress_parser_val> ()) - { - os << "virtual void" << endl - << "_post ();" - << endl; - } + os << "virtual void" << endl + << "_post ();" + << endl; } diff --git a/xsde/cxx/hybrid/parser-source.cxx b/xsde/cxx/hybrid/parser-source.cxx index 94f05df..64d12d6 100644 --- a/xsde/cxx/hybrid/parser-source.cxx +++ b/xsde/cxx/hybrid/parser-source.cxx @@ -335,13 +335,39 @@ namespace CXX // os << "void " << name << "::" << endl << "_characters (const " << string_type << "& s)" + << "{" + << "if (this->_facets ().whitespace_ == 2 &&" << endl + << "this->" << state << ".str_.size () == 0)" + << "{" + << string_type << " tmp (s.data (), s.size ());" + << endl + << "if (::xsde::cxx::trim_left (tmp) != 0)" << "{"; if (stl) - os << "this->" << state << ".str_.append (s.data (), s.size ());"; + os << "this->" << state << ".str_ += tmp;" + << "}" + << "}" + << "else" << endl + << "this->" << state << ".str_ += s;"; else { if (exceptions) + os << "this->" << state << ".str_.append (tmp.data (), " << + "tmp.size ());"; + else + { + os << "if (this->" << state << ".str_.append (" << + "tmp.data (), tmp.size ()))" << endl + << "this->_sys_error (::xsde::cxx::sys_error::no_memory);"; + } + + os << "}" + << "}" + << "else" + << "{"; + + if (exceptions) os << "this->" << state << ".str_.append (s.data (), s.size ());"; else { @@ -349,34 +375,37 @@ namespace CXX "s.data (), s.size ()))" << endl << "this->_sys_error (::xsde::cxx::sys_error::no_memory);"; } + + os << "}"; } os << "}"; // _post // + os << "void " << name << "::" << endl + << "_post ()" + << "{"; + if (!options.value<CLI::suppress_validation> () && !options.value<CLI::suppress_parser_val> ()) { - // Do facet validation. - // - os << "void " << name << "::" << endl - << "_post ()" - << "{" - << "::xsde::cxx::parser::validating::string_common::" << - "validate_facets (" << endl; - - if (stl) - os << "this->" << state << ".str_.c_str ()," << endl - << "this->" << state << ".str_.size ()," << endl; - else - os << "this->" << state << ".str_.data ()," << endl - << "this->" << state << ".str_.size ()," << endl; + os << "::xsde::cxx::parser::validating::string_common::" << + "validate_facets (" << endl + << "this->" << state << ".str_," << endl + << "this->_facets ()," << endl + << "this->_context ());"; + } + else + { - os << "this->_facets ()," << endl - << "this->_context ());" - << "}"; + os << "::xsde::cxx::parser::non_validating::string_common::" << + "process_facets (" << endl + << "this->" << state << ".str_," << endl + << "this->_facets ());"; } + + os << "}"; } // post @@ -2073,14 +2102,17 @@ namespace CXX Void generate_parser_source (Context& ctx) { - if (ctx.enum_ && - !ctx.options.value<CLI::suppress_validation> () && - !ctx.options.value<CLI::suppress_parser_val> ()) + if (ctx.enum_) { // We need this functionality for enum mapping. // - ctx.os << "#include <xsde/cxx/parser/validating/string-common.hxx>" << endl - << endl; + if (!ctx.options.value<CLI::suppress_validation> () && + !ctx.options.value<CLI::suppress_parser_val> ()) + ctx.os << "#include <xsde/cxx/parser/validating/string-common.hxx>" << endl + << endl; + else + ctx.os << "#include <xsde/cxx/parser/non-validating/string-common.hxx>" << endl + << endl; } { diff --git a/xsde/cxx/parser/elements.cxx b/xsde/cxx/parser/elements.cxx index 7cf1fec..2c138ce 100644 --- a/xsde/cxx/parser/elements.cxx +++ b/xsde/cxx/parser/elements.cxx @@ -193,6 +193,49 @@ namespace CXX return t.context ().get<String> ("p:impl"); } + Boolean Context:: + has_facets (SemanticGraph::Complex& c) + { + if (restriction_p (c)) + { + using SemanticGraph::Restricts; + Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); + + if (r.facet_empty ()) + return false; + + SemanticGraph::Type& ub (ultimate_base (c)); + Restricts::FacetIterator end (r.facet_end ()); + + if ((ub.is_a<SemanticGraph::Fundamental::String> () || + ub.is_a<SemanticGraph::Fundamental::AnyURI> ()) && + r.facet_find (L"whiteSpace") != end) + return true; + + if (validation) + { + if (ub.is_a<SemanticGraph::Fundamental::Short> () || + ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () || + ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () || + ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () || + ub.is_a<SemanticGraph::Fundamental::String> () || + ub.is_a<SemanticGraph::Fundamental::AnyURI> ()) + { + if (r.facet_find (L"length") != end || + r.facet_find (L"minLength") != end || + r.facet_find (L"maxLength") != end || + r.facet_find (L"minInclusive") != end || + r.facet_find (L"minExclusive") != end || + r.facet_find (L"maxInclusive") != end || + r.facet_find (L"maxExclusive") != end) + return true; + } + } + } + + return false; + } + // Includes // Void TypeForward:: diff --git a/xsde/cxx/parser/elements.hxx b/xsde/cxx/parser/elements.hxx index 4af395f..497577f 100644 --- a/xsde/cxx/parser/elements.hxx +++ b/xsde/cxx/parser/elements.hxx @@ -163,6 +163,11 @@ namespace CXX static String const& eimpl (SemanticGraph::Type&); + + public: + Boolean + has_facets (SemanticGraph::Complex& c); + public: CLI::Options const& options; String& xml_parser; diff --git a/xsde/cxx/parser/parser-header.cxx b/xsde/cxx/parser/parser-header.cxx index f03d588..11176f9 100644 --- a/xsde/cxx/parser/parser-header.cxx +++ b/xsde/cxx/parser/parser-header.cxx @@ -28,13 +28,15 @@ namespace CXX SemanticGraph::Type& base (e.inherits ().base ()); String fq_base (fq_name (base)); - Boolean facets (false); // Whether we need to set facets. + Boolean enum_facets (false); // Whether we need to set enum facets. if (validation) { - StringBasedType t (facets); + StringBasedType t (enum_facets); t.dispatch (e); } + Boolean facets (enum_facets || has_facets (e)); + os << "class " << name << ": public " << (mixin ? "virtual " : "") << fq_base << "{" @@ -101,7 +103,7 @@ namespace CXX << name << " (" << name << "*, void*);"; } - if (facets) + if (enum_facets) { UnsignedLong enum_count (0); @@ -737,6 +739,7 @@ namespace CXX // Boolean hb (c.inherits_p ()); Boolean restriction (restriction_p (c)); + Boolean facets (has_facets (c)); Boolean he (has<Traversal::Element> (c)); Boolean ha (has<Traversal::Attribute> (c)); @@ -752,35 +755,6 @@ namespace CXX names (c, names_test); } - Boolean facets (false); // Defines facets. - if (validation && restriction) - { - SemanticGraph::Type& ub (ultimate_base (c)); - - if (ub.is_a<SemanticGraph::Fundamental::Short> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () || - ub.is_a<SemanticGraph::Fundamental::String> ()) - { - using SemanticGraph::Restricts; - Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); - - if (!r.facet_empty ()) - { - Restricts::FacetIterator end (r.facet_end ()); - facets = - r.facet_find (L"length") != end || - r.facet_find (L"minLength") != end || - r.facet_find (L"maxLength") != end || - r.facet_find (L"minInclusive") != end || - r.facet_find (L"minExclusive") != end || - r.facet_find (L"maxInclusive") != end || - r.facet_find (L"maxExclusive") != end; - } - } - } - // // os << "class " << name << ": public "; diff --git a/xsde/cxx/parser/parser-inline.cxx b/xsde/cxx/parser/parser-inline.cxx index 528ff86..984eca6 100644 --- a/xsde/cxx/parser/parser-inline.cxx +++ b/xsde/cxx/parser/parser-inline.cxx @@ -14,6 +14,61 @@ namespace CXX { namespace { + Void + facet_calls (SemanticGraph::Complex& c, Context& ctx) + { + std::wostream& os (ctx.os); + + using SemanticGraph::Restricts; + Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); + + for (Restricts::FacetIterator i (r.facet_begin ()); + i != r.facet_end (); ++i) + { + if (i->first == L"length") + { + os << "this->_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"minLength") + { + os << "this->_min_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"maxLength") + { + os << "this->_max_length_facet (" << i->second << "UL);"; + } + else if (i->first == L"minInclusive") + { + os << "this->_min_facet (" << i->second << ", true);"; + } + else if (i->first == L"minExclusive") + { + os << "this->_min_facet (" << i->second << ", false);"; + } + else if (i->first == L"maxInclusive") + { + os << "this->_max_facet (" << i->second << ", true);"; + } + else if (i->first == L"maxExclusive") + { + os << "this->_max_facet (" << i->second << ", false);"; + } + else if (i->first == L"whiteSpace") + { + os << "this->_whitespace_facet ("; + + if (i->second == L"preserve") + os << "0"; + else if (i->second == L"replace") + os << "1"; + else if (i->second == L"collapse") + os << "2"; + + os << ");"; + } + } + } + struct Enumeration: Traversal::Enumeration, Context { Enumeration (Context& c) @@ -26,21 +81,23 @@ namespace CXX { String const& name (ename (e)); - Boolean facets (false); // Whether we need to set facets. + Boolean enum_facets (false); // Whether we need to set enum facets. if (validation) { - StringBasedType t (facets); + StringBasedType t (enum_facets); t.dispatch (e); } UnsignedLong enum_count (0); - if (facets) + if (enum_facets) { for (Type::NamesIterator i (e.names_begin ()), end (e.names_end ()); i != end; ++i) ++enum_count; } + Boolean facets (enum_facets || has_facets (e)); + if (facets || tiein) os << "// " << name << endl << "//" << endl @@ -51,10 +108,9 @@ namespace CXX os << inl << name << "::" << endl << name << " ()" << endl - << "{" - << "this->_enumeration_facet (_xsde_" << name << "_enums_, " << - enum_count << "UL);" - << "}"; + << "{"; + facet_calls (e, enum_count); + os << "}"; } if (tiein) @@ -76,8 +132,7 @@ namespace CXX << "{"; if (facets) - os << "this->_enumeration_facet (_xsde_" << name << - "_enums_, " << enum_count << "UL);"; + facet_calls (e, enum_count); os << "}"; @@ -89,12 +144,22 @@ namespace CXX << "{"; if (facets) - os << "this->_enumeration_facet (_xsde_" << name << - "_enums_, " << enum_count << "UL);"; + facet_calls (e, enum_count); os << "}"; } } + + private: + Void + facet_calls (Type& e, UnsignedLong enum_count) + { + Parser::facet_calls (e, *this); + + if (enum_count != 0) + os << "this->_enumeration_facet (_xsde_" << ename (e) << + "_enums_, " << enum_count << "UL);"; + } }; // @@ -454,6 +519,7 @@ namespace CXX traverse (Type& c) { Boolean hb (c.inherits_p ()); + Boolean facets (has_facets (c)); Boolean he (has<Traversal::Element> (c)); Boolean ha (has<Traversal::Attribute> (c)); @@ -469,35 +535,6 @@ namespace CXX Boolean restriction (restriction_p (c)); - Boolean facets (false); // Defines facets. - if (validation && restriction) - { - SemanticGraph::Type& ub (ultimate_base (c)); - - if (ub.is_a<SemanticGraph::Fundamental::Short> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () || - ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () || - ub.is_a<SemanticGraph::Fundamental::String> ()) - { - using SemanticGraph::Restricts; - Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); - - if (!r.facet_empty ()) - { - Restricts::FacetIterator end (r.facet_end ()); - facets = - r.facet_find (L"length") != end || - r.facet_find (L"minLength") != end || - r.facet_find (L"maxLength") != end || - r.facet_find (L"minInclusive") != end || - r.facet_find (L"minExclusive") != end || - r.facet_find (L"maxInclusive") != end || - r.facet_find (L"maxExclusive") != end; - } - } - } - if (!(tiein || facets || (!restriction && (he || ha)) || (validation && (he || hae || hra)))) @@ -643,7 +680,7 @@ namespace CXX os << "{"; if (facets) - facet_calls (c); + facet_calls (c, *this); os << "}"; @@ -721,54 +758,13 @@ namespace CXX os << "{"; if (facets) - facet_calls (c); + facet_calls (c, *this); os << "}"; } } private: - Void - facet_calls (Type& c) - { - using SemanticGraph::Restricts; - Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); - - for (Restricts::FacetIterator i (r.facet_begin ()); - i != r.facet_end (); ++i) - { - if (i->first == L"length") - { - os << "this->_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minLength") - { - os << "this->_min_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"maxLength") - { - os << "this->_max_length_facet (" << i->second << "UL);"; - } - else if (i->first == L"minInclusive") - { - os << "this->_min_facet (" << i->second << ", true);"; - } - else if (i->first == L"minExclusive") - { - os << "this->_min_facet (" << i->second << ", false);"; - } - else if (i->first == L"maxInclusive") - { - os << "this->_max_facet (" << i->second << ", true);"; - } - else if (i->first == L"maxExclusive") - { - os << "this->_max_facet (" << i->second << ", false);"; - } - } - } - - private: // // Traversal::Compositor compositor_accessor_; diff --git a/xsde/cxx/serializer/serializer-header.cxx b/xsde/cxx/serializer/serializer-header.cxx index 3a10942..550d742 100644 --- a/xsde/cxx/serializer/serializer-header.cxx +++ b/xsde/cxx/serializer/serializer-header.cxx @@ -1066,7 +1066,8 @@ namespace CXX ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () || ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () || ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () || - ub.is_a<SemanticGraph::Fundamental::String> ()) + ub.is_a<SemanticGraph::Fundamental::String> () || + ub.is_a<SemanticGraph::Fundamental::AnyURI> ()) { using SemanticGraph::Restricts; Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); diff --git a/xsde/cxx/serializer/serializer-inline.cxx b/xsde/cxx/serializer/serializer-inline.cxx index e14680e..fe36e4a 100644 --- a/xsde/cxx/serializer/serializer-inline.cxx +++ b/xsde/cxx/serializer/serializer-inline.cxx @@ -441,7 +441,8 @@ namespace CXX ub.is_a<SemanticGraph::Fundamental::UnsignedByte> () || ub.is_a<SemanticGraph::Fundamental::UnsignedShort> () || ub.is_a<SemanticGraph::Fundamental::UnsignedInt> () || - ub.is_a<SemanticGraph::Fundamental::String> ()) + ub.is_a<SemanticGraph::Fundamental::String> () || + ub.is_a<SemanticGraph::Fundamental::AnyURI> ()) { using SemanticGraph::Restricts; Restricts& r (dynamic_cast<Restricts&> (c.inherits ())); |