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/contacts/.gitignore | 1 + xsd-examples/cxx/tree/custom/contacts/README | 40 +++++++++++++++++ xsd-examples/cxx/tree/custom/contacts/buildfile | 25 +++++++++++ .../cxx/tree/custom/contacts/contacts-custom.cxx | 50 ++++++++++++++++++++++ .../cxx/tree/custom/contacts/contacts-custom.hxx | 43 +++++++++++++++++++ xsd-examples/cxx/tree/custom/contacts/contacts.xml | 20 +++++++++ xsd-examples/cxx/tree/custom/contacts/contacts.xsd | 31 ++++++++++++++ xsd-examples/cxx/tree/custom/contacts/driver.cxx | 38 ++++++++++++++++ 8 files changed, 248 insertions(+) create mode 100644 xsd-examples/cxx/tree/custom/contacts/.gitignore create mode 100644 xsd-examples/cxx/tree/custom/contacts/README create mode 100644 xsd-examples/cxx/tree/custom/contacts/buildfile create mode 100644 xsd-examples/cxx/tree/custom/contacts/contacts-custom.cxx create mode 100644 xsd-examples/cxx/tree/custom/contacts/contacts-custom.hxx create mode 100644 xsd-examples/cxx/tree/custom/contacts/contacts.xml create mode 100644 xsd-examples/cxx/tree/custom/contacts/contacts.xsd create mode 100644 xsd-examples/cxx/tree/custom/contacts/driver.cxx (limited to 'xsd-examples/cxx/tree/custom/contacts') diff --git a/xsd-examples/cxx/tree/custom/contacts/.gitignore b/xsd-examples/cxx/tree/custom/contacts/.gitignore new file mode 100644 index 0000000..43c214d --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/.gitignore @@ -0,0 +1 @@ +contacts.?xx diff --git a/xsd-examples/cxx/tree/custom/contacts/README b/xsd-examples/cxx/tree/custom/contacts/README new file mode 100644 index 0000000..072ede3 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/README @@ -0,0 +1,40 @@ +This example shows how to map a user-defined XML Schema type to a custom +C++ class. It presents the simple case where the customized type is not +used as a base in the same schema. For the complex case see the taxonomy +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: + +contacts.xsd + XML Schema definition for a simple contacts database. + +contacts.xml + Sample XML instance document. + +contacts.hxx +contacts.ixx +contacts.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 contacts.xsd with the + --custom-type option in order to customize the contact type. + +contacts-custom.hxx + Header file which defines our own contact class by inheriting from the + generated contact_base. It is included at the end of contacts.hxx using + the --hxx-epilogue option. + +contacts-custom.cxx + Source file which contains the implementation of our contact class. + +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 contacts to STDERR. + +To run the example on the sample XML instance document simply execute: + +$ ./driver contacts.xml diff --git a/xsd-examples/cxx/tree/custom/contacts/buildfile b/xsd-examples/cxx/tree/custom/contacts/buildfile new file mode 100644 index 0000000..190306c --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/buildfile @@ -0,0 +1,25 @@ +# file : cxx/tree/custom/contacts/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}{* -contacts} {hxx ixx cxx}{contacts} $libs + +exe{driver}: xml{contacts}: test.input = true + +<{hxx ixx cxx}{contacts}>: xsd{contacts} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree --std c++11 \ + --generate-inline \ + --custom-type contact=/contact_base \ + --hxx-epilogue '#include "contacts-custom.hxx"' \ + --output-dir $out_base \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" diff --git a/xsd-examples/cxx/tree/custom/contacts/contacts-custom.cxx b/xsd-examples/cxx/tree/custom/contacts/contacts-custom.cxx new file mode 100644 index 0000000..208b00f --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/contacts-custom.cxx @@ -0,0 +1,50 @@ +// file : cxx/tree/custom/contacts/contacts-custom.cxx +// copyright : not copyrighted - public domain + +#include + +// Include contacts.hxx instead of contacts-custom.hxx here. +// +#include "contacts.hxx" + +namespace contacts +{ + // We implement the following constructs by simply forwarding + // to our base. + // + contact:: + contact (const name_type& n, + const email_type& e, + const phone_type& p) + : contact_base (n, e, p) + { + } + + contact:: + contact (const xercesc::DOMElement& e, + xml_schema::flags f, + xml_schema::container* c) + : contact_base (e, f, c) + { + } + + contact:: + contact (const contact& x, + xml_schema::flags f, + xml_schema::container* c) + : contact_base (x, f, c) + { + } + + contact* contact:: + _clone (xml_schema::flags f, xml_schema::container* c) const + { + return new contact (*this, f, c); + } + + void contact:: + print (std::ostream& os) const + { + os << name () << " e| " << email () << " t| " << phone () << std::endl; + } +} diff --git a/xsd-examples/cxx/tree/custom/contacts/contacts-custom.hxx b/xsd-examples/cxx/tree/custom/contacts/contacts-custom.hxx new file mode 100644 index 0000000..a5bc893 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/contacts-custom.hxx @@ -0,0 +1,43 @@ +// file : cxx/tree/custom/contacts/contacts-custom.hxx +// copyright : not copyrighted - public domain + +// Do not include this file directly, use contacts.hxx instead. This +// file is included into generated contacts.hxx so we do not need to +// guard against multiple inclusions. +// + +#include // std::ostream + +namespace contacts +{ + class contact: public contact_base + { + // The following constructor signatures are copied from + // contact_base except for the copy constructor and the + // _clone function where we had to change the type from + // contact_base to contact. + // + public: + contact (const name_type&, + const email_type&, + const phone_type&); + + contact (const xercesc::DOMElement&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + contact (const contact&, + xml_schema::flags = 0, + xml_schema::container* = 0); + + virtual contact* + _clone (xml_schema::flags = 0, + xml_schema::container* = 0) const; + + // Our customizations. + // + public: + void + print (std::ostream&) const; + }; +} diff --git a/xsd-examples/cxx/tree/custom/contacts/contacts.xml b/xsd-examples/cxx/tree/custom/contacts/contacts.xml new file mode 100644 index 0000000..884c25e --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/contacts.xml @@ -0,0 +1,20 @@ + + + + + + + + Joe Dirt + joe@dirt.com + 555 DIRT + + + diff --git a/xsd-examples/cxx/tree/custom/contacts/contacts.xsd b/xsd-examples/cxx/tree/custom/contacts/contacts.xsd new file mode 100644 index 0000000..5348810 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/contacts.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xsd-examples/cxx/tree/custom/contacts/driver.cxx b/xsd-examples/cxx/tree/custom/contacts/driver.cxx new file mode 100644 index 0000000..a0c7510 --- /dev/null +++ b/xsd-examples/cxx/tree/custom/contacts/driver.cxx @@ -0,0 +1,38 @@ +// file : cxx/tree/custom/contacts/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include "contacts.hxx" + +using std::cerr; +using std::endl; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " contacts.xml" << endl; + return 1; + } + + try + { + using namespace contacts; + + std::unique_ptr c (catalog_ (argv[1])); + + for (catalog::contact_const_iterator i (c->contact ().begin ()); + i != c->contact ().end (); ++i) + { + i->print (cerr); + } + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } +} -- cgit v1.1