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/binary/cdr/.gitignore | 1 + xsd-examples/cxx/tree/binary/cdr/README | 36 ++++++++++++ xsd-examples/cxx/tree/binary/cdr/buildfile | 28 +++++++++ xsd-examples/cxx/tree/binary/cdr/driver.cxx | 87 ++++++++++++++++++++++++++++ xsd-examples/cxx/tree/binary/cdr/library.xml | 52 +++++++++++++++++ xsd-examples/cxx/tree/binary/cdr/library.xsd | 75 ++++++++++++++++++++++++ 6 files changed, 279 insertions(+) create mode 100644 xsd-examples/cxx/tree/binary/cdr/.gitignore create mode 100644 xsd-examples/cxx/tree/binary/cdr/README create mode 100644 xsd-examples/cxx/tree/binary/cdr/buildfile create mode 100644 xsd-examples/cxx/tree/binary/cdr/driver.cxx create mode 100644 xsd-examples/cxx/tree/binary/cdr/library.xml create mode 100644 xsd-examples/cxx/tree/binary/cdr/library.xsd (limited to 'xsd-examples/cxx/tree/binary/cdr') diff --git a/xsd-examples/cxx/tree/binary/cdr/.gitignore b/xsd-examples/cxx/tree/binary/cdr/.gitignore new file mode 100644 index 0000000..c116ec1 --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/.gitignore @@ -0,0 +1 @@ +library.?xx diff --git a/xsd-examples/cxx/tree/binary/cdr/README b/xsd-examples/cxx/tree/binary/cdr/README new file mode 100644 index 0000000..914d27c --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/README @@ -0,0 +1,36 @@ +This example shows how to save/load the object model to/from CDR +(Common Data Representation) binary format using ACE CDR streams. +Support for other data representation streams can be easily added. You +will need the ACE library[1] installed in order to build and run this +example. + +[1] http://www.cs.wustl.edu/~schmidt/ACE.html + +The example consists of the following files: + +library.xsd + XML Schema which describes a library of books. + +library.xml + Sample XML instance document. + +library.hxx +library.cxx + C++ types that represent the given vocabulary as well as data + representation stream insertion and extraction operations. These + are generated by XSD from library.xsd. Note that the + --generate-insertion and --generate-extraction options are used + to generate the insertion and extraction operations for ACE CDR + stream. + +driver.cxx + Driver for the example. It first calls one of the parsing functions + that constructs the object model from the input XML file. It then + saves the object model to ACE_OuputCDR and loads it back from + ACE_InputCDR. Additionally, it prints the resulting binary + representation as well as the content of the object model before + saving it to the CDR stream and after loading it from the CDR stream. + +To run the example on the sample XML instance document simply execute: + +$ ./driver library.xml diff --git a/xsd-examples/cxx/tree/binary/cdr/buildfile b/xsd-examples/cxx/tree/binary/cdr/buildfile new file mode 100644 index 0000000..d78a56a --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/buildfile @@ -0,0 +1,28 @@ +# file : cxx/tree/binary/cdr/buildfile +# license : not copyrighted - public domain + +import libs = libxsd%lib{xsd} +import libs += libxerces-c%lib{xerces-c} +import libs += libace%lib{ACE} + +./: exe{driver} doc{README} + +exe{driver}: {hxx cxx}{* -library} {hxx ixx cxx}{library} $libs + +exe{driver}: xml{library}: test.input = true + +<{hxx ixx cxx}{library}>: xsd{library} $xsd +{{ + diag xsd ($<[0]) # @@ TMP + + $xsd cxx-tree --std c++11 \ + --generate-inline \ + --generate-ostream \ + --generate-insertion 'ACE_OutputCDR' \ + --generate-extraction 'ACE_InputCDR' \ + --generate-comparison \ + --output-dir $out_base \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" diff --git a/xsd-examples/cxx/tree/binary/cdr/driver.cxx b/xsd-examples/cxx/tree/binary/cdr/driver.cxx new file mode 100644 index 0000000..2ab0674 --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/driver.cxx @@ -0,0 +1,87 @@ +// file : cxx/tree/binary/cdr/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include // std::memcpy +#include + +#include // ACE_HEX_DUMP +#include + +// The following two headers define XSD-specific insertion/extraction +// operations for ACE CDR streams. You can use the content of these +// headers as a guide to implementing insertion/extraction to/from +// your own data representation streams: +// +// xsd/cxx/tree/ace-cdr-stream-insertion.hxx +// xsd/cxx/tree/ace-cdr-stream-extraction.hxx + +#include "library.hxx" + +using std::cerr; +using std::endl; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " library.xml" << endl; + return 1; + } + + try + { + using namespace library; + + // Read in the file. + // + std::unique_ptr c (catalog_ (argv[1])); + + cerr << *c << endl; + + // Save to a CDR stream. + // + ACE_OutputCDR ace_ocdr; + xml_schema::ostream ocdr (ace_ocdr); + + ocdr << *c; + + // Print the binary representation and at the same time save + // it into a continuous buffer. + // + cerr << endl + << "binary representation size: " << ace_ocdr.total_length () << endl; + + xml_schema::buffer buf (ace_ocdr.total_length ()); + char* data (buf.data ()); + + for (const ACE_Message_Block* mb = ace_ocdr.begin (); + mb != 0; + mb = mb->cont ()) + { + std::memcpy (data, mb->rd_ptr (), mb->length ()); + data += mb->length (); + + ACE_HEX_DUMP ((LM_DEBUG, mb->rd_ptr (), mb->length ())); + } + + // Load from a CDR stream. Note that ACE_InputCDR expects the + // buffer to be properly aligned. Since our buffer is dynamically + // allocated, its alignment should be good enough. + // + ACE_InputCDR ace_icdr (buf.data (), buf.size ()); + xml_schema::istream icdr (ace_icdr); + + std::unique_ptr copy (new catalog (icdr)); + + cerr << *copy << endl; + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } + + return 0; // ACE makes our main() an ordinary function. +} diff --git a/xsd-examples/cxx/tree/binary/cdr/library.xml b/xsd-examples/cxx/tree/binary/cdr/library.xml new file mode 100644 index 0000000..5700131 --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/library.xml @@ -0,0 +1,52 @@ + + + + + + + + 0679760806 + The Master and Margarita + fiction + + + Mikhail Bulgakov + 1891-05-15 + 1940-03-10 + + + + + + 0679600841 + War and Peace + history + + + Leo Tolstoy + 1828-09-09 + 1910-11-20 + + + + + + 0679420290 + Crime and Punishment + philosophy + + + Fyodor Dostoevsky + 1821-11-11 + 1881-02-09 + + + + diff --git a/xsd-examples/cxx/tree/binary/cdr/library.xsd b/xsd-examples/cxx/tree/binary/cdr/library.xsd new file mode 100644 index 0000000..c7f056e --- /dev/null +++ b/xsd-examples/cxx/tree/binary/cdr/library.xsd @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1