aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-09-24 02:53:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-09-24 02:53:52 +0200
commitbe9dc66e3c607bade96b4e56cde0336578f027f3 (patch)
tree2b0a76873d39d5d8b469646a824cee273e759307
parent789e93956aa3034ff28edf62b9874c8068d41123 (diff)
Handle abstract bases in binary serialization
-rw-r--r--xsd/cxx/tree/stream-extraction-source.cxx91
-rw-r--r--xsd/cxx/tree/stream-insertion-source.cxx58
2 files changed, 96 insertions, 53 deletions
diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx
index a0bdcfc..192d9e9 100644
--- a/xsd/cxx/tree/stream-extraction-source.cxx
+++ b/xsd/cxx/tree/stream-extraction-source.cxx
@@ -337,6 +337,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<SemanticGraph::Complex*> (&t)) != 0 &&
+ tc->abstract_p ();
+ }
+
char const* r (
(poly || !fund) && std >= cxx_version::cxx11
? "::std::move (r)"
@@ -362,15 +372,18 @@ namespace CXX
if (poly)
{
- os << "bool d;"
- << auto_ptr << "< " << type << " > r;"
- << "s >> d;"
- << endl
- << "if (!d)" << endl
- << "r.reset (new " << type << " (s, f, this));"
- << "else"
- << "{"
- << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
+ os << auto_ptr << "< " << type << " > r;";
+
+ if (!abst)
+ os << "bool d;"
+ << "s >> d;"
+ << endl
+ << "if (!d)" << endl
+ << "r.reset (new " << type << " (s, f, this));"
+ << "else"
+ << "{";
+
+ os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
<< "::xsd::cxx::tree::stream_extraction_map_instance< " <<
poly_plate << ", " << stream << ", " << char_type <<
" > ().extract (" << endl
@@ -380,8 +393,10 @@ namespace CXX
<< "tmp.release ();"
<< "else" << endl
<< "throw ::xsd::cxx::tree::not_derived< " << char_type <<
- " > ();"
- << "}";
+ " > ();";
+
+ if (!abst)
+ os << "}";
}
else if (fund)
{
@@ -411,15 +426,18 @@ namespace CXX
if (poly)
{
- os << "bool d;"
- << auto_ptr << "< " << type << " > r;"
- << "s >> d;"
- << endl
- << "if (!d)" << endl
- << "r.reset (new " << type << " (s, f, this));"
- << "else"
- << "{"
- << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
+ os << auto_ptr << "< " << type << " > r;";
+
+ if (!abst)
+ os << "bool d;"
+ << "s >> d;"
+ << endl
+ << "if (!d)" << endl
+ << "r.reset (new " << type << " (s, f, this));"
+ << "else"
+ << "{";
+
+ os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
<< "::xsd::cxx::tree::stream_extraction_map_instance< " <<
poly_plate << ", " << stream << ", " << char_type <<
" > ().extract (" << endl
@@ -429,8 +447,10 @@ namespace CXX
<< "tmp.release ();"
<< "else" << endl
<< "throw ::xsd::cxx::tree::not_derived< " << char_type <<
- " > ();"
- << "}";
+ " > ();";
+
+ if (!abst)
+ os << "}";
}
else if (fund)
{
@@ -455,15 +475,18 @@ namespace CXX
if (poly)
{
- os << "bool d;"
- << auto_ptr << "< " << type << " > r;"
- << "s >> d;"
- << endl
- << "if (!d)" << endl
- << "r.reset (new " << type << " (s, f, this));"
- << "else"
- << "{"
- << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
+ os << auto_ptr << "< " << type << " > r;";
+
+ if (!abst)
+ os << "bool d;"
+ << "s >> d;"
+ << endl
+ << "if (!d)" << endl
+ << "r.reset (new " << type << " (s, f, this));"
+ << "else"
+ << "{";
+
+ os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl
<< "::xsd::cxx::tree::stream_extraction_map_instance< " <<
poly_plate << ", " << stream << ", " << char_type <<
" > ().extract (" << endl
@@ -473,8 +496,10 @@ namespace CXX
<< "tmp.release ();"
<< "else" << endl
<< "throw ::xsd::cxx::tree::not_derived< " << char_type <<
- " > ();"
- << "}";
+ " > ();";
+
+ if (!abst)
+ os << "}";
}
else if (fund)
{
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<SemanticGraph::Complex*> (&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);"
<< "}";