diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-03-26 17:09:53 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-03-26 17:09:53 +0200 |
commit | e4c22d3686da0e973e21eae0561c1169c0eeff36 (patch) | |
tree | 0a49e9167edc88938b0287949080931314e8afea /libxsde/xsde/cxx/hybrid | |
parent | 0d62005a3ff3b62d02c2eb3fd8644e0e19b202e8 (diff) |
Implement support for XML Schema polymorphism in C++/Hybrid
examples/cxx/hybrid/polyroot/
examples/cxx/hybrid/polymorphism/: new examples
tests/cxx/hybrid/polymorphism/: new tests
Diffstat (limited to 'libxsde/xsde/cxx/hybrid')
-rw-r--r-- | libxsde/xsde/cxx/hybrid/any-type.cxx | 53 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/any-type.hxx | 28 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/parser-map.cxx | 59 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/parser-map.hxx | 52 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/serializer-map.cxx | 61 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/serializer-map.hxx | 52 |
6 files changed, 305 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/hybrid/any-type.cxx b/libxsde/xsde/cxx/hybrid/any-type.cxx new file mode 100644 index 0000000..b16356c --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/hybrid/any-type.cxx +// 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 <xsde/cxx/hybrid/any-type.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // any_type + // +#ifdef XSDE_POLYMORPHIC + any_type:: + ~any_type () + { + } + +#ifdef XSDE_STL + const std::string& any_type:: + _dynamic_type () const + { + return _static_type (); + } + + static const std::string any_type_static_type_ = + "anyType http://www.w3.org/2001/XMLSchema"; + + const std::string& any_type:: + _static_type () + { + return any_type_static_type_; + } +#else + const char* any_type:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_type:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } +#endif +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type.hxx b/libxsde/xsde/cxx/hybrid/any-type.hxx index db512c2..f94f007 100644 --- a/libxsde/xsde/cxx/hybrid/any-type.hxx +++ b/libxsde/xsde/cxx/hybrid/any-type.hxx @@ -6,6 +6,14 @@ #ifndef XSDE_CXX_HYBRID_ANY_TYPE_HXX #define XSDE_CXX_HYBRID_ANY_TYPE_HXX +#include <xsde/cxx/config.hxx> + +/* +#ifdef XSDE_STL +# include <string> +#endif +*/ + namespace xsde { namespace cxx @@ -14,6 +22,26 @@ namespace xsde { struct any_type { + /* +#ifdef XSDE_POLYMORPHIC + virtual + ~any_type (); + +#ifdef XSDE_STL + virtual const std::string& + _dynamic_type () const; + + static const std::string& + _static_type (); +#else + virtual const char* + _dynamic_type () const; + + static const char* + _static_type (); +#endif +#endif + */ }; struct any_simple_type diff --git a/libxsde/xsde/cxx/hybrid/parser-map.cxx b/libxsde/xsde/cxx/hybrid/parser-map.cxx new file mode 100644 index 0000000..c19325c --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/parser-map.cxx @@ -0,0 +1,59 @@ +// file : xsde/cxx/hybrid/parser-map.cxx +// 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 <string.h> // strcmp + +#include <xsde/cxx/hybrid/parser-map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + parser::parser_base* parser_map_impl:: + find (const char* tid) const + { + // Binary search. + // + if (size_ == 0) + return 0; + + size_t l = 0; + size_t h = size_ - 1; + + while (l <= h) + { + size_t m = l + (h - l)/2; + int r = strcmp (entries_[m].type_id, tid); + + if (r > 0) + h = m - 1; + else if (r < 0) + l = m + 1; + else + return entries_[m].parser; + } + + return 0; + } + + void parser_map_impl:: + reset () const + { + if (resetting_) + return; + + bool& r = const_cast<bool&> (resetting_); + r = true; + + for (const entry* p = entries_; p != entries_ + size_; ++p) + p->parser->_reset (); + + r = false; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/parser-map.hxx b/libxsde/xsde/cxx/hybrid/parser-map.hxx new file mode 100644 index 0000000..df84f22 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/parser-map.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/hybrid/parser-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_PARSER_MAP_HXX +#define XSDE_CXX_HYBRID_PARSER_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class parser_map_impl: public parser::parser_map + { + public: + struct entry + { + const char* type_id; + parser::parser_base* parser; + }; + + parser_map_impl (entry* entries, size_t size) + : entries_ (entries), size_ (size), resetting_ (false) + { + } + + virtual parser::parser_base* + find (const char* type_id) const; + + virtual void + reset () const; + + private: + parser_map_impl (const parser_map_impl&); + parser_map_impl& operator= (const parser_map_impl&); + + private: + entry* entries_; + size_t size_; + bool resetting_; + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_PARSER_MAP_HXX diff --git a/libxsde/xsde/cxx/hybrid/serializer-map.cxx b/libxsde/xsde/cxx/hybrid/serializer-map.cxx new file mode 100644 index 0000000..7fce5fd --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/serializer-map.cxx @@ -0,0 +1,61 @@ +// file : xsde/cxx/hybrid/serializer-map.cxx +// 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 <string.h> // strcmp + +#include <xsde/cxx/hybrid/serializer-map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + serializer::serializer_base* serializer_map_impl:: + find (const void* v) const + { + const char* tid = static_cast<const char*> (v); + + // Binary search. + // + if (size_ == 0) + return 0; + + size_t l = 0; + size_t h = size_ - 1; + + while (l <= h) + { + size_t m = l + (h - l)/2; + int r = strcmp (entries_[m].type_id, tid); + + if (r > 0) + h = m - 1; + else if (r < 0) + l = m + 1; + else + return entries_[m].serializer; + } + + return 0; + } + + void serializer_map_impl:: + reset () const + { + if (resetting_) + return; + + bool& r = const_cast<bool&> (resetting_); + r = true; + + for (const entry* p = entries_; p != entries_ + size_; ++p) + p->serializer->_reset (); + + r = false; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/serializer-map.hxx b/libxsde/xsde/cxx/hybrid/serializer-map.hxx new file mode 100644 index 0000000..5e3fb1a --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/serializer-map.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/hybrid/serializer-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_SERIALIZER_MAP_HXX +#define XSDE_CXX_HYBRID_SERIALIZER_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/serializer/map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class serializer_map_impl: public serializer::serializer_map + { + public: + struct entry + { + const char* type_id; + serializer::serializer_base* serializer; + }; + + serializer_map_impl (entry* entries, size_t size) + : entries_ (entries), size_ (size), resetting_ (true) + { + } + + virtual serializer::serializer_base* + find (const void* type_id) const; + + virtual void + reset () const; + + private: + serializer_map_impl (const serializer_map_impl&); + serializer_map_impl& operator= (const serializer_map_impl&); + + private: + entry* entries_; + size_t size_; + bool resetting_; + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_SERIALIZER_MAP_HXX |