From 21c6360236813e9a6993b1cdcf844e14f110ed67 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 18 Sep 2016 23:31:16 +0200 Subject: Save order information in binary formats for ordered types Note that while we ignore wildcards and mixed content, their order information is still saved. --- xsd/cxx/tree/stream-extraction-source.cxx | 35 +++++++++++++++++++++++++++++-- xsd/cxx/tree/stream-insertion-source.cxx | 30 +++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) (limited to 'xsd') diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx index 7c1382e..a0bdcfc 100644 --- a/xsd/cxx/tree/stream-extraction-source.cxx +++ b/xsd/cxx/tree/stream-extraction-source.cxx @@ -575,6 +575,8 @@ namespace CXX virtual void traverse (Type& c) { + SemanticGraph::Context& ctx (c.context ()); + String name (ename (c)); // If renamed name is empty then we do not need to generate @@ -583,6 +585,7 @@ namespace CXX if (renamed_type (c, name) && !name) return; + bool ordered (ordered_p (c) && !ctx.count ("order-in-base")); bool has_members (has (c)); bool facets (false); @@ -608,7 +611,6 @@ namespace CXX for (NarrowStrings::const_iterator i (st.begin ()); i != st.end (); ++i) { - os << name << "::" << endl << name << " (" << istream_type << "< " << i->c_str () << " >& s," << endl @@ -646,7 +648,7 @@ namespace CXX // Parse // - if (has_members) + if (ordered || has_members) { os << "void " << name << "::" << endl << unclash (name, "parse") << " (" << @@ -654,6 +656,35 @@ namespace CXX << flags_type << " f)" << "{" << "XSD_UNUSED (f);"; // Can be unused. + + // Read the order sequence. + // + if (ordered) + { + String const& t (ctx.get ("order-type")); + String const& m (ctx.get ("order-member")); + + os << "{" + << "::std::size_t n;" + << "::xsd::cxx::tree::istream_common::as_size< " << + "::std::size_t > na (n);" + << "s >> na;" + << "if (n > 0)" + << "{" + << "this->" << m << ".reserve (n);" + << "while (n--)" + << "{" + << "::std::size_t id, in;" + << "::xsd::cxx::tree::istream_common::as_size< " << + "::std::size_t > ida (id), ina (in);" + << "s >> ida;" + << "s >> ina;" + << "this->" << m << ".push_back (" << t << " (id, in));" + << "}" // while + << "}" // if + << "}"; + } + { Element element (*this, *i); Attribute attribute (*this); diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx index f2e47a8..007e32c 100644 --- a/xsd/cxx/tree/stream-insertion-source.cxx +++ b/xsd/cxx/tree/stream-insertion-source.cxx @@ -398,6 +398,8 @@ namespace CXX virtual void traverse (Type& c) { + SemanticGraph::Context& ctx (c.context ()); + String name (ename (c)); // If renamed name is empty then we do not need to generate @@ -406,7 +408,10 @@ namespace CXX if (renamed_type (c, name) && !name) return; - bool has_body (has (c) || c.inherits_p ()); + bool ordered (ordered_p (c) && !ctx.count ("order-in-base")); + bool has_body (ordered || + has (c) || + c.inherits_p ()); size_t n (0); NarrowStrings const& st (options.generate_insertion ()); @@ -429,6 +434,29 @@ namespace CXX os << "& > (x);"; } + // Write the order sequence. + // + if (ordered) + { + String const& ci (ctx.get ("order-const-iterator")); + String const& an (ctx.get ("order-aname")); + + os << "s << ::xsd::cxx::tree::ostream_common::as_size< " << + "::std::size_t > (" << endl + << "x." << an << " ().size ());" + << endl + << "for (" << name << "::" << ci << endl + << "b (x." << an << " ().begin ()), n (x." << an << + " ().end ());" << endl + << "b != n; ++b)" + << "{" + << "s << ::xsd::cxx::tree::ostream_common::as_size< " << + "::std::size_t > (b->id);" + << "s << ::xsd::cxx::tree::ostream_common::as_size< " << + "::std::size_t > (b->index);" + << "}"; + } + { Traversal::Names names_member; Element element (*this, name, *i); -- cgit v1.1