aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-07-30 10:19:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-07-30 10:19:30 +0200
commitcc5cdb07e40f30e614bd15d81a5091faf717f4f4 (patch)
treeb717b3216c1730db484e7ebfb6dbe1281621ede9
parent94cba986108a0e0f42295572ca42c356d59328d7 (diff)
Add support for abstract complex types in C++/Tree
-rw-r--r--NEWS8
-rw-r--r--libxsd/xsd/cxx/tree/type-factory-map.txx23
-rw-r--r--tests/cxx/tree/polymorphism/comparison/driver.cxx12
-rw-r--r--tests/cxx/tree/polymorphism/comparison/makefile2
-rw-r--r--tests/cxx/tree/polymorphism/comparison/test.xsd2
-rw-r--r--tests/cxx/tree/polymorphism/ostream/test.xsd13
-rw-r--r--xsd/cxx/tree/serialization-source.cxx5
-rw-r--r--xsd/cxx/tree/stream-extraction-source.cxx1
-rw-r--r--xsd/cxx/tree/stream-insertion-source.cxx1
-rw-r--r--xsd/cxx/tree/stream-source.cxx1
-rw-r--r--xsd/cxx/tree/tree-header.cxx3
-rw-r--r--xsd/cxx/tree/tree-source.cxx27
12 files changed, 73 insertions, 25 deletions
diff --git a/NEWS b/NEWS
index faa77b0..03f5942 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Version 4.1.0
+
+C++/Tree
+
+ * Support for abstract XML Schema types. The corresponding C++ classes
+ now have _clone() declared pure virtual which prevents construction
+ of their instances.
+
Version 4.0.0
* Xerces-C++ 2-series (2.8.0 and earlier) is no longer supported.
diff --git a/libxsd/xsd/cxx/tree/type-factory-map.txx b/libxsd/xsd/cxx/tree/type-factory-map.txx
index e1fe0cc..c8d2f18 100644
--- a/libxsd/xsd/cxx/tree/type-factory-map.txx
+++ b/libxsd/xsd/cxx/tree/type-factory-map.txx
@@ -290,23 +290,26 @@ namespace xsd
if (qn.name () == name &&
(qualified ? qn.namespace_ () == ns : ns[0] == C ('\0')))
{
- f = static_type;
+ f = static_type; // NULL for abstract types.
}
- else if (global)
+ else
{
// See if we have a substitution.
//
- typename element_map::const_iterator i (
- element_map_.find (qualified_name (name, ns)));
-
- if (i != element_map_.end ())
+ if (global)
{
- f = find_substitution (i->second, qn);
+ typename element_map::const_iterator i (
+ element_map_.find (qualified_name (name, ns)));
+
+ if (i != element_map_.end ())
+ {
+ f = find_substitution (i->second, qn);
+ }
}
- }
- if (f == 0)
- return XSD_AUTO_PTR<type> (); // No match.
+ if (f == 0)
+ return XSD_AUTO_PTR<type> (); // No match.
+ }
// Check for xsi:type
//
diff --git a/tests/cxx/tree/polymorphism/comparison/driver.cxx b/tests/cxx/tree/polymorphism/comparison/driver.cxx
index 5394991..d291f6c 100644
--- a/tests/cxx/tree/polymorphism/comparison/driver.cxx
+++ b/tests/cxx/tree/polymorphism/comparison/driver.cxx
@@ -6,6 +6,7 @@
//
#include <memory> // std::auto_ptr/unique_ptr
+#include <sstream>
#include <iostream>
#include "test.hxx"
@@ -65,6 +66,17 @@ main (int argc, char* argv[])
assert (*r != r1);
}
+
+ xml_schema::namespace_infomap map;
+
+ map["t"].name = "test";
+
+ stringstream s;
+ root (s, *r, map);
+
+ XSD_AUTO_PTR<type> c (root (s, xml_schema::flags::dont_validate));
+
+ assert (*r == *c);
}
catch (xml_schema::exception const& e)
{
diff --git a/tests/cxx/tree/polymorphism/comparison/makefile b/tests/cxx/tree/polymorphism/comparison/makefile
index ef3e70a..6ab3e92 100644
--- a/tests/cxx/tree/polymorphism/comparison/makefile
+++ b/tests/cxx/tree/polymorphism/comparison/makefile
@@ -34,7 +34,7 @@ gen := $(addprefix $(out_base)/,$(genf))
$(gen): xsd := $(out_root)/xsd/xsd
$(gen): xsd_options += --generate-polymorphic --polymorphic-type base \
---generate-comparison
+--generate-comparison --generate-serialization
$(gen): $(out_root)/xsd/xsd
$(call include-dep,$(dep),$(obj),$(gen))
diff --git a/tests/cxx/tree/polymorphism/comparison/test.xsd b/tests/cxx/tree/polymorphism/comparison/test.xsd
index 18532f2..364d1b3 100644
--- a/tests/cxx/tree/polymorphism/comparison/test.xsd
+++ b/tests/cxx/tree/polymorphism/comparison/test.xsd
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
- <complexType name="base">
+ <complexType name="base" abstract="true">
<sequence>
<element name="a" type="string"/>
<element name="fund" type="int"/>
diff --git a/tests/cxx/tree/polymorphism/ostream/test.xsd b/tests/cxx/tree/polymorphism/ostream/test.xsd
index ddeaeae..688cd5a 100644
--- a/tests/cxx/tree/polymorphism/ostream/test.xsd
+++ b/tests/cxx/tree/polymorphism/ostream/test.xsd
@@ -2,12 +2,21 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test"
targetNamespace="test" elementFormDefault="qualified">
- <complexType name="base">
+ <complexType name="abst_base" abstract="1">
<sequence>
<element name="a" type="string"/>
- <element name="fund" type="int"/>
</sequence>
</complexType>
+
+ <complexType name="base">
+ <complexContent>
+ <extension base="t:abst_base">
+ <sequence>
+ <element name="fund" type="int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
<element name="base" type="t:base"/>
<complexType name="derived1">
diff --git a/xsd/cxx/tree/serialization-source.cxx b/xsd/cxx/tree/serialization-source.cxx
index 559a3cf..8a94c74 100644
--- a/xsd/cxx/tree/serialization-source.cxx
+++ b/xsd/cxx/tree/serialization-source.cxx
@@ -956,7 +956,10 @@ namespace CXX
// but substitutes, then it will be registered as part of the
// substitution registration.
//
- if (polymorphic && polymorphic_p (c) && !anonymous_p (c))
+ if (polymorphic &&
+ polymorphic_p (c) &&
+ !c.abstract_p () &&
+ !anonymous_p (c))
{
// Note that we are using the original type name.
//
diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx
index ceb56c1..7c1382e 100644
--- a/xsd/cxx/tree/stream-extraction-source.cxx
+++ b/xsd/cxx/tree/stream-extraction-source.cxx
@@ -673,6 +673,7 @@ namespace CXX
//
if (polymorphic &&
polymorphic_p (c) &&
+ !c.abstract_p () &&
(!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx
index 2c82cfd..f2e47a8 100644
--- a/xsd/cxx/tree/stream-insertion-source.cxx
+++ b/xsd/cxx/tree/stream-insertion-source.cxx
@@ -448,6 +448,7 @@ namespace CXX
//
if (polymorphic &&
polymorphic_p (c) &&
+ !c.abstract_p () &&
(!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
diff --git a/xsd/cxx/tree/stream-source.cxx b/xsd/cxx/tree/stream-source.cxx
index 935ad40..656f0ed 100644
--- a/xsd/cxx/tree/stream-source.cxx
+++ b/xsd/cxx/tree/stream-source.cxx
@@ -385,6 +385,7 @@ namespace CXX
//
if (polymorphic &&
polymorphic_p (c) &&
+ !c.abstract_p () &&
(!anonymous_p (c) || anonymous_substitutes_p (c)))
{
// Note that we are using the original type name.
diff --git a/xsd/cxx/tree/tree-header.cxx b/xsd/cxx/tree/tree-header.cxx
index f0c3560..320e0c6 100644
--- a/xsd/cxx/tree/tree-header.cxx
+++ b/xsd/cxx/tree/tree-header.cxx
@@ -3296,7 +3296,8 @@ namespace CXX
os << "virtual " << name << "*" << endl
<< "_clone (" << flags_type << " f = 0," << endl
- << container << "* c = 0) const;"
+ << container << "* c = 0) const" <<
+ (c.abstract_p () ? " = 0" : "") << ";"
<< endl;
// operator=
diff --git a/xsd/cxx/tree/tree-source.cxx b/xsd/cxx/tree/tree-source.cxx
index 8a01c5a..5720dbd 100644
--- a/xsd/cxx/tree/tree-source.cxx
+++ b/xsd/cxx/tree/tree-source.cxx
@@ -729,8 +729,16 @@ namespace CXX
<< strlit (e.name ()) << "," << endl
<< (e.qualified_p ()
? strlit (e.namespace_ ().name ())
- : L + String ("\"\"")) << "," << endl
- << "&::xsd::cxx::tree::factory_impl< " << type << " >," << endl
+ : L + String ("\"\"")) << "," << endl;
+
+ SemanticGraph::Complex* tc;
+ if ((tc = dynamic_cast<SemanticGraph::Complex*> (&t)) != 0 &&
+ tc->abstract_p ())
+ os << "0,";
+ else
+ os << "&::xsd::cxx::tree::factory_impl< " << type << " >,";
+
+ os << endl
<< (e.global_p () ? "true" : "false") << ", " <<
(e.qualified_p () ? "true" : "false") << ", " <<
"i, n, f, this));"
@@ -3309,12 +3317,13 @@ namespace CXX
// _clone
//
- os << name << "* " << name << "::" << endl
- << "_clone (" << flags_type << " f," << endl
- << container << "* c) const"
- << "{"
- << "return new class " << name << " (*this, f, c);"
- << "}";
+ if (!c.abstract_p ())
+ os << name << "* " << name << "::" << endl
+ << "_clone (" << flags_type << " f," << endl
+ << container << "* c) const"
+ << "{"
+ << "return new class " << name << " (*this, f, c);"
+ << "}";
// operator=
//
@@ -3364,7 +3373,7 @@ namespace CXX
// Register with type factory map.
//
- if (polymorphic && polymorphic_p (c))
+ if (polymorphic && polymorphic_p (c) && !c.abstract_p ())
{
// Note that we are using the original type name.
//