From 707cc94fe52463870a9c6c8e2e66eaaa389e601d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2009 15:16:26 +0200 Subject: Start tracking XSD/e with git after version 3.0.0 --- examples/cxx/serializer/hello/README | 25 +++++++++ examples/cxx/serializer/hello/driver.cxx | 90 ++++++++++++++++++++++++++++++++ examples/cxx/serializer/hello/hello.xsd | 22 ++++++++ examples/cxx/serializer/hello/makefile | 64 +++++++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 examples/cxx/serializer/hello/README create mode 100644 examples/cxx/serializer/hello/driver.cxx create mode 100644 examples/cxx/serializer/hello/hello.xsd create mode 100644 examples/cxx/serializer/hello/makefile (limited to 'examples/cxx/serializer/hello') diff --git a/examples/cxx/serializer/hello/README b/examples/cxx/serializer/hello/README new file mode 100644 index 0000000..a560fac --- /dev/null +++ b/examples/cxx/serializer/hello/README @@ -0,0 +1,25 @@ +This is a "Hello, world!" example that shows how to use the +Embedded C++/Serializer mapping to serialize XML documents. + +The example consists of the following files: + +hello.xsd + XML Schema which describes "hello" instance documents. + +hello-sskel.hxx +hello-sskel.ixx +hello-sskel.cxx + Serializer skeletons generated by XSD/e from hello.xsd. + +driver.cxx + A serializer implementation and a driver for the example. + The serializer implementation simply creates an XML + document with pre-defined data. The driver first constructs + a serializer instance from the serializer implementation + mentioned above and a couple of predefined serializers for + the XML Schema built-in types. In then invokes this serializer + instance to write the XML document to STDOUT. + +To run the example simply execute: + +$ ./driver diff --git a/examples/cxx/serializer/hello/driver.cxx b/examples/cxx/serializer/hello/driver.cxx new file mode 100644 index 0000000..e895add --- /dev/null +++ b/examples/cxx/serializer/hello/driver.cxx @@ -0,0 +1,90 @@ +// file : examples/cxx/serializer/hello/driver.cxx +// author : Boris Kolpackov +// copyright : not copyrighted - public domain + +#include +#include +#include + +#include "hello-sskel.hxx" + +using namespace std; + +struct hello_simpl: hello_sskel +{ + hello_simpl () + { + names_.push_back ("sun"); + names_.push_back ("moon"); + names_.push_back ("world"); + } + + virtual void + pre () + { + i_ = names_.begin (); + } + + virtual string + greeting () + { + return "Hello"; + } + + virtual bool + name_next () + { + return i_ != names_.end (); + } + + virtual string + name () + { + return *i_++; + } + +private: + typedef vector names; + + names names_; + names::iterator i_; +}; + + +int +main () +{ + try + { + // Construct the serializer. + // + xml_schema::string_simpl string_s; + hello_simpl hello_s; + + hello_s.greeting_serializer (string_s); + hello_s.name_serializer (string_s); + + + // Create the XML instance document. The second argument to the + // document's constructor is the document's root element name. + // + xml_schema::document_simpl doc_s (hello_s, "hello"); + doc_s.add_no_namespace_schema ("hello.xsd"); + + hello_s.pre (); + doc_s.serialize (cout); + hello_s.post (); + } + catch (const xml_schema::serializer_exception& e) + { + cerr << "error: " << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << "error: write failure" << endl; + return 1; + } + + return 0; +} diff --git a/examples/cxx/serializer/hello/hello.xsd b/examples/cxx/serializer/hello/hello.xsd new file mode 100644 index 0000000..d2affb5 --- /dev/null +++ b/examples/cxx/serializer/hello/hello.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + diff --git a/examples/cxx/serializer/hello/makefile b/examples/cxx/serializer/hello/makefile new file mode 100644 index 0000000..c2721bb --- /dev/null +++ b/examples/cxx/serializer/hello/makefile @@ -0,0 +1,64 @@ +# file : examples/cxx/serializer/hello/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +xsd := hello.xsd +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-sskel.o)) +dep := $(obj:.o=.o.d) + +xsde.l := $(out_root)/libxsde/xsde/xsde.l +xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options + +driver := $(out_base)/driver +clean := $(out_base)/.clean + + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): cpp_options := -I$(out_base) +$(obj) $(dep): $(xsde.l.cpp-options) + +skel := $(out_base)/$(xsd:.xsd=-sskel.hxx) \ + $(out_base)/$(xsd:.xsd=-sskel.ixx) \ + $(out_base)/$(xsd:.xsd=-sskel.cxx) + +$(skel): xsde := $(out_root)/xsde/xsde +$(skel): $(out_root)/xsde/xsde + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=-sskel.cxx.xsd.clean)) + + +# How to. +# +$(call include,$(bld_root)/cxx/o-e.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(scf_root)/xsde/serializer/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) -- cgit v1.1