From 0fdf19714613a82a184f4f6e75fb9a4f9b62f18a Mon Sep 17 00:00:00 2001
From: Boris Kolpackov
@@ -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 3 Overall Mapping Configuration
-
- 3.1 Character Type and Encoding
- 3.2 Support for Polymorphism
- 3.3 Namespace Mapping
+ 3.4 Thread Safety
+ 3.1 C++ Standard
+ 3.2 Character Type and Encoding
+ 3.3 Support for Polymorphism
+ 3.4 Namespace Mapping 3.5 Thread Safety --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".
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.
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.
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.
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
-
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 eitherstd::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