summaryrefslogtreecommitdiff
path: root/examples/cxx/tree/custom/wildcard
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-18 18:48:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-02-25 13:45:48 +0300
commit5e527213a2430bb3018e5eebd909aef294edf9b5 (patch)
tree94de33c82080b53d9a9e300170f6d221d89078f4 /examples/cxx/tree/custom/wildcard
parent7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff)
Switch to build2
Diffstat (limited to 'examples/cxx/tree/custom/wildcard')
-rw-r--r--examples/cxx/tree/custom/wildcard/README45
-rw-r--r--examples/cxx/tree/custom/wildcard/driver.cxx47
-rw-r--r--examples/cxx/tree/custom/wildcard/makefile115
-rw-r--r--examples/cxx/tree/custom/wildcard/wildcard-custom.cxx84
-rw-r--r--examples/cxx/tree/custom/wildcard/wildcard-custom.hxx66
-rw-r--r--examples/cxx/tree/custom/wildcard/wildcard.xml14
-rw-r--r--examples/cxx/tree/custom/wildcard/wildcard.xsd25
7 files changed, 0 insertions, 396 deletions
diff --git a/examples/cxx/tree/custom/wildcard/README b/examples/cxx/tree/custom/wildcard/README
deleted file mode 100644
index 70eaea4..0000000
--- a/examples/cxx/tree/custom/wildcard/README
+++ /dev/null
@@ -1,45 +0,0 @@
-This example shows how to use type customization to parse and serialize
-a specific attribute that is matched by a wildcard (anyAttribute). The
-example achieves this by customizing the type to include the data
-members and accessors/modifiers that represent the attribute as well as
-the parsing constructor and serialization operator where the attribute
-value is extracted from and inserted back to DOM, respectively. For
-more information on the C++/Tree mapping customization see the C++/Tree
-Mapping Customization Guide[1].
-
-[1] http://wiki.codesynthesis.com/Tree/Customization_guide
-
-The example consists of the following files:
-
-wildcard.xsd
- XML Schema definition for simple data type and element.
-
-wildcard.xml
- Sample XML instance document.
-
-wildcard.hxx
-wildcard.ixx
-wildcard.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 wildcard.xsd
- with the --custom-type option in order to customize the data type.
-
-wildcard-custom.hxx
- Header file which defines our own data class by inheriting from the
- generated data_base. It is included at the end of wildcard.hxx using
- the --hxx-epilogue option.
-
-wildcard-custom.cxx
- Source file which contains the implementation of our data class.
-
-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 data to STDERR, including the extra attribute. Finally, the driver
- serializes the object model back to XML.
-
-To run the example on the sample XML instance document simply execute:
-
-$ ./driver wildcard.xml
diff --git a/examples/cxx/tree/custom/wildcard/driver.cxx b/examples/cxx/tree/custom/wildcard/driver.cxx
deleted file mode 100644
index d29f125..0000000
--- a/examples/cxx/tree/custom/wildcard/driver.cxx
+++ /dev/null
@@ -1,47 +0,0 @@
-// file : examples/cxx/tree/custom/wildcard/driver.cxx
-// copyright : not copyrighted - public domain
-
-#include <memory> // std::auto_ptr
-#include <iostream>
-
-#include "wildcard.hxx"
-
-using std::cerr;
-using std::endl;
-
-int
-main (int argc, char* argv[])
-{
- if (argc != 2)
- {
- cerr << "usage: " << argv[0] << " wildcard.xml" << endl;
- return 1;
- }
-
- try
- {
- using namespace wildcard;
-
- // Parse.
- //
- std::auto_ptr<data> d (data_ (argv[1]));
-
- // Print.
- //
- cerr << *d << endl;
-
- // Serialize.
- //
- xml_schema::namespace_infomap map;
-
- map["wc"].name = "http://www.codesynthesis.com/wildcard";
- map["wc"].schema = "wildcard.xsd";
-
- data_ (std::cout, *d, map);
- }
- catch (const xml_schema::exception& e)
- {
- cerr << e << endl;
- return 1;
- }
-}
diff --git a/examples/cxx/tree/custom/wildcard/makefile b/examples/cxx/tree/custom/wildcard/makefile
deleted file mode 100644
index ed8801c..0000000
--- a/examples/cxx/tree/custom/wildcard/makefile
+++ /dev/null
@@ -1,115 +0,0 @@
-# file : examples/cxx/tree/custom/wildcard/makefile
-# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
-
-include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make
-
-xsd := wildcard.xsd
-cxx := driver.cxx wildcard-custom.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
-
-# We have to double-escape '#' because the message function
-# (which is used in command scripts) expands things twice.
-#
-$(gen): xsd_options += \
---generate-inline \
---generate-ostream \
---generate-serialization \
---custom-type data=/data_base \
---hxx-epilogue '\#include "wildcard-custom.hxx"'
-
-$(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)/wildcard.xsd,$(install_doc_dir)/xsd/$(path)/wildcard.xsd)
- $(call install-data,$(src_base)/wildcard.xml,$(install_doc_dir)/xsd/$(path)/wildcard.xml)
- $(call install-data,$(src_base)/wildcard-custom.hxx,$(install_doc_dir)/xsd/$(path)/wildcard-custom.hxx)
- $(call install-data,$(src_base)/wildcard-custom.cxx,$(install_doc_dir)/xsd/$(path)/wildcard-custom.cxx)
-
-$(dist-common):
- $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx)
- $(call install-data,$(src_base)/wildcard.xsd,$(dist_prefix)/$(path)/wildcard.xsd)
- $(call install-data,$(src_base)/wildcard.xml,$(dist_prefix)/$(path)/wildcard.xml)
- $(call install-data,$(src_base)/wildcard-custom.hxx,$(dist_prefix)/$(path)/wildcard-custom.hxx)
- $(call install-data,$(src_base)/wildcard-custom.cxx,$(dist_prefix)/$(path)/wildcard-custom.cxx)
-
-$(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/examples/cxx/tree/custom/wildcard/wildcard-custom.cxx b/examples/cxx/tree/custom/wildcard/wildcard-custom.cxx
deleted file mode 100644
index 006f93a..0000000
--- a/examples/cxx/tree/custom/wildcard/wildcard-custom.cxx
+++ /dev/null
@@ -1,84 +0,0 @@
-// file : examples/cxx/tree/custom/wildcard/wildcard-custom.cxx
-// copyright : not copyrighted - public domain
-
-#include <ostream>
-
-// Include wildcard.hxx instead of wildcard-custom.hxx here.
-//
-#include "wildcard.hxx"
-
-namespace wildcard
-{
- data::
- data (const xml_schema::string& d)
- : data_base (d), scope_present_ (false)
- {
- }
-
- data::
- data (const xercesc::DOMElement& e,
- xml_schema::flags f,
- xml_schema::container* c)
- : data_base (e, f, c), scope_present_ (false)
- {
- // Check if we've got the scope attribute.
- //
- namespace xml = xsd::cxx::xml;
- xml::string name ("scope");
-
- if (e.hasAttribute (name.c_str ()))
- {
- scope (xml::transcode<char> (e.getAttribute (name.c_str ())));
- }
- }
-
- data::
- data (const data& d,
- xml_schema::flags f,
- xml_schema::container* c)
- : data_base (d, f, c),
- scope_present_ (d.scope_present_),
- scope_ (d.scope_)
- {
- }
-
- data* data::
- _clone (xml_schema::flags f, xml_schema::container* c) const
- {
- return new data (*this, f, c);
- }
-
- void
- operator<< (xercesc::DOMElement& e, const data& x)
- {
- // Use our base to serialize data and id.
- //
- const data_base& b (x);
- e << b;
-
- // Add the scope attribute if present.
- //
- if (x.scope_present ())
- {
- namespace xml = xsd::cxx::xml;
- xml::string name ("scope");
- xml::string value (x.scope ());
-
- e.setAttribute (name.c_str (), value.c_str ());
- }
- }
-
- std::ostream&
- operator<< (std::ostream& os, const data& x)
- {
- // Use our base to print date and id.
- //
- const data_base& b (x);
- os << b;
-
- if (x.scope_present ())
- os << std::endl << "scope: " << x.scope ();
-
- return os;
- }
-}
diff --git a/examples/cxx/tree/custom/wildcard/wildcard-custom.hxx b/examples/cxx/tree/custom/wildcard/wildcard-custom.hxx
deleted file mode 100644
index 0546d38..0000000
--- a/examples/cxx/tree/custom/wildcard/wildcard-custom.hxx
+++ /dev/null
@@ -1,66 +0,0 @@
-// file : examples/cxx/tree/custom/wildcard/wildcard-custom.hxx
-// copyright : not copyrighted - public domain
-
-// Do not include this file directly, use wildcard.hxx instead. This
-// file is included into generated wildcard.hxx so we do not need to
-// guard against multiple inclusions.
-//
-
-namespace wildcard
-{
- class data: public data_base
- {
- // Standard constructors.
- //
- public:
- data (const xml_schema::string&);
-
- data (const xercesc::DOMElement&,
- xml_schema::flags = 0,
- xml_schema::container* = 0);
-
- data (const data&,
- xml_schema::flags = 0,
- xml_schema::container* = 0);
-
- virtual data*
- _clone (xml_schema::flags = 0,
- xml_schema::container* = 0) const;
-
- // Our customizations.
- //
- public:
- bool
- scope_present () const
- {
- return scope_present_;
- }
-
- const xml_schema::string&
- scope () const
- {
- return scope_;
- }
-
- void
- scope (const xml_schema::string& s)
- {
- scope_present_ = true;
- scope_ = s;
- }
-
- private:
- bool scope_present_;
- xml_schema::string scope_;
- };
-
- // Serialization operator.
- //
- void
- operator<< (xercesc::DOMElement&, const data&);
-
- // std::ostream insertion operator.
- //
- std::ostream&
- operator<< (std::ostream&, const data&);
-}
diff --git a/examples/cxx/tree/custom/wildcard/wildcard.xml b/examples/cxx/tree/custom/wildcard/wildcard.xml
deleted file mode 100644
index 80f215a..0000000
--- a/examples/cxx/tree/custom/wildcard/wildcard.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/wildcard/wildcard.xml
-copyright : not copyrighted - public domain
-
--->
-
-<wc:data xmlns:wc="http://www.codesynthesis.com/wildcard"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.codesynthesis.com/wildcard wildcard.xsd"
- id="1"
- scope="global">abc123</wc:data>
diff --git a/examples/cxx/tree/custom/wildcard/wildcard.xsd b/examples/cxx/tree/custom/wildcard/wildcard.xsd
deleted file mode 100644
index 1a32b1e..0000000
--- a/examples/cxx/tree/custom/wildcard/wildcard.xsd
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
-
-file : examples/cxx/tree/custom/wildcard/wildcard.xsd
-copyright : not copyrighted - public domain
-
--->
-
-<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:wc="http://www.codesynthesis.com/wildcard"
- targetNamespace="http://www.codesynthesis.com/wildcard">
-
- <xsd:complexType name="data">
- <xsd:simpleContent>
- <xsd:extension base="xsd:string">
- <xsd:attribute name="id" type="xsd:unsignedInt"/>
- <xsd:anyAttribute namespace="##any" processContents="skip"/>
- </xsd:extension>
- </xsd:simpleContent>
- </xsd:complexType>
-
- <xsd:element name="data" type="wc:data"/>
-
-</xsd:schema>