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 --- doc/cxx/tree/guide/index.xhtml | 80 ++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 23 deletions(-) (limited to 'doc/cxx/tree/guide/index.xhtml') diff --git a/doc/cxx/tree/guide/index.xhtml b/doc/cxx/tree/guide/index.xhtml index 7d2ac54..df54d1f 100644 --- a/doc/cxx/tree/guide/index.xhtml +++ b/doc/cxx/tree/guide/index.xhtml @@ -226,10 +226,11 @@ 3Overall Mapping Configuration - - - - + + + + +
3.1Character Type and Encoding
3.2Support for Polymorphism
3.3Namespace Mapping
3.4Thread Safety
3.1C++ Standard
3.2Character Type and Encoding
3.3Support for Polymorphism
3.4Namespace Mapping
3.5Thread Safety
@@ -621,8 +622,29 @@ hello (std::istream&); global element in XML Schema is a valid document root. By default XSD generated a set of parsing functions for each global element defined in XML Schema (this can be overridden - with the --root-element-* options). For more - information on parsing functions see Chapter 5, + with the --root-element-* options). Parsing + functions return a dynamically allocated object model as an + automatic pointer. The actual pointer used depends on the + C++ standard selected. For C++98 it is std::auto_ptr + as shown above. For C++11 it is std::unique_ptr. + For example, if we modify our XSD compiler invocation to + select C++11:

+ +
+$ xsd cxx-tree --std c++11 hello.xsd
+  
+ +

Then the parsing function signatures will become:

+ +
+std::unique_ptr<hello_t>
+hello (const std::string& uri);
+
+std::unique_ptr<hello_t>
+hello (std::istream&);
+  
+ +

For more information on parsing functions see Chapter 5, "Parsing".

2.3 Implementing Application Logic

@@ -1134,16 +1156,25 @@ $ doxygen hello.doxygen determine the overall properties and behavior of the generated code. Configuration parameters are specified with the XSD command line options. This chapter describes configuration aspects that are most - commonly encountered by application developers. These include: - the character type that is used by the generated code, handling of - vocabularies that use XML Schema polymorphism, XML Schema to C++ - namespace mapping, and thread safety. For more ways to configure + commonly encountered by application developers. These include: the + C++ standard, the character type that is used by the generated code, + handling of vocabularies that use XML Schema polymorphism, XML Schema + to C++ namespace mapping, and thread safety. For more ways to configure the generated code refer to the XSD Compiler Command Line Manual.

-

3.1 Character Type and Encoding

+

3.1 C++ Standard

+ +

The C++/Tree mapping provides support for ISO/IEC C++ 1998/2003 (C++98) + and ISO/IEC C++ 2011 (C++11). To select the C++ standard for the + generated code we use the --std XSD compiler command + line option. While the majority of the examples in this guide use + C++98, support for the new functionality and library components + introduced in C++11 are discussed throughout the document.

+ +

3.2 Character Type and Encoding

The C++/Tree mapping has built-in support for two character types: char and wchar_t. You can select the @@ -1174,7 +1205,7 @@ $ doxygen hello.doxygen all three (object mode, input XML, and output XML) can have different encodings.

-

3.2 Support for Polymorphism

+

3.3 Support for Polymorphism

By default XSD generates non-polymorphic code. If your vocabulary uses XML Schema polymorphism in the form of xsi:type @@ -1186,7 +1217,7 @@ $ doxygen hello.doxygen "Mapping for xsi:type and Substitution Groups" in the C++/Tree Mapping User Manual.

-

3.3 Namespace Mapping

+

3.4 Namespace Mapping

XSD maps XML namespaces specified in the targetNamespace attribute in XML Schema to one or more nested C++ namespaces. By @@ -1213,7 +1244,7 @@ $ doxygen hello.doxygen --namespace-map =cs -

3.4 Thread Safety

+

3.5 Thread Safety

XSD-generated code is thread-safe in the sense that you can use different instantiations of the object model in several @@ -1829,7 +1860,7 @@ ps.push_back (jane); of the passed objects:

-// Add the John Doe record.
+// Add the John Doe record. C++98 version.
 //
 auto_ptr<person_t> john_p (
   new person_t ("John",           // first-name
@@ -1839,15 +1870,15 @@ auto_ptr<person_t> john_p (
                 1));
 ps.push_back (john_p); // assumes ownership
 
-// Add the Jane Doe record.
+// Add the Jane Doe record. C++11 version
 //
-auto_ptr<person_t> jane_p (
+unique_ptr<person_t> jane_p (
   new person_t ("Jane",           // first-name
                 "Doe",            // last-name
                 gender_t::female, // gender
                 28,               // age
                 2));              // id
-ps.push_back (jane_p); // assumes ownership
+ps.push_back (std::move (jane_p)); // assumes ownership
   

For more information on the non-copying modifier functions refer to @@ -2221,17 +2252,17 @@ ps.push_back (jane_p); // assumes ownership on the following three parsing functions:

-std::auto_ptr<people_t>
+std::[auto|unique]_ptr<people_t>
 people (const std::string& uri,
 	xml_schema::flags f = 0,
 	const xml_schema::properties& p = xml_schema::properties ());
 
-std::auto_ptr<people_t>
+std::[auto|unique]_ptr<people_t>
 people (std::istream& is,
         xml_schema::flags f = 0,
         const xml_schema::properties& p = xml_schema::properties ());
 
-std::auto_ptr<people_t>
+std::[auto|unique]_ptr<people_t>
 people (std::istream& is,
         const std::string& resource_id,
         xml_schema::flags f = 0,
@@ -2251,8 +2282,11 @@ people (std::istream& is,
      to fine-tune the parsing process. The properties argument allows
      to pass additional information to the parsing functions. We will
      use these two arguments in Section 5.1, "XML Schema
-     Validation and Searching" below. The following example shows
-     how we can use the above parsing functions:

+ Validation and Searching" below. All three functions return + the object model as either std::auto_ptr (C++98) or + std::unique_ptr (C++11), depending on the C++ standard + selected (--std XSD compiler option). The following + example shows how we can use the above parsing functions:

 using std::auto_ptr;
-- 
cgit v1.1