From e4c22d3686da0e973e21eae0561c1169c0eeff36 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Mar 2009 17:09:53 +0200 Subject: Implement support for XML Schema polymorphism in C++/Hybrid examples/cxx/hybrid/polyroot/ examples/cxx/hybrid/polymorphism/: new examples tests/cxx/hybrid/polymorphism/: new tests --- xsde/cxx/hybrid/tree-header.cxx | 94 ++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 15 deletions(-) (limited to 'xsde/cxx/hybrid/tree-header.cxx') diff --git a/xsde/cxx/hybrid/tree-header.cxx b/xsde/cxx/hybrid/tree-header.cxx index c2e8bf4..3003e4c 100644 --- a/xsde/cxx/hybrid/tree-header.cxx +++ b/xsde/cxx/hybrid/tree-header.cxx @@ -32,6 +32,9 @@ namespace CXX // if (name) { + Boolean cd (lc.count ("cd-name")); + Boolean poly (polymorphic (l)); + os << "// " << comment (l.name ()) << " (variable-length)" << endl << "//" << endl; @@ -50,17 +53,23 @@ namespace CXX os << "public:" << endl << name << " ();"; + // d-tor + // + if (poly) + os << "virtual ~" << name << " ();"; + + os << endl; + // Custom data. // - if (lc.count ("cd-name")) + if (cd) { String const& name (ecd_name (l)); String const& sequence (ecd_sequence (l)); String const& iterator (ecd_iterator (l)); String const& const_iterator (ecd_const_iterator (l)); - os << endl - << "// Custom data." << endl + os << "// Custom data." << endl << "//" << endl; // sequence & iterators @@ -84,9 +93,28 @@ namespace CXX os << sequence << "&" << endl << name << " ();" << endl; + } + + if (poly && typeinfo) + { + os << "// Type information." << endl + << "//" << endl; + os << "static const " << + (stl ? "::std::string&" : "char*") << endl + << "_static_type ();" + << endl; + + os << "virtual const " << + (stl ? "::std::string&" : "char*") << endl + << "_dynamic_type () const;" + << endl; + } + + if (cd) + { os << "private:" << endl - << sequence << " " << ecd_member (l) << ";"; + << ecd_sequence (l) << " " << ecd_member (l) << ";"; } os << "};"; @@ -128,15 +156,18 @@ namespace CXX // if (name) { + Boolean fl (fixed_length (u)); + Boolean poly (polymorphic (u)); Boolean cd (uc.count ("cd-name")); - os << "// " << comment (u.name ()) << " (variable-length)" << endl + os << "// " << comment (u.name ()) << " (" << + (fl ? "fixed-length" : "variable-length") << ")" << endl << "//" << endl; os << "class " << name << "{"; - if (!fixed_length (u)) + if (!fl) os << "private:" << endl << name << " (const " << name << "&);" << name << "& operator= (const " << name << "&);" @@ -148,13 +179,18 @@ namespace CXX // os << name << " ();"; + // d-tor + // + if (!stl || poly) + os << (poly ? "virtual " : "") << "~" << name << " ();"; + + os << endl; + String const& value (uc.get ("value")); String const& member (uc.get ("value-member")); if (stl) { - os << endl; - // const std::string& // name () const // @@ -178,11 +214,6 @@ namespace CXX } else { - // d-tor - // - os << "~" << name << " ();" - << endl; - // const char* // name () const // @@ -250,6 +281,22 @@ namespace CXX << endl; } + if (poly && typeinfo) + { + os << "// Type information." << endl + << "//" << endl; + + os << "static const " << + (stl ? "::std::string&" : "char*") << endl + << "_static_type ();" + << endl; + + os << "virtual const " << + (stl ? "::std::string&" : "char*") << endl + << "_dynamic_type () const;" + << endl; + } + if (stl) { os << "private:" << endl @@ -2337,6 +2384,7 @@ namespace CXX if (name) { Boolean fl (fixed_length (c)); + Boolean poly (polymorphic (c)); Boolean restriction (restriction_p (c)); Boolean cd (cc.count ("cd-name")); @@ -2361,8 +2409,8 @@ namespace CXX // d-tor // - if (!restriction) - os << "~" << name << " ();"; + if (!restriction || poly) + os << (poly ? "virtual " : "") << "~" << name << " ();"; // copy c-tor & operator= // @@ -2421,6 +2469,22 @@ namespace CXX << endl; } + if (poly && typeinfo) + { + os << "// Type information." << endl + << "//" << endl; + + os << "static const " << + (stl ? "::std::string&" : "char*") << endl + << "_static_type ();" + << endl; + + os << "virtual const " << + (stl ? "::std::string&" : "char*") << endl + << "_dynamic_type () const;" + << endl; + } + if (!restriction || cd) os << "private:" << endl; -- cgit v1.1