diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2024-03-06 10:24:46 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2024-03-06 10:24:46 +0100 |
commit | 372a0e99c2f61543d9e14d9933b59d9d1f4cb26e (patch) | |
tree | bbadf39aed0610c8f8f7b41fefff47773b8ac205 /xsd/examples/cxx/tree/polymorphism | |
parent | 23d41842168ac1a1580111b9c5c73500ceee3d57 (diff) | |
parent | 4538829ab86b5a1cd4e845e7eab165029c9d6d46 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'xsd/examples/cxx/tree/polymorphism')
-rw-r--r-- | xsd/examples/cxx/tree/polymorphism/README | 32 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/polymorphism/driver.cxx | 59 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/polymorphism/makefile | 104 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/polymorphism/supermen.xml | 25 | ||||
-rw-r--r-- | xsd/examples/cxx/tree/polymorphism/supermen.xsd | 48 |
5 files changed, 0 insertions, 268 deletions
diff --git a/xsd/examples/cxx/tree/polymorphism/README b/xsd/examples/cxx/tree/polymorphism/README deleted file mode 100644 index 6e54e49..0000000 --- a/xsd/examples/cxx/tree/polymorphism/README +++ /dev/null @@ -1,32 +0,0 @@ -This example shows how to use XML Schema polymorphism features such as -xsi:type attributes and substitution groups in the C++/Tree mapping. - -The example consists of the following files: - -supermen.xsd - XML Schema which describes the "supermen" instance documents. - -supermen.xml - Sample XML instance document. - -supermen.hxx -supermen.cxx - C++ types that represent the given vocabulary, a set of parsing - functions that convert XML instance documents to a tree-like in-memory - object model, and a set of serialization functions that convert the - object model back to XML. These are generated by XSD from supermen.xsd. - Note also that we use the --generate-polymorphic command line option - and that we don't need to use --polymorphic-type to explicitly mark - types as polymorphic because this is automatically deduced by the - XSD compiler from the substitution groups used in the supermen.xsd - schema. - -driver.cxx - Driver for the example. It first calls one of the parsing functions - that constructs the object model from the input file. It then prints - the content of the object model to STDERR. Finally, the driver serializes - the object model back to XML. - -To run the example on the sample XML instance document simply execute: - -$ ./driver instance.xml diff --git a/xsd/examples/cxx/tree/polymorphism/driver.cxx b/xsd/examples/cxx/tree/polymorphism/driver.cxx deleted file mode 100644 index 3f1598f..0000000 --- a/xsd/examples/cxx/tree/polymorphism/driver.cxx +++ /dev/null @@ -1,59 +0,0 @@ -// file : examples/cxx/tree/polymorphism/driver.cxx -// copyright : not copyrighted - public domain - -#include <memory> // std::auto_ptr -#include <iostream> - -#include "supermen.hxx" - -using std::cerr; -using std::endl; -using std::auto_ptr; - -int -main (int argc, char* argv[]) -{ - if (argc != 2) - { - cerr << "usage: " << argv[0] << " supermen.xml" << endl; - return 1; - } - - try - { - auto_ptr<supermen> sm (supermen_ (argv[1])); - - supermen copy (*sm); // Dynamic types are preserved in copies. - - // Print what we've got. - // - for (supermen::person_const_iterator i (copy.person ().begin ()); - i != copy.person ().end (); - ++i) - { - cerr << i->name (); - - if (const superman* s = dynamic_cast<const superman*> (&*i)) - { - if (s->can_fly ()) - cerr << ", flying superman"; - else - cerr << ", superman"; - } - - cerr << endl; - } - - // Serialize back to XML. - // - xml_schema::namespace_infomap map; - map[""].schema = "supermen.xsd"; - - supermen_ (std::cout, copy, map); - } - catch (const xml_schema::exception& e) - { - cerr << e << endl; - return 1; - } -} diff --git a/xsd/examples/cxx/tree/polymorphism/makefile b/xsd/examples/cxx/tree/polymorphism/makefile deleted file mode 100644 index 2ee16e7..0000000 --- a/xsd/examples/cxx/tree/polymorphism/makefile +++ /dev/null @@ -1,104 +0,0 @@ -# file : examples/cxx/tree/polymorphism/makefile -# copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC -# license : GNU GPL v2 + exceptions; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make - -xsd := supermen.xsd -cxx := driver.cxx - -obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.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=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): xsd := $(out_root)/xsd/xsd -$(gen): xsd_options += --generate-polymorphic --generate-serialization \ ---root-element-last -$(gen): $(out_root)/xsd/xsd - -$(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)/supermen.xsd,$(install_doc_dir)/xsd/$(path)/supermen.xsd) - $(call install-data,$(src_base)/supermen.xml,$(install_doc_dir)/xsd/$(path)/supermen.xml) - -$(dist-common): - $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx) - $(call install-data,$(src_base)/supermen.xsd,$(dist_prefix)/$(path)/supermen.xsd) - $(call install-data,$(src_base)/supermen.xml,$(dist_prefix)/$(path)/supermen.xml) - -$(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=.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/tree/xsd-cxx.make) - -# Dependencies. -# -$(call import,$(src_root)/xsd/makefile) diff --git a/xsd/examples/cxx/tree/polymorphism/supermen.xml b/xsd/examples/cxx/tree/polymorphism/supermen.xml deleted file mode 100644 index 1b5b1df..0000000 --- a/xsd/examples/cxx/tree/polymorphism/supermen.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0"?> - -<!-- - -file : examples/cxx/tree/polymorphism/supermen.xml -copyright : not copyrighted - public domain - ---> - -<supermen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:noNamespaceSchemaLocation="supermen.xsd"> - - <person> - <name>John Doe</name> - </person> - - <superman can-fly="false"> - <name>James "007" Bond</name> - </superman> - - <superman can-fly="true" wing-span="10" xsi:type="batman"> - <name>Bruce Wayne</name> - </superman> - -</supermen> diff --git a/xsd/examples/cxx/tree/polymorphism/supermen.xsd b/xsd/examples/cxx/tree/polymorphism/supermen.xsd deleted file mode 100644 index 0d37e3d..0000000 --- a/xsd/examples/cxx/tree/polymorphism/supermen.xsd +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0"?> - -<!-- - -file : examples/cxx/tree/polymorphism/supermen.xsd -copyright : not copyrighted - public domain - ---> - -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - - <xsd:complexType name="person"> - <xsd:sequence> - <xsd:element name="name" type="xsd:string"/> - </xsd:sequence> - </xsd:complexType> - - <!-- substitution group root --> - <xsd:element name="person" type="person"/> - - - <xsd:complexType name="superman"> - <xsd:complexContent> - <xsd:extension base="person"> - <xsd:attribute name="can-fly" type="xsd:boolean" use="required"/> - </xsd:extension> - </xsd:complexContent> - </xsd:complexType> - - <xsd:element name="superman" type="superman" substitutionGroup="person"/> - - <xsd:complexType name="batman"> - <xsd:complexContent> - <xsd:extension base="superman"> - <xsd:attribute name="wing-span" type="xsd:unsignedInt" use="required"/> - </xsd:extension> - </xsd:complexContent> - </xsd:complexType> - - <xsd:complexType name="supermen"> - <xsd:sequence> - <xsd:element ref="person" maxOccurs="unbounded"/> - </xsd:sequence> - </xsd:complexType> - - <xsd:element name="supermen" type="supermen"/> - -</xsd:schema> |