aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/compositors
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cxx/hybrid/compositors')
-rw-r--r--examples/cxx/hybrid/compositors/README28
-rw-r--r--examples/cxx/hybrid/compositors/compositors.xsd44
-rw-r--r--examples/cxx/hybrid/compositors/driver.cxx89
-rw-r--r--examples/cxx/hybrid/compositors/makefile62
4 files changed, 223 insertions, 0 deletions
diff --git a/examples/cxx/hybrid/compositors/README b/examples/cxx/hybrid/compositors/README
new file mode 100644
index 0000000..b02a023
--- /dev/null
+++ b/examples/cxx/hybrid/compositors/README
@@ -0,0 +1,28 @@
+This example shows how to create, access, and modify object models with
+complex nested choice and sequence compositors in the Embedded C++/Hybrid
+mapping.
+
+For more information about nested compositors see Section 4.4, "Compositors"
+in the Embedded C++/Hybrid Mapping Getting Started Guide.
+
+
+The example consists of the following files:
+
+compositors.xsd
+ XML Schema which defines a number of types with nested compositors.
+
+compositors.hxx
+compositors.cxx
+
+ Object model classes. These are generated by the XSD/e compiler from
+ compositors.xsd.
+
+driver.cxx
+ Driver for the example. It shows how to create, access, and modify object
+ models that use nested choice and sequence compositors. The driver does
+ not produce any output.
+
+
+To run the example simply execute:
+
+$ ./driver
diff --git a/examples/cxx/hybrid/compositors/compositors.xsd b/examples/cxx/hybrid/compositors/compositors.xsd
new file mode 100644
index 0000000..85f0db7
--- /dev/null
+++ b/examples/cxx/hybrid/compositors/compositors.xsd
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : examples/cxx/hybrid/compositors/compositors.xsd
+author : Boris Kolpackov <boris@codesynthesis.com>
+copyright : not copyrighted - public domain
+
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:complexType name="simple_choice">
+ <xsd:choice>
+ <xsd:element name="a" type="xsd:int"/>
+ <xsd:element name="b" type="xsd:string" minOccurs="0"/>
+ <xsd:element name="c" type="xsd:boolean" maxOccurs="unbounded"/>
+ </xsd:choice>
+ </xsd:complexType>
+
+ <xsd:complexType name="nested_choice">
+ <xsd:sequence>
+ <xsd:choice minOccurs="0">
+ <xsd:element name="a" type="xsd:int"/>
+ <xsd:sequence>
+ <xsd:element name="b" type="xsd:int"/>
+ <xsd:element name="c" type="xsd:boolean"/>
+ </xsd:sequence>
+ </xsd:choice>
+ <xsd:element name="d" type="xsd:int"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="nested_sequence">
+ <xsd:sequence maxOccurs="unbounded">
+ <xsd:element name="a" type="xsd:int"/>
+ <xsd:sequence minOccurs="0">
+ <xsd:element name="b" type="xsd:int"/>
+ <xsd:element name="c" type="xsd:boolean"/>
+ </xsd:sequence>
+ </xsd:sequence>
+ </xsd:complexType>
+
+</xsd:schema>
diff --git a/examples/cxx/hybrid/compositors/driver.cxx b/examples/cxx/hybrid/compositors/driver.cxx
new file mode 100644
index 0000000..5d7dd01
--- /dev/null
+++ b/examples/cxx/hybrid/compositors/driver.cxx
@@ -0,0 +1,89 @@
+// file : examples/cxx/hybrid/compositors/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : not copyrighted - public domain
+
+#include "compositors.hxx"
+
+int
+main (int, char*[])
+{
+ // Simple choice.
+ //
+ simple_choice sc;
+
+ sc.a (123); // Automatically sets arm to a_tag.
+
+ switch (sc.choice_arm ())
+ {
+ case simple_choice::a_tag:
+ {
+ sc.a ()++;
+ break;
+ }
+ case simple_choice::b_tag:
+ {
+ // The b element is optional so we first need to check
+ // if it is present.
+ //
+ if (sc.b_present ())
+ {
+ sc.b_present (false);
+ }
+
+ break;
+ }
+ case simple_choice::c_tag:
+ {
+ // The c element is a sequence.
+ //
+ simple_choice::c_sequence& s = sc.c ();
+
+ for (simple_choice::c_iterator i = s.begin (); i != s.end(); ++i)
+ {
+ *i = !*i;
+ }
+
+ break;
+ }
+ }
+
+
+ // Nested choice.
+ //
+ nested_choice nc;
+
+ // Initialize the choice with the 'sequence' arm.
+ //
+ nc.choice_present (true);
+ nested_choice::choice_type& c = nc.choice ();
+ c.choice_arm (nested_choice::choice_type::sequence_tag);
+ c.sequence ().b (123);
+ c.sequence ().c (true);
+
+ nc.d (456);
+
+
+ // Nested sequence.
+ //
+ nested_sequence ns;
+ nested_sequence::sequence_sequence& s = ns.sequence ();
+
+ for (int i = 0; i < 10; ++i)
+ {
+ nested_sequence::sequence_type x;
+ x.a (i);
+
+ if (i % 2)
+ {
+ // Initialize the nested sequence.
+ //
+ x.sequence1_present (true);
+ x.sequence1 ().b (i);
+ x.sequence1 ().c (true);
+ }
+
+ s.push_back (x);
+ }
+
+ return 0;
+}
diff --git a/examples/cxx/hybrid/compositors/makefile b/examples/cxx/hybrid/compositors/makefile
new file mode 100644
index 0000000..2bab6e1
--- /dev/null
+++ b/examples/cxx/hybrid/compositors/makefile
@@ -0,0 +1,62 @@
+# file : examples/cxx/hybrid/compositors/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# 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 := compositors.xsd
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.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): $(xsde.l.cpp-options)
+
+gen := $(out_base)/$(xsd:.xsd=.hxx) \
+ $(out_base)/$(xsd:.xsd=.cxx)
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen): xsde_options += --generate-inline
+
+$(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=.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/hybrid/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)