From 0bce70a0e483294b83b8bf9d5468838a63405612 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Mar 2009 17:23:30 +0200 Subject: Add support for binary representations xsde/cxx/hybrid/insertion-*: insertion operators generator xsde/cxx/hybrid/extraction-*: extraction operators generator libxsde/xsde/cxx/hybrid/cdr/: CDR support code libxsde/xsde/cxx/hybrid/xdr/: XDR support code tests/cxx/hybrid/binary/: new tests examples/cxx/hybrid/binary/: new examples documentation/cxx/hybrid/guide/: new chapter --- examples/cxx/hybrid/binary/custom/driver.cxx | 107 +++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 examples/cxx/hybrid/binary/custom/driver.cxx (limited to 'examples/cxx/hybrid/binary/custom/driver.cxx') diff --git a/examples/cxx/hybrid/binary/custom/driver.cxx b/examples/cxx/hybrid/binary/custom/driver.cxx new file mode 100644 index 0000000..e453a37 --- /dev/null +++ b/examples/cxx/hybrid/binary/custom/driver.cxx @@ -0,0 +1,107 @@ +// file : examples/cxx/hybrid/binary/custom/driver.cxx +// author : Boris Kolpackov +// copyright : not copyrighted - public domain + +#include // std::auto_ptr +#include + +#include "orawstream.hxx" +#include "irawstream.hxx" + +#include "library.hxx" +#include "library-pimpl.hxx" +#include "library-simpl.hxx" + +using std::cerr; +using std::endl; + +int +main (int argc, char* argv[]) +{ + const char* input; + + if (argc < 2) + { + input = "STDIN"; + cerr << "XML file not specified, reading from STDIN" << endl; + } + else + input = argv[1]; + + try + { + using namespace library; + + // Parse. + // + catalog_paggr catalog_p; + + xml_schema::document_pimpl doc_p ( + catalog_p.root_parser (), + catalog_p.root_namespace (), + catalog_p.root_name ()); + + catalog_p.pre (); + + if (argc < 2) + doc_p.parse (std::cin); + else + doc_p.parse (argv[1]); + + std::auto_ptr c (catalog_p.post ()); + + // Save the object model to a RAW stream. + // + xml_schema::buffer buf; + orawstream oraw (buf); + oraw << *c; + + cerr << "binary representation size: " << buf.size () << endl + << endl; + + // Load the object model from a RAW stream. + // + irawstream iraw (buf); + std::auto_ptr copy (new catalog); + iraw >> *copy; + + // Serialize the copy back to XML. + // + catalog_saggr catalog_s; + + xml_schema::document_simpl doc_s ( + catalog_s.root_serializer (), + catalog_s.root_namespace (), + catalog_s.root_name ()); + + doc_s.add_prefix ("lib", "http://www.codesynthesis.com/library"); + doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); + + catalog_s.pre (*c); + doc_s.serialize (std::cout); + catalog_s.post (); + } + catch (const raw_exception&) + { + cerr << "RAW stream operation failed" << endl; + return 1; + } + catch (const xml_schema::parser_exception& e) + { + cerr << input << ":" << e.line () << ":" << e.column () << ": " + << e.text () << endl; + return 1; + } + catch (const xml_schema::serializer_exception& e) + { + cerr << "error: " << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << input << ": unable to open or read/write failure" << endl; + return 1; + } + + return 0; +} -- cgit v1.1