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/custom/taxonomy/.gitignore | 2 + xsd-examples/cxx/tree/custom/taxonomy/README | 53 +++++++ xsd-examples/cxx/tree/custom/taxonomy/buildfile | 31 ++++ xsd-examples/cxx/tree/custom/taxonomy/driver.cxx | 38 +++++ .../cxx/tree/custom/taxonomy/people-custom-fwd.hxx | 19 +++ .../cxx/tree/custom/taxonomy/people-custom.cxx | 156 +++++++++++++++++++++ .../cxx/tree/custom/taxonomy/people-custom.hxx | 105 ++++++++++++++ xsd-examples/cxx/tree/custom/taxonomy/people.xml | 26 ++++ xsd-examples/cxx/tree/custom/taxonomy/people.xsd | 44 ++++++ 9 files changed, 474 insertions(+) create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/.gitignore create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/README create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/buildfile create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/driver.cxx create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/people-custom-fwd.hxx create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/people-custom.cxx create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/people-custom.hxx create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/people.xml create mode 100644 xsd-examples/cxx/tree/custom/taxonomy/people.xsd (limited to 'xsd-examples/cxx/tree/custom/taxonomy') diff --git a/xsd-examples/cxx/tree/custom/taxonomy/.gitignore b/xsd-examples/cxx/tree/custom/taxonomy/.gitignore new file mode 100644 index 0000000..71428ab --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/.gitignore @@ -0,0 +1,2 @@ +people.?xx +people-fwd.hxx diff --git a/xsd-examples/cxx/tree/custom/taxonomy/README b/xsd-examples/cxx/tree/custom/taxonomy/README new file mode 100644 index 0000000..c2e425a --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/README @@ -0,0 +1,53 @@ +This example shows how to map user-defined XML Schema types to custom C++ +classes. It presents the complex case where the customized types are +inherited from in the same schema. For the simple case see the contacts +example. For more information on the C++/Tree mapping customization see +the C++/Tree Mapping Customization Guide[1]. + +[1] http://wiki.codesynthesis.com/Tree/Customization_guide + +The example consists of the following files: + +people.xsd + XML Schema definition for a simple people database. + +people.xml + Sample XML instance document. + +people-fwd.hxx +people.hxx +people.ixx +people.cxx + C++ types that represent the given vocabulary and a set of parsing + functions that convert XML instance documents to a tree-like in-memory + object model. These are generated by XSD from people.xsd with the + --custom-type option in order to customize the person, superman, and + batman types. Generation of the people-fwd.hxx forward declaration + file is requested with the --generate-forward option. Note also that + we use the --generate-polymorphic command line option as well as + --polymorphic-type to mark the type hierarchy starting with the + person type as polymorphic. + +people-custom-fwd.hxx + Header file which forward-declares our own person, superman, and batman + as class templates. It is included at the beginning of people-fwd.hxx + using the --fwd-prologue option. + +people-custom.hxx + Header file which defines our own person, superman, and batman class + templates by inheriting from the generated person_base, superman_base, + and batman_base. It is included at the beginning of people.hxx using + the --hxx-prologue option. + +people-custom.cxx + Source file which contains the implementations and instantiations of + our person, superman, and batman class templates. + +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 database to STDERR. + +To run the example on the sample XML instance document simply execute: + +$ ./driver people.xml diff --git a/xsd-examples/cxx/tree/custom/taxonomy/buildfile b/xsd-examples/cxx/tree/custom/taxonomy/buildfile new file mode 100644 index 0000000..9267c68 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/buildfile @@ -0,0 +1,31 @@ +# file : cxx/tree/custom/taxonomy/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}{* -people} {hxx ixx cxx}{people} hxx{people-fwd} $libs + +exe{driver}: xml{people}: test.input = true + +<{hxx ixx cxx}{people} hxx{people-fwd}>: xsd{people} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree --std c++11 \ + --generate-inline \ + --generate-forward \ + --generate-polymorphic \ + --polymorphic-type person \ + --custom-type "person=person_impl/person_base" \ + --custom-type "superman=superman_impl/superman_base" \ + --custom-type "batman=batman_impl/batman_base" \ + --fwd-prologue '#include "people-custom-fwd.hxx"' \ + --hxx-prologue '#include "people-custom.hxx"' \ + --output-dir $out_base \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" diff --git a/xsd-examples/cxx/tree/custom/taxonomy/driver.cxx b/xsd-examples/cxx/tree/custom/taxonomy/driver.cxx new file mode 100644 index 0000000..f719bbb --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/driver.cxx @@ -0,0 +1,38 @@ +// file : cxx/tree/custom/taxonomy/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include "people.hxx" + +using std::cerr; +using std::endl; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " people.xml" << endl; + return 1; + } + + try + { + using namespace people; + + std::unique_ptr c (catalog_ (argv[1])); + + for (catalog::person_const_iterator i (c->person ().begin ()); + i != c->person ().end (); ++i) + { + i->print (cerr); + } + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/xsd-examples/cxx/tree/custom/taxonomy/people-custom-fwd.hxx b/xsd-examples/cxx/tree/custom/taxonomy/people-custom-fwd.hxx new file mode 100644 index 0000000..1b59a54 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/people-custom-fwd.hxx @@ -0,0 +1,19 @@ +// file : cxx/tree/custom/taxonomy/people-custom-fwd.hxx +// copyright : not copyrighted - public domain + +// Do not include this file directly, use people-fwd.hxx instead. This +// file is included into generated people-fwd.hxx so we do not need to +// guard against multiple inclusions. +// + +namespace people +{ + template + class person_impl; + + template + class superman_impl; + + template + class batman_impl; +} diff --git a/xsd-examples/cxx/tree/custom/taxonomy/people-custom.cxx b/xsd-examples/cxx/tree/custom/taxonomy/people-custom.cxx new file mode 100644 index 0000000..decc847 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/people-custom.cxx @@ -0,0 +1,156 @@ +// file : cxx/tree/custom/taxonomy/people-custom.cxx +// copyright : not copyrighted - public domain + +#include + +// Include people.hxx instead of people-custom.hxx here. +// +#include "people.hxx" + +namespace people +{ + // person_impl + // + template + person_impl:: + person_impl (const xml_schema::string& name) + : base (name) + { + } + + template + person_impl:: + person_impl (const xercesc::DOMElement& e, + xml_schema::flags f, + xml_schema::container* c) + : base (e, f, c) + { + } + + template + person_impl:: + person_impl (const person_impl& p, + xml_schema::flags f, + xml_schema::container* c) + : base (p, f, c) + { + } + + template + person_impl* person_impl:: + _clone (xml_schema::flags f, xml_schema::container* c) const + { + return new person_impl (*this, f, c); + } + + template + void person_impl:: + print (std::ostream& os) const + { + os << this->name () << std::endl; + } + + // Explicitly instantiate person_impl class template for person_base. + // + template class person_impl; + + + // superman_impl + // + template + superman_impl:: + superman_impl (const xml_schema::string& name, bool can_fly) + : base (name, can_fly) + { + } + + template + superman_impl:: + superman_impl (const xercesc::DOMElement& e, + xml_schema::flags f, + xml_schema::container* c) + : base (e, f, c) + { + } + + template + superman_impl:: + superman_impl (const superman_impl& s, + xml_schema::flags f, + xml_schema::container* c) + : base (s, f, c) + { + } + + template + superman_impl* superman_impl:: + _clone (xml_schema::flags f, xml_schema::container* c) const + { + return new superman_impl (*this, f, c); + } + + template + void superman_impl:: + print (std::ostream& os) const + { + if (this->can_fly ()) + os << "Flying superman "; + else + os << "Superman "; + + os << this->name () << std::endl; + } + + // Explicitly instantiate superman_impl class template for superman_base. + // + template class superman_impl; + + + // batman_impl + // + template + batman_impl:: + batman_impl (const xml_schema::string& name, + bool can_fly, + unsigned int wing_span) + : base (name, can_fly, wing_span) + { + } + + template + batman_impl:: + batman_impl (const xercesc::DOMElement& e, + xml_schema::flags f, + xml_schema::container* c) + : base (e, f, c) + { + } + + template + batman_impl:: + batman_impl (const batman_impl& s, + xml_schema::flags f, + xml_schema::container* c) + : base (s, f, c) + { + } + + template + batman_impl* batman_impl:: + _clone (xml_schema::flags f, xml_schema::container* c) const + { + return new batman_impl (*this, f, c); + } + + template + void batman_impl:: + print (std::ostream& os) const + { + os << "Batman " << this->name () << " with " << + this->wing_span () << "m wing span" << std::endl; + } + + // Explicitly instantiate batman_impl class template for batman_base. + // + template class batman_impl; +} diff --git a/xsd-examples/cxx/tree/custom/taxonomy/people-custom.hxx b/xsd-examples/cxx/tree/custom/taxonomy/people-custom.hxx new file mode 100644 index 0000000..58c94c4 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/people-custom.hxx @@ -0,0 +1,105 @@ +// file : cxx/tree/custom/taxonomy/people-custom.hxx +// copyright : not copyrighted - public domain + +// Do not include this file directly, use people.hxx instead. This +// file is included into generated people.hxx so we do not need to +// guard against multiple inclusions. +// + +#include // std::ostream + +// Include people-fwd.hxx here so that we can refer to the generated +// types. +// +#include "people-fwd.hxx" + +namespace people +{ + // + // + template + class person_impl: public base + { + public: + person_impl (const xml_schema::string& name); + + person_impl (const xercesc::DOMElement&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + person_impl (const person_impl&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + person_impl& + operator= (const person_impl&) = default; + + virtual person_impl* + _clone (xml_schema::flags = 0, + xml_schema::container* = 0) const; + + public: + virtual void + print (std::ostream&) const; + }; + + + // + // + template + class superman_impl: public base + { + public: + superman_impl (const xml_schema::string& name, bool can_fly); + + superman_impl (const xercesc::DOMElement&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + superman_impl (const superman_impl&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + virtual superman_impl* + _clone (xml_schema::flags = 0, + xml_schema::container* = 0) const; + + superman_impl& + operator= (const superman_impl&) = default; + + public: + virtual void + print (std::ostream&) const; + }; + + + // + // + template + class batman_impl: public base + { + public: + batman_impl (const xml_schema::string& name, + bool can_fly, + unsigned int wing_span); + + batman_impl (const xercesc::DOMElement&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + batman_impl (const batman_impl&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + batman_impl& + operator= (const batman_impl&) = default; + + virtual batman_impl* + _clone (xml_schema::flags = 0, + xml_schema::container* = 0) const; + + public: + virtual void + print (std::ostream&) const; + }; +} diff --git a/xsd-examples/cxx/tree/custom/taxonomy/people.xml b/xsd-examples/cxx/tree/custom/taxonomy/people.xml new file mode 100644 index 0000000..831c547 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/people.xml @@ -0,0 +1,26 @@ + + + + + + + + Joe Dirt + + + + James "007" Bond + + + + Bruce Wayne + + + diff --git a/xsd-examples/cxx/tree/custom/taxonomy/people.xsd b/xsd-examples/cxx/tree/custom/taxonomy/people.xsd new file mode 100644 index 0000000..b07f338 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/taxonomy/people.xsd @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1