From 0fdf19714613a82a184f4f6e75fb9a4f9b62f18a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 19 Jan 2014 10:05:08 +0200 Subject: Use std::unique_ptr instead of std::auto_ptr in C++11 mode --- xsd/cxx/elements.cxx | 15 +- xsd/cxx/elements.hxx | 9 + xsd/cxx/options.cli | 18 +- xsd/cxx/parser/attribute-validation-source.cxx | 2 +- xsd/cxx/parser/element-validation-source.cxx | 2 +- xsd/cxx/parser/generator.cxx | 12 +- xsd/cxx/parser/parser-header.cxx | 4 +- xsd/cxx/parser/print-impl-common.hxx | 2 +- xsd/cxx/tree/elements.cxx | 61 ++--- xsd/cxx/tree/elements.hxx | 53 ++-- xsd/cxx/tree/fundamental-header.hxx | 11 +- xsd/cxx/tree/generator.cxx | 111 +++++---- xsd/cxx/tree/parser-header.cxx | 30 +-- xsd/cxx/tree/parser-source.cxx | 102 ++++---- xsd/cxx/tree/stream-extraction-source.cxx | 39 +-- xsd/cxx/tree/tree-header.cxx | 63 ++--- xsd/cxx/tree/tree-inline.cxx | 21 +- xsd/cxx/tree/tree-source.cxx | 324 ++++++++++++++++--------- 18 files changed, 519 insertions(+), 360 deletions(-) (limited to 'xsd/cxx') diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx index 4a76444..5ee1f28 100644 --- a/xsd/cxx/elements.cxx +++ b/xsd/cxx/elements.cxx @@ -118,10 +118,12 @@ namespace CXX schema_root (root), schema_path (schema_path_), options (ops), + std (ops.std ()), char_type (char_type_), char_encoding (char_encoding_), L (L_), string_type (string_type_), + auto_ptr (auto_ptr_), string_literal_map (string_literal_map_), type_exp (type_exp_), inst_exp (inst_exp_), @@ -184,6 +186,12 @@ namespace CXX else string_type_ = L"::std::basic_string< " + char_type + L" >"; + // Automatic pointer type. + // + auto_ptr_ = std >= cxx_version::cxx11 + ? "::std::unique_ptr" + : "::std::auto_ptr"; + // Default encoding. // if (!char_encoding) @@ -197,7 +205,7 @@ namespace CXX // Default mapping. // nsr_mapping_.push_back ( - Regex (L"#^.* (.*?/)??"L"(([a-zA-Z_]\\w*)(/[a-zA-Z_]\\w*)*)/?$#$2#")); + Regex (L"#^.* (.*?/)??" L"(([a-zA-Z_]\\w*)(/[a-zA-Z_]\\w*)*)/?$#$2#")); nsr_mapping_.push_back ( Regex (L"#^.* http://www\\.w3\\.org/2001/XMLSchema$#xml_schema#")); @@ -1093,9 +1101,10 @@ namespace CXX { if (escape) { - // Close and open the string so there are no clashes. + // Close and open the string so there are no clashes. C++11 + // requires a space between " and L. // - r += L"\"L\""; + r += L"\" L\""; escape = false; } diff --git a/xsd/cxx/elements.hxx b/xsd/cxx/elements.hxx index f978f51..d0d07e7 100644 --- a/xsd/cxx/elements.hxx +++ b/xsd/cxx/elements.hxx @@ -159,10 +159,12 @@ namespace CXX schema_root (c.schema_root), schema_path (c.schema_path), options (c.options), + std (c.std), char_type (c.char_type), char_encoding (c.char_encoding), L (c.L), string_type (c.string_type), + auto_ptr (c.auto_ptr), string_literal_map (c.string_literal_map), type_exp (c.type_exp), inst_exp (c.inst_exp), @@ -184,10 +186,12 @@ namespace CXX schema_root (c.schema_root), schema_path (c.schema_path), options (c.options), + std (c.std), char_type (c.char_type), char_encoding (c.char_encoding), L (c.L), string_type (c.string_type), + auto_ptr (c.auto_ptr), string_literal_map (c.string_literal_map), type_exp (c.type_exp), inst_exp (c.inst_exp), @@ -328,10 +332,14 @@ namespace CXX options_type const& options; + cxx_version std; + String& char_type; String& char_encoding; String& L; // string literal prefix String& string_type; + String& auto_ptr; + StringLiteralMap const* string_literal_map; String& type_exp; @@ -350,6 +358,7 @@ namespace CXX String char_encoding_; String L_; String string_type_; + String auto_ptr_; String type_exp_; String inst_exp_; diff --git a/xsd/cxx/options.cli b/xsd/cxx/options.cli index 2203188..78fd587 100644 --- a/xsd/cxx/options.cli +++ b/xsd/cxx/options.cli @@ -21,7 +21,23 @@ namespace CXX { "", "Specify the C++ standard that the generated code should conform to. - Valid values are \cb{c++98} (default) and \cb{c++11}." + Valid values are \cb{c++98} (default) and \cb{c++11}. + + The C++ standard affects various aspects of the generated code that + are discussed in more detail in various mapping-specific + documentation. Overall, when C++11 is selected, the generated + code relies on the move semantics and uses \cb{std::unique_ptr} + instead of deprecated \cb{std::auto_ptr}. + + When the C++11 mode is selected, you normally don't need to + perform any extra steps other than enable C++11 in your C++ + compiler, if required. The XSD compiler will automatically + add the necessary macro defines to the generated header files + that will switch the header-only XSD runtime library (\cb{libxsd}) + to the C++11 mode. However, if you include any of the XSD runtime + headers directly in your application (normally you just include + the generated headers), then you will need to define the + \cb{XSD_CXX11} macro for your entire project." }; // Character type and encoding. diff --git a/xsd/cxx/parser/attribute-validation-source.cxx b/xsd/cxx/parser/attribute-validation-source.cxx index c4fe5ad..ba412b0 100644 --- a/xsd/cxx/parser/attribute-validation-source.cxx +++ b/xsd/cxx/parser/attribute-validation-source.cxx @@ -126,7 +126,7 @@ namespace CXX // compilers (e.g., IBM xlC that needs an lvalue to pass // std::auto_ptr). // - if (options.std () == cxx_version::cxx98) + if (std == cxx_version::cxx98) os << arg_type (type) << " tmp (this->" << inst << "->" << post << " ());" << "this->" << name << " (tmp);"; diff --git a/xsd/cxx/parser/element-validation-source.cxx b/xsd/cxx/parser/element-validation-source.cxx index 310ea27..1bc506a 100644 --- a/xsd/cxx/parser/element-validation-source.cxx +++ b/xsd/cxx/parser/element-validation-source.cxx @@ -314,7 +314,7 @@ namespace CXX // compilers (e.g., IBM xlC that needs an lvalue to pass // std::auto_ptr). // - if (options.std () == cxx_version::cxx98) + if (std == cxx_version::cxx98) os << arg_type (type) << " tmp (" << inst << "->" << post << " ());" << "this->" << name << " (tmp);"; diff --git a/xsd/cxx/parser/generator.cxx b/xsd/cxx/parser/generator.cxx index a262004..46a0687 100644 --- a/xsd/cxx/parser/generator.cxx +++ b/xsd/cxx/parser/generator.cxx @@ -290,12 +290,14 @@ namespace CXX string_type = L"::std::basic_string< " + char_type + L" >"; String xns; + String auto_ptr; { Context ctx (std::wcerr, schema, file_path, ops, 0, 0, 0, 0); xns = ctx.xs_ns_name (); + auto_ptr = ctx.auto_ptr; } - String buffer (L"::std::auto_ptr< " + xns + L"::buffer >"); + String buffer (auto_ptr + L"< " + xns + L"::buffer >"); TypeMap::Namespace xsd ("http://www\\.w3\\.org/2001/XMLSchema"); xsd.types_push_back ("string", string_type); @@ -777,6 +779,14 @@ namespace CXX << "#define " << guard << endl << endl; + if (ctx.std >= cxx_version::cxx11) + { + hxx << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl + << endl; + } + // Version check. // hxx << "#include " << endl diff --git a/xsd/cxx/parser/parser-header.cxx b/xsd/cxx/parser/parser-header.cxx index 5db1ef4..cd266ae 100644 --- a/xsd/cxx/parser/parser-header.cxx +++ b/xsd/cxx/parser/parser-header.cxx @@ -1008,7 +1008,7 @@ namespace CXX virtual void traverse (SemanticGraph::Fundamental::Base64Binary& t) { - String buffer (L"::std::auto_ptr< " + xs_ns_ + L"::buffer >"); + String buffer (auto_ptr + L"< " + xs_ns_ + L"::buffer >"); gen_typedef (t, buffer, "base64_binary_pskel", "base64_binary_pimpl"); } @@ -1016,7 +1016,7 @@ namespace CXX virtual void traverse (SemanticGraph::Fundamental::HexBinary& t) { - String buffer (L"::std::auto_ptr< " + xs_ns_ + L"::buffer >"); + String buffer (auto_ptr + L"< " + xs_ns_ + L"::buffer >"); gen_typedef (t, buffer, "hex_binary_pskel", "hex_binary_pimpl"); } diff --git a/xsd/cxx/parser/print-impl-common.hxx b/xsd/cxx/parser/print-impl-common.hxx index db26ea8..ab38ea4 100644 --- a/xsd/cxx/parser/print-impl-common.hxx +++ b/xsd/cxx/parser/print-impl-common.hxx @@ -605,7 +605,7 @@ namespace CXX void gen_buffer (SemanticGraph::Type& t) { - String type (L"::std::auto_ptr< " + xs_ns_name () + L"::buffer >"); + String type (auto_ptr + L"< " + xs_ns_name () + L"::buffer >"); if (default_type (t, type)) { diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx index 8021287..10bf999 100644 --- a/xsd/cxx/tree/elements.cxx +++ b/xsd/cxx/tree/elements.cxx @@ -93,7 +93,10 @@ namespace CXX xsc.get ("error-handler"); } - dom_auto_ptr_ = xs_name + L"::dom::auto_ptr"; + dom_auto_ptr_ = xs_name + (std >= cxx_version::cxx11 + ? L"::dom::unique_ptr" + : L"::dom::auto_ptr"); + dom_node_key_ = xs_name + L"::dom::" + xsc.get ("tree-node-key"); @@ -828,7 +831,7 @@ namespace CXX // FromBaseCtorArg // FromBaseCtorArg:: - FromBaseCtorArg (Context& c, ArgType at, bool arg) + FromBaseCtorArg (Context& c, CtorArgType at, bool arg) : Context (c), arg_type_ (at), arg_ (arg) { } @@ -863,29 +866,29 @@ namespace CXX os << "," << endl; - bool auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << auto_ptr << "< " << etype (e) << " >"; else os << "const " << etype (e) << "&"; @@ -916,7 +919,7 @@ namespace CXX // CtorArgs // CtorArgs:: - CtorArgs (Context& c, ArgType at) + CtorArgs (Context& c, CtorArgType at) : Context (c), arg_type_ (at), base_arg_ (0), @@ -928,7 +931,7 @@ namespace CXX } CtorArgs:: - CtorArgs (Context& c, ArgType at, String& base_arg) + CtorArgs (Context& c, CtorArgType at, String& base_arg) : Context (c), arg_type_ (at), base_arg_ (&base_arg), @@ -1000,29 +1003,29 @@ namespace CXX if (min (e) == 1 && max (e) == 1) { - bool auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << comma () << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << comma () << auto_ptr << "< " << etype (e) << " >"; else os << comma () << "const " << etype (e) << "&"; @@ -1059,7 +1062,7 @@ namespace CXX // CtorArgsWithoutBase // CtorArgsWithoutBase:: - CtorArgsWithoutBase (Context& c, ArgType at, bool arg, bool first) + CtorArgsWithoutBase (Context& c, CtorArgType at, bool arg, bool first) : Context (c), arg_type_ (at), arg_ (arg), first_ (first) { *this >> inherits_ >> *this; @@ -1089,29 +1092,29 @@ namespace CXX if (min (e) == 1 && max (e) == 1) { - bool auto_ptr (false); + bool ptr (false); switch (arg_type_) { - case arg_complex_auto_ptr: + case CtorArgType::complex_auto_ptr: { bool simple (true); IsSimpleType t (simple); t.dispatch (e.type ()); - auto_ptr = !simple; + ptr = !simple; break; } - case arg_poly_auto_ptr: + case CtorArgType::poly_auto_ptr: { - auto_ptr = polymorphic && polymorphic_p (e.type ()); + ptr = polymorphic && polymorphic_p (e.type ()); break; } - case arg_type: + case CtorArgType::type: break; } - if (auto_ptr) - os << comma () << "::std::auto_ptr< " << etype (e) << " >&"; + if (ptr) + os << comma () << auto_ptr << "< " << etype (e) << " >"; else os << comma () << "const " << etype (e) << "&"; diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx index b7d6626..deb3a5e 100644 --- a/xsd/cxx/tree/elements.hxx +++ b/xsd/cxx/tree/elements.hxx @@ -1496,6 +1496,24 @@ namespace CXX Traversal::Names names_; }; + // Contructor argument types. + // + struct CtorArgType + { + enum Value + { + type, + complex_auto_ptr, + poly_auto_ptr + }; + + CtorArgType (Value v = Value (0)) : v_ (v) {} + operator Value () const {return v_;} + + private: + Value v_; + }; + // Immediate non-optional member. Note that AnyAttribute is always // mapped to a sequence. // @@ -1504,14 +1522,7 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; - - FromBaseCtorArg (Context& c, ArgType, bool arg); + FromBaseCtorArg (Context& c, CtorArgType, bool arg); virtual void traverse (SemanticGraph::Any&); @@ -1523,7 +1534,7 @@ namespace CXX traverse (SemanticGraph::Element&); private: - ArgType arg_type_; + CtorArgType arg_type_; bool arg_; }; @@ -1538,18 +1549,11 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; - // The second version outputs the argument name and stores // in in the base_arg string. // - CtorArgs (Context&, ArgType); - CtorArgs (Context&, ArgType, String& base_arg); + CtorArgs (Context&, CtorArgType); + CtorArgs (Context&, CtorArgType, String& base_arg); virtual void traverse (SemanticGraph::Type&); @@ -1571,7 +1575,7 @@ namespace CXX comma (); private: - ArgType arg_type_; + CtorArgType arg_type_; String base_; String* base_arg_; bool first_; @@ -1705,14 +1709,7 @@ namespace CXX Traversal::Attribute, Context { - enum ArgType - { - arg_type, - arg_complex_auto_ptr, - arg_poly_auto_ptr - }; - - CtorArgsWithoutBase (Context& c, ArgType, bool arg, bool first); + CtorArgsWithoutBase (Context& c, CtorArgType, bool arg, bool first); virtual void traverse (SemanticGraph::Any&); @@ -1728,7 +1725,7 @@ namespace CXX comma (); private: - ArgType arg_type_; + CtorArgType arg_type_; bool arg_; bool first_; diff --git a/xsd/cxx/tree/fundamental-header.hxx b/xsd/cxx/tree/fundamental-header.hxx index 2171de4..18a5e61 100644 --- a/xsd/cxx/tree/fundamental-header.hxx +++ b/xsd/cxx/tree/fundamental-header.hxx @@ -1146,7 +1146,8 @@ namespace CXX << "{"; // @@ Disregarding current naming convention by using the - // fixed name (no template typedef). + // fixed name (even in C++11, template alias is not yet + // widely supported). // if (doxygen) os << "/**" << endl @@ -1156,8 +1157,12 @@ namespace CXX os << "// Automatic pointer for DOMDocument." << endl << "//" << endl; - os << "using ::xsd::cxx::xml::dom::auto_ptr;" - << endl; + if (std >= cxx_version::cxx11) + os << "using ::xsd::cxx::xml::dom::unique_ptr;"; + else + os << "using ::xsd::cxx::xml::dom::auto_ptr;"; + + os << endl; if (parsing) { diff --git a/xsd/cxx/tree/generator.cxx b/xsd/cxx/tree/generator.cxx index b373d31..35c53bc 100644 --- a/xsd/cxx/tree/generator.cxx +++ b/xsd/cxx/tree/generator.cxx @@ -188,6 +188,7 @@ namespace CXX FileList& file_list, AutoUnlinks& unlinks) { + using cutl::shared_ptr; typedef cutl::re::regexsub Regex; typedef vector Paths; @@ -711,29 +712,13 @@ namespace CXX << "#define " << guard << endl << endl; - // Version check. - // - fwd << "#include " << endl - << endl - << "#if (XSD_INT_VERSION != " << XSD_INT_VERSION << "L)" << endl - << "#error XSD runtime version mismatch" << endl - << "#endif" << endl - << endl; - - fwd << "#include " << endl + if (ctx.std >= cxx_version::cxx11) + { + fwd << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl << endl; - - // Copy prologue. - // - fwd << "// Begin prologue." << endl - << "//" << endl; - - append (fwd, ops.fwd_prologue (), ops.prologue ()); - append (fwd, ops.fwd_prologue_file (), prologue); - - fwd << "//" << endl - << "// End prologue." << endl - << endl; + } if (ctx.char_type == L"char") { @@ -760,6 +745,30 @@ namespace CXX << endl; } + // Version check. + // + fwd << "#include " << endl + << endl + << "#if (XSD_INT_VERSION != " << XSD_INT_VERSION << "L)" << endl + << "#error XSD runtime version mismatch" << endl + << "#endif" << endl + << endl; + + fwd << "#include " << endl + << endl; + + // Copy prologue. + // + fwd << "// Begin prologue." << endl + << "//" << endl; + + append (fwd, ops.fwd_prologue (), ops.prologue ()); + append (fwd, ops.fwd_prologue_file (), prologue); + + fwd << "//" << endl + << "// End prologue." << endl + << endl; + // Generate. // { @@ -817,34 +826,16 @@ namespace CXX << "#define " << guard << endl << endl; - // Version check. - // - hxx << "#include " << endl - << endl - << "#if (XSD_INT_VERSION != " << XSD_INT_VERSION << "L)" << endl - << "#error XSD runtime version mismatch" << endl - << "#endif" << endl - << endl; - - hxx << "#include " << endl - << endl; - - // Copy prologue. - // - hxx << "// Begin prologue." << endl - << "//" << endl; - - append (hxx, ops.hxx_prologue (), ops.prologue ()); - append (hxx, ops.hxx_prologue_file (), prologue); - - hxx << "//" << endl - << "// End prologue." << endl - << endl; - - // Generate character selection defines. - // if (!forward) { + if (ctx.std >= cxx_version::cxx11) + { + hxx << "#ifndef XSD_CXX11" << endl + << "#define XSD_CXX11" << endl + << "#endif" << endl + << endl; + } + if (ctx.char_type == L"char") { hxx << "#ifndef XSD_USE_CHAR" << endl @@ -871,6 +862,30 @@ namespace CXX } } + // Version check. + // + hxx << "#include " << endl + << endl + << "#if (XSD_INT_VERSION != " << XSD_INT_VERSION << "L)" << endl + << "#error XSD runtime version mismatch" << endl + << "#endif" << endl + << endl; + + hxx << "#include " << endl + << endl; + + // Copy prologue. + // + hxx << "// Begin prologue." << endl + << "//" << endl; + + append (hxx, ops.hxx_prologue (), ops.prologue ()); + append (hxx, ops.hxx_prologue_file (), prologue); + + hxx << "//" << endl + << "// End prologue." << endl + << endl; + // Generate. // { diff --git a/xsd/cxx/tree/parser-header.cxx b/xsd/cxx/tree/parser-header.cxx index 59cc043..cdad52c 100644 --- a/xsd/cxx/tree/parser-header.cxx +++ b/xsd/cxx/tree/parser-header.cxx @@ -71,7 +71,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -94,7 +94,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -120,7 +120,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << string_type << "& uri," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -149,7 +149,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -172,7 +172,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -198,7 +198,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -225,7 +225,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << flags_type << " f = 0," << endl @@ -256,7 +256,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << error_handler << "& eh," << endl @@ -288,7 +288,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& id," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl @@ -318,7 +318,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -342,7 +342,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << error_handler << "& eh," << endl << flags_type << " f = 0," << endl @@ -368,7 +368,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << xerces_ns << "::InputSource& is," << endl << xerces_ns << "::DOMErrorHandler& eh," << endl << flags_type << " f = 0," << endl @@ -395,7 +395,7 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (const " << xerces_ns << "::DOMDocument& d," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" @@ -420,9 +420,9 @@ namespace CXX } os << inst_exp - << "::std::auto_ptr< " << type_name (e) << " >" << endl + << auto_ptr << "< " << type_name (e) << " >" << endl << name << " (" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument >& d," << endl + "::DOMDocument > d," << endl << flags_type << " f = 0," << endl << "const " << properties_type << "& p = " << properties_type << " ());" << endl; diff --git a/xsd/cxx/tree/parser-source.cxx b/xsd/cxx/tree/parser-source.cxx index 362e9e6..be641e5 100644 --- a/xsd/cxx/tree/parser-source.cxx +++ b/xsd/cxx/tree/parser-source.cxx @@ -38,9 +38,11 @@ namespace CXX // confused if the name is 'type'. (see tests/schema/anonymous) // + char const* d (std >= cxx_version::cxx11 ? "std::move (d)" : "d"); + // URI. // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -59,19 +61,17 @@ namespace CXX if (options.disable_multi_import ()) os << " | ::xsd::cxx::xml::dom::no_muliple_imports"; - os << "));" + os << "));" << endl << "h.throw_if_failed< ::xsd::cxx::tree::parsing< " << char_type << " > > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -94,14 +94,12 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (const " << string_type << "& u," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -120,17 +118,15 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; // istream // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -143,7 +139,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -157,7 +153,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -167,7 +163,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << flags_type << " f," << endl @@ -181,7 +177,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << error_handler << "& h," << endl @@ -196,7 +192,7 @@ namespace CXX << "return " << fq_name (e, "parser") << " (isrc, h, f, p);" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (::std::istream& is," << endl << "const " << string_type << "& sid," << endl << xerces_ns << "::DOMErrorHandler& h," << endl @@ -210,7 +206,7 @@ namespace CXX // InputSource. // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" @@ -230,14 +226,12 @@ namespace CXX << "h.throw_if_failed< ::xsd::cxx::tree::parsing< " << char_type << " > > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << error_handler << "& h," << endl << flags_type << " f," << endl @@ -256,15 +250,13 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << xerces_ns << "::InputSource& i," << endl << xerces_ns << "::DOMErrorHandler& h," << endl << flags_type << " f," << endl @@ -283,11 +275,9 @@ namespace CXX << "if (!d.get ())" << endl << "throw ::xsd::cxx::tree::parsing< " << char_type << " > ();" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "d, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}"; @@ -308,32 +298,30 @@ namespace CXX // const DOMDocument& // - os << "::std::auto_ptr< " << type << " >" << endl - << name << " (const " << xerces_ns << "::DOMDocument& d," << endl + os << auto_ptr << "< " << type << " >" << endl + << name << " (const " << xerces_ns << "::DOMDocument& doc," << endl << flags_type << " f," << endl << "const " << properties_type << "& p)" << "{" << "if (f & " << flags_type << "::keep_dom)" << "{" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument > c (" << endl + "::DOMDocument > d (" << endl << "static_cast< " << xerces_ns << - "::DOMDocument* > (d.cloneNode (true)));" + "::DOMDocument* > (doc.cloneNode (true)));" << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << "return " << auto_ptr << "< " << type << " > (" << endl << fq_name (e, "parser") << " (" << endl - << "c, f | " << flags_type << "::own_dom, p));" - << endl - << "return r;" + << d << ", f | " << flags_type << "::own_dom, p));" << "}" - << "const " << xerces_ns << "::DOMElement& e (*d.getDocumentElement ());" + << "const " << xerces_ns << "::DOMElement& e (*doc.getDocumentElement ());" << "const " << qname_type << " n (" << endl << "::xsd::cxx::xml::dom::name< " << char_type << " > (e));" << endl; if (poly) { - os << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::type_factory_map_instance< " << poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl @@ -343,7 +331,7 @@ namespace CXX << endl << "if (tmp.get () != 0)" << "{" - << "::std::auto_ptr< " << type << " > r (" << endl + << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl @@ -361,7 +349,7 @@ namespace CXX if (fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "new " << type << " (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type; @@ -376,7 +364,7 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type << " >::create (" << endl << "e, f, 0));"; @@ -394,11 +382,11 @@ namespace CXX << "}"; - // dom::auto_ptr + // dom::auto_ptr/unique_ptr // - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << name << " (" << dom_auto_ptr << "< " << xerces_ns << - "::DOMDocument >& d," << endl + "::DOMDocument > d," << endl << flags_type << " f," << endl << "const " << properties_type << "&)" << "{" @@ -425,7 +413,7 @@ namespace CXX if (poly) { - os << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + os << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::type_factory_map_instance< " << poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl @@ -444,7 +432,7 @@ namespace CXX if (fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "new " << type << " (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type; @@ -459,7 +447,7 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "::xsd::cxx::tree::traits< " << type << ", " << char_type << " >::create (" << endl << "e, f, 0));"; @@ -469,7 +457,7 @@ namespace CXX if (poly) { os << endl - << "::std::auto_ptr< " << type << " > r (" << endl + << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx index 4704fb3..05e47b5 100644 --- a/xsd/cxx/tree/stream-extraction-source.cxx +++ b/xsd/cxx/tree/stream-extraction-source.cxx @@ -337,6 +337,11 @@ namespace CXX // bool poly (polymorphic && polymorphic_p (t) && !anonymous_p (t)); + char const* r ( + (poly || !fund) && std >= cxx_version::cxx11 + ? "::std::move (r)" + : "r"); + if (max (e) != 1) { // sequence @@ -358,14 +363,14 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::stream_extraction_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().extract (" << endl @@ -385,11 +390,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << + os << auto_ptr << "< " << type << " > r (new " << type << " (s, f, this));"; } - os << "c.push_back (r);" + os << "c.push_back (" << r << ");" << "}" // while << "}" // if << "}"; @@ -407,14 +412,14 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::stream_extraction_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().extract (" << endl @@ -434,11 +439,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << + os << auto_ptr << "< " << type << " > r (new " << type << " (s, f, this));"; } - os << "this->" << member << ".set (r);" + os << "this->" << member << ".set (" << r << ");" << "}" // if (p) << "}"; } @@ -451,14 +456,14 @@ namespace CXX if (poly) { os << "bool d;" - << "::std::auto_ptr< " << type << " > r;" + << auto_ptr << "< " << type << " > r;" << "s >> d;" << endl << "if (!d)" << endl << "r.reset (new " << type << " (s, f, this));" << "else" << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::stream_extraction_map_instance< " << poly_plate << ", " << stream << ", " << char_type << " > ().extract (" << endl @@ -478,11 +483,11 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << + os << auto_ptr << "< " << type << " > r (new " << type << " (s, f, this));"; } - os << "this->" << member << ".set (r);" + os << "this->" << member << ".set (" << r << ");" << "}"; } } @@ -526,9 +531,8 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));" - << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << auto_ptr << "< " << + type << " > (new " << type << " (s, f, this)));"; } os << "}" // if (p) @@ -546,9 +550,8 @@ namespace CXX } else { - os << "::std::auto_ptr< " << type << " > r (new " << type << - " (s, f, this));" - << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << auto_ptr << "< " << + type << " > (new " << type << " (s, f, this)));"; } os << "}"; diff --git a/xsd/cxx/tree/tree-header.cxx b/xsd/cxx/tree/tree-header.cxx index 4024bc3..56bf932 100644 --- a/xsd/cxx/tree/tree-header.cxx +++ b/xsd/cxx/tree/tree-header.cxx @@ -1250,7 +1250,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } } @@ -1339,7 +1339,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } @@ -1363,7 +1363,7 @@ namespace CXX << " */" << endl; } - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << edname (m) << " ();" << endl; } @@ -2506,7 +2506,7 @@ namespace CXX inherits (c, inherits_member_); os << "&"; { - FromBaseCtorArg args (*this, FromBaseCtorArg::arg_type, false); + FromBaseCtorArg args (*this, CtorArgType::type, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2525,7 +2525,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2538,7 +2538,7 @@ namespace CXX os << "&"; { FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_complex_auto_ptr, false); + *this, CtorArgType::complex_auto_ptr, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2559,7 +2559,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2572,7 +2572,7 @@ namespace CXX os << "&"; { FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_poly_auto_ptr, false); + *this, CtorArgType::poly_auto_ptr, false); Traversal::Names args_names (args); names (c, args_names); } @@ -2598,7 +2598,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, true); + *this, CtorArgType::type, false, true); ctor_args.dispatch (c); } os << ");" @@ -2616,7 +2616,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from initializers " << "for required " << endl - << " * elements and attributes (auto_ptr version)." << endl + << " * elements and attributes (" << auto_ptr << + " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2627,7 +2628,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_complex_auto_ptr, false, true); + *this, CtorArgType::complex_auto_ptr, false, true); ctor_args.dispatch (c); } os << ");" @@ -2645,7 +2646,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from initializers " << "for required " << endl - << " * elements and attributes (auto_ptr version)." << endl + << " * elements and attributes (" << auto_ptr << + " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2656,7 +2658,7 @@ namespace CXX os << name << " ("; { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_poly_auto_ptr, false, true); + *this, CtorArgType::poly_auto_ptr, false, true); ctor_args.dispatch (c); } os << ");" @@ -2687,7 +2689,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2710,7 +2712,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2732,7 +2734,7 @@ namespace CXX { CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, false, false); + *this, CtorArgType::type, false, false); ctor_args.dispatch (c); } @@ -2756,7 +2758,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_type); + CtorArgs ctor_args (*this, CtorArgType::type); ctor_args.dispatch (c); } @@ -2775,7 +2777,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2786,7 +2788,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_complex_auto_ptr); + CtorArgs ctor_args (*this, CtorArgType::complex_auto_ptr); ctor_args.dispatch (c); } @@ -2806,7 +2808,7 @@ namespace CXX "base and" << endl << " * initializers for required elements and " << "attributes" << endl - << " * (auto_ptr version)." << endl + << " * (" << auto_ptr << " version)." << endl << " *" << endl << " * This constructor will try to use the passed " << "values directly" << endl @@ -2817,7 +2819,7 @@ namespace CXX os << name << " ("; { - CtorArgs ctor_args (*this, CtorArgs::arg_poly_auto_ptr); + CtorArgs ctor_args (*this, CtorArgType::poly_auto_ptr); ctor_args.dispatch (c); } @@ -3326,7 +3328,7 @@ namespace CXX } os << "void" << endl - << mname << " (::std::auto_ptr< " << type << " > p);" + << mname << " (" << auto_ptr << "< " << type << " > p);" << endl; } @@ -3348,7 +3350,7 @@ namespace CXX << " */" << endl; } - os << "::std::auto_ptr< " << type << " >" << endl + os << auto_ptr << "< " << type << " >" << endl << edname (e) << " ();" << endl; } @@ -3455,7 +3457,8 @@ namespace CXX os << "/**" << endl << " * @brief Create an instance from an initializer " << "for" << endl - << " * the element value (auto_ptr version)." << endl + << " * the element value (" << auto_ptr << + " version)." << endl << " *" << endl << " * @param p Element value to use." << endl << " *" << endl @@ -3465,7 +3468,7 @@ namespace CXX << " */" << endl; } - os << name << " (::std::auto_ptr< " << type << " > p);" + os << name << " (" << auto_ptr << "< " << type << " > p);" << endl; } @@ -3802,10 +3805,14 @@ namespace CXX { bool inline_ (ctx.options.generate_inline ()); - ctx.os << "#include // std::auto_ptr" << endl + ctx.os << "#include // " << ctx.auto_ptr << endl << "#include // std::numeric_limits" << endl - << "#include // std::binary_search" << endl - << endl; + << "#include // std::binary_search" << endl; + + if (ctx.std >= cxx_version::cxx11) + ctx.os << "#include // std::move" << endl; + + ctx.os << endl; if (ctx.char_type == L"char" && ctx.char_encoding != L"custom") { diff --git a/xsd/cxx/tree/tree-inline.cxx b/xsd/cxx/tree/tree-inline.cxx index 0641a4d..0c64650 100644 --- a/xsd/cxx/tree/tree-inline.cxx +++ b/xsd/cxx/tree/tree-inline.cxx @@ -537,9 +537,10 @@ namespace CXX if (!fund) os << inl << "void " << scope_ << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > x)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "this->" << member << ".set (x);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; } else @@ -589,9 +590,10 @@ namespace CXX if (!fund) os << inl << "void " << scope_ << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > x)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "this->" << member << ".set (x);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; // auto_ptr @@ -599,7 +601,7 @@ namespace CXX // if (detach && !fund) os << inl - << "::std::auto_ptr< " << q_type << " > " << + << auto_ptr << "< " << q_type << " > " << scope_ << "::" << endl << edname (m) << " ()" << "{" @@ -976,7 +978,7 @@ namespace CXX << "void " << name << "::" << endl << mname << " (const " << type << "& x)" << "{" - << "return this->" << member << ".set (x);" + << "this->" << member << ".set (x);" << "}"; // void @@ -986,9 +988,10 @@ namespace CXX { os << inl << "void " << name << "::" << endl - << mname << " (::std::auto_ptr< " << type << " > p)" + << mname << " (" << auto_ptr << "< " << type << " > x)" << "{" - << "return this->" << member << ".set (p);" + << "this->" << member << ".set (" << + (std >= cxx_version::cxx11 ? "std::move (x)" : "x") << ");" << "}"; } @@ -997,7 +1000,7 @@ namespace CXX // if (detach && !fund) os << inl - << "::std::auto_ptr< " << name << "::" << type << " > " << + << auto_ptr << "< " << name << "::" << type << " > " << name << "::" << endl << edname (e) << " ()" << "{" diff --git a/xsd/cxx/tree/tree-source.cxx b/xsd/cxx/tree/tree-source.cxx index 8f41a37..423f3bf 100644 --- a/xsd/cxx/tree/tree-source.cxx +++ b/xsd/cxx/tree/tree-source.cxx @@ -721,7 +721,7 @@ namespace CXX if (poly) { os << "{" - << "::std::auto_ptr< ::xsd::cxx::tree::type > tmp (" << endl + << auto_ptr << "< ::xsd::cxx::tree::type > tmp (" << endl << "::xsd::cxx::tree::type_factory_map_instance< " << poly_plate << ", " << char_type << " > ().create (" << endl << strlit (e.name ()) << "," << endl @@ -753,7 +753,7 @@ namespace CXX if (!fund) { - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << tr << "::create (i, f, this));" << endl; } @@ -793,7 +793,7 @@ namespace CXX { // Cast to static type. // - os << "::std::auto_ptr< " << type << " > r (" << endl + os << auto_ptr << "< " << type << " > r (" << endl << "dynamic_cast< " << type << "* > (tmp.get ()));" << endl << "if (r.get ())" << endl @@ -804,23 +804,25 @@ namespace CXX << endl; } + char const* r (std >= cxx_version::cxx11 ? "::std::move (r)" : "r"); + if (max (e) != 1) { // sequence // - os << "this->" << member << ".push_back (r);"; + os << "this->" << member << ".push_back (" << r << ");"; } else if (min (e) == 0) { // optional // - os << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << r << ");"; } else { // one // - os << "this->" << member << ".set (r);"; + os << "this->" << member << ".set (" << r << ");"; } } else @@ -1096,26 +1098,8 @@ namespace CXX << "{"; } - bool fund (false); - { - IsFundamentalType traverser (fund); - traverser.dispatch (a.type ()); - } - - if (fund) - { - os << "this->" << member << ".set (" << tr << - "::create (i, f, this));"; - } - else - { - String type (etype (a)); - - os << "::std::auto_ptr< " << type << " > r (" << endl - << tr << "::create (i, f, this));" - << endl - << "this->" << member << ".set (r);"; - } + os << "this->" << member << ".set (" << tr << + "::create (i, f, this));"; os << "continue;" << "}"; @@ -1259,33 +1243,31 @@ namespace CXX Traversal::Type, Context { - // If base_arg is empty then no base argument is - // generated. + // If base_arg is empty then no base argument is generated. // - CtorBase (Context& c, String const& base_arg) - : Context (c), base_arg_ (base_arg) + CtorBase (Context& c, CtorArgType at, String const& base_arg) + : Context (c), args_ (c, at, base_arg) { } virtual void traverse (SemanticGraph::Type&) { - if (base_arg_) - os << base_arg_; + if (args_.base_arg_) + os << args_.base_arg_; } virtual void traverse (SemanticGraph::Enumeration&) { - if (base_arg_) - os << base_arg_; + if (args_.base_arg_) + os << args_.base_arg_; } void traverse (SemanticGraph::Complex& c) { - Args args (*this, base_arg_); - args.traverse (c); + args_.traverse (c); } private: @@ -1300,8 +1282,9 @@ namespace CXX Traversal::Attribute, Context { - Args (Context& c, String const& base_arg) - : Context (c), base_arg_ (base_arg), first_ (true) + Args (Context& c, CtorArgType at, String const& base_arg) + : Context (c), + arg_type_ (at), base_arg_ (base_arg), first_ (true) { *this >> inherits_ >> *this; *this >> names_ >> *this; @@ -1342,7 +1325,32 @@ namespace CXX { // one // - os << comma () << ename (e); + bool move (false); + + if (std >= cxx_version::cxx11) + { + switch (arg_type_) + { + case CtorArgType::complex_auto_ptr: + { + bool simple (true); + IsSimpleType t (simple); + t.dispatch (e.type ()); + move = !simple; + break; + } + case CtorArgType::poly_auto_ptr: + { + move = polymorphic && polymorphic_p (e.type ()); + break; + } + case CtorArgType::type: + break; + } + } + + os << comma () << (move ? "std::move (" : "") << ename (e) << + (move ? ")" : ""); } } @@ -1371,15 +1379,18 @@ namespace CXX return tmp ? "" : ",\n"; } - private: + public: + CtorArgType arg_type_; String base_arg_; + + private: bool first_; Traversal::Inherits inherits_; Traversal::Names names_; }; - String base_arg_; + Args args_; }; @@ -1387,8 +1398,8 @@ namespace CXX Traversal::Attribute, Context { - CtorMember (Context& c) - : Context (c) + CtorMember (Context& c, CtorArgType at) + : Context (c), arg_type_ (at) { } @@ -1418,8 +1429,33 @@ namespace CXX { // one // + bool move (false); + + if (std >= cxx_version::cxx11) + { + switch (arg_type_) + { + case CtorArgType::complex_auto_ptr: + { + bool simple (true); + IsSimpleType t (simple); + t.dispatch (e.type ()); + move = !simple; + break; + } + case CtorArgType::poly_auto_ptr: + { + move = polymorphic && polymorphic_p (e.type ()); + break; + } + case CtorArgType::type: + break; + } + } + os << "," << endl - << " " << member << " (" << ename (e) << ", this)"; + << " " << member << " (" << (move ? "std::move (" : "") << + ename (e) << (move ? ")" : "") << ", this)"; } } @@ -1458,6 +1494,9 @@ namespace CXX } } } + + private: + CtorArgType arg_type_; }; struct CtorAny: Traversal::Any, @@ -2134,7 +2173,7 @@ namespace CXX default_ctor_any_init_ (c), default_ctor_member_init_ (c), ctor_any_ (c), - ctor_member_ (c), + ctor_member_ (c, CtorArgType::type), element_ctor_any_ (c), element_ctor_member_ (c), assign_any_ (c), @@ -2184,6 +2223,8 @@ namespace CXX virtual void traverse (Type& c) { + bool gen_wildcard (options.generate_wildcard ()); + String name (ename (c)); // If renamed name is empty then we do not need to generate @@ -2348,7 +2389,7 @@ namespace CXX inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args (*this, FromBaseCtorArg::arg_type, true); + FromBaseCtorArg args (*this, CtorArgType::type, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2375,13 +2416,14 @@ namespace CXX // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + os << name << "::" << endl << name << " (const "; inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_complex_auto_ptr, true); + FromBaseCtorArg args (*this, at, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2396,7 +2438,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2410,13 +2460,14 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + os << name << "::" << endl << name << " (const "; inherits (c, inherits_member_); os << "& " << base_arg; { - FromBaseCtorArg args ( - *this, FromBaseCtorArg::arg_poly_auto_ptr, true); + FromBaseCtorArg args (*this, at, true); Traversal::Names args_names (args); names (c, args_names); } @@ -2431,7 +2482,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2445,17 +2504,18 @@ namespace CXX // if (generate_no_base_ctor) { + CtorArgType const at (CtorArgType::type); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2483,17 +2543,18 @@ namespace CXX // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_complex_auto_ptr, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2508,7 +2569,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2522,17 +2591,18 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + os << name << "::" << endl << name << " ("; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_poly_auto_ptr, true, true); + CtorArgsWithoutBase ctor_args (*this, at, true, true); ctor_args.dispatch (c); } os << ")" << endl << ": " << base << " ("; { - CtorBase base (*this, ""); + CtorBase base (*this, at, ""); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2547,7 +2617,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2564,6 +2642,7 @@ namespace CXX { // c-tor (enum-value, all-non-optional-members) // + CtorArgType const at (CtorArgType::type); String base_arg (L"_xsd_" + ename (*enum_base) + L"_base"); os << name << "::" << endl @@ -2571,8 +2650,7 @@ namespace CXX evalue (*enum_base) << " " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2580,7 +2658,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2604,6 +2682,7 @@ namespace CXX os << "}"; } + CtorArgType const at (CtorArgType::type); String base_arg (L"_xsd_" + ename (ultimate_base (c)) + L"_base"); // c-tor (const char*, all-non-optional-members) @@ -2612,8 +2691,7 @@ namespace CXX << name << " (const " << char_type << "* " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2621,7 +2699,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2651,8 +2729,7 @@ namespace CXX << name << " (const " << string_type << "& " << base_arg; { - CtorArgsWithoutBase ctor_args ( - *this, CtorArgsWithoutBase::arg_type, true, false); + CtorArgsWithoutBase ctor_args (*this, at, true, false); ctor_args.dispatch (c); } @@ -2660,7 +2737,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2686,57 +2763,60 @@ namespace CXX // c-tor (ultimate-base, all-non-optional-members) // + { + CtorArgType const at (CtorArgType::type); - os << name << "::" << endl - << name << " ("; + os << name << "::" << endl + << name << " ("; - String base_arg; + String base_arg; - { - CtorArgs ctor_args (*this, CtorArgs::arg_type, base_arg); - ctor_args.dispatch (c); - } + { + CtorArgs ctor_args (*this, at, base_arg); + ctor_args.dispatch (c); + } - os << ")" << endl - << ": " << base << " ("; + os << ")" << endl + << ": " << base << " ("; - { - CtorBase base (*this, base_arg); - Traversal::Inherits inherits_base (base); + { + CtorBase base (*this, at, base_arg); + Traversal::Inherits inherits_base (base); - inherits (c, inherits_base); - } + inherits (c, inherits_base); + } - os << ")"; + os << ")"; - if (edom_document_member_p (c)) - { - os << "," << endl - << " " << edom_document_member (c) << " (" << - "::xsd::cxx::xml::dom::create_document< " << char_type << - " > ())"; - } + if (edom_document_member_p (c)) + { + os << "," << endl + << " " << edom_document_member (c) << " (" << + "::xsd::cxx::xml::dom::create_document< " << char_type << + " > ())"; + } - names (c, ctor_names_); + names (c, ctor_names_); - os << "{"; - if (facets) - os << "this->_facet_table (_xsd_" << name << "_facet_table);"; - os << "}"; + os << "{"; + if (facets) + os << "this->_facet_table (_xsd_" << name << "_facet_table);"; + os << "}"; + } // If we have any complex arguments in the previous c-tor // then also generate the auto_ptr version. // if (has_complex_non_op_args) { + CtorArgType const at (CtorArgType::complex_auto_ptr); + String base_arg; + os << name << "::" << endl << name << " ("; - String base_arg; - { - CtorArgs ctor_args ( - *this, CtorArgs::arg_complex_auto_ptr, base_arg); + CtorArgs ctor_args (*this, at, base_arg); ctor_args.dispatch (c); } @@ -2744,7 +2824,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2760,7 +2840,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2774,14 +2862,14 @@ namespace CXX if (polymorphic && has_poly_non_op_args && !complex_poly_args_clash) { + CtorArgType const at (CtorArgType::poly_auto_ptr); + String base_arg; + os << name << "::" << endl << name << " ("; - String base_arg; - { - CtorArgs ctor_args ( - *this, CtorArgs::arg_poly_auto_ptr, base_arg); + CtorArgs ctor_args (*this, at, base_arg); ctor_args.dispatch (c); } @@ -2789,7 +2877,7 @@ namespace CXX << ": " << base << " ("; { - CtorBase base (*this, base_arg); + CtorBase base (*this, at, base_arg); Traversal::Inherits inherits_base (base); inherits (c, inherits_base); @@ -2805,7 +2893,15 @@ namespace CXX " > ())"; } - names (c, ctor_names_); + { + CtorMember t (*this, at); + Traversal::Names n (t); + + if (gen_wildcard) + n >> ctor_any_; + + names (c, n); + } os << "{"; if (facets) @@ -2838,7 +2934,7 @@ namespace CXX names >> copy_member; - if (options.generate_wildcard ()) + if (gen_wildcard) names >> copy_any; Complex::names (c, names); @@ -2857,8 +2953,6 @@ namespace CXX bool ha (has (c)); bool haa (has (c)); - bool gen_wildcard (options.generate_wildcard ()); - // // if (!options.suppress_parsing ()) @@ -3291,7 +3385,7 @@ namespace CXX if (!simple || (polymorphic && polymorphic_p (t))) { os << name << "::" << endl - << name << " (::std::auto_ptr< " << type << " > p)" << endl + << name << " (" << auto_ptr << "< " << type << " > p)" << endl << ": " << member << " (p, 0)" << "{" << "}"; -- cgit v1.1