From be9dc66e3c607bade96b4e56cde0336578f027f3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 24 Sep 2016 02:53:52 +0200 Subject: Handle abstract bases in binary serialization --- xsd/cxx/tree/stream-insertion-source.cxx | 58 +++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'xsd/cxx/tree/stream-insertion-source.cxx') diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx index 007e32c..e98199e 100644 --- a/xsd/cxx/tree/stream-insertion-source.cxx +++ b/xsd/cxx/tree/stream-insertion-source.cxx @@ -269,6 +269,16 @@ namespace CXX // bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + // Check if this element is abstract. + // + bool abst (false); + if (poly) + { + SemanticGraph::Complex* tc; + abst = (tc = dynamic_cast (&t)) != 0 && + tc->abstract_p (); + } + if (max (e) != 1) { // sequence @@ -286,12 +296,14 @@ namespace CXX if (poly) { - os << "bool d (typeid (" << type << ") != typeid (*i));" - << "s << d;" - << "if (!d)" << endl - << "s << *i;" - << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< " << + if (!abst) + os << "bool d (typeid (" << type << ") != typeid (*i));" + << "s << d;" + << "if (!d)" << endl + << "s << *i;" + << "else" << endl; + + os << "::xsd::cxx::tree::stream_insertion_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().insert (s, *i);"; } @@ -313,13 +325,16 @@ namespace CXX if (poly) { os << "{" - << "const " << type << "& i (*x." << aname << " ());" - << "bool d (typeid (" << type << ") != typeid (i));" - << "s << d;" - << "if (!d)" << endl - << "s << i;" - << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< " << + << "const " << type << "& i (*x." << aname << " ());"; + + if (!abst) + os << "bool d (typeid (" << type << ") != typeid (i));" + << "s << d;" + << "if (!d)" << endl + << "s << i;" + << "else" << endl; + + os << "::xsd::cxx::tree::stream_insertion_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().insert (s, i);" << "}"; @@ -337,13 +352,16 @@ namespace CXX if (poly) { os << "{" - << "const " << type << "& i (x." << aname << " ());" - << "bool d (typeid (" << type << ") != typeid (i));" - << "s << d;" - << "if (!d)" << endl - << "s << i;" - << "else" << endl - << "::xsd::cxx::tree::stream_insertion_map_instance< " << + << "const " << type << "& i (x." << aname << " ());"; + + if (!abst) + os << "bool d (typeid (" << type << ") != typeid (i));" + << "s << d;" + << "if (!d)" << endl + << "s << i;" + << "else" << endl; + + os << "::xsd::cxx::tree::stream_insertion_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().insert (s, i);" << "}"; -- cgit v1.1