From 2fc01f7a270d76177e8653e2b74f8ca1b7711cc3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 17 Mar 2010 13:10:42 +0200 Subject: Partial support for simple type facet validation For now only certain types and facets are supported. --- xsde/cxx/serializer/serializer-inline.cxx | 91 +++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 6 deletions(-) (limited to 'xsde/cxx/serializer/serializer-inline.cxx') diff --git a/xsde/cxx/serializer/serializer-inline.cxx b/xsde/cxx/serializer/serializer-inline.cxx index b6bd696..3ff9bab 100644 --- a/xsde/cxx/serializer/serializer-inline.cxx +++ b/xsde/cxx/serializer/serializer-inline.cxx @@ -394,7 +394,36 @@ namespace CXX Boolean ha (has (c)); Boolean restriction (restriction_p (c)); - if (!(tiein || (!restriction && (he || ha)))) + Boolean facets (false); // Defines facets. + if (validation && restriction) + { + SemanticGraph::Type& ub (ultimate_base (c)); + + if (ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a () || + ub.is_a ()) + { + using SemanticGraph::Restricts; + Restricts& r (dynamic_cast (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)))) return; String const& name (ename (c)); @@ -458,7 +487,8 @@ namespace CXX else os << name << " ()" << endl; - os << ": "; + if (tiein || (!restriction && (he || ha))) + os << ": "; Boolean comma (false); @@ -507,8 +537,12 @@ namespace CXX } } - os << "{" - << "}"; + os << "{"; + + if (facets) + facet_calls (c); + + os << "}"; // Tiein c-tor. // @@ -558,8 +592,53 @@ namespace CXX } } - os << "{" - << "}"; + os << "{"; + + if (facets) + facet_calls (c); + + os << "}"; + } + } + + private: + Void + facet_calls (Type& c) + { + using SemanticGraph::Restricts; + Restricts& r (dynamic_cast (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);"; + } } } -- cgit v1.1