From 5e527213a2430bb3018e5eebd909aef294edf9b5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- xsd-examples/cxx/tree/polymorphism/.gitignore | 1 + xsd-examples/cxx/tree/polymorphism/README | 32 ++++++++++++++ xsd-examples/cxx/tree/polymorphism/buildfile | 26 +++++++++++ xsd-examples/cxx/tree/polymorphism/driver.cxx | 59 +++++++++++++++++++++++++ xsd-examples/cxx/tree/polymorphism/supermen.xml | 25 +++++++++++ xsd-examples/cxx/tree/polymorphism/supermen.xsd | 48 ++++++++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 xsd-examples/cxx/tree/polymorphism/.gitignore create mode 100644 xsd-examples/cxx/tree/polymorphism/README create mode 100644 xsd-examples/cxx/tree/polymorphism/buildfile create mode 100644 xsd-examples/cxx/tree/polymorphism/driver.cxx create mode 100644 xsd-examples/cxx/tree/polymorphism/supermen.xml create mode 100644 xsd-examples/cxx/tree/polymorphism/supermen.xsd (limited to 'xsd-examples/cxx/tree/polymorphism') diff --git a/xsd-examples/cxx/tree/polymorphism/.gitignore b/xsd-examples/cxx/tree/polymorphism/.gitignore new file mode 100644 index 0000000..f2e9b04 --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/.gitignore @@ -0,0 +1 @@ +supermen.?xx diff --git a/xsd-examples/cxx/tree/polymorphism/README b/xsd-examples/cxx/tree/polymorphism/README new file mode 100644 index 0000000..6e54e49 --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/README @@ -0,0 +1,32 @@ +This example shows how to use XML Schema polymorphism features such as +xsi:type attributes and substitution groups in the C++/Tree mapping. + +The example consists of the following files: + +supermen.xsd + XML Schema which describes the "supermen" instance documents. + +supermen.xml + Sample XML instance document. + +supermen.hxx +supermen.cxx + C++ types that represent the given vocabulary, a set of parsing + functions that convert XML instance documents to a tree-like in-memory + object model, and a set of serialization functions that convert the + object model back to XML. These are generated by XSD from supermen.xsd. + Note also that we use the --generate-polymorphic command line option + and that we don't need to use --polymorphic-type to explicitly mark + types as polymorphic because this is automatically deduced by the + XSD compiler from the substitution groups used in the supermen.xsd + schema. + +driver.cxx + Driver for the example. It first calls one of the parsing functions + that constructs the object model from the input file. It then prints + the content of the object model to STDERR. Finally, the driver serializes + the object model back to XML. + +To run the example on the sample XML instance document simply execute: + +$ ./driver instance.xml diff --git a/xsd-examples/cxx/tree/polymorphism/buildfile b/xsd-examples/cxx/tree/polymorphism/buildfile new file mode 100644 index 0000000..754c6c2 --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/buildfile @@ -0,0 +1,26 @@ +# file : cxx/tree/polymorphism/buildfile +# license : not copyrighted - public domain + +import libs = libxsd%lib{xsd} +import libs += libxerces-c%lib{xerces-c} + +./: exe{driver} doc{README} + +exe{driver}: {hxx cxx}{* -supermen} {hxx ixx cxx}{supermen} $libs + +exe{driver}: xml{supermen}: test.input = true + +<{hxx ixx cxx}{supermen}>: xsd{supermen} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree --std c++11 \ + --generate-inline \ + --generate-polymorphic \ + --generate-serialization \ + --root-element-last \ + --output-dir $out_base \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" diff --git a/xsd-examples/cxx/tree/polymorphism/driver.cxx b/xsd-examples/cxx/tree/polymorphism/driver.cxx new file mode 100644 index 0000000..6458170 --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/driver.cxx @@ -0,0 +1,59 @@ +// file : cxx/tree/polymorphism/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include "supermen.hxx" + +using std::cerr; +using std::endl; +using std::unique_ptr; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " supermen.xml" << endl; + return 1; + } + + try + { + unique_ptr sm (supermen_ (argv[1])); + + supermen copy (*sm); // Dynamic types are preserved in copies. + + // Print what we've got. + // + for (supermen::person_const_iterator i (copy.person ().begin ()); + i != copy.person ().end (); + ++i) + { + cerr << i->name (); + + if (const superman* s = dynamic_cast (&*i)) + { + if (s->can_fly ()) + cerr << ", flying superman"; + else + cerr << ", superman"; + } + + cerr << endl; + } + + // Serialize back to XML. + // + xml_schema::namespace_infomap map; + map[""].schema = "supermen.xsd"; + + supermen_ (std::cout, copy, map); + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd-examples/cxx/tree/polymorphism/supermen.xml b/xsd-examples/cxx/tree/polymorphism/supermen.xml new file mode 100644 index 0000000..08430fa --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/supermen.xml @@ -0,0 +1,25 @@ + + + + + + + + John Doe + + + + James "007" Bond + + + + Bruce Wayne + + + diff --git a/xsd-examples/cxx/tree/polymorphism/supermen.xsd b/xsd-examples/cxx/tree/polymorphism/supermen.xsd new file mode 100644 index 0000000..cf5ff0c --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/supermen.xsd @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1