summaryrefslogtreecommitdiff
path: root/examples/cxx/parser/mixin
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/parser/mixin')
-rw-r--r--examples/cxx/parser/mixin/README34
-rw-r--r--examples/cxx/parser/mixin/driver.cxx103
-rw-r--r--examples/cxx/parser/mixin/instance.xml16
-rw-r--r--examples/cxx/parser/mixin/makefile106
-rw-r--r--examples/cxx/parser/mixin/schema.map7
-rw-r--r--examples/cxx/parser/mixin/schema.xsd30
-rw-r--r--examples/cxx/parser/mixin/types.hxx43
7 files changed, 0 insertions, 339 deletions
diff --git a/examples/cxx/parser/mixin/README b/examples/cxx/parser/mixin/README
deleted file mode 100644
index 343e379..0000000
--- a/examples/cxx/parser/mixin/README
+++ /dev/null
@@ -1,34 +0,0 @@
-This example shows how to reuse implementations of base parsers
-in derived parsers using the mixin C++ idiom.
-
-The example consists of the following files:
-
-schema.xsd
- XML Schema which defined two data types: base and
- derived.
-
-instance.xml
- Sample XML instance document.
-
-types.hxx
- C++ classes that correspond to the base and derived
- types in schema.xsd.
-
-schema.map
- Type map. It maps XML Schema types defined in schema.xsd
- to C++ types defined in types.hxx.
-
-schema-pskel.hxx
-schema-pskel.cxx
- Parser skeletons generated by XSD from schema.xsd and
- schema.map.
-
-driver.cxx
- Parser implementations and a driver for the example. It
- shows how to mix the implementation of the base parser
- into the derived parser.
-
-To run the example on the sample XML instance document simply
-execute:
-
-$ ./driver instance.xml
diff --git a/examples/cxx/parser/mixin/driver.cxx b/examples/cxx/parser/mixin/driver.cxx
deleted file mode 100644
index 04466a1..0000000
--- a/examples/cxx/parser/mixin/driver.cxx
+++ /dev/null
@@ -1,103 +0,0 @@
-// file : examples/cxx/parser/mixin/driver.cxx
-// copyright : not copyrighted - public domain
-
-#include <memory>
-#include <iostream>
-
-#include "types.hxx"
-#include "schema-pskel.hxx"
-
-using namespace std;
-
-struct base_pimpl: virtual base_pskel
-{
- virtual void
- pre ()
- {
- base_.reset (new ::base);
- }
-
- virtual void
- a (bool v)
- {
- base_->a (v);
- }
-
- virtual base*
- post_base ()
- {
- return base_.release ();
- }
-
-protected:
- auto_ptr<base> base_;
-};
-
-// Implement derived parser by mixing-in base's implementation.
-//
-struct derived_pimpl: derived_pskel, base_pimpl
-{
- virtual void
- pre ()
- {
- // Override base's pre() with the new implementation that
- // instantiates derived instead of base.
- //
- base_.reset (new ::derived);
- }
-
- virtual void
- b (int v)
- {
- // We could also store a pointer to derived in derived_impl to
- // avoid casting.
- //
- static_cast< ::derived* > (base_.get ())->b (v);
- }
-
- virtual derived*
- post_derived ()
- {
- return static_cast<derived*> (base_.release ());
- }
-};
-
-int
-main (int argc, char* argv[])
-{
- if (argc != 2)
- {
- cerr << "usage: " << argv[0] << " instance.xml" << endl;
- return 1;
- }
-
- try
- {
- // Construct the parser.
- //
- xml_schema::boolean_pimpl bool_p;
- xml_schema::int_pimpl int_p;
- derived_pimpl derived_p;
-
- derived_p.parsers (bool_p, int_p);
-
- xml_schema::document doc_p (derived_p, "root");
-
- derived_p.pre ();
- doc_p.parse (argv[1]);
- auto_ptr<derived> d (derived_p.post_derived ());
-
- cerr << "a: " << boolalpha << d->a () << endl;
- cerr << "b: " << d->b () << endl;
- }
- catch (const xml_schema::exception& e)
- {
- cerr << e << endl;
- return 1;
- }
- catch (const std::ios_base::failure&)
- {
- cerr << argv[1] << ": unable to open or read failure" << endl;
- return 1;
- }
-}
diff --git a/examples/cxx/parser/mixin/instance.xml b/examples/cxx/parser/mixin/instance.xml
deleted file mode 100644
index 253f348..0000000
--- a/examples/cxx/parser/mixin/instance.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/parser/mixin/instance.xml
-copyright : not copyrighted - public domain
-
--->
-
-<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="schema.xsd">
-
- <a>true</a>
- <b>1</b>
-
-</root>
diff --git a/examples/cxx/parser/mixin/makefile b/examples/cxx/parser/mixin/makefile
deleted file mode 100644
index c4203d8..0000000
--- a/examples/cxx/parser/mixin/makefile
+++ /dev/null
@@ -1,106 +0,0 @@
-# file : examples/cxx/parser/mixin/makefile
-# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
-
-xsd := schema.xsd
-cxx := driver.cxx
-
-obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.o))
-dep := $(obj:.o=.o.d)
-
-driver := $(out_base)/driver
-install := $(out_base)/.install
-dist := $(out_base)/.dist
-dist-win := $(out_base)/.dist-win
-clean := $(out_base)/.clean
-
-
-# Import.
-#
-$(call import,\
- $(scf_root)/import/libxerces-c/stub.make,\
- l: xerces_c.l,cpp-options: xerces_c.l.cpp-options)
-
-
-# Build.
-#
-$(driver): $(obj) $(xerces_c.l)
-
-$(obj) $(dep): cpp_options := -I$(out_base) -I$(src_base) -I$(src_root)/libxsd
-$(obj) $(dep): $(xerces_c.l.cpp-options)
-
-genf := $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.ixx) $(xsd:.xsd=-pskel.cxx)
-gen := $(addprefix $(out_base)/,$(genf))
-
-$(gen): xsd := $(out_root)/xsd/xsd
-$(gen): xsd_options += --type-map $(src_base)/schema.map
-$(gen): $(out_root)/xsd/xsd $(src_base)/schema.map
-
-$(call include-dep,$(dep),$(obj),$(gen))
-
-# Convenience alias for default target.
-#
-$(out_base)/: $(driver)
-
-
-# Install & Dist.
-#
-dist-common := $(out_base)/.dist-common
-
-$(install) $(dist) $(dist-win) $(dist-common): path := $(subst $(src_root)/,,$(src_base))
-
-$(install):
- $(call install-data,$(src_base)/README,$(install_doc_dir)/xsd/$(path)/README)
- $(call install-data,$(src_base)/driver.cxx,$(install_doc_dir)/xsd/$(path)/driver.cxx)
- $(call install-data,$(src_base)/schema.xsd,$(install_doc_dir)/xsd/$(path)/schema.xsd)
- $(call install-data,$(src_base)/instance.xml,$(install_doc_dir)/xsd/$(path)/instance.xml)
- $(call install-data,$(src_base)/schema.map,$(install_doc_dir)/xsd/$(path)/schema.map)
- $(call install-data,$(src_base)/types.hxx,$(install_doc_dir)/xsd/$(path)/types.hxx)
-
-$(dist-common):
- $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx)
- $(call install-data,$(src_base)/schema.xsd,$(dist_prefix)/$(path)/schema.xsd)
- $(call install-data,$(src_base)/instance.xml,$(dist_prefix)/$(path)/instance.xml)
- $(call install-data,$(src_base)/schema.map,$(dist_prefix)/$(path)/schema.map)
- $(call install-data,$(src_base)/types.hxx,$(dist_prefix)/$(path)/types.hxx)
-
-$(dist): $(dist-common)
- $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README)
-
-$(dist-win): $(dist-common)
- $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README.txt)
- $(call message,,todos $(dist_prefix)/$(path)/README.txt)
-
-
-# Clean.
-#
-$(clean): $(driver).o.clean \
- $(addsuffix .cxx.clean,$(obj)) \
- $(addsuffix .cxx.clean,$(dep)) \
- $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.cxx.xsd.clean))
-
-# Generated .gitignore.
-#
-ifeq ($(out_base),$(src_base))
-$(gen): | $(out_base)/.gitignore
-$(driver): | $(out_base)/.gitignore
-
-$(out_base)/.gitignore: files := driver $(genf)
-$(clean): $(out_base)/.gitignore.clean
-
-$(call include,$(bld_root)/git/gitignore.make)
-endif
-
-# 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,$(bld_root)/install.make)
-$(call include,$(scf_root)/xsd/parser/xsd-cxx.make)
-
-
-# Dependencies.
-#
-$(call import,$(src_root)/xsd/makefile)
diff --git a/examples/cxx/parser/mixin/schema.map b/examples/cxx/parser/mixin/schema.map
deleted file mode 100644
index a93c881..0000000
--- a/examples/cxx/parser/mixin/schema.map
+++ /dev/null
@@ -1,7 +0,0 @@
-# file : examples/cxx/parser/mixin/schema.map
-# copyright : not copyrighted - public domain
-
-include "types.hxx";
-
-base ::base*;
-derived ::derived*;
diff --git a/examples/cxx/parser/mixin/schema.xsd b/examples/cxx/parser/mixin/schema.xsd
deleted file mode 100644
index d2d195d..0000000
--- a/examples/cxx/parser/mixin/schema.xsd
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/parser/mixin/schema.xsd
-copyright : not copyrighted - public domain
-
--->
-
-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
- <xsd:complexType name="base">
- <xsd:sequence>
- <xsd:element name="a" type="xsd:boolean"/>
- </xsd:sequence>
- </xsd:complexType>
-
- <xsd:complexType name="derived">
- <xsd:complexContent>
- <xsd:extension base="base">
- <xsd:sequence>
- <xsd:element name="b" type="xsd:int"/>
- </xsd:sequence>
- </xsd:extension>
- </xsd:complexContent>
- </xsd:complexType>
-
- <xsd:element name="root" type="derived"/>
-
-</xsd:schema>
diff --git a/examples/cxx/parser/mixin/types.hxx b/examples/cxx/parser/mixin/types.hxx
deleted file mode 100644
index 930033d..0000000
--- a/examples/cxx/parser/mixin/types.hxx
+++ /dev/null
@@ -1,43 +0,0 @@
-// file : examples/cxx/parser/mixin/types.hxx
-// copyright : not copyrighted - public domain
-
-#ifndef TYPES_HXX
-#define TYPES_HXX
-
-struct base
-{
- bool
- a () const
- {
- return a_;
- }
-
- void
- a (bool v)
- {
- a_ = v;
- }
-
-private:
- bool a_;
-};
-
-struct derived: base
-{
- int
- b () const
- {
- return b_;
- }
-
- void
- b (int v)
- {
- b_ = v;
- }
-
-private:
- int b_;
-};
-
-#endif // TYPES_HXX