diff options
Diffstat (limited to 'xsd/libxsd/xsd/cxx/tree')
84 files changed, 27052 insertions, 0 deletions
diff --git a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx new file mode 100644 index 0000000..7c3fc96 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx @@ -0,0 +1,26 @@ +// file : xsd/cxx/tree/ace-cdr-stream-common.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX + +#include <xsd/cxx/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Base exception for ACE CDR insertion/extraction exceptions. + // + struct ace_cdr_stream_operation: xsd::cxx::exception + { + }; + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx new file mode 100644 index 0000000..53e1f6c --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -0,0 +1,334 @@ +// file : xsd/cxx/tree/ace-cdr-stream-extraction.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX + +#include <cstddef> // std::size_t +#include <string> + +#include <ace/ACE.h> // ACE::strdelete +#include <ace/CDR_Stream.h> + +#include <xsd/cxx/auto-array.hxx> + +#include <xsd/cxx/tree/buffer.hxx> +#include <xsd/cxx/tree/istream.hxx> +#include <xsd/cxx/tree/ace-cdr-stream-common.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_extraction: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream extraction operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_size<T>& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r) || + r > ~(T (0))) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } +#else + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_size<T>& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } +#endif + + + // 8-bit + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_int8<T>& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_uint8<T>& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + + // 16-bit + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_int16<T>& x) + { + ACE_CDR::Short r; + + if (!s.impl ().read_short (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_uint16<T>& x) + { + ACE_CDR::UShort r; + + if (!s.impl ().read_ushort (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + + // 32-bit + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_int32<T>& x) + { + ACE_CDR::Long r; + + if (!s.impl ().read_long (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_uint32<T>& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + + // 64-bit + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_int64<T>& x) + { + ACE_CDR::LongLong r; + + if (!s.impl ().read_longlong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_uint64<T>& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + + // Boolean + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_bool<T>& x) + { + ACE_CDR::Boolean r; + + if (!s.impl ().read_boolean (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + + // Floating-point + // + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_float32<T>& x) + { + ACE_CDR::Float r; + + if (!s.impl ().read_float (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + template <typename T> + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, + istream<ACE_InputCDR>::as_float64<T>& x) + { + ACE_CDR::Double r; + + if (!s.impl ().read_double (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast<T> (r); + + return s; + } + + // Extraction of std::basic_string. + // + + namespace bits + { + template<typename C> + struct ace_str_deallocator + { + void + deallocate (C* s) + { + ACE::strdelete (s); + } + }; + } + + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, std::basic_string<char>& x) + { + typedef bits::ace_str_deallocator<char> deallocator; + + deallocator d; + char* r; + + if (!s.impl ().read_string (r)) + throw ace_cdr_stream_extraction (); + + auto_array<char, deallocator> ar (r, d); + + x = r; + + return s; + } + +#ifdef ACE_HAS_WCHAR + inline istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, std::basic_string<wchar_t>& x) + { + typedef bits::ace_str_deallocator<wchar_t> deallocator; + + deallocator d; + wchar_t* r; + + if (!s.impl ().read_wstring (r)) + throw ace_cdr_stream_extraction (); + + auto_array<wchar_t, deallocator> ar (r, d); + + x = r; + + return s; + } +#endif + + + // Extraction of a binary buffer. + // + template <typename C> + istream<ACE_InputCDR>& + operator>> (istream<ACE_InputCDR>& s, buffer<C>& x) + { + ACE_CDR::ULong size; + + if (!s.impl ().read_ulong (size)) + throw ace_cdr_stream_extraction (); + + x.size (size); + + if (!s.impl ().read_octet_array ( + reinterpret_cast<ACE_CDR::Octet*> (x.data ()), size)) + throw ace_cdr_stream_extraction (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx new file mode 100644 index 0000000..0f723d0 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx @@ -0,0 +1,249 @@ +// file : xsd/cxx/tree/ace-cdr-stream-insertion.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX + +#include <cstddef> // std::size_t +#include <string> + +#include <ace/CDR_Stream.h> + +#include <xsd/cxx/tree/buffer.hxx> +#include <xsd/cxx/tree/ostream.hxx> +#include <xsd/cxx/tree/ace-cdr-stream-common.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_insertion: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream insertion operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_size<T> x) + { + if (!s.impl ().write_ulonglong ( + static_cast<ACE_CDR::ULongLong> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } +#else + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_size<T> x) + { + if (x.x_ > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast<ACE_CDR::ULong> (x.x_))) + throw ace_cdr_stream_insertion (); + + return s; + } +#endif + + + // 8-bit + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_int8<T> x) + { + ACE_CDR::Octet r (static_cast<ACE_CDR::Octet> (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_uint8<T> x) + { + ACE_CDR::Octet r (static_cast<ACE_CDR::Octet> (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + + // 16-bit + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_int16<T> x) + { + if (!s.impl ().write_short (static_cast<ACE_CDR::Short> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_uint16<T> x) + { + if (!s.impl ().write_ushort (static_cast<ACE_CDR::UShort> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 32-bit + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_int32<T> x) + { + if (!s.impl ().write_long (static_cast<ACE_CDR::Long> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_uint32<T> x) + { + if (!s.impl ().write_ulong (static_cast<ACE_CDR::ULong> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 64-bit + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_int64<T> x) + { + if (!s.impl ().write_longlong (static_cast<ACE_CDR::LongLong> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_uint64<T> x) + { + if (!s.impl ().write_ulonglong ( + static_cast<ACE_CDR::ULongLong> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Boolean + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_bool<T> x) + { + if (!s.impl ().write_boolean (static_cast<ACE_CDR::Boolean> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Floating-point + // + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_float32<T> x) + { + if (!s.impl ().write_float (static_cast<ACE_CDR::Float> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template <typename T> + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + ostream<ACE_OutputCDR>::as_float64<T> x) + { + if (!s.impl ().write_double (static_cast<ACE_CDR::Double> (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + // Insertion of std::basic_string. + // + + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, const std::basic_string<char>& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_string ( + static_cast<ACE_CDR::ULong> (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } + +#ifdef ACE_HAS_WCHAR + inline ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, + const std::basic_string<wchar_t>& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_wstring ( + static_cast<ACE_CDR::ULong> (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } +#endif + + // Insertion of a binary buffer. + // + template <typename C> + ostream<ACE_OutputCDR>& + operator<< (ostream<ACE_OutputCDR>& s, const buffer<C>& x) + { + std::size_t size (x.size ()); + + // It is not possible to write an array with a 64-bit size. + // + if (size > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast<ACE_CDR::ULong> (size)) || + !s.impl ().write_octet_array ( + reinterpret_cast<const ACE_CDR::Octet*> (x.data ()), size)) + throw ace_cdr_stream_insertion (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/bits/literals.hxx b/xsd/libxsd/xsd/cxx/tree/bits/literals.hxx new file mode 100644 index 0000000..49ac0ca --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/bits/literals.hxx @@ -0,0 +1,261 @@ +// file : xsd/cxx/tree/bits/literals.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_BITS_LITERALS_HXX +#define XSD_CXX_TREE_BITS_LITERALS_HXX + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // Boolean literals + // + template<typename C> + const C* + true_ (); + + template<typename C> + const C* + one (); + + // Float literals: INF -INF NaN. + // + template<typename C> + const C* + positive_inf (); + + template<typename C> + const C* + negative_inf (); + + template<typename C> + const C* + nan (); + + // Optional "not present" literal. + // + template<typename C> + const C* + not_present (); + + // XML Schema namespace + // + template <typename C> + const C* + xml_schema (); + + // Built-in XML Schema type names. + // + template <typename C> + const C* + any_type (); + + template <typename C> + const C* + any_simple_type (); + + template <typename C> + const C* + string (); + + template <typename C> + const C* + normalized_string (); + + template <typename C> + const C* + token (); + + template <typename C> + const C* + name (); + + template <typename C> + const C* + nmtoken (); + + template <typename C> + const C* + nmtokens (); + + template <typename C> + const C* + ncname (); + + template <typename C> + const C* + language (); + + template <typename C> + const C* + id (); + + template <typename C> + const C* + idref (); + + template <typename C> + const C* + idrefs (); + + template <typename C> + const C* + any_uri (); + + template <typename C> + const C* + qname (); + + template <typename C> + const C* + base64_binary (); + + template <typename C> + const C* + hex_binary (); + + template <typename C> + const C* + date (); + + template <typename C> + const C* + date_time (); + + template <typename C> + const C* + duration (); + + template <typename C> + const C* + gday (); + + template <typename C> + const C* + gmonth (); + + template <typename C> + const C* + gmonth_day (); + + template <typename C> + const C* + gyear (); + + template <typename C> + const C* + gyear_month (); + + template <typename C> + const C* + time (); + + template <typename C> + const C* + entity (); + + template <typename C> + const C* + entities (); + + // gday ("---") and gmonth ("--") prefixes. + // + template <typename C> + const C* + gday_prefix (); + + template <typename C> + const C* + gmonth_prefix (); + + // Exception and diagnostics string literals. + // + template <typename C> + const C* + ex_error_error (); // " error: " + + template <typename C> + const C* + ex_error_warning (); // " warning: " + + template <typename C> + const C* + ex_parsing_msg (); // "instance document parsing failed" + + template <typename C> + const C* + ex_eel_expected (); // "expected element '" + + template <typename C> + const C* + ex_uel_expected (); // "expected element '" + + template <typename C> + const C* + ex_uel_instead (); // "' instead of '" + + template <typename C> + const C* + ex_uel_unexpected (); // "unexpected element '" + + template <typename C> + const C* + ex_eat_expected (); // "expected attribute '" + + template <typename C> + const C* + ex_uen_unexpected (); // "unexpected enumerator '" + + template <typename C> + const C* + ex_etc_msg (); // "expected text content" + + template <typename C> + const C* + ex_nti_no_type_info (); // "no type information available for type '" + + template <typename C> + const C* + ex_nei_no_element_info (); // "no parsing or serialization information + // available for element '" + template <typename C> + const C* + ex_nd_type (); // "type '" + + template <typename C> + const C* + ex_nd_not_derived (); // "' is not derived from '" + + template <typename C> + const C* + ex_di_id (); // "ID '" + + template <typename C> + const C* + ex_di_already_exist (); // "' already exist" + + template <typename C> + const C* + ex_serialization_msg (); // "serialization failed" + + template <typename C> + const C* + ex_npm_no_mapping (); // "no mapping provided for namespace prefix '" + + template <typename C> + const C* + ex_bounds_msg (); // "buffer boundary rules have been violated" + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_HXX + +#include <xsd/cxx/tree/bits/literals.ixx> diff --git a/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx b/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx new file mode 100644 index 0000000..260a9e7 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx @@ -0,0 +1,876 @@ +// file : xsd/cxx/tree/bits/literals.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX +#define XSD_CXX_TREE_BITS_LITERALS_IXX + +// The char versions of the following literals are required even +// if we are using wchar_t as the character type. +// +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + positive_inf<char> () + { + return "INF"; + } + + template<> + inline const char* + negative_inf<char> () + { + return "-INF"; + } + + template<> + inline const char* + nan<char> () + { + return "NaN"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX + + +#if defined(XSD_CXX_TREE_USE_CHAR) || !defined(XSD_CXX_TREE_USE_WCHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + true_<char> () + { + return "true"; + } + + template<> + inline const char* + one<char> () + { + return "1"; + } + + // + // + template<> + inline const char* + not_present<char> () + { + return "<not present>"; + } + + // + // + template <> + inline const char* + xml_schema<char> () + { + return "http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const char* + any_type<char> () + { + return "anyType"; + } + + template <> + inline const char* + any_simple_type<char> () + { + return "anySimpleType"; + } + + template <> + inline const char* + string<char> () + { + return "string"; + } + + template <> + inline const char* + normalized_string<char> () + { + return "normalizedString"; + } + + template <> + inline const char* + token<char> () + { + return "token"; + } + + template <> + inline const char* + name<char> () + { + return "Name"; + } + + template <> + inline const char* + nmtoken<char> () + { + return "NMTOKEN"; + } + + template <> + inline const char* + nmtokens<char> () + { + return "NMTOKENS"; + } + + template <> + inline const char* + ncname<char> () + { + return "NCName"; + } + + template <> + inline const char* + language<char> () + { + return "language"; + } + + + template <> + inline const char* + id<char> () + { + return "ID"; + } + + template <> + inline const char* + idref<char> () + { + return "IDREF"; + } + + template <> + inline const char* + idrefs<char> () + { + return "IDREFS"; + } + + template <> + inline const char* + any_uri<char> () + { + return "anyURI"; + } + + template <> + inline const char* + qname<char> () + { + return "QName"; + } + + template <> + inline const char* + base64_binary<char> () + { + return "base64Binary"; + } + + template <> + inline const char* + hex_binary<char> () + { + return "hexBinary"; + } + + template <> + inline const char* + date<char> () + { + return "date"; + } + + template <> + inline const char* + date_time<char> () + { + return "dateTime"; + } + + template <> + inline const char* + duration<char> () + { + return "duration"; + } + + template <> + inline const char* + gday<char> () + { + return "gDay"; + } + + template <> + inline const char* + gmonth<char> () + { + return "gMonth"; + } + + template <> + inline const char* + gmonth_day<char> () + { + return "gMonthDay"; + } + + template <> + inline const char* + gyear<char> () + { + return "gYear"; + } + + template <> + inline const char* + gyear_month<char> () + { + return "gYearMonth"; + } + + template <> + inline const char* + time<char> () + { + return "time"; + } + + template <> + inline const char* + entity<char> () + { + return "ENTITY"; + } + + template <> + inline const char* + entities<char> () + { + return "ENTITIES"; + } + + template <> + inline const char* + gday_prefix<char> () + { + return "---"; + } + + template <> + inline const char* + gmonth_prefix<char> () + { + return "--"; + } + + // + // + template <> + inline const char* + ex_error_error<char> () + { + return " error: "; + } + + template <> + inline const char* + ex_error_warning<char> () + { + return " warning: "; + } + + template <> + inline const char* + ex_parsing_msg<char> () + { + return "instance document parsing failed"; + } + + template <> + inline const char* + ex_eel_expected<char> () + { + return "expected element '"; + } + + template <> + inline const char* + ex_uel_expected<char> () + { + return "expected element '"; + } + + template <> + inline const char* + ex_uel_instead<char> () + { + return "' instead of '"; + } + + template <> + inline const char* + ex_uel_unexpected<char> () + { + return "unexpected element '"; + } + + template <> + inline const char* + ex_eat_expected<char> () + { + return "expected attribute '"; + } + + template <> + inline const char* + ex_uen_unexpected<char> () + { + return "unexpected enumerator '"; + } + + template <> + inline const char* + ex_etc_msg<char> () + { + return "expected text content"; + } + + template <> + inline const char* + ex_nti_no_type_info<char> () + { + return "no type information available for type '"; + } + + template <> + inline const char* + ex_nei_no_element_info<char> () + { + return "no parsing or serialization information available for " + "element '"; + } + template <> + inline const char* + ex_nd_type<char> () + { + return "type '"; + } + + template <> + inline const char* + ex_nd_not_derived<char> () + { + return "' is not derived from '"; + } + + template <> + inline const char* + ex_di_id<char> () + { + return "ID '"; + } + + template <> + inline const char* + ex_di_already_exist<char> () + { + return "' already exist"; + } + + template <> + inline const char* + ex_serialization_msg<char> () + { + return "serialization failed"; + } + + template <> + inline const char* + ex_npm_no_mapping<char> () + { + return "no mapping provided for namespace prefix '"; + } + + template <> + inline const char* + ex_bounds_msg<char> () + { + return "buffer boundary rules have been violated"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#endif // XSD_CXX_TREE_USE_CHAR + + +#if defined(XSD_CXX_TREE_USE_WCHAR) || !defined(XSD_CXX_TREE_USE_CHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const wchar_t* + true_<wchar_t> () + { + return L"true"; + } + + template<> + inline const wchar_t* + one<wchar_t> () + { + return L"1"; + } + + // + // + template<> + inline const wchar_t* + positive_inf<wchar_t> () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf<wchar_t> () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan<wchar_t> () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + not_present<wchar_t> () + { + return L"<not present>"; + } + + // + // + template <> + inline const wchar_t* + xml_schema<wchar_t> () + { + return L"http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const wchar_t* + any_type<wchar_t> () + { + return L"anyType"; + } + + template <> + inline const wchar_t* + any_simple_type<wchar_t> () + { + return L"anySimpleType"; + } + + template <> + inline const wchar_t* + string<wchar_t> () + { + return L"string"; + } + + template <> + inline const wchar_t* + normalized_string<wchar_t> () + { + return L"normalizedString"; + } + + template <> + inline const wchar_t* + token<wchar_t> () + { + return L"token"; + } + + template <> + inline const wchar_t* + name<wchar_t> () + { + return L"Name"; + } + + template <> + inline const wchar_t* + nmtoken<wchar_t> () + { + return L"NMTOKEN"; + } + + template <> + inline const wchar_t* + nmtokens<wchar_t> () + { + return L"NMTOKENS"; + } + + template <> + inline const wchar_t* + ncname<wchar_t> () + { + return L"NCName"; + } + + template <> + inline const wchar_t* + language<wchar_t> () + { + return L"language"; + } + + + template <> + inline const wchar_t* + id<wchar_t> () + { + return L"ID"; + } + + template <> + inline const wchar_t* + idref<wchar_t> () + { + return L"IDREF"; + } + + template <> + inline const wchar_t* + idrefs<wchar_t> () + { + return L"IDREFS"; + } + + template <> + inline const wchar_t* + any_uri<wchar_t> () + { + return L"anyURI"; + } + + template <> + inline const wchar_t* + qname<wchar_t> () + { + return L"QName"; + } + + template <> + inline const wchar_t* + base64_binary<wchar_t> () + { + return L"base64Binary"; + } + + template <> + inline const wchar_t* + hex_binary<wchar_t> () + { + return L"hexBinary"; + } + + template <> + inline const wchar_t* + date<wchar_t> () + { + return L"date"; + } + + template <> + inline const wchar_t* + date_time<wchar_t> () + { + return L"dateTime"; + } + + template <> + inline const wchar_t* + duration<wchar_t> () + { + return L"duration"; + } + + template <> + inline const wchar_t* + gday<wchar_t> () + { + return L"gDay"; + } + + template <> + inline const wchar_t* + gmonth<wchar_t> () + { + return L"gMonth"; + } + + template <> + inline const wchar_t* + gmonth_day<wchar_t> () + { + return L"gMonthDay"; + } + + template <> + inline const wchar_t* + gyear<wchar_t> () + { + return L"gYear"; + } + + template <> + inline const wchar_t* + gyear_month<wchar_t> () + { + return L"gYearMonth"; + } + + template <> + inline const wchar_t* + time<wchar_t> () + { + return L"time"; + } + + template <> + inline const wchar_t* + entity<wchar_t> () + { + return L"ENTITY"; + } + + template <> + inline const wchar_t* + entities<wchar_t> () + { + return L"ENTITIES"; + } + + template <> + inline const wchar_t* + gday_prefix<wchar_t> () + { + return L"---"; + } + + template <> + inline const wchar_t* + gmonth_prefix<wchar_t> () + { + return L"--"; + } + + // + // + template <> + inline const wchar_t* + ex_error_error<wchar_t> () + { + return L" error: "; + } + + template <> + inline const wchar_t* + ex_error_warning<wchar_t> () + { + return L" warning: "; + } + + template <> + inline const wchar_t* + ex_parsing_msg<wchar_t> () + { + return L"instance document parsing failed"; + } + + template <> + inline const wchar_t* + ex_eel_expected<wchar_t> () + { + return L"expected element '"; + } + + template <> + inline const wchar_t* + ex_uel_expected<wchar_t> () + { + return L"expected element '"; + } + + template <> + inline const wchar_t* + ex_uel_instead<wchar_t> () + { + return L"' instead of '"; + } + + template <> + inline const wchar_t* + ex_uel_unexpected<wchar_t> () + { + return L"unexpected element '"; + } + + template <> + inline const wchar_t* + ex_eat_expected<wchar_t> () + { + return L"expected attribute '"; + } + + template <> + inline const wchar_t* + ex_uen_unexpected<wchar_t> () + { + return L"unexpected enumerator '"; + } + + template <> + inline const wchar_t* + ex_etc_msg<wchar_t> () + { + return L"expected text content"; + } + + template <> + inline const wchar_t* + ex_nti_no_type_info<wchar_t> () + { + return L"no type information available for type '"; + } + + template <> + inline const wchar_t* + ex_nei_no_element_info<wchar_t> () + { + return L"no parsing or serialization information available for " + L"element '"; + } + template <> + inline const wchar_t* + ex_nd_type<wchar_t> () + { + return L"type '"; + } + + template <> + inline const wchar_t* + ex_nd_not_derived<wchar_t> () + { + return L"' is not derived from '"; + } + + template <> + inline const wchar_t* + ex_di_id<wchar_t> () + { + return L"ID '"; + } + + template <> + inline const wchar_t* + ex_di_already_exist<wchar_t> () + { + return L"' already exist"; + } + + template <> + inline const wchar_t* + ex_serialization_msg<wchar_t> () + { + return L"serialization failed"; + } + + template <> + inline const wchar_t* + ex_npm_no_mapping<wchar_t> () + { + return L"no mapping provided for namespace prefix '"; + } + + template <> + inline const wchar_t* + ex_bounds_msg<wchar_t> () + { + return L"buffer boundary rules have been violated"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#endif // XSD_CXX_TREE_USE_WCHAR diff --git a/xsd/libxsd/xsd/cxx/tree/buffer.hxx b/xsd/libxsd/xsd/cxx/tree/buffer.hxx new file mode 100644 index 0000000..24da287 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/buffer.hxx @@ -0,0 +1,337 @@ +// file : xsd/cxx/tree/buffer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains a simple binary buffer abstraction that is used to + * implement the base64Binary and hexBinary XML Schema built-in types. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_BUFFER_HXX +#define XSD_CXX_TREE_BUFFER_HXX + +#include <new> // operator new/delete +#include <cstddef> // std::size_t +#include <cstring> // std::memcpy, std::memcmp + +#include <xsd/cxx/tree/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + //@cond + + class buffer_base + { + protected: + virtual + ~buffer_base () + { + if (free_ && data_) + operator delete (data_); + } + + buffer_base () + : data_ (0), size_ (0), capacity_ (0), free_ (true) + { + } + + protected: + char* data_; + size_t size_; + size_t capacity_; + bool free_; + }; + + //@endcond + + /** + * @brief Simple binary %buffer abstraction + * + * The %buffer class manages a continuous binary %buffer. The base + * concepts are data (actual memory region), size (the portion of + * the %buffer that contains useful information), and capacity (the + * actual size of the underlying memory region). The bounds + * %exception is thrown from the constructors and modifier functions + * if the (size <= capacity) constraint is violated. + * + * Note that the template parameter is only used to instantiate + * %exception types. The underlying %buffer type is always @c char. + * + * @nosubgrouping + */ + template<typename C> + class buffer: protected buffer_base + { + public: + /** + * @brief Size type + */ + typedef std::size_t size_t; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Allocate a %buffer of the specified size. + * + * The resulting %buffer has the same size and capacity. + * + * @param size A %buffer size in bytes. + */ + explicit + buffer (size_t size = 0); + + /** + * @brief Allocate a %buffer of the specified size and capacity. + * + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (size_t size, size_t capacity); + + /** + * @brief Allocate a %buffer of the specified size and copy + * the data. + * + * The resulting %buffer has the same size and capacity with + * @a size bytes copied from @a data. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + */ + buffer (const void* data, size_t size); + + /** + * @brief Allocate a %buffer of the specified size and capacity + * and copy the data. + * + * @a size bytes are copied from @a data to the resulting + * %buffer. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (const void* data, size_t size, size_t capacity); + + /** + * @brief Reuse an existing %buffer. + * + * If the @a assume_ownership argument is true, the %buffer will + * assume ownership of @a data and will release the memory + * by calling @c operator @c delete(). + * + * @param data A %buffer to reuse. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @param assume_ownership A boolean value indication whether to + * assume ownership. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + + /** + * @brief Copy constructor. + * + * The copy constructor performs a deep copy of the underlying + * memory %buffer. + * + * @param x An instance to make a copy of. + */ + buffer (const buffer& x); + + //@} + + public: + /** + * @brief Copy assignment operator. + * + * The copy assignment operator changes the buffer's capacity + * to @c x.capacity() and copies @c x.size() bytes from @a x. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + buffer& + operator= (const buffer& x); + + public: + /** + * @brief Get buffer's capacity. + * + * @return A number of bytes that the %buffer can hold without + * reallocation. + */ + size_t + capacity () const + { + return capacity_; + } + + /** + * @brief Set buffer's capacity. + * + * @param c The new capacity in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + capacity (size_t c) + { + return this->capacity (c, true); + } + + public: + /** + * @brief Get buffer's size. + * + * @return A number of bytes that the %buffer holds. + */ + size_t + size () const {return size_;} + + /** + * @brief Set buffer's size. + * + * @param s The new size in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + size (size_t s) + { + bool r (false); + + if (s > capacity_) + r = capacity (s); + + size_ = s; + + return r; + } + + public: + /** + * @brief Get the underlying memory region. + * + * @return A constant pointer to the underlying memory region. + */ + const char* + data () const {return data_;} + + /** + * @brief Get the underlying memory region. + * + * @return A pointer to the underlying memory region. + */ + char* + data () {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A constant pointer to the first byte of the underlying + * memory region. + */ + const char* + begin () const {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A pointer to the first byte of the underlying memory + * region. + */ + char* + begin () {return data_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A constant pointer to the one past last byte of the + * underlying memory region (that is @c %begin() @c + @c %size() ). + */ + const char* + end () const {return data_ + size_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A pointer to the one past last byte of the underlying + * memory region (that is @c %begin() @c + @c %size() ). + */ + char* + end () {return data_ + size_;} + + public: + /** + * @brief Swap data with another %buffer. + * + * @param x A %buffer to swap with. + */ + void + swap (buffer& x); + + private: + bool + capacity (size_t capacity, bool copy); + }; + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have the same sizes and the same + * data. + */ + template <typename C> + inline bool + operator== (const buffer<C>& a, const buffer<C>& b) + { + return a.size () == b.size () && + std::memcmp (a.data (), b.data (), a.size ()) == 0; + } + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have different sizes or different + * data. + */ + template <typename C> + inline bool + operator!= (const buffer<C>& a, const buffer<C>& b) + { + return !(a == b); + } + } + } +} + +#include <xsd/cxx/tree/buffer.txx> + +#endif // XSD_CXX_TREE_BUFFER_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/buffer.txx b/xsd/libxsd/xsd/cxx/tree/buffer.txx new file mode 100644 index 0000000..f88f140 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/buffer.txx @@ -0,0 +1,147 @@ +// file : xsd/cxx/tree/buffer.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + buffer<C>:: + buffer (size_t size) + { + capacity (size); + size_ = size; + } + + template <typename C> + buffer<C>:: + buffer (size_t size, size_t capacity) + { + if (size > capacity) + throw bounds<C> (); + + this->capacity (capacity); + size_ = size; + } + + template <typename C> + buffer<C>:: + buffer (const void* data, size_t size) + { + capacity (size); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template <typename C> + buffer<C>:: + buffer (const void* data, size_t size, size_t capacity) + { + if (size > capacity) + throw bounds<C> (); + + this->capacity (capacity); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template <typename C> + buffer<C>:: + buffer (void* data, size_t size, size_t capacity, bool own) + { + if (size > capacity) + throw bounds<C> (); + + data_ = reinterpret_cast<char*> (data); + size_ = size; + capacity_ = capacity; + free_ = own; + } + + template <typename C> + buffer<C>:: + buffer (const buffer& other) + : buffer_base () + { + capacity (other.capacity_); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + template <typename C> + buffer<C>& buffer<C>:: + operator= (const buffer& other) + { + if (this != &other) + { + capacity (other.capacity_, false); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + return *this; + } + + template <typename C> + void buffer<C>:: + swap (buffer& other) + { + char* tmp_data (data_); + size_t tmp_size (size_); + size_t tmp_capacity (capacity_); + bool tmp_free (free_); + + data_ = other.data_; + size_ = other.size_; + capacity_ = other.capacity_; + free_ = other.free_; + + other.data_ = tmp_data; + other.size_ = tmp_size; + other.capacity_ = tmp_capacity; + other.free_ = tmp_free; + } + + template <typename C> + bool buffer<C>:: + capacity (size_t capacity, bool copy) + { + if (size_ > capacity) + throw bounds<C> (); + + if (capacity <= capacity_) + { + return false; // Do nothing if shrinking is requested. + } + else + { + char* data (reinterpret_cast<char*> (operator new (capacity))); + + if (copy && size_ > 0) + std::memcpy (data, data_, size_); + + if (free_ && data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + free_ = true; + + return true; + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx b/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx new file mode 100644 index 0000000..b7794f4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx @@ -0,0 +1,113 @@ +// file : xsd/cxx/tree/comparison-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_COMPARISON_MAP_HXX +#define XSD_CXX_TREE_COMPARISON_MAP_HXX + +#include <map> +#include <cstddef> // std::size_t +#include <typeinfo> + +#include <xsd/cxx/tree/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct comparison_map + { + typedef std::type_info type_id; + typedef bool (*comparator) (const type&, const type&); + + comparison_map (); + + void + register_type (const type_id&, comparator, bool override = true); + + void + unregister_type (const type_id&); + + bool + compare (const type&, const type&); + + public: + comparator + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map<const type_id*, comparator, type_id_comparator> + type_map; + + type_map type_map_; + }; + + // + // + template<unsigned long id, typename C> + struct comparison_plate + { + static comparison_map<C>* map; + static std::size_t count; + + comparison_plate (); + ~comparison_plate (); + }; + + template<unsigned long id, typename C> + comparison_map<C>* comparison_plate<id, C>::map = 0; + + template<unsigned long id, typename C> + std::size_t comparison_plate<id, C>::count = 0; + + + // + // + template<unsigned long id, typename C> + inline comparison_map<C>& + comparison_map_instance () + { + return *comparison_plate<id, C>::map; + } + + // + // + template<typename T> + bool + comparator_impl (const type&, const type&); + + template<unsigned long id, typename C, typename T> + struct comparison_initializer + { + comparison_initializer (); + ~comparison_initializer (); + }; + } + } +} + +#include <xsd/cxx/tree/comparison-map.txx> + +#endif // XSD_CXX_TREE_COMPARISON_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/comparison-map.txx b/xsd/libxsd/xsd/cxx/tree/comparison-map.txx new file mode 100644 index 0000000..e638ed4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/comparison-map.txx @@ -0,0 +1,301 @@ +// file : xsd/cxx/tree/comparison-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/tree/types.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // comparison_map + // + template <typename C> + comparison_map<C>:: + comparison_map () + { + // anyType and anySimpleType. + // + + //register_type ( + // typeid (type), + // &comparator_impl<type>, + // false); + + typedef simple_type<type> simple_type; + + //register_type ( + // typeid (simple_type), + // &comparator_impl<simple_type>, + // false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + typeid (string), + &comparator_impl<string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + typeid (normalized_string), + &comparator_impl<normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + typeid (token), + &comparator_impl<token>, + false); + + typedef name<C, token> name; + register_type ( + typeid (name), + &comparator_impl<name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + typeid (nmtoken), + &comparator_impl<nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + typeid (nmtokens), + &comparator_impl<nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + typeid (ncname), + &comparator_impl<ncname>, + false); + + typedef language<C, token> language; + register_type ( + typeid (language), + &comparator_impl<language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + typeid (id), + &comparator_impl<id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + typeid (idref), + &comparator_impl<idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + typeid (idrefs), + &comparator_impl<idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + typeid (uri), + &comparator_impl<uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + typeid (qname), + &comparator_impl<qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + typeid (base64_binary), + &comparator_impl<base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + typeid (hex_binary), + &comparator_impl<hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + typeid (gday), + &comparator_impl<gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + typeid (gmonth), + &comparator_impl<gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + typeid (gyear), + &comparator_impl<gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + typeid (gmonth_day), + &comparator_impl<gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + typeid (gyear_month), + &comparator_impl<gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + typeid (date), + &comparator_impl<date>, + false); + + typedef time<C, simple_type> time; + register_type ( + typeid (time), + &comparator_impl<time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + typeid (date_time), + &comparator_impl<date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + typeid (duration), + &comparator_impl<duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + typeid (entity), + &comparator_impl<entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + typeid (entities), + &comparator_impl<entities>, + false); + } + + template <typename C> + void comparison_map<C>:: + register_type (const type_id& tid, comparator c, bool override) + { + if (override || type_map_.find (&tid) == type_map_.end ()) + type_map_[&tid] = c; + } + + template <typename C> + void comparison_map<C>:: + unregister_type (const type_id& tid) + { + type_map_.erase (&tid); + } + + template <typename C> + bool comparison_map<C>:: + compare (const type& x, const type& y) + { + const type_id& xi (typeid (x)); + + if (xi != typeid (y)) + return false; + + if (comparator c = find (xi)) + return c (x, y); + else + throw no_type_info<C> (std::basic_string<C> (), + std::basic_string<C> ()); // @@ TODO + } + + template <typename C> + typename comparison_map<C>::comparator + comparison_map<C>:: + find (const type_id& tid) const + { + typename type_map::const_iterator i (type_map_.find (&tid)); + return i == type_map_.end () ? 0 : i->second; + } + + + // comparison_plate + // + template<unsigned long id, typename C> + comparison_plate<id, C>:: + comparison_plate () + { + if (count == 0) + map = new comparison_map<C>; + + ++count; + } + + template<unsigned long id, typename C> + comparison_plate<id, C>:: + ~comparison_plate () + { + if (--count == 0) + delete map; + } + + // + // + template<typename T> + bool + comparator_impl (const type& x, const type& y) + { + return static_cast<const T&> (x) == static_cast<const T&> (y); + } + + // comparison_initializer + // + template<unsigned long id, typename C, typename T> + comparison_initializer<id, C, T>:: + comparison_initializer () + { + comparison_map_instance<id, C> ().register_type ( + typeid (T), &comparator_impl<T>); + } + + template<unsigned long id, typename C, typename T> + comparison_initializer<id, C, T>:: + ~comparison_initializer () + { + comparison_map_instance<id, C> ().unregister_type (typeid (T)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx b/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx new file mode 100644 index 0000000..5313507 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx @@ -0,0 +1,1335 @@ +// file : xsd/cxx/tree/containers-wildcard.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX +#define XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX + +#include <set> +#include <string> + +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> +#include <xercesc/dom/DOMDocument.hpp> +#include <xercesc/util/XMLString.hpp> + +#include <xsd/cxx/xml/string.hxx> + +#include <xsd/cxx/tree/containers.hxx> // iterator_adapter + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // one (for internal use only) + // + class element_one + { + public: + ~element_one () + { + if (x_) + x_->release (); + } + + explicit + element_one (xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + } + + element_one (const xercesc::DOMElement& x, xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + set (x); + } + + element_one (const element_one& x, xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + if (x.present ()) + set (x.get ()); + } + + element_one& + operator= (const element_one& x) + { + if (this == &x) + return *this; + + if (x.present ()) + set (x.get ()); + else if (x_) + { + x_->release (); + x_ = 0; + } + + return *this; + } + + public: + const xercesc::DOMElement& + get () const + { + return *x_; + } + + xercesc::DOMElement& + get () + { + return *x_; + } + + void + set (const xercesc::DOMElement& x) + { + using xercesc::DOMElement; + + DOMElement* r ( + static_cast<DOMElement*> ( + doc_.importNode (const_cast<DOMElement*> (&x), true))); + + if (x_) + x_->release (); + + x_ = r; + } + + void + set (xercesc::DOMElement* x) + { + assert (x->getOwnerDocument () == &doc_); + + if (x_) + x_->release (); + + x_ = x; + } + + bool + present () const + { + return x_ != 0; + } + + protected: + xercesc::DOMElement* x_; + xercesc::DOMDocument& doc_; + }; + + + // + // + class element_optional + { + public: + ~element_optional () + { + if (x_) + x_->release (); + } + + explicit + element_optional (xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + } + + element_optional (const xercesc::DOMElement& x, + xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + set (x); + } + + element_optional (xercesc::DOMElement* x, xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + set (x); + } + + element_optional (const element_optional& x, + xercesc::DOMDocument& doc) + : x_ (0), doc_ (doc) + { + if (x) + set (*x); + } + + element_optional& + operator= (const xercesc::DOMElement& x) + { + if (x_ == &x) + return *this; + + set (x); + + return *this; + } + + element_optional& + operator= (const element_optional& x) + { + if (this == &x) + return *this; + + if (x) + set (*x); + else + reset (); + + return *this; + } + + // Pointer-like interface. + // + public: + const xercesc::DOMElement* + operator-> () const + { + return x_; + } + + xercesc::DOMElement* + operator-> () + { + return x_; + } + + const xercesc::DOMElement& + operator* () const + { + return *x_; + } + + xercesc::DOMElement& + operator* () + { + return *x_; + } + + typedef void (element_optional::*bool_convertible) (); + + operator bool_convertible () const + { + return x_ != 0 ? &element_optional::true_ : 0; + } + + // Get/set interface. + // + public: + bool + present () const + { + return x_ != 0; + } + + const xercesc::DOMElement& + get () const + { + return *x_; + } + + xercesc::DOMElement& + get () + { + return *x_; + } + + void + set (const xercesc::DOMElement& x) + { + using xercesc::DOMElement; + + DOMElement* r ( + static_cast<DOMElement*> ( + doc_.importNode (const_cast<DOMElement*> (&x), true))); + + if (x_) + x_->release (); + + x_ = r; + } + + void + set (xercesc::DOMElement* x) + { + assert (x->getOwnerDocument () == &doc_); + + if (x_) + x_->release (); + + x_ = x; + } + + void + reset () + { + if (x_) + x_->release (); + + x_ = 0; + } + + private: + void + true_ () + { + } + + private: + xercesc::DOMElement* x_; + xercesc::DOMDocument& doc_; + }; + + // Comparison operators. + // + + inline bool + operator== (const element_optional& a, const element_optional& b) + { + return !a || !b + ? a.present () == b.present () + : a->isEqualNode (&b.get ()); + } + + inline bool + operator!= (const element_optional& a, const element_optional& b) + { + return !(a == b); + } + + + // + // + class element_sequence + { + protected: + // This is a dangerously destructive automatic pointer. We are going + // to use it in a controlled environment to save us a lot of coding. + // + struct ptr + { + ~ptr () + { + if (x_) + x_->release (); + } + + explicit + ptr (xercesc::DOMElement* x = 0) + : x_ (x) + { + } + + ptr (const ptr& y) + : x_ (y.x_) + { + // Yes, hostile takeover. + // + y.x_ = 0; + } + + ptr& + operator= (const ptr& y) + { + if (this != &y) + { + // Yes, hostile takeover. + // + if (x_) + x_->release (); + + x_ = y.x_; + y.x_ = 0; + } + + return *this; + } + + public: + xercesc::DOMElement& + operator* () const + { + return *x_; + } + + xercesc::DOMElement* + get () const + { + return x_; + } + + private: + mutable xercesc::DOMElement* x_; + }; + + typedef std::vector<ptr> base_sequence; + typedef base_sequence::iterator base_iterator; + typedef base_sequence::const_iterator base_const_iterator; + + public: + typedef xercesc::DOMElement value_type; + typedef xercesc::DOMElement* pointer; + typedef const xercesc::DOMElement* const_pointer; + typedef xercesc::DOMElement& reference; + typedef const xercesc::DOMElement& const_reference; + + typedef + iterator_adapter<base_sequence::iterator, xercesc::DOMElement> + iterator; + + typedef + iterator_adapter<base_sequence::const_iterator, + const xercesc::DOMElement> + const_iterator; + + typedef + iterator_adapter<base_sequence::reverse_iterator, xercesc::DOMElement> + reverse_iterator; + + typedef + iterator_adapter<base_sequence::const_reverse_iterator, + const xercesc::DOMElement> + const_reverse_iterator; + + typedef base_sequence::size_type size_type; + typedef base_sequence::difference_type difference_type; + typedef base_sequence::allocator_type allocator_type; + + public: + explicit + element_sequence (xercesc::DOMDocument& doc) + : doc_ (doc) + { + } + + // DOMElement cannot be default-constructed. + // + // explicit + // element_sequence (size_type n); + + element_sequence (size_type n, + const xercesc::DOMElement& x, + xercesc::DOMDocument& doc) + : doc_ (doc) + { + assign (n, x); + } + + template <typename I> + element_sequence (const I& begin, const I& end, + xercesc::DOMDocument& doc) + : doc_ (doc) + { + assign (begin, end); + } + + element_sequence (const element_sequence& v, + xercesc::DOMDocument& doc) + : doc_ (doc) + { + v_.reserve (v.v_.size ()); + + for (base_const_iterator i (v.v_.begin ()), e (v.v_.end ()); + i != e; ++i) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode (i->get (), true))); + + v_.push_back (p); + } + } + + element_sequence& + operator= (const element_sequence& v) + { + if (this == &v) + return *this; + + v_.assign (v.v_.size (), ptr ()); + + base_iterator di (v_.begin ()), de (v_.end ()); + base_const_iterator si (v.v_.begin ()), se (v.v_.end ()); + + for (; si != se && di != de; ++si, ++di) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode (si->get (), true))); + *di = p; + } + + return *this; + } + + public: + void + assign (size_type n, const xercesc::DOMElement& x) + { + v_.assign (n, ptr ()); + + for (base_iterator i (v_.begin ()), e (v_.end ()); i != e; ++i) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&x), true))); + *i = p; + } + } + + template <typename I> + void + assign (const I& begin, const I& end) + { + // This is not the fastest way to do it. + // + v_.clear (); + + for (I i (begin); i != end; ++i) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&(*i)), true))); + v_.push_back (p); + } + } + + public: + // This version of resize can only be used to shrink the + // sequence because DOMElement cannot be default-constructed. + // + void + resize (size_type n) + { + assert (n <= v_.size ()); + v_.resize (n, ptr ()); + } + + void + resize (size_type n, const xercesc::DOMElement& x) + { + size_type old (v_.size ()); + v_.resize (n, ptr ()); + + if (old < n) + { + for (base_iterator i (v_.begin () + old), e (v_.end ()); + i != e; ++i) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&x), true))); + *i = p; + } + } + } + + public: + size_type + size () const + { + return v_.size (); + } + + size_type + max_size () const + { + return v_.max_size (); + } + + size_type + capacity () const + { + return v_.capacity (); + } + + bool + empty () const + { + return v_.empty (); + } + + void + reserve (size_type n) + { + v_.reserve (n); + } + + void + clear () + { + v_.clear (); + } + + public: + const_iterator + begin () const + { + return const_iterator (v_.begin ()); + } + + const_iterator + end () const + { + return const_iterator (v_.end ()); + } + + iterator + begin () + { + return iterator (v_.begin ()); + } + + iterator + end () + { + return iterator (v_.end ()); + } + + // reverse + // + + const_reverse_iterator + rbegin () const + { + return const_reverse_iterator (v_.rbegin ()); + } + + const_reverse_iterator + rend () const + { + return const_reverse_iterator (v_.rend ()); + } + + reverse_iterator + rbegin () + { + return reverse_iterator (v_.rbegin ()); + } + + reverse_iterator + rend () + { + return reverse_iterator (v_.rend ()); + } + + public: + xercesc::DOMElement& + operator[] (size_type n) + { + return *(v_[n]); + } + + const xercesc::DOMElement& + operator[] (size_type n) const + { + return *(v_[n]); + } + + xercesc::DOMElement& + at (size_type n) + { + return *(v_.at (n)); + } + + const xercesc::DOMElement& + at (size_type n) const + { + return *(v_.at (n)); + } + + xercesc::DOMElement& + front () + { + return *(v_.front ()); + } + + const xercesc::DOMElement& + front () const + { + return *(v_.front ()); + } + + xercesc::DOMElement& + back () + { + return *(v_.back ()); + } + + const xercesc::DOMElement& + back () const + { + return *(v_.back ()); + } + + public: + // Makes a deep copy. + // + void + push_back (const xercesc::DOMElement& x) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&x), true))); + + v_.push_back (p); + } + + // Assumes ownership. + // + void + push_back (xercesc::DOMElement* x) + { + assert (x->getOwnerDocument () == &doc_); + v_.push_back (ptr (x)); + } + + void + pop_back () + { + v_.pop_back (); + } + + // Makes a deep copy. + // + iterator + insert (iterator position, const xercesc::DOMElement& x) + { + ptr p (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&x), true))); + + return iterator (v_.insert (position.base (), p)); + } + + // Assumes ownership. + // + iterator + insert (iterator position, xercesc::DOMElement* x) + { + assert (x->getOwnerDocument () == &doc_); + return iterator (v_.insert (position.base (), ptr (x))); + } + + void + insert (iterator position, size_type n, const xercesc::DOMElement& x) + { + difference_type d (v_.end () - position.base ()); + v_.insert (position.base (), n, ptr ()); + + for (base_iterator i (v_.end () - d); n != 0; --n) + { + ptr r (static_cast<xercesc::DOMElement*> ( + doc_.importNode ( + const_cast<xercesc::DOMElement*> (&x), true))); + *(--i) = r; + } + } + + template <typename I> + void + insert (iterator position, const I& begin, const I& end) + { + // This is not the fastest way to do it. + // + if (begin != end) + { + base_iterator p (position.base ()); + + for (I i (end);;) + { + --i; + ptr r (static_cast<xercesc::DOMElement*> ( + doc_.importNode (i->get (), true))); + + p = v_.insert (p, r); + + if (i == begin) + break; + } + } + } + + iterator + erase (iterator position) + { + return iterator (v_.erase (position.base ())); + } + + iterator + erase (iterator begin, iterator end) + { + return iterator (v_.erase (begin.base (), end.base ())); + } + + public: + // Note that the DOMDocument object of the two sequences being + // swapped should be the same. + // + void + swap (element_sequence& x) + { + assert (&doc_ == &x.doc_); + v_.swap (x.v_); + } + + private: + base_sequence v_; + xercesc::DOMDocument& doc_; + }; + + // Comparison operators. + // + + inline bool + operator== (const element_sequence& a, const element_sequence& b) + { + if (a.size () != b.size ()) + return false; + + element_sequence::const_iterator + ai (a.begin ()), ae (a.end ()), bi (b.begin ()); + + for (; ai != ae; ++ai, ++bi) + if (!ai->isEqualNode (&(*bi))) + return false; + + return true; + } + + inline bool + operator!= (const element_sequence& a, const element_sequence& b) + { + return !(a == b); + } + + + // Attribute set. + // + + class attribute_set_common + { + protected: + // Set entry. It can either act as a dangerously destructive + // automatic pointer for DOMAttr or as an entry containing the + // name we are searching for. + // + struct entry + { + ~entry () + { + if (a_) + a_->release (); + } + + explicit + entry (xercesc::DOMAttr* a) + : a_ (a), ns_ (0), name_ (0) + { + ns_ = a->getNamespaceURI (); + name_ = ns_ == 0 ? a->getName () : a->getLocalName (); + } + + // Note: uses shallow copy. + // + explicit + entry (const XMLCh* ns, const XMLCh* name) + : a_ (0), ns_ (ns), name_ (name) + { + } + + entry (const entry& y) + : a_ (y.a_), ns_ (y.ns_), name_ (y.name_) + { + // Yes, hostile takeover. + // + y.a_ = 0; + y.ns_ = 0; + y.name_ = 0; + } + + entry& + operator= (const entry& y) + { + if (this != &y) + { + // Yes, hostile takeover. + // + if (a_) + a_->release (); + + a_ = y.a_; + ns_ = y.ns_; + name_ = y.name_; + + y.a_ = 0; + y.ns_ = 0; + y.name_ = 0; + } + + return *this; + } + + public: + xercesc::DOMAttr& + operator* () const + { + return *a_; + } + + xercesc::DOMAttr* + get () const + { + return a_; + } + + const XMLCh* + ns () const + { + return ns_; + } + + const XMLCh* + name () const + { + return name_; + } + + void + release () + { + a_ = 0; + } + + private: + mutable xercesc::DOMAttr* a_; + mutable const XMLCh* ns_; + mutable const XMLCh* name_; + }; + + struct entry_cmp + { + bool + operator() (const entry& a, const entry& b) const + { + using xercesc::XMLString; + + const XMLCh* ans (a.ns ()); + const XMLCh* bns (b.ns ()); + + const XMLCh* an (a.name ()); + const XMLCh* bn (b.name ()); + + if (ans == 0) + return bns != 0 + ? true + : (XMLString::compareString (an, bn) < 0); + + if (ans != 0 && bns == 0) + return false; + + int r (XMLString::compareString (ans, bns)); + + return r < 0 + ? true + : (r > 0 ? false : XMLString::compareString (an, bn)); + } + }; + + typedef std::set<entry, entry_cmp> base_set; + typedef base_set::iterator base_iterator; + typedef base_set::const_iterator base_const_iterator; + }; + + template <typename C> + class attribute_set: public attribute_set_common + { + public: + typedef xercesc::DOMAttr key_type; + typedef xercesc::DOMAttr value_type; + typedef xercesc::DOMAttr* pointer; + typedef const xercesc::DOMAttr* const_pointer; + typedef xercesc::DOMAttr& reference; + typedef const xercesc::DOMAttr& const_reference; + + typedef + iterator_adapter<base_set::iterator, xercesc::DOMAttr> + iterator; + + typedef + iterator_adapter<base_set::const_iterator, const xercesc::DOMAttr> + const_iterator; + + typedef + iterator_adapter<base_set::reverse_iterator, xercesc::DOMAttr> + reverse_iterator; + + typedef + iterator_adapter<base_set::const_reverse_iterator, + const xercesc::DOMAttr> + const_reverse_iterator; + + typedef base_set::size_type size_type; + typedef base_set::difference_type difference_type; + typedef base_set::allocator_type allocator_type; + + public: + attribute_set (xercesc::DOMDocument& doc) + : doc_ (doc) + { + } + + template <typename I> + attribute_set (const I& begin, + const I& end, + xercesc::DOMDocument& doc) + : doc_ (doc) + { + insert (begin, end); + } + + attribute_set (const attribute_set& s, xercesc::DOMDocument& doc) + : doc_ (doc) + { + // Can be done faster with the "hinted" insert. + // + insert (s.begin (), s.end ()); + } + + attribute_set& + operator= (const attribute_set& s) + { + if (this == &s) + return *this; + + // Can be done faster with the "hinted" insert. + // + clear (); + insert (s.begin (), s.end ()); + + return *this; + } + + public: + const_iterator + begin () const + { + return const_iterator (s_.begin ()); + } + + const_iterator + end () const + { + return const_iterator (s_.end ()); + } + + iterator + begin () + { + return iterator (s_.begin ()); + } + + iterator + end () + { + return iterator (s_.end ()); + } + + // reverse + // + + const_reverse_iterator + rbegin () const + { + return const_reverse_iterator (s_.rbegin ()); + } + + const_reverse_iterator + rend () const + { + return const_reverse_iterator (s_.rend ()); + } + + reverse_iterator + rbegin () + { + return reverse_iterator (s_.rbegin ()); + } + + reverse_iterator + rend () + { + return reverse_iterator (s_.rend ()); + } + + public: + size_type + size () const + { + return s_.size (); + } + + size_type + max_size () const + { + return s_.max_size (); + } + + bool + empty () const + { + return s_.empty (); + } + + void + clear () + { + s_.clear (); + } + + public: + // Makes a deep copy. + // + std::pair<iterator, bool> + insert (const xercesc::DOMAttr& a) + { + entry e (static_cast<xercesc::DOMAttr*> ( + doc_.importNode ( + const_cast<xercesc::DOMAttr*> (&a), true))); + + std::pair<base_iterator, bool> r (s_.insert (e)); + + return std::pair<iterator, bool> (iterator (r.first), r.second); + } + + // Assumes ownership. + // + std::pair<iterator, bool> + insert (xercesc::DOMAttr* a) + { + assert (a->getOwnerDocument () == &doc_); + entry e (a); + std::pair<base_iterator, bool> r (s_.insert (e)); + + if (!r.second) + e.release (); // Detach the attribute of insert failed. + + return std::pair<iterator, bool> (iterator (r.first), r.second); + } + + // Makes a deep copy. + // + iterator + insert (iterator position, const xercesc::DOMAttr& a) + { + entry e (static_cast<xercesc::DOMAttr*> ( + doc_.importNode ( + const_cast<xercesc::DOMAttr*> (&a), true))); + + return iterator (s_.insert (position.base (), e)); + } + + // Assumes ownership. + // + iterator + insert (iterator position, xercesc::DOMAttr* a) + { + assert (a->getOwnerDocument () == &doc_); + entry e (a); + base_iterator r (s_.insert (position.base (), e)); + + if (r->get () != a) + e.release (); // Detach the attribute of insert failed. + + return iterator (r); + } + + template <typename I> + void + insert (const I& begin, const I& end) + { + for (I i (begin); i != end; ++i) + { + entry e (static_cast<xercesc::DOMAttr*> ( + doc_.importNode ( + const_cast<xercesc::DOMAttr*> (&(*i)), true))); + + s_.insert (e); + } + } + + public: + void + erase (iterator position) + { + s_.erase (position.base ()); + } + + size_type + erase (const std::basic_string<C>& name) + { + return s_.erase (entry (0, xml::string (name).c_str ())); + } + + size_type + erase (const std::basic_string<C>& namespace_, + const std::basic_string<C>& name) + { + return s_.erase (entry (xml::string (namespace_).c_str (), + xml::string (name).c_str ())); + } + + size_type + erase (const XMLCh* name) + { + return s_.erase (entry (0, name)); + } + + size_type + erase (const XMLCh* namespace_, const XMLCh* name) + { + return s_.erase (entry (namespace_, name)); + } + + void + erase (iterator begin, iterator end) + { + s_.erase (begin.base (), end.base ()); + } + + public: + size_type + count (const std::basic_string<C>& name) const + { + return s_.count (entry (0, xml::string (name).c_str ())); + } + + size_type + count (const std::basic_string<C>& namespace_, + const std::basic_string<C>& name) const + { + return s_.count (entry (xml::string (namespace_).c_str (), + xml::string (name).c_str ())); + } + + size_type + count (const XMLCh* name) const + { + return s_.count (entry (0, name)); + } + + size_type + count (const XMLCh* namespace_, const XMLCh* name) const + { + return s_.count (entry (namespace_, name)); + } + + // find + // + + iterator + find (const std::basic_string<C>& name) + { + return iterator (s_.find (entry (0, xml::string (name).c_str ()))); + } + + iterator + find (const std::basic_string<C>& namespace_, + const std::basic_string<C>& name) + { + return iterator ( + s_.find (entry (xml::string (namespace_).c_str (), + xml::string (name).c_str ()))); + } + + iterator + find (const XMLCh* name) + { + return iterator (s_.find (entry (0, name))); + } + + iterator + find (const XMLCh* namespace_, const XMLCh* name) + { + return iterator (s_.find (entry (namespace_, name))); + } + + const_iterator + find (const std::basic_string<C>& name) const + { + return const_iterator ( + s_.find (entry (0, xml::string (name).c_str ()))); + } + + const_iterator + find (const std::basic_string<C>& namespace_, + const std::basic_string<C>& name) const + { + return const_iterator ( + s_.find (entry (xml::string (namespace_).c_str (), + xml::string (name).c_str ()))); + } + + const_iterator + find (const XMLCh* name) const + { + return const_iterator (s_.find (entry (0, name))); + } + + const_iterator + find (const XMLCh* namespace_, const XMLCh* name) const + { + return const_iterator (s_.find (entry (namespace_, name))); + } + + public: + // Note that the DOMDocument object of the two sets being + // swapped should be the same. + // + void + swap (attribute_set& x) + { + assert (&doc_ == &x.doc_); + s_.swap (x.s_); + } + + private: + base_set s_; + xercesc::DOMDocument& doc_; + }; + + // Comparison operators. + // + + template <typename C> + inline bool + operator== (const attribute_set<C>& a, const attribute_set<C>& b) + { + if (a.size () != b.size ()) + return false; + + typename attribute_set<C>::const_iterator + ai (a.begin ()), ae (a.end ()), bi (b.begin ()); + + for (; ai != ae; ++ai, ++bi) + if (!ai->isEqualNode (&(*bi))) + return false; + + return true; + } + + template <typename C> + inline bool + operator!= (const attribute_set<C>& a, const attribute_set<C>& b) + { + return !(a == b); + } + } + } +} + +#endif // XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/containers.hxx b/xsd/libxsd/xsd/cxx/tree/containers.hxx new file mode 100644 index 0000000..ba76eae --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/containers.hxx @@ -0,0 +1,1458 @@ +// file : xsd/cxx/tree/containers.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_CONTAINERS_HXX +#define XSD_CXX_TREE_CONTAINERS_HXX + +#include <cstddef> // std::ptrdiff_t +#include <string> +#include <vector> +#include <memory> // std::auto_ptr +#include <iterator> // std::iterator_traits +#include <algorithm> // std::equal, std::lexicographical_compare +#include <iosfwd> + +#include <xsd/cxx/tree/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Test whether T is a fundamental C++ type. + // + + template <typename T> + struct fundamental_p + { + static const bool r = false; + }; + + // byte + // + template <> + struct fundamental_p<signed char> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<unsigned char> + { + static const bool r = true; + }; + + // short + // + template <> + struct fundamental_p<short> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<unsigned short> + { + static const bool r = true; + }; + + // int + // + template <> + struct fundamental_p<int> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<unsigned int> + { + static const bool r = true; + }; + + // long + // + template <> + struct fundamental_p<long> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<unsigned long> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<long long> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<unsigned long long> + { + static const bool r = true; + }; + + // bool + // + template <> + struct fundamental_p<bool> + { + static const bool r = true; + }; + + // float + // + template <> + struct fundamental_p<float> + { + static const bool r = true; + }; + + template <> + struct fundamental_p<double> + { + static const bool r = true; + }; + + // one (for internal use only) + // + template <typename T, bool fund = fundamental_p<T>::r> + class one; + + template <typename T> + class one<T, false> + { + public: + ~one (); + + one (flags, container*); + + one (const T&, flags, container*); + + one (std::auto_ptr<T>, flags, container*); + + one (const one&, flags, container*); + + one& + operator= (const one&); + + public: + const T& + get () const + { + return *x_; + } + + T& + get () + { + return *x_; + } + + void + set (const T&); + + void + set (std::auto_ptr<T>); + + bool + present () const + { + return x_ != 0; + } + + std::auto_ptr<T> + detach () + { + T* x (x_); + x->_container (0); + x_ = 0; + return std::auto_ptr<T> (x); + } + + protected: + T* x_; + flags flags_; + container* container_; + }; + + + template <typename T> + class one<T, true> + { + public: + one (flags, container*) + : present_ (false) + { + } + + one (const T& x, flags, container*) + : x_ (x), present_ (true) + { + } + + one (const one& x, flags, container*) + : x_ (x.x_), present_ (x.present_) + { + } + + one& + operator= (const one& x) + { + if (this == &x) + return *this; + + x_ = x.x_; + present_ = x.present_; + + return *this; + } + + public: + const T& + get () const + { + return x_; + } + + T& + get () + { + return x_; + } + + void + set (const T& x) + { + x_ = x; + present_ = true; + } + + bool + present () const + { + return present_; + } + + protected: + T x_; + bool present_; + }; + + + // Note that I cannot get rid of fund because of HP aCC3. + // + template <typename T, bool fund = fundamental_p<T>::r> + class optional; + + template <typename T> + class optional<T, false> + { + public: + ~optional (); + + explicit + optional (flags = 0, container* = 0); + + explicit + optional (const T&, flags = 0, container* = 0); + + explicit + optional (std::auto_ptr<T>, flags = 0, container* = 0); + + optional (const optional&, flags = 0, container* = 0); + + optional& + operator= (const T&); + + optional& + operator= (const optional&); + + // Pointer-like interface. + // + public: + const T* + operator-> () const + { + return x_; + } + + T* + operator-> () + { + return x_; + } + + const T& + operator* () const + { + return *x_; + } + + T& + operator* () + { + return *x_; + } + + typedef optional self_; // Simplifier for Sun C++ 5.7. + typedef void (self_::*bool_convertible) (); + + operator bool_convertible () const + { + return x_ != 0 ? &self_::true_ : 0; + } + + // Get/set interface. + // + public: + bool + present () const + { + return x_ != 0; + } + + const T& + get () const + { + return *x_; + } + + T& + get () + { + return *x_; + } + + void + set (const T&); + + void + set (std::auto_ptr<T>); + + void + reset (); + + std::auto_ptr<T> + detach () + { + T* x (x_); + x->_container (0); + x_ = 0; + return std::auto_ptr<T> (x); + } + + private: + void + true_ (); + + private: + T* x_; + flags flags_; + container* container_; + }; + + + // + // + template <typename T> + class optional<T, true> + { + public: + explicit + optional (flags = 0, container* = 0) + : present_ (false) + { + } + + explicit + optional (const T&, flags = 0, container* = 0); + + optional (const optional&, flags = 0, container* = 0); + + optional& + operator= (const T&); + + optional& + operator= (const optional&); + + // Pointer-like interface. + // + public: + const T* + operator-> () const + { + return &x_; + } + + T* + operator-> () + { + return &x_; + } + + const T& + operator* () const + { + return get (); + } + + T& + operator* () + { + return get (); + } + + typedef optional self_; // Simplifier for Sun C++ 5.7. + typedef void (self_::*bool_convertible) (); + + operator bool_convertible () const + { + return present () ? &self_::true_ : 0; + } + + // Get/set interface. + // + public: + bool + present () const + { + return present_; + } + + const T& + get () const + { + return x_; + } + + T& + get () + { + return x_; + } + + void + set (const T& y) + { + x_ = y; + present_ = true; + } + + void + reset () + { + present_ = false; + } + + private: + void + true_ (); + + private: + bool present_; + T x_; + }; + + // Comparison operators. + // + + template <typename T, bool fund> + inline bool + operator== (const optional<T, fund>& a, const optional<T, fund>& b) + { + return !a || !b ? a.present () == b.present () : *a == *b; + } + + template <typename T, bool fund> + inline bool + operator!= (const optional<T, fund>& a, const optional<T, fund>& b) + { + return !(a == b); + } + + template <typename T, bool fund> + inline bool + operator< (const optional<T, fund>& a, const optional<T, fund>& b) + { + return a && (!b || *a < *b); + } + + template <typename T, bool fund> + inline bool + operator> (const optional<T, fund>& a, const optional<T, fund>& b) + { + return b < a; + } + + template <typename T, bool fund> + inline bool + operator<= (const optional<T, fund>& a, const optional<T, fund>& b) + { + return !(a > b); + } + + template <typename T, bool fund> + inline bool + operator>= (const optional<T, fund>& a, const optional<T, fund>& b) + { + return !(a < b); + } + + // Provide an ostream insertion opretaor to prevent confusion from + // the implicit bool conversion. + // + template <typename C, typename T, bool fund> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>&, const optional<T, fund>&); + + + // Sequence. + // + + // Note that I cannot get rid of 'fund' because HP aCC3 likes it + // this way. + // + template <typename T, bool fund = fundamental_p<T>::r> + class sequence; + + + // Sun CC's <iterator> does not have iterator_traits. To overcome + // this, we will wrap std::iterator_traits into our own and also + // specialize it for pointer types. Since Sun CC uses pointer + // for vector::iterator, it will use the specialization and won't + // notice the std::iterator_traits. + // +#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC + template <typename I> + struct iterator_traits + { + typedef + typename std::iterator_traits<I>::iterator_category + iterator_category; + + typedef + typename std::iterator_traits<I>::value_type + value_type; + + typedef + typename std::iterator_traits<I>::difference_type + difference_type; + }; +#else + // The Pointer specialization does not work for reverse and + // set iterators. But these iterators are user-dfined types + // and have suitable typedefs that we can use. + // + template <typename I> + struct iterator_traits + { + typedef typename I::iterator_category iterator_category; + typedef typename I::value_type value_type; + typedef typename I::difference_type difference_type; + }; + + template <typename T> + struct iterator_traits<T*> + { + typedef std::random_access_iterator_tag iterator_category; + typedef T value_type; + typedef std::ptrdiff_t difference_type; + }; +#endif + + // Iterator adapter for complex types. It expects I to point to + // a smart pointer-like object that has operator*() that returns + // a refernce to a type static_cast'able to T and get() that + // returns a pointer to a type static_cast'able to T. + // + + template <typename I, typename T> + struct iterator_adapter + { + typedef T value_type; + typedef value_type& reference; + typedef value_type* pointer; + + typedef + typename iterator_traits<I>::iterator_category + iterator_category; + + typedef + typename iterator_traits<I>::difference_type + difference_type; + + + public: + iterator_adapter () + : i_ () // i_ can be of a pointer type. + { + } + + // Allow iterator to const_iterator conversion. + // + template <typename J, typename T2> + iterator_adapter (const iterator_adapter<J, T2>& j) + : i_ (j.base ()) + { + } + + explicit + iterator_adapter (const I& i) + : i_ (i) + { + } + + public: + // Forward iterator requirements. + // + reference + operator* () const + { + return static_cast<reference> (**i_); + } + + pointer + operator-> () const + { + return static_cast<pointer> (i_->get ()); + } + + iterator_adapter& + operator++ () + { + ++i_; + return *this; + } + + iterator_adapter + operator++ (int) + { + iterator_adapter r (*this); + ++i_; + return r; + } + + // Bidirectional iterator requirements. + // + iterator_adapter& + operator-- () + { + --i_; + return *this; + } + + iterator_adapter + operator-- (int) + { + iterator_adapter r (*this); + --i_; + return r; + } + + // Random access iterator requirements. + // + reference + operator[] (difference_type n) const + { + return static_cast<reference> (*(i_[n])); + } + + iterator_adapter& + operator+= (difference_type n) + { + i_ += n; + return *this; + } + + iterator_adapter + operator+ (difference_type n) const + { + return iterator_adapter (i_ + n); + } + + iterator_adapter& + operator-= (difference_type n) + { + i_ -= n; + return *this; + } + + iterator_adapter + operator- (difference_type n) const + { + return iterator_adapter (i_ - n); + } + + public: + const I& + base () const + { + return i_; + } + + private: + I i_; + }; + + // Note: We use different types for left- and right-hand-side + // arguments to allow comparison between iterator and const_iterator. + // + + // Forward iterator requirements. + // + template <typename I, typename J, typename T1, typename T2> + inline bool + operator== (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () == j.base (); + } + + template <typename I, typename J, typename T1, typename T2> + inline bool + operator!= (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () != j.base (); + } + + // Random access iterator requirements + // + template <typename I, typename J, typename T1, typename T2> + inline bool + operator< (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () < j.base (); + } + + template <typename I, typename J, typename T1, typename T2> + inline bool + operator> (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () > j.base (); + } + + template <typename I, typename J, typename T1, typename T2> + inline bool + operator<= (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () <= j.base (); + } + + template <typename I, typename J, typename T1, typename T2> + inline bool + operator>= (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () >= j.base (); + } + + template <typename I, typename J, typename T1, typename T2> + inline typename iterator_adapter<I, T1>::difference_type + operator- (const iterator_adapter<I, T1>& i, + const iterator_adapter<J, T2>& j) + { + return i.base () - j.base (); + } + + template <typename I, typename T> + inline iterator_adapter<I, T> + operator+ (typename iterator_adapter<I, T>::difference_type n, + const iterator_adapter<I, T>& i) + { + return iterator_adapter<I, T> (i.base () + n); + } + + // + // + class sequence_common + { + protected: + // This is a dangerously destructive automatic pointer. We are going + // to use it in a controlled environment to save us a lot of coding. + // + struct ptr + { + ~ptr () + { + delete x_; + } + + explicit + ptr (type* x = 0) + : x_ (x) + { + } + + ptr (const ptr& y) + : x_ (y.x_) + { + // Yes, hostile takeover. + // + y.x_ = 0; + } + + ptr& + operator= (const ptr& y) + { + if (this != &y) + { + // Yes, hostile takeover. + // + delete x_; + x_ = y.x_; + y.x_ = 0; + } + + return *this; + } + + public: + type& + operator* () const + { + return *x_; + } + + type* + operator-> () const + { + return x_; + } + + type* + get () const + { + return x_; + } + + type* + release () + { + type* x (x_); + x_ = 0; + return x; + } + + private: + mutable type* x_; + }; + + protected: + typedef std::vector<ptr> base_sequence; + typedef base_sequence::iterator base_iterator; + typedef base_sequence::const_iterator base_const_iterator; + + typedef base_sequence::size_type size_type; + typedef base_sequence::difference_type difference_type; + typedef base_sequence::allocator_type allocator_type; + + protected: + sequence_common (flags f, container* c) + : flags_ (f), container_ (c) + { + } + + sequence_common (size_type n, const type& x, container* c) + : flags_ (0), container_ (c) + { + assign (n, x); + } + + template <typename I> + sequence_common (const I& begin, const I& end, container* c) + : flags_ (0), container_ (c) + { + assign (begin, end); + } + + sequence_common (const sequence_common& v, flags f, container* c) + : flags_ (f), container_ (c) + { + v_.reserve (v.v_.size ()); + + for (base_const_iterator i (v.v_.begin ()), e (v.v_.end ()); + i != e; ++i) + { + ptr p ((**i)._clone (flags_, container_)); + v_.push_back (p); + } + } + + public: + sequence_common& + operator= (const sequence_common& v) + { + if (this == &v) + return *this; + + v_.assign (v.v_.size (), ptr ()); + + base_iterator di (v_.begin ()), de (v_.end ()); + base_const_iterator si (v.v_.begin ()), se (v.v_.end ()); + + for (; si != se && di != de; ++si, ++di) + { + // We have no ptr_ref. + // + ptr p ((**si)._clone (flags_, container_)); + *di = p; + } + + return *this; + } + + public: + size_type + size () const + { + return v_.size (); + } + + size_type + max_size () const + { + return v_.max_size (); + } + + size_type + capacity () const + { + return v_.capacity (); + } + + bool + empty () const + { + return v_.empty (); + } + + void + reserve (size_type n) + { + v_.reserve (n); + } + + void + clear () + { + v_.clear (); + } + + protected: + void + assign (size_type n, const type& x) + { + v_.assign (n, ptr ()); + + for (base_iterator i (v_.begin ()), e (v_.end ()); i != e; ++i) + { + ptr p (x._clone (flags_, container_)); + *i = p; + } + } + + template <typename I> + void + assign (const I& begin, const I& end) + { + // This is not the fastest way to do it. Also I's type may not + // have _clone. + // + v_.clear (); + + for (I i (begin); i != end; ++i) + { + ptr p (i->_clone (flags_, container_)); + v_.push_back (p); + } + } + + void + resize (size_type n, const type& x) + { + size_type old (v_.size ()); + v_.resize (n, ptr ()); + + if (old < n) + { + for (base_iterator i (v_.begin () + old), e (v_.end ()); + i != e; ++i) + { + ptr p (x._clone (flags_, container_)); + *i = p; + } + } + } + + void + insert (base_iterator p, size_type n, const type& x) + { + difference_type d (v_.end () - p); + v_.insert (p, n, ptr ()); + + for (base_iterator i (v_.end () - d); n != 0; --n) + { + ptr r (x._clone (flags_, container_)); + *(--i) = r; + } + } + + template <typename I> + void + insert (base_iterator p, const I& begin, const I& end) + { + // This is not the fastest way to do it. Also I's type may not + // have _clone. + // + if (begin != end) + { + for (I i (end);;) + { + --i; + ptr r (i->_clone (flags_, container_)); + p = v_.insert (p, r); + + if (i == begin) + break; + } + } + } + + protected: + flags flags_; + container* container_; + base_sequence v_; + }; + + // + // + template <typename T> + class sequence<T, false>: public sequence_common + { + protected: + // For IBM XL C++ 8.0. + // + typedef sequence_common::ptr ptr; + + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef + iterator_adapter<base_sequence::iterator, T> + iterator; + + typedef + iterator_adapter<base_sequence::const_iterator, const T> + const_iterator; + + typedef + iterator_adapter<base_sequence::reverse_iterator, T> + reverse_iterator; + + typedef + iterator_adapter<base_sequence::const_reverse_iterator, const T> + const_reverse_iterator; + + typedef sequence_common::size_type size_type; + typedef sequence_common::difference_type difference_type; + typedef sequence_common::allocator_type allocator_type; + + public: + explicit + sequence (flags f = 0, container* c = 0) + : sequence_common (f, c) + { + } + + // The first version causes trouble on IBM XL C++ 7.0 when + // a type does not have the default c-tor. While the second + // breaks VC++ 8.0 when using dllexport (it appears to + // instantiate everything instead of only what's used). + // +#ifdef _MSC_VER + explicit + sequence (size_type n, const T& x = T (), container* c = 0) + : sequence_common (n, x, c) + { + } +#else + explicit + sequence (size_type n, container* c = 0) + : sequence_common (n, T (), c) + { + } + + sequence (size_type n, const T& x, container* c = 0) + : sequence_common (n, x, c) + { + } +#endif + + template <typename I> + sequence (const I& begin, const I& end, container* c = 0) + : sequence_common (begin, end, c) + { + } + + sequence (const sequence& v, flags f = 0, container* c = 0) + : sequence_common (v, f, c) + { + } + + public: + void + assign (size_type n, const T& x) + { + sequence_common::assign (n, x); + } + + template <typename I> + void + assign (const I& begin, const I& end) + { + sequence_common::assign (begin, end); + } + + public: + // The first version causes trouble on IBM XL C++ 7.0 when + // a type does not have the default c-tor. While the second + // breaks VC++ 8.0 when using dllexport (it appears to + // instantiate everything instead of only what's used). + // +#ifdef _MSC_VER + void + resize (size_type n, const T& x = T ()) + { + sequence_common::resize (n, x); + } +#else + void + resize (size_type n) + { + sequence_common::resize (n, T ()); + } + + void + resize (size_type n, const T& x) + { + sequence_common::resize (n, x); + } +#endif + + public: + const_iterator + begin () const + { + return const_iterator (v_.begin ()); + } + + const_iterator + end () const + { + return const_iterator (v_.end ()); + } + + iterator + begin () + { + return iterator (v_.begin ()); + } + + iterator + end () + { + return iterator (v_.end ()); + } + + // reverse + // + + const_reverse_iterator + rbegin () const + { + return const_reverse_iterator (v_.rbegin ()); + } + + const_reverse_iterator + rend () const + { + return const_reverse_iterator (v_.rend ()); + } + + reverse_iterator + rbegin () + { + return reverse_iterator (v_.rbegin ()); + } + + reverse_iterator + rend () + { + return reverse_iterator (v_.rend ()); + } + + public: + T& + operator[] (size_type n) + { + return static_cast<T&> (*(v_[n])); + } + + const T& + operator[] (size_type n) const + { + return static_cast<const T&> (*(v_[n])); + } + + T& + at (size_type n) + { + return static_cast<T&> (*(v_.at (n))); + } + + const T& + at (size_type n) const + { + return static_cast<const T&> (*(v_.at (n))); + } + + T& + front () + { + return static_cast<T&> (*(v_.front ())); + } + + const T& + front () const + { + return static_cast<const T&> (*(v_.front ())); + } + + T& + back () + { + return static_cast<T&> (*(v_.back ())); + } + + const T& + back () const + { + return static_cast<const T&> (*(v_.back ())); + } + + public: + void + push_back (const T& x) + { + v_.push_back (ptr (x._clone (flags_, container_))); + } + + void + push_back (std::auto_ptr<T> x) + { + if (x->_container () != container_) + x->_container (container_); + + v_.push_back (ptr (x.release ())); + } + + void + pop_back () + { + v_.pop_back (); + } + + std::auto_ptr<T> + detach_back (bool pop = true) + { + ptr& p (v_.back ()); + p->_container (0); + T* x (static_cast<T*> (p.release ())); + + if (pop) + v_.pop_back (); + + return std::auto_ptr<T> (x); + } + + iterator + insert (iterator position, const T& x) + { + return iterator ( + v_.insert ( + position.base (), ptr (x._clone (flags_, container_)))); + } + + iterator + insert (iterator position, std::auto_ptr<T> x) + { + if (x->_container () != container_) + x->_container (container_); + + return iterator (v_.insert (position.base (), ptr (x.release ()))); + } + + void + insert (iterator position, size_type n, const T& x) + { + sequence_common::insert (position.base (), n, x); + } + + template <typename I> + void + insert (iterator position, const I& begin, const I& end) + { + sequence_common::insert (position.base (), begin, end); + } + + iterator + erase (iterator position) + { + return iterator (v_.erase (position.base ())); + } + + iterator + erase (iterator begin, iterator end) + { + return iterator (v_.erase (begin.base (), end.base ())); + } + + iterator + detach (iterator position, std::auto_ptr<T>& r, bool erase = true) + { + ptr& p (*position.base ()); + p->_container (0); + std::auto_ptr<T> tmp (static_cast<T*> (p.release ())); + r = tmp; + + if (erase) + return iterator (v_.erase (position.base ())); + else + return ++position; + } + + // Note that the container object of the two sequences being + // swapped should be the same. + // + void + swap (sequence& x) + { + assert (container_ == x.container_); + v_.swap (x.v_); + } + }; + + + // Specialization for fundamental types. + // + template <typename T> + class sequence<T, true>: public std::vector<T> + { + typedef std::vector<T> base_sequence; + + public: + explicit + sequence (flags = 0, container* = 0) + { + } + + explicit + sequence (typename base_sequence::size_type n, + const T& x = T (), + container* = 0) + : base_sequence (n, x) + { + } + + template <typename I> + sequence (const I& begin, const I& end, container* = 0) + : base_sequence (begin, end) + { + } + + sequence (const sequence& s, flags = 0, container* = 0) + : base_sequence (s) + { + } + }; + + + // Comparison operators. + // + + template <typename T, bool fund> + inline bool + operator== (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return (a.size () == b.size () + && std::equal (a.begin (), a.end (), b.begin ())); + } + + template <typename T, bool fund> + inline bool + operator!= (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return !(a == b); + } + + template <typename T, bool fund> + inline bool + operator< (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return std::lexicographical_compare (a.begin (), a.end (), + b.begin (), b.end ()); + } + + template <typename T, bool fund> + inline bool + operator> (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return b < a; + } + + template <typename T, bool fund> + inline bool + operator<= (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return !(a > b); + } + + template <typename T, bool fund> + inline bool + operator>= (const sequence<T, fund>& a, const sequence<T, fund>& b) + { + return !(a < b); + } + + // Note that the container object of the two sequences being + // swapped should be the same. + // + template <typename T, bool fund> + inline void + swap (sequence<T, fund>& x, sequence<T, fund>& y) + { + x.swap (y); + } + } + } +} + +#include <xsd/cxx/tree/containers.txx> + +#endif // XSD_CXX_TREE_CONTAINERS_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/containers.txx b/xsd/libxsd/xsd/cxx/tree/containers.txx new file mode 100644 index 0000000..fdc0bfd --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/containers.txx @@ -0,0 +1,284 @@ +// file : xsd/cxx/tree/containers.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <ostream> +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // one + // + template<typename T> + one<T, false>:: + ~one () + { + delete x_; + } + + template<typename T> + one<T, false>:: + one (flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + } + + template<typename T> + one<T, false>:: + one (const T& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template<typename T> + one<T, false>:: + one (std::auto_ptr<T> x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template<typename T> + one<T, false>:: + one (const one<T, false>& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + if (x.present ()) + set (x.get ()); + } + + template<typename T> + one<T, false>& one<T, false>:: + operator= (const one<T, false>& x) + { + if (this == &x) + return *this; + + if (x.present ()) + set (x.get ()); + else + { + delete x_; + x_ = 0; + } + + return *this; + } + + template<typename T> + void one<T, false>:: + set (const T& x) + { + // We always do a fresh copy because T may not be x's + // dynamic type. + // + T* r (x._clone (flags_, container_)); + + delete x_; + x_ = r; + } + + template<typename T> + void one<T, false>:: + set (std::auto_ptr<T> x) + { + T* r (0); + + if (x.get () != 0) + { + if (x->_container () != container_) + x->_container (container_); + + r = x.release (); + } + + delete x_; + x_ = r; + } + + // optional + // + template <typename T> + optional<T, false>:: + ~optional () + { + delete x_; + } + + template <typename T> + optional<T, false>:: + optional (flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + } + + template <typename T> + optional<T, false>:: + optional (const T& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template <typename T> + optional<T, false>:: + optional (std::auto_ptr<T> x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template <typename T> + optional<T, false>:: + optional (const optional<T, false>& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + if (x) + set (*x); + } + + template <typename T> + optional<T, false>& optional<T, false>:: + operator= (const T& x) + { + if (x_ == &x) + return *this; + + set (x); + + return *this; + } + + template <typename T> + optional<T, false>& optional<T, false>:: + operator= (const optional<T, false>& x) + { + if (this == &x) + return *this; + + if (x) + set (*x); + else + reset (); + + return *this; + } + + template <typename T> + void optional<T, false>:: + set (const T& x) + { + // We always do a fresh copy because T may not be x's + // dynamic type. + // + T* r (x._clone (flags_, container_)); + + delete x_; + x_ = r; + } + + template <typename T> + void optional<T, false>:: + set (std::auto_ptr<T> x) + { + T* r (0); + + if (x.get () != 0) + { + if (x->_container () != container_) + x->_container (container_); + + r = x.release (); + } + + delete x_; + x_ = r; + } + + template <typename T> + void optional<T, false>:: + reset () + { + delete x_; + x_ = 0; + } + + template <typename T> + void optional<T, false>:: + true_ () + { + } + + + // optional + // + template <typename T> + optional<T, true>:: + optional (const T& y, flags, container*) + : present_ (false) + { + set (y); + } + + template <typename T> + optional<T, true>:: + optional (const optional<T, true>& y, flags, container*) + : present_ (false) + { + if (y) + set (*y); + } + + template <typename T> + optional<T, true>& optional<T, true>:: + operator= (const T& y) + { + if (&x_ == &y) + return *this; + + set (y); + + return *this; + } + + template <typename T> + optional<T, true>& optional<T, true>:: + operator= (const optional<T, true>& y) + { + if (this == &y) + return *this; + + if (y) + set (*y); + else + reset (); + + return *this; + } + + template <typename T> + void optional<T, true>:: + true_ () + { + } + + template <typename C, typename T, bool fund> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const optional<T, fund>& x) + { + if (x) + os << *x; + else + os << bits::not_present<C> (); + + return os; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx b/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx new file mode 100644 index 0000000..317b80f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx @@ -0,0 +1,157 @@ +// file : xsd/cxx/tree/date-time-extraction.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + template <typename S> + inline void time_zone:: + zone_extract (istream<S>& s) + { + s >> hours_ >> minutes_; + present_ = true; + } + + // gday + // + template <typename C, typename B> + template <typename S> + gday<C, B>:: + gday (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> day_ >> zp; + + if (zp) + zone_extract (s); + } + + // gmonth + // + template <typename C, typename B> + template <typename S> + gmonth<C, B>:: + gmonth (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> month_ >> zp; + + if (zp) + zone_extract (s); + } + + // gyear + // + template <typename C, typename B> + template <typename S> + gyear<C, B>:: + gyear (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> year_ >> zp; + + if (zp) + zone_extract (s); + } + + // gmonth_day + // + template <typename C, typename B> + template <typename S> + gmonth_day<C, B>:: + gmonth_day (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> month_ >> day_ >> zp; + + if (zp) + zone_extract (s); + } + + // gyear_month + // + template <typename C, typename B> + template <typename S> + gyear_month<C, B>:: + gyear_month (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> year_ >> month_ >> zp; + + if (zp) + zone_extract (s); + } + + // date + // + template <typename C, typename B> + template <typename S> + date<C, B>:: + date (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> year_ >> month_ >> day_ >> zp; + + if (zp) + zone_extract (s); + } + + // time + // + template <typename C, typename B> + template <typename S> + time<C, B>:: + time (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> hours_ >> minutes_ >> seconds_ >> zp; + + if (zp) + zone_extract (s); + } + + // date_time + // + template <typename C, typename B> + template <typename S> + date_time<C, B>:: + date_time (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + bool zp; + s >> year_ >> month_ >> day_ + >> hours_ >> minutes_ >> seconds_ >> zp; + + if (zp) + zone_extract (s); + } + + // duration + // + template <typename C, typename B> + template <typename S> + duration<C, B>:: + duration (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + s >> negative_ + >> years_ >> months_ >> days_ + >> hours_ >> minutes_ >> seconds_; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx b/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx new file mode 100644 index 0000000..db24ae1 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx @@ -0,0 +1,188 @@ +// file : xsd/cxx/tree/date-time-insertion.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, const time_zone& z) + { + return s << z.zone_hours () << z.zone_minutes (); + } + + // gday + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const gday<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.day () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // gmonth + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const gmonth<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.month () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // gyear + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const gyear<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.year () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // gmonth_day + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const gmonth_day<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.month () << x.day () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // gyear_month + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const gyear_month<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.year () << x.month () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // date + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const date<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.year () << x.month () << x.day () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // time + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const time<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.hours () << x.minutes () << x.seconds () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // date_time + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const date_time<C, B>& x) + { + bool zp (x.zone_present ()); + + s << x.year () << x.month () << x.day () + << x.hours () << x.minutes () << x.seconds () << zp; + + if (zp) + { + const time_zone& z (x); + s << z; + } + + return s; + } + + // duration + // + template <typename S, typename C, typename B> + ostream<S>& + operator<< (ostream<S>& s, const duration<C, B>& x) + { + s << x.negative () + << x.years () << x.months () << x.days () + << x.hours () << x.minutes () << x.seconds (); + + return s; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx b/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx new file mode 100644 index 0000000..90073f4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx @@ -0,0 +1,324 @@ +// file : xsd/cxx/tree/date-time-ostream.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <ostream> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + template <typename C> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const time_zone& z) + { + short h = z.zone_hours (); + short m = z.zone_minutes (); + + if (h == 0 && m == 0) + { + os << C ('Z'); + } + else + { + if (h < 0 || m < 0) + { + h = -h; + m = -m; + os << C ('-'); + } + else + os << C ('+'); + + C f (os.fill (C ('0'))); + + os.width (2); + os << h << C (':'); + os.width (2); + os << m; + + os.fill (f); + } + + return os; + } + + // gday + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const gday<C, B>& x) + { + C f (os.fill (C ('0'))); + os.width (2); + os << x.day (); + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // gmonth + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const gmonth<C, B>& x) + { + C f (os.fill (C ('0'))); + os.width (2); + os << x.month (); + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // gyear + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const gyear<C, B>& x) + { + C f (os.fill (C ('0'))); + os.width (4); + os << x.year (); + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // gmonth_day + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const gmonth_day<C, B>& x) + { + C f (os.fill (C ('0'))); + + os.width (2); + os << x.month () << C ('-'); + + os.width (2); + os << x.day (); + + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + + // gyear_month + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const gyear_month<C, B>& x) + { + C f (os.fill (C ('0'))); + + os.width (4); + os << x.year () << C ('-'); + + os.width (2); + os << x.month (); + + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // date + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const date<C, B>& x) + { + C f (os.fill (C ('0'))); + + os.width (4); + os << x.year () << C ('-'); + + os.width (2); + os << x.month () << C ('-'); + + os.width (2); + os << x.day (); + + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // time + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const time<C, B>& x) + { + C f (os.fill (C ('0'))); + + os.width (2); + os << x.hours () << C (':'); + + os.width (2); + os << x.minutes () << C (':'); + + os.width (9); + std::ios_base::fmtflags ff ( + os.setf (std::ios::fixed, std::ios::floatfield)); + os << x.seconds (); + os.setf (ff, std::ios::floatfield); + + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // date_time + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const date_time<C, B>& x) + { + C f (os.fill (C ('0'))); + + os.width (4); + os << x.year () << C ('-'); + + os.width (2); + os << x.month () << C ('-'); + + os.width (2); + os << x.day () << C ('T'); + + os.width (2); + os << x.hours () << C (':'); + + os.width (2); + os << x.minutes () << C (':'); + + os.width (9); + std::ios_base::fmtflags ff ( + os.setf (std::ios::fixed, std::ios::floatfield)); + os << x.seconds (); + os.setf (ff, std::ios::floatfield); + + os.fill (f); + + if (x.zone_present ()) + { + const time_zone& z (x); + os << z; + } + + return os; + } + + // duration + // + template <typename C, typename B> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const duration<C, B>& x) + { + if (x.negative ()) + os << C ('-'); + + os << C ('P'); + + // In case it is 0-duration, use the years field to handle + // this case. + // + if (x.years () != 0 || + (x.months () == 0 && + x.days () == 0 && + x.hours () == 0 && + x.minutes () == 0 && + x.seconds () == 0.0)) + { + os << x.years () << C ('Y'); + } + + if (x.months () != 0) + { + os << x.months () << C ('M'); + } + + if (x.days () != 0) + { + os << x.days () << C ('D'); + } + + // Figure out if we need the 'T' delimiter. + // + if (x.hours () != 0 || + x.minutes () != 0 || + x.seconds () != 0.0) + os << C ('T'); + + if (x.hours () != 0) + { + os << x.hours () << C ('H'); + } + + if (x.minutes () != 0) + { + os << x.minutes () << C ('M'); + } + + if (x.seconds () > 0.0) + { + std::ios_base::fmtflags ff ( + os.setf (std::ios::fixed, std::ios::floatfield)); + os << x.seconds () << C ('S'); + os.setf (ff, std::ios::floatfield); + } + + return os; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.hxx b/xsd/libxsd/xsd/cxx/tree/date-time.hxx new file mode 100644 index 0000000..abde516 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time.hxx @@ -0,0 +1,1951 @@ +// file : xsd/cxx/tree/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains C++ class definitions for the XML Schema date/time types. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_DATE_TIME_HXX +#define XSD_CXX_TREE_DATE_TIME_HXX + +#include <string> +#include <cstddef> // std::size_t + +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/istream-fwd.hxx> + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + /** + * @brief Time zone representation + * + * The %time_zone class represents an optional %time zone and + * is used as a base class for date/time types. + * + * The %time zone can negative in which case both the hours and + * minutes components should be negative. + * + * @nosubgrouping + */ + class time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor. + * + * This constructor initializes the instance to the 'not specified' + * state. + */ + time_zone (); + + /** + * @brief Initialize an instance with the hours and minutes + * components. + * + * @param hours The %time zone hours component. + * @param minutes The %time zone minutes component. + */ + time_zone (short hours, short minutes); + + //@} + + /** + * @brief Determine if %time zone is specified. + * + * @return True if %time zone is specified, false otherwise. + */ + bool + zone_present () const; + + /** + * @brief Reset the %time zone to the 'not specified' state. + * + */ + void + zone_reset (); + + /** + * @brief Get the hours component of the %time zone. + * + * @return The hours component of the %time zone. + */ + short + zone_hours () const; + + /** + * @brief Set the hours component of the %time zone. + * + * @param h The new hours component. + */ + void + zone_hours (short h); + + + /** + * @brief Get the minutes component of the %time zone. + * + * @return The minutes component of the %time zone. + */ + short + zone_minutes () const; + + /** + * @brief Set the minutes component of the %time zone. + * + * @param m The new minutes component. + */ + void + zone_minutes (short m); + + protected: + //@cond + + template <typename C> + void + zone_parse (const C*, std::size_t); + + template <typename S> + void + zone_extract (istream<S>&); + + //@endcond + + private: + bool present_; + short hours_; + short minutes_; + }; + + /** + * @brief %time_zone comparison operator. + * + * @return True if both %time zones are either not specified or + * have equal hours and minutes components, false otherwise. + */ + bool + operator== (const time_zone&, const time_zone&); + + /** + * @brief %time_zone comparison operator. + * + * @return False if both %time zones are either not specified or + * have equal hours and minutes components, true otherwise. + */ + bool + operator!= (const time_zone&, const time_zone&); + + + /** + * @brief Class corresponding to the XML Schema gDay built-in type. + * + * The %gday class represents a day of the month with an optional + * %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class gday: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the day component. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param day The day component. + */ + explicit + gday (unsigned short day); + + /** + * @brief Initialize an instance with the day component and %time + * zone. + * + * @param day The day component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + gday (unsigned short day, short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + gday (const gday& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual gday* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + gday (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gday (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gday (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gday (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the day component. + * + * @return The day component. + */ + unsigned short + day () const; + + /** + * @brief Set the day component. + * + * @param d The new day component. + */ + void + day (unsigned short d); + + protected: + //@cond + + gday (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + unsigned short day_; + }; + + /** + * @brief %gday comparison operator. + * + * @return True if the day components and %time zones are equal, false + * otherwise. + */ + template <typename C, typename B> + bool + operator== (const gday<C, B>&, const gday<C, B>&); + + /** + * @brief %gday comparison operator. + * + * @return False if the day components and %time zones are equal, true + * otherwise. + */ + template <typename C, typename B> + bool + operator!= (const gday<C, B>&, const gday<C, B>&); + + /** + * @brief Class corresponding to the XML Schema gMonth built-in type. + * + * The %gmonth class represents a month of the year with an optional + * %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class gmonth: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the month component. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param month The month component. + */ + explicit + gmonth (unsigned short month); + + /** + * @brief Initialize an instance with the month component and %time + * zone. + * + * @param month The month component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + gmonth (unsigned short month, short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + gmonth (const gmonth& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual gmonth* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + gmonth (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the month component. + * + * @return The month component. + */ + unsigned short + month () const; + + /** + * @brief Set the month component. + * + * @param m The new month component. + */ + void + month (unsigned short m); + + protected: + //@cond + + gmonth (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + unsigned short month_; + }; + + /** + * @brief %gmonth comparison operator. + * + * @return True if the month components and %time zones are equal, false + * otherwise. + */ + template <typename C, typename B> + bool + operator== (const gmonth<C, B>&, const gmonth<C, B>&); + + /** + * @brief %gmonth comparison operator. + * + * @return False if the month components and %time zones are equal, true + * otherwise. + */ + template <typename C, typename B> + bool + operator!= (const gmonth<C, B>&, const gmonth<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema gYear built-in type. + * + * The %gyear class represents a year with an optional %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class gyear: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the year component. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param year The year component. + */ + explicit + gyear (int year); + + /** + * @brief Initialize an instance with the year component and %time + * zone. + * + * @param year The year component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + gyear (int year, short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + gyear (const gyear& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual gyear* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + gyear (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the year component. + * + * @return The year component. + */ + int + year () const; + + /** + * @brief Set the year component. + * + * @param y The new year component. + */ + void + year (int y); + + protected: + //@cond + + gyear (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + int year_; + }; + + /** + * @brief %gyear comparison operator. + * + * @return True if the year components and %time zones are equal, false + * otherwise. + */ + template <typename C, typename B> + bool + operator== (const gyear<C, B>&, const gyear<C, B>&); + + /** + * @brief %gyear comparison operator. + * + * @return False if the year components and %time zones are equal, true + * otherwise. + */ + template <typename C, typename B> + bool + operator!= (const gyear<C, B>&, const gyear<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema gMonthDay built-in type. + * + * The %gmonth_day class represents day and month of the year with an + * optional %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class gmonth_day: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the month and day components. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param month The month component. + * @param day The day component. + */ + gmonth_day (unsigned short month, unsigned short day); + + /** + * @brief Initialize an instance with the month and day components + * as well as %time zone. + * + * @param month The month component. + * @param day The day component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + gmonth_day (unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + gmonth_day (const gmonth_day& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual gmonth_day* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + gmonth_day (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth_day (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth_day (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gmonth_day (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the month component. + * + * @return The month component. + */ + unsigned short + month () const; + + /** + * @brief Set the month component. + * + * @param m The new month component. + */ + void + month (unsigned short m); + + /** + * @brief Get the day component. + * + * @return The day component. + */ + unsigned short + day () const; + + /** + * @brief Set the day component. + * + * @param d The new day component. + */ + void + day (unsigned short d); + + protected: + //@cond + + gmonth_day (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + unsigned short month_; + unsigned short day_; + }; + + /** + * @brief %gmonth_day comparison operator. + * + * @return True if the month and day components as well as %time zones + * are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const gmonth_day<C, B>&, const gmonth_day<C, B>&); + + /** + * @brief %gmonth_day comparison operator. + * + * @return False if the month and day components as well as %time zones + * are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const gmonth_day<C, B>&, const gmonth_day<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema gYearMonth built-in + * type. + * + * The %gyear_month class represents year and month with an optional + * %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class gyear_month: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the year and month components. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param year The year component. + * @param month The month component. + */ + gyear_month (int year, unsigned short month); + + /** + * @brief Initialize an instance with the year and month components + * as well as %time zone. + * + * @param year The year component. + * @param month The month component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + gyear_month (int year, unsigned short month, + short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + gyear_month (const gyear_month& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual gyear_month* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + gyear_month (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear_month (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear_month (const xercesc::DOMAttr& a, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + gyear_month (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the year component. + * + * @return The year component. + */ + int + year () const; + + /** + * @brief Set the year component. + * + * @param y The new year component. + */ + void + year (int y); + + /** + * @brief Get the month component. + * + * @return The month component. + */ + unsigned short + month () const; + + /** + * @brief Set the month component. + * + * @param m The new month component. + */ + void + month (unsigned short m); + + protected: + //@cond + + gyear_month (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + int year_; + unsigned short month_; + }; + + /** + * @brief %gyear_month comparison operator. + * + * @return True if the year and month components as well as %time zones + * are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const gyear_month<C, B>&, const gyear_month<C, B>&); + + /** + * @brief %gyear_month comparison operator. + * + * @return False if the year and month components as well as %time zones + * are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const gyear_month<C, B>&, const gyear_month<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema %date built-in type. + * + * The %date class represents day, month, and year with an optional + * %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class date: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the year, month, and day + * components. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param year The year component. + * @param month The month component. + * @param day The day component. + */ + date (int year, unsigned short month, unsigned short day); + + /** + * @brief Initialize an instance with the year, month, and day + * components as well as %time zone. + * + * @param year The year component. + * @param month The month component. + * @param day The day component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + date (int year, unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + date (const date& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual date* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + date (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the year component. + * + * @return The year component. + */ + int + year () const; + + /** + * @brief Set the year component. + * + * @param y The new year component. + */ + void + year (int y); + + /** + * @brief Get the month component. + * + * @return The month component. + */ + unsigned short + month () const; + + /** + * @brief Set the month component. + * + * @param m The new month component. + */ + void + month (unsigned short m); + + /** + * @brief Get the day component. + * + * @return The day component. + */ + unsigned short + day () const; + + /** + * @brief Set the day component. + * + * @param d The new day component. + */ + void + day (unsigned short d); + + protected: + //@cond + + date (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + int year_; + unsigned short month_; + unsigned short day_; + }; + + /** + * @brief %date comparison operator. + * + * @return True if the year, month, and day components as well as %time + * zones are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const date<C, B>&, const date<C, B>&); + + /** + * @brief %date comparison operator. + * + * @return False if the year, month, and day components as well as %time + * zones are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const date<C, B>&, const date<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema %time built-in type. + * + * The %time class represents hours, minutes, and seconds with an + * optional %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class time: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the hours, minutes, and + * seconds components. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param hours The hours component. + * @param minutes The minutes component. + * @param seconds The seconds component. + */ + time (unsigned short hours, unsigned short minutes, double seconds); + + /** + * @brief Initialize an instance with the hours, minutes, and + * seconds components as well as %time zone. + * + * @param hours The hours component. + * @param minutes The minutes component. + * @param seconds The seconds component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + time (unsigned short hours, unsigned short minutes, double seconds, + short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + time (const time& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual time* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + time (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + time (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + time (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + time (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the hours component. + * + * @return The hours component. + */ + unsigned short + hours () const; + + /** + * @brief Set the hours component. + * + * @param h The new hours component. + */ + void + hours (unsigned short h); + + /** + * @brief Get the minutes component. + * + * @return The minutes component. + */ + unsigned short + minutes () const; + + /** + * @brief Set the minutes component. + * + * @param m The new minutes component. + */ + void + minutes (unsigned short m); + + /** + * @brief Get the seconds component. + * + * @return The seconds component. + */ + double + seconds () const; + + /** + * @brief Set the seconds component. + * + * @param s The new seconds component. + */ + void + seconds (double s); + + protected: + //@cond + + time (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + /** + * @brief %time comparison operator. + * + * @return True if the hours, seconds, and minutes components as well + * as %time zones are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const time<C, B>&, const time<C, B>&); + + /** + * @brief %time comparison operator. + * + * @return False if the hours, seconds, and minutes components as well + * as %time zones are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const time<C, B>&, const time<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema dateTime built-in type. + * + * The %date_time class represents year, month, day, hours, minutes, + * and seconds with an optional %time zone. + * + * @nosubgrouping + */ + template <typename C, typename B> + class date_time: public B, public time_zone + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with the year, month, day, hours, + * minutes, and seconds components. + * + * When this constructor is used, the %time zone is left + * unspecified. + * + * @param year The year component. + * @param month The month component. + * @param day The day component. + * @param hours The hours component. + * @param minutes The minutes component. + * @param seconds The seconds component. + */ + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, + double seconds); + + /** + * @brief Initialize an instance with the year, month, day, hours, + * minutes, and seconds components as well as %time zone. + * + * @param year The year component. + * @param month The month component. + * @param day The day component. + * @param hours The hours component. + * @param minutes The minutes component. + * @param seconds The seconds component. + * @param zone_hours The %time zone hours component. + * @param zone_minutes The %time zone minutes component. + */ + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, + double seconds, short zone_hours, short zone_minutes); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + date_time (const date_time& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual date_time* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + date_time (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date_time (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date_time (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + date_time (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Get the year component. + * + * @return The year component. + */ + int + year () const; + + /** + * @brief Set the year component. + * + * @param y The new year component. + */ + void + year (int y); + + /** + * @brief Get the month component. + * + * @return The month component. + */ + unsigned short + month () const; + + /** + * @brief Set the month component. + * + * @param m The new month component. + */ + void + month (unsigned short m); + + /** + * @brief Get the day component. + * + * @return The day component. + */ + unsigned short + day () const; + + /** + * @brief Set the day component. + * + * @param d The new day component. + */ + void + day (unsigned short d); + + /** + * @brief Get the hours component. + * + * @return The hours component. + */ + unsigned short + hours () const; + + /** + * @brief Set the hours component. + * + * @param h The new hours component. + */ + void + hours (unsigned short h); + + /** + * @brief Get the minutes component. + * + * @return The minutes component. + */ + unsigned short + minutes () const; + + /** + * @brief Set the minutes component. + * + * @param m The new minutes component. + */ + void + minutes (unsigned short m); + + /** + * @brief Get the seconds component. + * + * @return The seconds component. + */ + double + seconds () const; + + /** + * @brief Set the seconds component. + * + * @param s The new seconds component. + */ + void + seconds (double s); + + protected: + //@cond + + date_time (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + /** + * @brief %date_time comparison operator. + * + * @return True if the year, month, day, hours, seconds, and minutes + * components as well as %time zones are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const date_time<C, B>&, const date_time<C, B>&); + + /** + * @brief %date_time comparison operator. + * + * @return False if the year, month, day, hours, seconds, and minutes + * components as well as %time zones are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const date_time<C, B>&, const date_time<C, B>&); + + + /** + * @brief Class corresponding to the XML Schema %duration built-in type. + * + * The %duration class represents a potentially negative %duration in + * the form of years, months, days, hours, minutes, and seconds. + * + * @nosubgrouping + */ + template <typename C, typename B> + class duration: public B + { + public: + /** + * @name Constructors + */ + //@{ + /** + * @brief Initialize a potentially negative instance with the years, + * months, days, hours, minutes, and seconds components. + * + * @param negative A boolean value indicating whether the %duration + * is negative (true) or positive (false). + * @param years The years component. + * @param months The months component. + * @param days The days component. + * @param hours The hours component. + * @param minutes The minutes component. + * @param seconds The seconds component. + */ + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds); + + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the _clone function instead. + */ + duration (const duration& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual duration* + _clone (flags f = 0, container* c = 0) const; + + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + duration (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + duration (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + duration (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + duration (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Determine if %duration is negative. + * + * @return True if %duration is negative, false otherwise. + */ + bool + negative () const; + + /** + * @brief Change %duration sign. + * + * @param n A boolean value indicating whether %duration is + * negative (true) or positive (false). + */ + void + negative (bool n); + + /** + * @brief Get the years component. + * + * @return The years component. + */ + unsigned int + years () const; + + /** + * @brief Set the years component. + * + * @param y The new years component. + */ + void + years (unsigned int y); + + /** + * @brief Get the months component. + * + * @return The months component. + */ + unsigned int + months () const; + + /** + * @brief Set the months component. + * + * @param m The new months component. + */ + void + months (unsigned int m); + + /** + * @brief Get the days component. + * + * @return The days component. + */ + unsigned int + days () const; + + /** + * @brief Set the days component. + * + * @param d The new days component. + */ + void + days (unsigned int d); + + /** + * @brief Get the hours component. + * + * @return The hours component. + */ + unsigned int + hours () const; + + /** + * @brief Set the hours component. + * + * @param h The new hours component. + */ + void + hours (unsigned int h); + + /** + * @brief Get the minutes component. + * + * @return The minutes component. + */ + unsigned int + minutes () const; + + /** + * @brief Set the minutes component. + * + * @param m The new minutes component. + */ + void + minutes (unsigned int m); + + /** + * @brief Get the seconds component. + * + * @return The seconds component. + */ + double + seconds () const; + + /** + * @brief Set the seconds component. + * + * @param s The new seconds component. + */ + void + seconds (double s); + + protected: + //@cond + + duration (); + + void + parse (const std::basic_string<C>&); + + //@endcond + + private: + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + /** + * @brief %duration comparison operator. + * + * @return True if the sings as well as years, months, days, hours, + * seconds, and minutes components are equal, false otherwise. + */ + template <typename C, typename B> + bool + operator== (const duration<C, B>&, const duration<C, B>&); + + /** + * @brief %duration comparison operator. + * + * @return False if the sings as well as years, months, days, hours, + * seconds, and minutes components are equal, true otherwise. + */ + template <typename C, typename B> + bool + operator!= (const duration<C, B>&, const duration<C, B>&); + } + } +} + +#include <xsd/cxx/tree/date-time.ixx> +#include <xsd/cxx/tree/date-time.txx> + +#endif // XSD_CXX_TREE_DATE_TIME_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.ixx b/xsd/libxsd/xsd/cxx/tree/date-time.ixx new file mode 100644 index 0000000..5bc7200 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time.ixx @@ -0,0 +1,893 @@ +// file : xsd/cxx/tree/date-time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + inline time_zone:: + time_zone () + : present_ (false) + { + } + + inline time_zone:: + time_zone (short h, short m) + : present_ (true), hours_ (h), minutes_ (m) + { + } + + inline bool time_zone:: + zone_present () const + { + return present_; + } + + inline void time_zone:: + zone_reset () + { + present_ = false; + } + + inline short time_zone:: + zone_hours () const + { + return hours_; + } + + inline void time_zone:: + zone_hours (short h) + { + hours_ = h; + present_ = true; + } + + inline short time_zone:: + zone_minutes () const + { + return minutes_; + } + + inline void time_zone:: + zone_minutes (short m) + { + minutes_ = m; + present_ = true; + } + + inline bool + operator== (const time_zone& x, const time_zone& y) + { + return x.zone_present () + ? y.zone_present () && + x.zone_hours () == y.zone_hours () && + x.zone_minutes () == y.zone_minutes () + : !y.zone_present (); + } + + inline bool + operator!= (const time_zone& x, const time_zone& y) + { + return !(x == y); + } + + // gday + // + template <typename C, typename B> + inline gday<C, B>:: + gday () + { + } + + template <typename C, typename B> + inline gday<C, B>:: + gday (unsigned short day) + : day_ (day) + { + } + + template <typename C, typename B> + inline gday<C, B>:: + gday (unsigned short day, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), day_ (day) + { + } + + template <typename C, typename B> + inline gday<C, B>:: + gday (const gday& x, flags f, container* c) + : B (x, f, c), time_zone (x), day_ (x.day_) + { + } + + template <typename C, typename B> + inline unsigned short gday<C, B>:: + day () const + { + return day_; + } + + template <typename C, typename B> + inline void gday<C, B>:: + day (unsigned short day) + { + day_ = day; + } + + template <typename C, typename B> + inline bool + operator== (const gday<C, B>& x, const gday<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.day () == y.day () && xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const gday<C, B>& x, const gday<C, B>& y) + { + return !(x == y); + } + + // gmonth + // + template <typename C, typename B> + inline gmonth<C, B>:: + gmonth () + { + } + + template <typename C, typename B> + inline gmonth<C, B>:: + gmonth (unsigned short month) + : month_ (month) + { + } + + template <typename C, typename B> + inline gmonth<C, B>:: + gmonth (unsigned short month, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), month_ (month) + { + } + + template <typename C, typename B> + inline gmonth<C, B>:: + gmonth (const gmonth& x, flags f, container* c) + : B (x, f, c), time_zone (x), month_ (x.month_) + { + } + + template <typename C, typename B> + inline unsigned short gmonth<C, B>:: + month () const + { + return month_; + } + + template <typename C, typename B> + inline void gmonth<C, B>:: + month (unsigned short month) + { + month_ = month; + } + + template <typename C, typename B> + inline bool + operator== (const gmonth<C, B>& x, const gmonth<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.month () == y.month () && xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const gmonth<C, B>& x, const gmonth<C, B>& y) + { + return !(x == y); + } + + // gyear + // + template <typename C, typename B> + inline gyear<C, B>:: + gyear () + { + } + + template <typename C, typename B> + inline gyear<C, B>:: + gyear (int year) + : year_ (year) + { + } + + template <typename C, typename B> + inline gyear<C, B>:: + gyear (int year, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), year_ (year) + { + } + + template <typename C, typename B> + inline gyear<C, B>:: + gyear (const gyear& x, flags f, container* c) + : B (x, f, c), time_zone (x), year_ (x.year_) + { + } + + template <typename C, typename B> + inline int gyear<C, B>:: + year () const + { + return year_; + } + + template <typename C, typename B> + inline void gyear<C, B>:: + year (int year) + { + year_ = year; + } + + template <typename C, typename B> + inline bool + operator== (const gyear<C, B>& x, const gyear<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const gyear<C, B>& x, const gyear<C, B>& y) + { + return !(x == y); + } + + // gmonth_day + // + template <typename C, typename B> + inline gmonth_day<C, B>:: + gmonth_day () + { + } + + template <typename C, typename B> + inline gmonth_day<C, B>:: + gmonth_day (unsigned short month, unsigned short day) + : month_ (month), day_ (day) + { + } + + template <typename C, typename B> + inline gmonth_day<C, B>:: + gmonth_day (unsigned short month, unsigned short day, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), month_ (month), day_ (day) + { + } + + template <typename C, typename B> + inline gmonth_day<C, B>:: + gmonth_day (const gmonth_day& x, flags f, container* c) + : B (x, f, c), time_zone (x), month_ (x.month_), day_ (x.day_) + { + } + + template <typename C, typename B> + inline unsigned short gmonth_day<C, B>:: + month () const + { + return month_; + } + + template <typename C, typename B> + inline void gmonth_day<C, B>:: + month (unsigned short month) + { + month_ = month; + } + + template <typename C, typename B> + inline unsigned short gmonth_day<C, B>:: + day () const + { + return day_; + } + + template <typename C, typename B> + inline void gmonth_day<C, B>:: + day (unsigned short day) + { + day_ = day; + } + + template <typename C, typename B> + inline bool + operator== (const gmonth_day<C, B>& x, const gmonth_day<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.month () == y.month () && + x.day () == y.day () && + xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const gmonth_day<C, B>& x, const gmonth_day<C, B>& y) + { + return !(x == y); + } + + // gyear_month + // + template <typename C, typename B> + inline gyear_month<C, B>:: + gyear_month () + { + } + + template <typename C, typename B> + inline gyear_month<C, B>:: + gyear_month (int year, unsigned short month) + : year_ (year), month_ (month) + { + } + + template <typename C, typename B> + inline gyear_month<C, B>:: + gyear_month (int year, unsigned short month, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), year_ (year), month_ (month) + { + } + + template <typename C, typename B> + inline gyear_month<C, B>:: + gyear_month (const gyear_month& x, flags f, container* c) + : B (x, f, c), time_zone (x), year_ (x.year_), month_ (x.month_) + { + } + + template <typename C, typename B> + inline int gyear_month<C, B>:: + year () const + { + return year_; + } + + template <typename C, typename B> + inline void gyear_month<C, B>:: + year (int year) + { + year_ = year; + } + + template <typename C, typename B> + inline unsigned short gyear_month<C, B>:: + month () const + { + return month_; + } + + template <typename C, typename B> + inline void gyear_month<C, B>:: + month (unsigned short month) + { + month_ = month; + } + + template <typename C, typename B> + inline bool + operator== (const gyear_month<C, B>& x, const gyear_month<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const gyear_month<C, B>& x, const gyear_month<C, B>& y) + { + return !(x == y); + } + + // date + // + template <typename C, typename B> + inline date<C, B>:: + date () + { + } + + template <typename C, typename B> + inline date<C, B>:: + date (int year, unsigned short month, unsigned short day) + : year_ (year), month_ (month), day_ (day) + { + } + + template <typename C, typename B> + inline date<C, B>:: + date (int year, unsigned short month, unsigned short day, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + year_ (year), month_ (month), day_ (day) + { + } + + template <typename C, typename B> + inline date<C, B>:: + date (const date& x, flags f, container* c) + : B (x, f, c), time_zone (x), + year_ (x.year_), month_ (x.month_), day_ (x.day_) + { + } + + template <typename C, typename B> + inline int date<C, B>:: + year () const + { + return year_; + } + + template <typename C, typename B> + inline void date<C, B>:: + year (int year) + { + year_ = year; + } + + template <typename C, typename B> + inline unsigned short date<C, B>:: + month () const + { + return month_; + } + + template <typename C, typename B> + inline void date<C, B>:: + month (unsigned short month) + { + month_ = month; + } + + template <typename C, typename B> + inline unsigned short date<C, B>:: + day () const + { + return day_; + } + + template <typename C, typename B> + inline void date<C, B>:: + day (unsigned short day) + { + day_ = day; + } + + template <typename C, typename B> + inline bool + operator== (const date<C, B>& x, const date<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + x.day () == y.day () && + xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const date<C, B>& x, const date<C, B>& y) + { + return !(x == y); + } + + // time + // + template <typename C, typename B> + inline time<C, B>:: + time () + { + } + + template <typename C, typename B> + inline time<C, B>:: + time (unsigned short hours, unsigned short minutes, double seconds) + : hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + template <typename C, typename B> + inline time<C, B>:: + time (unsigned short hours, unsigned short minutes, double seconds, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + template <typename C, typename B> + inline time<C, B>:: + time (const time& x, flags f, container* c) + : B (x, f, c), time_zone (x), + hours_ (x.hours_), minutes_ (x.minutes_), seconds_ (x.seconds_) + { + } + + template <typename C, typename B> + inline unsigned short time<C, B>:: + hours () const + { + return hours_; + } + + template <typename C, typename B> + inline void time<C, B>:: + hours (unsigned short hours) + { + hours_ = hours; + } + + template <typename C, typename B> + inline unsigned short time<C, B>:: + minutes () const + { + return minutes_; + } + + template <typename C, typename B> + inline void time<C, B>:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + template <typename C, typename B> + inline double time<C, B>:: + seconds () const + { + return seconds_; + } + + template <typename C, typename B> + inline void time<C, B>:: + seconds (double seconds) + { + seconds_ = seconds; + } + + template <typename C, typename B> + inline bool + operator== (const time<C, B>& x, const time<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds () && + xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const time<C, B>& x, const time<C, B>& y) + { + return !(x == y); + } + + // date_time + // + template <typename C, typename B> + inline date_time<C, B>:: + date_time () + { + } + + template <typename C, typename B> + inline date_time<C, B>:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds) + : year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + template <typename C, typename B> + inline date_time<C, B>:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + template <typename C, typename B> + inline date_time<C, B>:: + date_time (const date_time& x, flags f, container* c) + : B (x, f, c), time_zone (x), + year_ (x.year_), month_ (x.month_), day_ (x.day_), + hours_ (x.hours_), minutes_ (x.minutes_), seconds_ (x.seconds_) + { + } + + template <typename C, typename B> + inline int date_time<C, B>:: + year () const + { + return year_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + year (int year) + { + year_ = year; + } + + template <typename C, typename B> + inline unsigned short date_time<C, B>:: + month () const + { + return month_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + month (unsigned short month) + { + month_ = month; + } + + template <typename C, typename B> + inline unsigned short date_time<C, B>:: + day () const + { + return day_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + day (unsigned short day) + { + day_ = day; + } + + template <typename C, typename B> + inline unsigned short date_time<C, B>:: + hours () const + { + return hours_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + hours (unsigned short hours) + { + hours_ = hours; + } + + template <typename C, typename B> + inline unsigned short date_time<C, B>:: + minutes () const + { + return minutes_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + template <typename C, typename B> + inline double date_time<C, B>:: + seconds () const + { + return seconds_; + } + + template <typename C, typename B> + inline void date_time<C, B>:: + seconds (double seconds) + { + seconds_ = seconds; + } + + template <typename C, typename B> + inline bool + operator== (const date_time<C, B>& x, const date_time<C, B>& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + x.day () == y.day () && + x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds () && + xz == yz; + } + + template <typename C, typename B> + inline bool + operator!= (const date_time<C, B>& x, const date_time<C, B>& y) + { + return !(x == y); + } + + // duration + // + template <typename C, typename B> + inline duration<C, B>:: + duration () + { + } + + template <typename C, typename B> + inline duration<C, B>:: + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds) + : negative_ (negative), + years_ (years), months_ (months), days_ (days), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + template <typename C, typename B> + inline duration<C, B>:: + duration (const duration& x, flags f, container* c) + : B (x, f, c), negative_ (x.negative_), + years_ (x.years_), months_ (x.months_), days_ (x.days_), + hours_ (x.hours_), minutes_ (x.minutes_), seconds_ (x.seconds_) + { + } + + template <typename C, typename B> + inline bool duration<C, B>:: + negative () const + { + return negative_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + negative (bool negative) + { + negative_ = negative; + } + + template <typename C, typename B> + inline unsigned int duration<C, B>:: + years () const + { + return years_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + years (unsigned int years) + { + years_ = years; + } + + template <typename C, typename B> + inline unsigned int duration<C, B>:: + months () const + { + return months_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + months (unsigned int months) + { + months_ = months; + } + + template <typename C, typename B> + inline unsigned int duration<C, B>:: + days () const + { + return days_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + days (unsigned int days) + { + days_ = days; + } + + template <typename C, typename B> + inline unsigned int duration<C, B>:: + hours () const + { + return hours_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + hours (unsigned int hours) + { + hours_ = hours; + } + + template <typename C, typename B> + inline unsigned int duration<C, B>:: + minutes () const + { + return minutes_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + minutes (unsigned int minutes) + { + minutes_ = minutes; + } + + template <typename C, typename B> + inline double duration<C, B>:: + seconds () const + { + return seconds_; + } + + template <typename C, typename B> + inline void duration<C, B>:: + seconds (double seconds) + { + seconds_ = seconds; + } + + template <typename C, typename B> + inline bool + operator== (const duration<C, B>& x, const duration<C, B>& y) + { + return x.negative () == y.negative () && + x.years () == y.years () && + x.months () == y.months () && + x.days () == y.days () && + x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds (); + } + + template <typename C, typename B> + inline bool + operator!= (const duration<C, B>& x, const duration<C, B>& y) + { + return !(x == y); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.txx b/xsd/libxsd/xsd/cxx/tree/date-time.txx new file mode 100644 index 0000000..34c6c84 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/date-time.txx @@ -0,0 +1,94 @@ +// file : xsd/cxx/tree/date-time.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // gday + // + template <typename C, typename B> + gday<C, B>* gday<C, B>:: + _clone (flags f, container* c) const + { + return new gday (*this, f, c); + } + + // gmonth + // + template <typename C, typename B> + gmonth<C, B>* gmonth<C, B>:: + _clone (flags f, container* c) const + { + return new gmonth (*this, f, c); + } + + // gyear + // + template <typename C, typename B> + gyear<C, B>* gyear<C, B>:: + _clone (flags f, container* c) const + { + return new gyear (*this, f, c); + } + + // gmonth_day + // + template <typename C, typename B> + gmonth_day<C, B>* gmonth_day<C, B>:: + _clone (flags f, container* c) const + { + return new gmonth_day (*this, f, c); + } + + // gyear_month + // + template <typename C, typename B> + gyear_month<C, B>* gyear_month<C, B>:: + _clone (flags f, container* c) const + { + return new gyear_month (*this, f, c); + } + + // date + // + template <typename C, typename B> + date<C, B>* date<C, B>:: + _clone (flags f, container* c) const + { + return new date (*this, f, c); + } + + // time + // + template <typename C, typename B> + time<C, B>* time<C, B>:: + _clone (flags f, container* c) const + { + return new time (*this, f, c); + } + + // date_time + // + template <typename C, typename B> + date_time<C, B>* date_time<C, B>:: + _clone (flags f, container* c) const + { + return new date_time (*this, f, c); + } + + // duration + // + template <typename C, typename B> + duration<C, B>* duration<C, B>:: + _clone (flags f, container* c) const + { + return new duration (*this, f, c); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/element-map.hxx b/xsd/libxsd/xsd/cxx/tree/element-map.hxx new file mode 100644 index 0000000..2f12b0b --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/element-map.hxx @@ -0,0 +1,146 @@ +// file : xsd/cxx/tree/element-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ELEMENT_MAP_HXX +#define XSD_CXX_TREE_ELEMENT_MAP_HXX + +#include <map> +#include <memory> // std::auto_ptr +#include <cstddef> // std::size_t +#include <string> + +#include <xsd/cxx/xml/qualified-name.hxx> +#include <xsd/cxx/tree/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + /** + * @brief Root element map. + * + * This class allows uniform parsing/serialization of multiple + * root elements via the element_type base class. + * + * @nosubgrouping + */ + template <typename C, typename T> + class element_map + { + public: + /** + * @brief Common base class for all element types. + */ + typedef tree::element_type<C, T> element_type; + + /** + * @brief Parse a DOM element. + * + * @param e A DOM element to parse. + * @param f Flags to create the new element object with. + * @return An automatic pointer to the new element object. + */ + static std::auto_ptr<element_type> + parse (const xercesc::DOMElement& e, flags f = 0); + + /** + * @brief Serialize an element object to a DOM element. + * + * @param e A DOM element to serialize to. + * @param x An element object to serialize. + */ + static void + serialize (xercesc::DOMElement& e, const element_type& x); + + public: + //@cond + + typedef xml::qualified_name<C> qualified_name; + + typedef std::auto_ptr<element_type> + (*parser) (const xercesc::DOMElement&, flags f); + + typedef void + (*serializer) (xercesc::DOMElement&, const element_type&); + + static void + register_parser (const qualified_name&, parser); + + static void + register_serializer (const qualified_name&, serializer); + + public: + struct map_entry + { + map_entry () : parser_ (0), serializer_ (0) {} + + parser parser_; + serializer serializer_; + }; + + typedef + std::map<qualified_name, map_entry> + map; + + static map* map_; + static std::size_t count_; + + private: + element_map (); + + //@endcond + }; + + //@cond + + template <typename C, typename T> + typename element_map<C, T>::map* element_map<C, T>::map_ = 0; + + template <typename C, typename T> + std::size_t element_map<C, T>::count_ = 0; + + template <typename C, typename T> + struct element_map_init + { + element_map_init (); + ~element_map_init (); + }; + + // + // + template<typename T, typename C, typename B> + std::auto_ptr<element_type<C, B> > + parser_impl (const xercesc::DOMElement&, flags); + + template<typename T, typename C, typename B> + struct parser_init + { + parser_init (const std::basic_string<C>& name, + const std::basic_string<C>& ns); + }; + + // + // + template<typename T, typename C, typename B> + void + serializer_impl (xercesc::DOMElement&, const element_type<C, B>&); + + template<typename T, typename C, typename B> + struct serializer_init + { + serializer_init (const std::basic_string<C>& name, + const std::basic_string<C>& ns); + }; + + //@endcond + } + } +} + +#include <xsd/cxx/tree/element-map.txx> + +#endif // XSD_CXX_TREE_ELEMENT_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/element-map.txx b/xsd/libxsd/xsd/cxx/tree/element-map.txx new file mode 100644 index 0000000..0ff5d2a --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/element-map.txx @@ -0,0 +1,71 @@ +// file : xsd/cxx/tree/element-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // element_map + // + template <typename C, typename T> + void element_map<C, T>:: + register_parser (const qualified_name& n, parser p) + { + (*map_)[n].parser_ = p; + } + + template <typename C, typename T> + void element_map<C, T>:: + register_serializer (const qualified_name& n, serializer s) + { + (*map_)[n].serializer_ = s; + } + + // element_map_init + // + template <typename C, typename T> + element_map_init<C, T>:: + element_map_init () + { + if (element_map<C, T>::count_ == 0) + element_map<C, T>::map_ = new typename element_map<C, T>::map; + + ++element_map<C, T>::count_; + } + + template <typename C, typename T> + element_map_init<C, T>:: + ~element_map_init () + { + if (--element_map<C, T>::count_ == 0) + delete element_map<C, T>::map_; + } + + // parser_init + // + template<typename T, typename C, typename B> + parser_init<T, C, B>:: + parser_init (const std::basic_string<C>& name, + const std::basic_string<C>& ns) + { + element_map<C, B>::register_parser ( + xml::qualified_name<C> (name, ns), &parser_impl<T, C, B>); + } + + // serializer_init + // + template<typename T, typename C, typename B> + serializer_init<T, C, B>:: + serializer_init (const std::basic_string<C>& name, + const std::basic_string<C>& ns) + { + element_map<C, B>::register_serializer ( + xml::qualified_name<C> (name, ns), &serializer_impl<T, C, B>); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/elements.hxx b/xsd/libxsd/xsd/cxx/tree/elements.hxx new file mode 100644 index 0000000..403fdb3 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/elements.hxx @@ -0,0 +1,1490 @@ +// file : xsd/cxx/tree/elements.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains C++ class definitions for XML Schema anyType and + * anySimpleType types as well as supporting code. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_ELEMENTS_HXX +#define XSD_CXX_TREE_ELEMENTS_HXX + +#include <map> +#include <string> +#include <memory> // std::auto_ptr +#include <istream> +#include <sstream> +#include <cassert> + +#include <xercesc/dom/DOMNode.hpp> +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> +#include <xercesc/dom/DOMDocument.hpp> +#include <xercesc/dom/DOMNamedNodeMap.hpp> + +#include <xsd/cxx/xml/elements.hxx> // xml::properties +#include <xsd/cxx/xml/dom/auto-ptr.hxx> // dom::auto_ptr + +#include <xsd/cxx/tree/facet.hxx> +#include <xsd/cxx/tree/exceptions.hxx> +#include <xsd/cxx/tree/istream-fwd.hxx> + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + /** + * @brief Parsing and %serialization %flags. + * + * Flags are used to modify the default behavior of %parsing and + * %serialization functions as well as %parsing constructors. + * + * @nosubgrouping + */ + class flags + { + public: + /** + * @name Flag constants + */ + //@{ + + /** + * @brief Keep DOM association in the resulting tree. + */ + static const unsigned long keep_dom = 0x00000100UL; + + /** + * @brief Assume ownership of the DOM document. + * + * This flag only makes sense together with the @c keep_dom + * flag in the call to the %parsing function with the + * @c dom::auto_ptr<DOMDocument> argument. + * + */ + static const unsigned long own_dom = 0x00000200UL; + + /** + * @brief Turn off XML Schema validation in the underlying XML + * parser. + */ + static const unsigned long dont_validate = 0x00000400UL; + + /** + * @brief Do not initialize the Xerces-C++ runtime. + */ + static const unsigned long dont_initialize = 0x00000001UL; + + /** + * @brief Do not write XML declaration during %serialization. + */ + static const unsigned long no_xml_declaration = 0x00010000UL; + + /** + * @brief Do not add extra spaces or new lines that make the + * resulting XML easier to read. + */ + static const unsigned long dont_pretty_print = 0x00020000UL; + + //@cond + + // The following flags are for internal use. + // + static const unsigned long base = 0x01000000UL; + + //@endcond + + // Notes on flag blocks: + // + // 0x000000FF - common (applicable to both parsing and serialization) + // 0x0000FF00 - parsing (values aligned with XML parsing) + // 0x00FF0000 - serialization (values aligned with XML serialization) + // 0xFF000000 - internal + + //@} + + public: + /** + * @brief Initialize an instance with an integer value. + * + * @param x A %flags value as an integer. + */ + flags (unsigned long x = 0) + : x_ (x) + { + } + + /** + * @brief Convert an instance to an integer value. + * + * @return An integer %flags value. + */ + operator unsigned long () const + { + return x_; + } + + /** + * @brief Combine two %flags. + * + * @return A %flags object that is a combination of the arguments. + */ + friend flags + operator| (const flags& a, const flags& b) + { + return flags (a.x_ | b.x_); + } + + /** + * @brief Combine two %flags. + * + * @return A %flags object that is a combination of the arguments. + */ + friend flags + operator| (const flags& a, unsigned long b) + { + return flags (a.x_ | b); + } + + /** + * @brief Combine two %flags. + * + * @return A %flags object that is a combination of the arguments. + */ + friend flags + operator| (unsigned long a, const flags& b) + { + return flags (a | b.x_); + } + + private: + unsigned long x_; + }; + + + // Parsing properties. Refer to xsd/cxx/xml/elements.hxx for XML- + // related properties. + // + template <typename C> + class properties: public xml::properties<C> + { + }; + + //@cond + + // DOM user data keys. + // + template <int dummy> + struct user_data_keys_template + { + // Back pointers to tree nodes. + // + static const XMLCh node[21]; + }; + + typedef user_data_keys_template<0> user_data_keys; + + // HP aCC3 complains about unresolved symbols without an explicit + // instantiation. + // +#if defined(__HP_aCC) && __HP_aCC <= 39999 + template struct user_data_keys_template<0>; +#endif + // + // + struct identity + { + virtual + ~identity () + { + } + + identity () + { + } + + virtual bool + before (const identity&) const = 0; + + virtual void + throw_duplicate_id () const = 0; + + private: + identity (const identity&); + + identity& + operator= (const identity&); + }; + + //@endcond + + + // anyType. VC++ has a name injection bug that makes it impossible + // to have a member with the same name as a base type. To address + // that we will have to choose some unique name for the definition + // and typedef it to 'type'. + // + class _type; + + /** + * @brief Class corresponding to the XML Schema anyType built-in type. + * + */ + typedef _type type; + + /** + * @brief Container type. + * + */ + typedef _type container; + + /** + * @brief Class corresponding to the XML Schema anyType built-in type. + * + * This class is a base for every generated and built-in type in the + * C++/Tree mapping. + * + * @nosubgrouping + */ + class _type + { + public: + virtual + ~_type () + { + // Everything should have been unregistered by now. + // + assert (map_.get () == 0 || map_->size () == 0); + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor. + */ + _type () + : container_ (0) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + _type (const type& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual type* + _clone (flags f = 0, container* c = 0) const + { + return new type (*this, f, c); + } + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + _type (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + _type (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + _type (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename C> + _type (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + type& + operator= (const type& x) + { + while (&x == 0) /* unused */; + return *this; + } + + // Container API. + // + public: + /** + * @brief Get a constant pointer to container, an object model + * node that contains this instance. + * + * @return A constant pointer to container, or 0 if this instance + * is not contained. + */ + const container* + _container () const + { + return container_; + } + + /** + * @brief Get a pointer to container, an object model node that + * contains this instance. + * + * @return A pointer to container, or 0 if this instance is not + * contained. + */ + container* + _container () + { + return container_; + } + + /** + * @brief Set this instance's new container, an object model node + * that contains this instance. + * + * @param c A pointer to container. + */ + virtual void + _container (container* c) + { + container* dr (0); + + if (c != 0) + { + dr = c->_root (); + + if (dr == 0) + dr = c; + } + + std::auto_ptr<map>& m (dr ? dr->map_ : map_); + + if (container_ == 0) + { + if (c != 0 && map_.get () != 0) + { + // Transfer our IDs to the new root. + // + if (m.get () != 0) + { + m->insert (map_->begin (), map_->end ()); + std::auto_ptr<map> tmp (0); + map_ = tmp; + } + else + m = map_; + } + } + else + { + container* sr (_root ()); + + if (sr->map_.get () != 0) + { + // Transfer IDs that belong to this subtree. + // + for (map::iterator i (sr->map_->begin ()), e (sr->map_->end ()); + i != e;) + { + type* x (i->second); + for (; x != this && x != sr; x = x->_container ()) ; + + if (x != sr) + { + // Part of our subtree. + // + if (m.get () == 0) + { + std::auto_ptr<map> tmp (new map); + m = tmp; + } + + m->insert (*i); + sr->map_->erase (i++); + } + else + ++i; + } + } + } + + container_ = c; + } + + /** + * @brief Get a constant pointer to object model's root node. + * + * @return A constant pointer to root node, or 0 if this instance + * is not contained. + */ + const container* + _root () const + { + const container* r (container_); + + for (const container* c (r); c != 0; c = c->container_) + r = c; + + return r; + } + + /** + * @brief Get a pointer to object model's root node. + * + * @return A pointer to root node, or 0 if this instance is not + * contained. + */ + container* + _root () + { + container* r (container_); + + for (container* c (r); c != 0; c = c->container_) + r = c; + + return r; + } + + // DOM association. + // + public: + /** + * @brief Get a constant pointer to a DOM node associated with + * this object model node. + * + * @return A constant pointer to DOM node, or 0 if none associated. + */ + const xercesc::DOMNode* + _node () const + { + return dom_info_.get () ? dom_info_->node() : 0; + } + + /** + * @brief Get a pointer to a DOM node associated with this object + * model node. + * + * @return A pointer to DOM node, or 0 if none associated. + */ + xercesc::DOMNode* + _node () + { + return dom_info_.get () ? dom_info_->node () : 0; + } + + /** + * @brief Exception indicating that a DOM node cannot be associated + * with an object model node. + */ + class bad_dom_node_type: public std::exception //@@ Inherit exception. + { + public: + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw () + { + return "DOM node is not an attribute node or element node"; + } + }; + + /** + * @brief Manually set a DOM node associated with this object + * model node. + * + * The DOM node should be a child of the parent's DOM node. If + * this object model node is a root of the tree, then it will + * assume the ownership of the whole DOM document to which this + * DOM node belongs. + * + * @param n A pointer to DOM node (should be either an element or + * an attribute). + */ + void + _node (xercesc::DOMNode* n) + { + switch (n->getNodeType ()) + { + case xercesc::DOMNode::ELEMENT_NODE: + { + if (container_ != 0) + { + // @@ Should be a throw. + // + assert (_root ()->_node () != 0); + assert (_root ()->_node ()->getOwnerDocument () == + n->getOwnerDocument ()); + } + + std::auto_ptr<dom_info> r ( + dom_info_factory::create ( + *static_cast<xercesc::DOMElement*> (n), + *this, + container_ == 0)); + + dom_info_ = r; + break; + } + case xercesc::DOMNode::ATTRIBUTE_NODE: + { + //@@ Should be a throw. + // + assert (container_ != 0); + assert (_root ()->_node () != 0); + assert (_root ()->_node ()->getOwnerDocument () == + n->getOwnerDocument ()); + + std::auto_ptr<dom_info> r ( + dom_info_factory::create ( + *static_cast<xercesc::DOMAttr*> (n), + *this)); + + dom_info_ = r; + break; + } + default: + { + throw bad_dom_node_type (); + } + } + } + + public: + //@cond + + void + _register_id (const identity& id, type* t) + { + // We should be the root. + // + assert (container_ == 0); + + if (map_.get () == 0) + { + std::auto_ptr<map> tmp (new map); + map_ = tmp; + } + + if (!map_->insert ( + std::pair<const identity*, type*> (&id, t)).second) + { + id.throw_duplicate_id (); + } + } + + //@@ Does not inherit from exception. + // + struct not_registered: std::exception + { + virtual const char* + what () const throw () + { + return "attempt to unregister non-existent id"; + } + }; + + void + _unregister_id (const identity& id) + { + // We should be the root. + // + assert (container_ == 0); + + if (map_.get () == 0 || map_->erase (&id) == 0) + throw not_registered (); + } + + type* + _lookup_id (const identity& id) const + { + if (map_.get ()) + { + map::const_iterator it (map_->find (&id)); + + if (it != map_->end ()) + return it->second; + } + + return 0; + } + + //@endcond + + private: + //@cond + + struct dom_info + { + virtual + ~dom_info () + { + } + + dom_info () + { + } + + virtual std::auto_ptr<dom_info> + clone (type& tree_node, container*) const = 0; + + virtual xercesc::DOMNode* + node () = 0; + + private: + dom_info (const dom_info&); + + dom_info& + operator= (const dom_info&); + }; + + + struct dom_element_info: public dom_info + { + dom_element_info (xercesc::DOMElement& e, type& n, bool root) + : doc_ (0), e_ (e) + { + e_.setUserData (user_data_keys::node, &n, 0); + + if (root) + { + // The caller should have associated a dom::auto_ptr object + // that owns this document with the document node using the + // xml_schema::dom::tree_node_key key. + // + xml::dom::auto_ptr<xercesc::DOMDocument>* pd ( + reinterpret_cast<xml::dom::auto_ptr<xercesc::DOMDocument>*> ( + e.getOwnerDocument ()->getUserData (user_data_keys::node))); + + assert (pd != 0); + assert (pd->get () == e.getOwnerDocument ()); + + doc_ = *pd; // Transfer ownership. + } + } + + virtual std::auto_ptr<dom_info> + clone (type& tree_node, container* c) const + { + using std::auto_ptr; + + // Check if we are a document root. + // + if (c == 0) + { + // We preserver DOM associations only in complete + // copies from root. + // + if (doc_.get () == 0) + return auto_ptr<dom_info> (0); + + return auto_ptr<dom_info> ( + new dom_element_info (*doc_, tree_node)); + } + + // Check if our container does not have DOM association (e.g., + // because it wasn't a complete copy of the tree). + // + using xercesc::DOMNode; + + DOMNode* cn (c->_node ()); + + if (cn == 0) + return auto_ptr<dom_info> (0); + + + // Now we are going to find the corresponding element in + // the new tree. + // + { + using xercesc::DOMElement; + + DOMNode& pn (*e_.getParentNode ()); + assert (pn.getNodeType () == DOMNode::ELEMENT_NODE); + + DOMNode* sn (pn.getFirstChild ()); // Source. + DOMNode* dn (cn->getFirstChild ()); // Destination. + + // We should have at least one child. + // + assert (sn != 0); + + // Move in parallel until we get to the needed node. + // + for (; sn != 0 && !e_.isSameNode (sn);) + { + sn = sn->getNextSibling (); + dn = dn->getNextSibling (); + } + + // e_ should be on the list. + // + assert (sn != 0); + + assert (dn->getNodeType () == DOMNode::ELEMENT_NODE); + + return auto_ptr<dom_info> ( + new dom_element_info (static_cast<DOMElement&> (*dn), + tree_node, + false)); + } + } + + virtual xercesc::DOMNode* + node () + { + return &e_; + } + + private: + dom_element_info (const xercesc::DOMDocument& d, type& n) + : doc_ (static_cast<xercesc::DOMDocument*> ( + d.cloneNode (true))), + e_ (*doc_->getDocumentElement ()) + { + e_.setUserData (user_data_keys::node, &n, 0); + } + + private: + xml::dom::auto_ptr<xercesc::DOMDocument> doc_; + xercesc::DOMElement& e_; + }; + + + struct dom_attribute_info: public dom_info + { + dom_attribute_info (xercesc::DOMAttr& a, type& n) + : a_ (a) + { + a_.setUserData (user_data_keys::node, &n, 0); + } + + virtual std::auto_ptr<dom_info> + clone (type& tree_node, container* c) const + { + using std::auto_ptr; + + // Check if we are a document root. + // + if (c == 0) + { + // We preserver DOM associations only in complete + // copies from root. + // + return auto_ptr<dom_info> (0); + } + + // Check if our container does not have DOM association (e.g., + // because it wasn't a complete copy of the tree). + // + using xercesc::DOMNode; + + DOMNode* cn (c->_node ()); + + if (cn == 0) + return auto_ptr<dom_info> (0); + + // We are going to find the corresponding attribute in + // the new tree. + // + using xercesc::DOMAttr; + using xercesc::DOMElement; + using xercesc::DOMNamedNodeMap; + + DOMElement& p (*a_.getOwnerElement ()); + DOMNamedNodeMap& nl (*p.getAttributes ()); + + XMLSize_t size (nl.getLength ()), i (0); + + // We should have at least one child. + // + assert (size != 0); + + for ( ;i < size && !a_.isSameNode (nl.item (i)); ++i)/*noop*/; + + // a_ should be in the list. + // + assert (i < size); + + DOMNode& n (*cn->getAttributes ()->item (i)); + assert (n.getNodeType () == DOMNode::ATTRIBUTE_NODE); + + return auto_ptr<dom_info> ( + new dom_attribute_info (static_cast<DOMAttr&> (n), tree_node)); + } + + virtual xercesc::DOMNode* + node () + { + return &a_; + } + + private: + xercesc::DOMAttr& a_; + }; + + // For Sun C++ 5.6. + // + struct dom_info_factory; + friend struct _type::dom_info_factory; + + struct dom_info_factory + { + static std::auto_ptr<dom_info> + create (const xercesc::DOMElement& e, type& n, bool root) + { + return std::auto_ptr<dom_info> ( + new dom_element_info ( + const_cast<xercesc::DOMElement&> (e), n, root)); + } + + static std::auto_ptr<dom_info> + create (const xercesc::DOMAttr& a, type& n) + { + return std::auto_ptr<dom_info> ( + new dom_attribute_info ( + const_cast<xercesc::DOMAttr&> (a), n)); + } + }; + + //@endcond + + std::auto_ptr<dom_info> dom_info_; + + + // ID/IDREF map. + // + private: + + //@cond + + struct identity_comparator + { + bool operator () (const identity* x, const identity* y) const + { + return x->before (*y); + } + }; + + //@endcond + + typedef + std::map<const identity*, type*, identity_comparator> + map; + + std::auto_ptr<map> map_; + + private: + container* container_; + }; + + inline _type:: + _type (const type& x, flags, container* c) + : container_ (c) + { + if (x.dom_info_.get ()) + { + std::auto_ptr<dom_info> r (x.dom_info_->clone (*this, c)); + dom_info_ = r; + } + } + + + /** + * @brief Class corresponding to the XML Schema anySimpleType built-in + * type. + * + * @nosubgrouping + */ + template <typename B> + class simple_type: public B + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor. + */ + simple_type (); + + /** + * @brief Create an instance from a string. + * + * @param s A string to initialize the instance with. + */ + template <typename C> + simple_type (const C* s); + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + simple_type (const simple_type& x, flags f = 0, container* c = 0); + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual simple_type* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + simple_type (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + simple_type (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + simple_type (const xercesc::DOMAttr& a, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename C> + simple_type (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + }; + + + /** + * @brief Base class for element types. + * + * This class is a base for every generated element type. + * + * @nosubgrouping + */ + template <typename C, typename T> + class element_type + { + public: + virtual + ~element_type () + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual element_type* + _clone (flags f = 0) const = 0; + + /** + * @brief Return the element name. + * + * @return A read-only string reference containing the element + * name. + */ + virtual const std::basic_string<C>& + _name () const = 0; + + /** + * @brief Return the element namespace. + * + * @return A read-only string reference containing the element + * namespace. Empty string is returned if the element is + * unqualified. + */ + virtual const std::basic_string<C>& + _namespace () const = 0; + + /** + * @brief Return the element value. + * + * @return A pointer to the element value or 0 if the element + * is of a fundamental type. + */ + virtual T* + _value () = 0; + + /** + * @brief Return the element value. + * + * @return A read-only pointer to the element value or 0 if the + * element is of a fundamental type. + */ + virtual const T* + _value () const = 0; + }; + + + //@cond + + // Extra schema type id to disambiguate certain cases where + // different XML Schema types (e.g., double and decimal) are + // mapped to the same fundamental C++ type (e.g., double). + // + struct schema_type + { + enum value + { + other, + double_, + decimal + }; + }; + + //@endcond + + + //@cond + template <typename T, + typename C, + schema_type::value ST = schema_type::other> + struct traits + { + typedef T type; + + static std::auto_ptr<T> + create (const xercesc::DOMElement& e, flags f, container* c) + { + return std::auto_ptr<T> (new T (e, f, c)); + } + + static std::auto_ptr<T> + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return std::auto_ptr<T> (new T (a, f, c)); + } + + static std::auto_ptr<T> + create (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + { + return std::auto_ptr<T> (new T (s, e, f, c)); + } + }; + + //@endcond + + + /** + * @brief Class template that emulates inheritance from a + * fundamental C++ type. + * + * @nosubgrouping + */ + template <typename T, + typename C, + typename B, + schema_type::value ST = schema_type::other> + class fundamental_base: public B + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor. + */ + fundamental_base () + : facet_table_ (0), x_ () + { + } + + /** + * @brief Initialize an instance with an underlying type value. + * + * @param x An underlying type value. + */ + fundamental_base (T x) + : facet_table_ (0), x_ (x) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + fundamental_base (const fundamental_base& x, + flags f = 0, + container* c = 0) + : B (x, f, c), facet_table_ (0), x_ (x.x_) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual fundamental_base* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + fundamental_base (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + fundamental_base (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + fundamental_base (const xercesc::DOMAttr& a, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + fundamental_base (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign an underlying type value to the instance. + * + * @param x An underlying type value. + * @return A reference to the instance. + */ + fundamental_base& + operator= (const T& x) + { + if (&x_ != &x) + x_ = x; + + return *this; + } + + public: + /** + * @brief Implicitly convert the instance to constant reference to + * the underlying type. + * + * @return A constant reference to the underlying type. + */ + operator const T& () const + { + return x_; + } + + /** + * @brief Implicitly convert the instance to reference to the + * underlying type. + * + * @return A reference to the underlying type. + */ + operator T& () + { + return x_; + } + + // The following extra conversion operators causes problems on + // some compilers (notably VC 7.1 and 9.0) and are disabled by + // default. + // +#ifdef XSD_TREE_EXTRA_FUND_CONV + /** + * @brief Implicitly convert the instance to another type (const + * version). + * + * @return A value converted to the target type. + */ + template <typename T2> + operator T2 () const + { + return x_; + } + + /** + * @brief Implicitly convert the instance to another type. + * + * @return A value converted to the target type. + */ + template <typename T2> + operator T2 () + { + return x_; + } +#endif // XSD_TREE_EXTRA_FUND_CONV + + public: + /** + * @brief Get the facet table associated with this type. + * + * @return A pointer to read-only facet table or 0. + */ + const facet* + _facet_table () const + { + return facet_table_; + } + + protected: + /** + * @brief Set the facet table associated with this type. + * + * @param ft A pointer to read-only facet table. + */ + void + _facet_table (const facet* ft) + { + facet_table_ = ft; + } + + private: + const facet* facet_table_; + T x_; + }; + + // While thse operators are not normally necessary, they + // help resolve ambiguities between implicit conversion and + // construction. + // + + /** + * @brief %fundamental_base comparison operator. + * + * @return True if the underlying values are equal, false otherwise. + */ + template <typename T, typename C, typename B, schema_type::value ST> + inline bool + operator== (const fundamental_base<T, C, B, ST>& x, + const fundamental_base<T, C, B, ST>& y) + { + T x_ (x); + T y_ (y); + return x_ == y_; + } + + /** + * @brief %fundamental_base comparison operator. + * + * @return True if the underlying values are not equal, false otherwise. + */ + template <typename T, typename C, typename B, schema_type::value ST> + inline bool + operator!= (const fundamental_base<T, C, B, ST>& x, + const fundamental_base<T, C, B, ST>& y) + { + T x_ (x); + T y_ (y); + return x_ != y_; + } + + + //@cond + + // Comparator for enum tables. + // + template <typename C> + struct enum_comparator + { + enum_comparator (const C* const* table) + : table_ (table) + { + } + + bool + operator() (std::size_t i, const std::basic_string<C>& s) const + { + return table_[i] < s; + } + + bool + operator() (const std::basic_string<C>& s, std::size_t i) const + { + return s < table_[i]; + } + + bool + operator() (std::size_t i, std::size_t j) const + { + return std::basic_string<C> (table_[i]) < table_[j]; + } + + private: + const C* const* table_; + }; + + //@endcond + } + } +} + +#include <xsd/cxx/tree/elements.ixx> +#include <xsd/cxx/tree/elements.txx> + +#endif // XSD_CXX_TREE_ELEMENTS_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/elements.ixx b/xsd/libxsd/xsd/cxx/tree/elements.ixx new file mode 100644 index 0000000..e4dd60a --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/elements.ixx @@ -0,0 +1,29 @@ +// file : xsd/cxx/tree/elements.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // simple_type + // + + template <typename B> + inline simple_type<B>:: + simple_type () + { + } + + template <typename B> + template <typename C> + inline simple_type<B>:: + simple_type (const C*) + { + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/elements.txx b/xsd/libxsd/xsd/cxx/tree/elements.txx new file mode 100644 index 0000000..084cb56 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/elements.txx @@ -0,0 +1,57 @@ +// file : xsd/cxx/tree/elements.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xercesc/util/XMLUniDefs.hpp> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // user_data_keys_template + // + template <int dummy> + const XMLCh user_data_keys_template<dummy>::node[21] = + {xercesc::chLatin_x, xercesc::chLatin_s, xercesc::chLatin_d, // xsd + xercesc::chColon, xercesc::chColon, // :: + xercesc::chLatin_c, xercesc::chLatin_x, xercesc::chLatin_x, // cxx + xercesc::chColon, xercesc::chColon, // :: + xercesc::chLatin_t, xercesc::chLatin_r, xercesc::chLatin_e, // tre + xercesc::chLatin_e, xercesc::chColon, xercesc::chColon, // e:: + xercesc::chLatin_n, xercesc::chLatin_o, xercesc::chLatin_d, // nod + xercesc::chLatin_e, xercesc::chNull // e\0 + }; + + + // simple_type + // + template <typename B> + simple_type<B>:: + simple_type (const simple_type& other, + flags f, + container* c) + : B (other, f, c) + { + } + + template <typename B> + simple_type<B>* simple_type<B>:: + _clone (flags f, container* c) const + { + return new simple_type (*this, f, c); + } + + // fundamental_base + // + template <typename T, typename C, typename B, schema_type::value ST> + fundamental_base<T, C, B, ST>* fundamental_base<T, C, B, ST>:: + _clone (flags f, container* c) const + { + return new fundamental_base (*this, f, c); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/error-handler.hxx b/xsd/libxsd/xsd/cxx/tree/error-handler.hxx new file mode 100644 index 0000000..6e4426b --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/error-handler.hxx @@ -0,0 +1,62 @@ +// file : xsd/cxx/tree/error-handler.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ERROR_HANDLER_HXX +#define XSD_CXX_TREE_ERROR_HANDLER_HXX + +#include <xsd/cxx/xml/error-handler.hxx> + +#include <xsd/cxx/tree/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + class error_handler: public xml::error_handler<C> + { + public: + typedef typename xml::error_handler<C>::severity severity; + + error_handler () + : failed_ (false) + { + } + + virtual bool + handle (const std::basic_string<C>& id, + unsigned long line, + unsigned long column, + severity, + const std::basic_string<C>& message); + + template <typename E> + void + throw_if_failed () const + { + if (failed_) + throw E (diagnostics_); + } + + void + reset () + { + failed_ = false; + diagnostics_.clear (); + } + + private: + bool failed_; + diagnostics<C> diagnostics_; + }; + } + } +} + +#include <xsd/cxx/tree/error-handler.txx> + +#endif // XSD_CXX_TREE_ERROR_HANDLER_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/error-handler.txx b/xsd/libxsd/xsd/cxx/tree/error-handler.txx new file mode 100644 index 0000000..c19d354 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/error-handler.txx @@ -0,0 +1,32 @@ +// file : xsd/cxx/tree/error-handler.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + bool error_handler<C>:: + handle (const std::basic_string<C>& id, + unsigned long line, + unsigned long column, + severity s, + const std::basic_string<C>& message) + { + diagnostics_.push_back ( + error<C> (s == severity::warning + ? tree::severity::warning + : tree::severity::error, id, line, column, message)); + + if (!failed_ && s != severity::warning) + failed_ = true; + + return true; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/exceptions.hxx b/xsd/libxsd/xsd/cxx/tree/exceptions.hxx new file mode 100644 index 0000000..f6ddb15 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/exceptions.hxx @@ -0,0 +1,1034 @@ +// file : xsd/cxx/tree/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains exception definitions for the C++/Tree mapping. + * + * This is an internal header and is included by the generated code. + * You normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_EXCEPTIONS_HXX +#define XSD_CXX_TREE_EXCEPTIONS_HXX + +#include <string> +#include <vector> +#include <ostream> + +#include <xsd/cxx/exceptions.hxx> // xsd::cxx::exception + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + /** + * @brief Root of the C++/Tree %exception hierarchy. + * + * You can catch this %exception in order to handle all C++/Tree + * errors. + * + * @nosubgrouping + */ + template <typename C> + class exception: public xsd::cxx::exception + { + public: + /** + * @brief Stream insertion operator for %exception. + */ + friend + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const exception& e) + { + e.print (os); + return os; + } + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const = 0; + + //@endcond + }; + + + /** + * @brief Error %severity. + * + * @nosubgrouping + */ + class severity + { + public: + /** + * @brief Underlying enum type. + */ + enum value + { + /** + * @brief Indicates the warning condition. + */ + warning, + + /** + * @brief Indicates the %error condition. + */ + error + }; + + /** + * @brief Initialize an instance with the underlying enum value. + * + * @param v An underlying enum value. + */ + severity (value v) : v_ (v) {} + + /** + * @brief Implicitly convert the instance to the underlying enum + * value. + * + * @return The underlying enum value. + */ + operator value () const { return v_; } + + private: + value v_; + }; + + /** + * @brief Error condition. + * + * @nosubgrouping + */ + template <typename C> + class error + { + public: + /** + * @brief Initialize an instance with %error description. + * + * @param s An %error %severity. + * @param res_id A resource %id where the %error occurred. + * @param line A line number where the %error occurred. + * @param column A column number where the %error occurred. + * @param message A message describing the %error. + */ + error (tree::severity s, + const std::basic_string<C>& res_id, + unsigned long line, + unsigned long column, + const std::basic_string<C>& message); + + /** + * @brief Get %error %severity. + * + * @return The %severity of this %error. + */ + tree::severity + severity () const + { + return severity_; + } + + /** + * @brief Get resource %id. + * + * @return The %id of the resource where this %error occurred. + */ + const std::basic_string<C>& + id () const + { + return id_; + } + + /** + * @brief Get %error line. + * + * @return The line number where this %error occurred. + */ + unsigned long + line () const + { + return line_; + } + + /** + * @brief Get %error column. + * + * @return The column number where this %error occurred. + */ + unsigned long + column () const + { + return column_; + } + + /** + * @brief Get %error message. + * + * @return The message for this %error. + */ + const std::basic_string<C>& + message () const + { + return message_; + } + + //@cond + + // Default c-tor that shouldn't be. Needed when we completely + // instantiate std::vector in diagnostics below. + // + error (); + + //@endcond + + + private: + tree::severity severity_; + std::basic_string<C> id_; + unsigned long line_; + unsigned long column_; + std::basic_string<C> message_; + }; + + // See exceptions.ixx for operator<< (error). + + + /** + * @brief List of %error conditions. + * + * @nosubgrouping + */ + template <typename C> + class diagnostics: public std::vector<error<C> > + { + }; + + // See exceptions.ixx for operator<< (diagnostics). + + /** + * @brief Exception indicating a %parsing failure. + * + * @nosubgrouping + */ + template <typename C> + class parsing: public exception<C> + { + public: + virtual + ~parsing () throw (); + + /** + * @brief Default constructor. + */ + parsing (); + + /** + * @brief Initialize an instance with a %list of %error conditions. + * + * @param d A %list of %error conditions. + */ + parsing (const tree::diagnostics<C>& d); + + public: + /** + * @brief Get the %list of %error conditions. + * + * @return The %list of %error conditions. + */ + const tree::diagnostics<C>& + diagnostics () const + { + return diagnostics_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + tree::diagnostics<C> diagnostics_; + }; + + + /** + * @brief Exception indicating that an expected element was not + * encountered. + * + * @nosubgrouping + */ + template <typename C> + class expected_element: public exception<C> + { + public: + virtual + ~expected_element () throw (); + + /** + * @brief Initialize an instance with the expected element + * description. + * + * @param name A name of the expected element. + * @param ns A namespace of the expected element. + */ + expected_element (const std::basic_string<C>& name, + const std::basic_string<C>& ns); + + + public: + /** + * @brief Get the name of the expected element. + * + * @return The name of the expected element. + */ + const std::basic_string<C>& + name () const + { + return name_; + } + + /** + * @brief Get the namespace of the expected element. + * + * @return The namespace of the expected element. + */ + const std::basic_string<C>& + namespace_ () const + { + return namespace__; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> name_; + std::basic_string<C> namespace__; + }; + + + /** + * @brief Exception indicating that an unexpected element was + * encountered. + * + * @nosubgrouping + */ + template <typename C> + class unexpected_element: public exception<C> + { + public: + virtual + ~unexpected_element () throw (); + + /** + * @brief Initialize an instance with the encountered and expected + * element descriptions. + * + * @param encountered_name A name of the encountered element. + * @param encountered_ns A namespace of the encountered element. + * @param expected_name A name of the expected element. + * @param expected_ns A namespace of the expected element. + */ + unexpected_element (const std::basic_string<C>& encountered_name, + const std::basic_string<C>& encountered_ns, + const std::basic_string<C>& expected_name, + const std::basic_string<C>& expected_ns); + + public: + /** + * @brief Get the name of the encountered element. + * + * @return The name of the encountered element. + */ + const std::basic_string<C>& + encountered_name () const + { + return encountered_name_; + } + + /** + * @brief Get the namespace of the encountered element. + * + * @return The namespace of the encountered element. + */ + const std::basic_string<C>& + encountered_namespace () const + { + return encountered_namespace_; + } + + /** + * @brief Get the name of the expected element. + * + * @return The name of the expected element. + */ + const std::basic_string<C>& + expected_name () const + { + return expected_name_; + } + + /** + * @brief Get the namespace of the expected element. + * + * @return The namespace of the expected element. + */ + const std::basic_string<C>& + expected_namespace () const + { + return expected_namespace_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> encountered_name_; + std::basic_string<C> encountered_namespace_; + std::basic_string<C> expected_name_; + std::basic_string<C> expected_namespace_; + }; + + + /** + * @brief Exception indicating that an expected attribute was not + * encountered. + * + * @nosubgrouping + */ + template <typename C> + class expected_attribute: public exception<C> + { + public: + virtual + ~expected_attribute () throw (); + + /** + * @brief Initialize an instance with the expected attribute + * description. + * + * @param name A name of the expected attribute. + * @param ns A namespace of the expected attribute. + */ + expected_attribute (const std::basic_string<C>& name, + const std::basic_string<C>& ns); + + public: + /** + * @brief Get the name of the expected attribute. + * + * @return The name of the expected attribute. + */ + const std::basic_string<C>& + name () const + { + return name_; + } + + /** + * @brief Get the namespace of the expected attribute. + * + * @return The namespace of the expected attribute. + */ + const std::basic_string<C>& + namespace_ () const + { + return namespace__; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> name_; + std::basic_string<C> namespace__; + }; + + + /** + * @brief Exception indicating that an unexpected enumerator was + * encountered. + * + * @nosubgrouping + */ + template <typename C> + class unexpected_enumerator: public exception<C> + { + public: + virtual + ~unexpected_enumerator () throw (); + + /** + * @brief Initialize an instance with the encountered enumerator. + * + * @param e A value of the encountered enumerator. + */ + unexpected_enumerator (const std::basic_string<C>& e); + + public: + /** + * @brief Get the value of the encountered enumerator. + * + * @return The value of the encountered enumerator. + */ + const std::basic_string<C>& + enumerator () const + { + return enumerator_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> enumerator_; + }; + + + /** + * @brief Exception indicating that the text content was expected + * for an element. + * + * @nosubgrouping + */ + template <typename C> + class expected_text_content: public exception<C> + { + public: + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + }; + + + /** + * @brief Exception indicating that the type information is not + * available for a type. + * + * @nosubgrouping + */ + template <typename C> + class no_type_info: public exception<C> + { + public: + virtual + ~no_type_info () throw (); + + /** + * @brief Initialize an instance with the type description. + * + * @param type_name A name of the type. + * @param type_ns A namespace of the type. + */ + no_type_info (const std::basic_string<C>& type_name, + const std::basic_string<C>& type_ns); + + public: + /** + * @brief Get the type name. + * + * @return The type name. + */ + const std::basic_string<C>& + type_name () const + { + return type_name_; + } + + /** + * @brief Get the type namespace. + * + * @return The type namespace. + */ + const std::basic_string<C>& + type_namespace () const + { + return type_namespace_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> type_name_; + std::basic_string<C> type_namespace_; + }; + + /** + * @brief Exception indicating that %parsing or %serialization + * information is not available for an element. + * + * @nosubgrouping + */ + template <typename C> + class no_element_info: public exception<C> + { + public: + virtual + ~no_element_info () throw (); + + /** + * @brief Initialize an instance with the element description. + * + * @param element_name An element name. + * @param element_ns An element namespace. + */ + no_element_info (const std::basic_string<C>& element_name, + const std::basic_string<C>& element_ns); + + public: + /** + * @brief Get the element name. + * + * @return The element name. + */ + const std::basic_string<C>& + element_name () const + { + return element_name_; + } + + /** + * @brief Get the element namespace. + * + * @return The element namespace. + */ + const std::basic_string<C>& + element_namespace () const + { + return element_namespace_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> element_name_; + std::basic_string<C> element_namespace_; + }; + + /** + * @brief Exception indicating that the types are not related by + * inheritance. + * + * @nosubgrouping + */ + template <typename C> + class not_derived: public exception<C> + { + public: + virtual + ~not_derived () throw (); + + //@cond + + // @@ tmp + // + not_derived () + { + } + + //@endcond + + /** + * @brief Initialize an instance with the type descriptions. + * + * @param base_type_name A name of the base type. + * @param base_type_ns A namespace of the base type. + * @param derived_type_name A name of the derived type. + * @param derived_type_ns A namespace of the derived type. + */ + not_derived (const std::basic_string<C>& base_type_name, + const std::basic_string<C>& base_type_ns, + const std::basic_string<C>& derived_type_name, + const std::basic_string<C>& derived_type_ns); + + public: + /** + * @brief Get the base type name. + * + * @return The base type name. + */ + const std::basic_string<C>& + base_type_name () const + { + return base_type_name_; + } + + /** + * @brief Get the base type namespace. + * + * @return The base type namespace. + */ + const std::basic_string<C>& + base_type_namespace () const + { + return base_type_namespace_; + } + + /** + * @brief Get the derived type name. + * + * @return The derived type name. + */ + const std::basic_string<C>& + derived_type_name () const + { + return derived_type_name_; + } + + /** + * @brief Get the derived type namespace. + * + * @return The derived type namespace. + */ + const std::basic_string<C>& + derived_type_namespace () const + { + return derived_type_namespace_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> base_type_name_; + std::basic_string<C> base_type_namespace_; + std::basic_string<C> derived_type_name_; + std::basic_string<C> derived_type_namespace_; + }; + + + /** + * @brief Exception indicating that a duplicate ID value was + * encountered in the object model. + * + * @nosubgrouping + */ + template <typename C> + class duplicate_id: public exception<C> + { + public: + virtual + ~duplicate_id () throw (); + + /** + * @brief Initialize an instance with the offending ID value. + * + * @param id An offending ID value. + */ + duplicate_id (const std::basic_string<C>& id); + + public: + /** + * @brief Get the offending ID value. + * + * @return The offending ID value. + */ + const std::basic_string<C>& + id () const + { + return id_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> id_; + }; + + + /** + * @brief Exception indicating a %serialization failure. + * + * @nosubgrouping + */ + template <typename C> + class serialization: public exception<C> + { + public: + virtual + ~serialization () throw (); + + /** + * @brief Default constructor. + */ + serialization (); + + /** + * @brief Initialize an instance with a %list of %error conditions. + * + * @param d A %list of %error conditions. + */ + serialization (const tree::diagnostics<C>& d); + + public: + /** + * @brief Get the %list of %error conditions. + * + * @return The %list of %error conditions. + */ + const tree::diagnostics<C>& + diagnostics () const + { + return diagnostics_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + tree::diagnostics<C> diagnostics_; + }; + + + /** + * @brief Exception indicating that a prefix-namespace mapping was + * not provided. + * + * @nosubgrouping + */ + template <typename C> + class no_prefix_mapping: public exception<C> + { + public: + virtual + ~no_prefix_mapping () throw (); + + /** + * @brief Initialize an instance with the prefix for which the + * prefix-namespace mapping was not provided. + * + * @param prefix A prefix. + */ + no_prefix_mapping (const std::basic_string<C>& prefix); + + public: + /** + * @brief Get the prefix for which the prefix-namespace mapping was + * not provided. + * + * @return The prefix. + */ + const std::basic_string<C>& + prefix () const + { + return prefix_; + } + + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + + private: + std::basic_string<C> prefix_; + }; + + + /** + * @brief Exception indicating that the size argument exceeds + * the capacity argument. + * + * See the buffer class for details. + * + * @nosubgrouping + */ + template <typename C> + class bounds: public exception<C> + { + public: + /** + * @brief Get %exception description. + * + * @return A C %string describing the %exception. + */ + virtual const char* + what () const throw (); + + protected: + //@cond + + virtual void + print (std::basic_ostream<C>&) const; + + //@endcond + }; + } + } +} + +#include <xsd/cxx/tree/exceptions.txx> + +#endif // XSD_CXX_TREE_EXCEPTIONS_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/exceptions.txx b/xsd/libxsd/xsd/cxx/tree/exceptions.txx new file mode 100644 index 0000000..8262fce --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/exceptions.txx @@ -0,0 +1,510 @@ +// file : xsd/cxx/tree/exceptions.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // error + // + template <typename C> + error<C>:: + error (tree::severity s, + const std::basic_string<C>& id, + unsigned long line, + unsigned long column, + const std::basic_string<C>& message) + : severity_ (s), + id_ (id), + line_ (line), + column_ (column), + message_ (message) + { + } + + template <typename C> + error<C>:: + error () + : severity_ (tree::severity::error), line_ (0), column_ (0) + { + } + + template <typename C> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const error<C>& e) + { + return os << e.id () << C (':') << e.line () << C (':') << e.column () + << (e.severity () == severity::error + ? bits::ex_error_error<C> () + : bits::ex_error_warning<C> ()) << e.message (); + } + + // diagnostics + // + template <typename C> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const diagnostics<C>& d) + { + for (typename diagnostics<C>::const_iterator b (d.begin ()), i (b); + i != d.end (); + ++i) + { + if (i != b) + os << C ('\n'); + + os << *i; + } + + return os; + } + + // parsing + // + template <typename C> + parsing<C>:: + ~parsing () throw () + { + } + + template <typename C> + parsing<C>:: + parsing () + { + } + + template <typename C> + parsing<C>:: + parsing (const tree::diagnostics<C>& diagnostics) + : diagnostics_ (diagnostics) + { + } + + template <typename C> + const char* parsing<C>:: + what () const throw () + { + return "instance document parsing failed"; + } + + template <typename C> + void parsing<C>:: + print (std::basic_ostream<C>& os) const + { + if (diagnostics_.empty ()) + os << bits::ex_parsing_msg<C> (); + else + os << diagnostics_; + } + + // expected_element + // + template <typename C> + expected_element<C>:: + ~expected_element () throw () + { + } + + template <typename C> + expected_element<C>:: + expected_element (const std::basic_string<C>& name, + const std::basic_string<C>& namespace_) + : name_ (name), namespace__ (namespace_) + { + } + + template <typename C> + const char* expected_element<C>:: + what () const throw () + { + return "expected element not encountered"; + } + + template <typename C> + void expected_element<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_eel_expected<C> (); + + if (!namespace_ ().empty ()) + os << namespace_ () << C ('#'); + + os << name () << C ('\''); + } + + // unexpected_element + // + template <typename C> + unexpected_element<C>:: + ~unexpected_element () throw () + { + } + + template <typename C> + unexpected_element<C>:: + unexpected_element (const std::basic_string<C>& encountered_name, + const std::basic_string<C>& encountered_namespace, + const std::basic_string<C>& expected_name, + const std::basic_string<C>& expected_namespace) + : encountered_name_ (encountered_name), + encountered_namespace_ (encountered_namespace), + expected_name_ (expected_name), + expected_namespace_ (expected_namespace) + { + } + + template <typename C> + const char* unexpected_element<C>:: + what () const throw () + { + return "unexpected element encountered"; + } + + template <typename C> + void unexpected_element<C>:: + print (std::basic_ostream<C>& os) const + { + if (!expected_name ().empty ()) + { + os << bits::ex_uel_expected<C> (); + + if (!expected_namespace ().empty ()) + os << expected_namespace () << C ('#'); + + os << expected_name () << bits::ex_uel_instead<C> (); + + if (!encountered_namespace ().empty ()) + os << encountered_namespace () << C ('#'); + + os << encountered_name () << C ('\''); + } + else + { + os << bits::ex_uel_unexpected<C> (); + + if (!encountered_namespace ().empty ()) + os << encountered_namespace () << C ('#'); + + os << encountered_name () << C ('\''); + } + } + + // expected_attribute + // + template <typename C> + expected_attribute<C>:: + ~expected_attribute () throw () + { + } + + template <typename C> + expected_attribute<C>:: + expected_attribute (const std::basic_string<C>& name, + const std::basic_string<C>& namespace_) + : name_ (name), namespace__ (namespace_) + { + } + + template <typename C> + const char* expected_attribute<C>:: + what () const throw () + { + return "expected attribute not encountered"; + } + + template <typename C> + void expected_attribute<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_eat_expected<C> (); + + if (!namespace_ ().empty ()) + os << namespace_ () << C ('#'); + + os << name () << C ('\''); + } + + // unexpected_enumerator + // + template <typename C> + unexpected_enumerator<C>:: + ~unexpected_enumerator () throw () + { + } + + template <typename C> + unexpected_enumerator<C>:: + unexpected_enumerator (const std::basic_string<C>& enumerator) + : enumerator_ (enumerator) + { + } + + template <typename C> + const char* unexpected_enumerator<C>:: + what () const throw () + { + return "unexpected enumerator encountered"; + } + + template <typename C> + void unexpected_enumerator<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_uen_unexpected<C> () << enumerator () << C ('\''); + } + + // expected_text_content + // + template <typename C> + const char* expected_text_content<C>:: + what () const throw () + { + return "expected text content"; + } + + template <typename C> + void expected_text_content<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_etc_msg<C> (); + } + + // no_type_info + // + template <typename C> + no_type_info<C>:: + ~no_type_info () throw () + { + } + + template <typename C> + no_type_info<C>:: + no_type_info (const std::basic_string<C>& type_name, + const std::basic_string<C>& type_namespace) + : type_name_ (type_name), + type_namespace_ (type_namespace) + { + } + + template <typename C> + const char* no_type_info<C>:: + what () const throw () + { + return "no type information available for a type"; + } + + template <typename C> + void no_type_info<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_nti_no_type_info<C> (); + + if (!type_namespace ().empty ()) + os << type_namespace () << C ('#'); + + os << type_name () << C ('\''); + } + + // no_element_info + // + template <typename C> + no_element_info<C>:: + ~no_element_info () throw () + { + } + + template <typename C> + no_element_info<C>:: + no_element_info (const std::basic_string<C>& element_name, + const std::basic_string<C>& element_namespace) + : element_name_ (element_name), + element_namespace_ (element_namespace) + { + } + + template <typename C> + const char* no_element_info<C>:: + what () const throw () + { + return "no parsing or serialization information available for " + "an element"; + } + + template <typename C> + void no_element_info<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_nei_no_element_info<C> (); + + if (!element_namespace ().empty ()) + os << element_namespace () << C ('#'); + + os << element_name () << C ('\''); + } + + // not_derived + // + template <typename C> + not_derived<C>:: + ~not_derived () throw () + { + } + + template <typename C> + not_derived<C>:: + not_derived (const std::basic_string<C>& base_type_name, + const std::basic_string<C>& base_type_namespace, + const std::basic_string<C>& derived_type_name, + const std::basic_string<C>& derived_type_namespace) + : base_type_name_ (base_type_name), + base_type_namespace_ (base_type_namespace), + derived_type_name_ (derived_type_name), + derived_type_namespace_ (derived_type_namespace) + { + } + + template <typename C> + const char* not_derived<C>:: + what () const throw () + { + return "type is not derived"; + } + + template <typename C> + void not_derived<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_nd_type<C> (); + + if (!derived_type_namespace ().empty ()) + os << derived_type_namespace () << C ('#'); + + os << derived_type_name () << bits::ex_nd_not_derived<C> (); + + if (!base_type_namespace ().empty ()) + os << base_type_namespace () << C ('#'); + + os << base_type_name () << C ('\''); + } + + // duplicate_id + // + template <typename C> + duplicate_id<C>:: + ~duplicate_id () throw () + { + } + + template <typename C> + duplicate_id<C>:: + duplicate_id (const std::basic_string<C>& id) + : id_ (id) + { + } + + template <typename C> + const char* duplicate_id<C>:: + what () const throw () + { + return "ID already exist"; + } + + template <typename C> + void duplicate_id<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_di_id<C> () << id () << bits::ex_di_already_exist<C> (); + } + + // serialization + // + template <typename C> + serialization<C>:: + ~serialization () throw () + { + } + + template <typename C> + serialization<C>:: + serialization () + { + } + + template <typename C> + serialization<C>:: + serialization (const tree::diagnostics<C>& diagnostics) + : diagnostics_ (diagnostics) + { + } + + template <typename C> + const char* serialization<C>:: + what () const throw () + { + return "serialization failed"; + } + + template <typename C> + void serialization<C>:: + print (std::basic_ostream<C>& os) const + { + if (diagnostics_.empty ()) + os << bits::ex_serialization_msg<C> (); + else + os << diagnostics_; + } + + + // no_prefix_mapping + // + template <typename C> + no_prefix_mapping<C>:: + ~no_prefix_mapping () throw () + { + } + + template <typename C> + no_prefix_mapping<C>:: + no_prefix_mapping (const std::basic_string<C>& prefix) + : prefix_ (prefix) + { + } + + template <typename C> + const char* no_prefix_mapping<C>:: + what () const throw () + { + return "no mapping provided for a namespace prefix"; + } + + template <typename C> + void no_prefix_mapping<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_npm_no_mapping<C> () << prefix () << C ('\''); + } + + + // bounds + // + template <typename C> + const char* bounds<C>:: + what () const throw () + { + return "buffer boundary rules have been violated"; + } + + template <typename C> + void bounds<C>:: + print (std::basic_ostream<C>& os) const + { + os << bits::ex_bounds_msg<C> (); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/facet.hxx b/xsd/libxsd/xsd/cxx/tree/facet.hxx new file mode 100644 index 0000000..c4fbcbe --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/facet.hxx @@ -0,0 +1,43 @@ +// file : xsd/cxx/tree/facet.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_FACET_HXX +#define XSD_CXX_TREE_FACET_HXX + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // We need to keep this type POD in order to be able to create a + // static array. + // + struct facet + { + enum id_type + { + none, + total_digits, + fraction_digits + }; + + id_type id; + unsigned long value; + + static const facet* + find (const facet* facets, facet::id_type id) + { + while (facets->id != id && facets->id != none) + ++facets; + + return facets->id != none ? facets : 0; + } + }; + } + } +} + +#endif // XSD_CXX_TREE_FACET_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/istream-fwd.hxx b/xsd/libxsd/xsd/cxx/tree/istream-fwd.hxx new file mode 100644 index 0000000..a523952 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/istream-fwd.hxx @@ -0,0 +1,21 @@ +// file : xsd/cxx/tree/istream-fwd.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ISTREAM_FWD_HXX +#define XSD_CXX_TREE_ISTREAM_FWD_HXX + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template<typename S> + class istream; + } + } +} + +#endif // XSD_CXX_TREE_ISTREAM_FWD_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/istream.hxx b/xsd/libxsd/xsd/cxx/tree/istream.hxx new file mode 100644 index 0000000..2f8f8cb --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/istream.hxx @@ -0,0 +1,258 @@ +// file : xsd/cxx/tree/istream.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ISTREAM_HXX +#define XSD_CXX_TREE_ISTREAM_HXX + +#include <cstddef> // std::size_t + +#include <xsd/cxx/tree/istream-fwd.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + class istream_common + { + public: + template <typename T> + struct as_size + { + explicit as_size (T& x) : x_ (x) {} + T& x_; + }; + + + // 8-bit + // + template <typename T> + struct as_int8 + { + explicit as_int8 (T& x) : x_ (x) {} + T& x_; + }; + + template <typename T> + struct as_uint8 + { + explicit as_uint8 (T& x) : x_ (x) {} + T& x_; + }; + + + // 16-bit + // + template <typename T> + struct as_int16 + { + explicit as_int16 (T& x) : x_ (x) {} + T& x_; + }; + + template <typename T> + struct as_uint16 + { + explicit as_uint16 (T& x) : x_ (x) {} + T& x_; + }; + + + // 32-bit + // + template <typename T> + struct as_int32 + { + explicit as_int32 (T& x) : x_ (x) {} + T& x_; + }; + + template <typename T> + struct as_uint32 + { + explicit as_uint32 (T& x) : x_ (x) {} + T& x_; + }; + + + // 64-bit + // + template <typename T> + struct as_int64 + { + explicit as_int64 (T& x) : x_ (x) {} + T& x_; + }; + + template <typename T> + struct as_uint64 + { + explicit as_uint64 (T& x) : x_ (x) {} + T& x_; + }; + + + // Boolean + // + template <typename T> + struct as_bool + { + explicit as_bool (T& x) : x_ (x) {} + T& x_; + }; + + + // Floating-point + // + template <typename T> + struct as_float32 + { + explicit as_float32 (T& x) : x_ (x) {} + T& x_; + }; + + template <typename T> + struct as_float64 + { + explicit as_float64 (T& x) : x_ (x) {} + T& x_; + }; + }; + + template<typename S> + class istream: public istream_common + { + public: + explicit + istream (S& s) + : s_ (s) + { + } + + S& + impl () + { + return s_; + } + + private: + istream (const istream&); + istream& + operator= (const istream&); + + private: + S& s_; + }; + + + // 8-bit + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, signed char& x) + { + istream_common::as_int8<signed char> as_int8 (x); + return s >> as_int8; + } + + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, unsigned char& x) + { + istream_common::as_uint8<unsigned char> as_uint8 (x); + return s >> as_uint8; + } + + + // 16-bit + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, short& x) + { + istream_common::as_int16<short> as_int16 (x); + return s >> as_int16; + } + + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, unsigned short& x) + { + istream_common::as_uint16<unsigned short> as_uint16 (x); + return s >> as_uint16; + } + + + // 32-bit + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, int& x) + { + istream_common::as_int32<int> as_int32 (x); + return s >> as_int32; + } + + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, unsigned int& x) + { + istream_common::as_uint32<unsigned int> as_uint32 (x); + return s >> as_uint32; + } + + + // 64-bit + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, long long& x) + { + istream_common::as_int64<long long> as_int64 (x); + return s >> as_int64; + } + + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, unsigned long long& x) + { + istream_common::as_uint64<unsigned long long> as_uint64 (x); + return s >> as_uint64; + } + + // Boolean + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, bool& x) + { + istream_common::as_bool<bool> as_bool (x); + return s >> as_bool; + } + + + // Floating-point + // + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, float& x) + { + istream_common::as_float32<float> as_float32 (x); + return s >> as_float32; + } + + template <typename S> + inline istream<S>& + operator>> (istream<S>& s, double& x) + { + istream_common::as_float64<double> as_float64 (x); + return s >> as_float64; + } + } + } +} + +#endif // XSD_CXX_TREE_ISTREAM_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/list.hxx b/xsd/libxsd/xsd/cxx/tree/list.hxx new file mode 100644 index 0000000..30636e9 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/list.hxx @@ -0,0 +1,134 @@ +// file : xsd/cxx/tree/list.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_LIST_HXX +#define XSD_CXX_TREE_LIST_HXX + +#include <string> + +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/tree/elements.hxx> // tree::istream +#include <xsd/cxx/tree/istream-fwd.hxx> // tree::istream +#include <xsd/cxx/tree/containers.hxx> // fundamental_p, sequence + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Class template for xsd:list mapping. Based on the sequence + // template. Note that I cannot get rid of 'fund' because HP + // aCC3 likes it this way. + // + template <typename T, + typename C, + schema_type::value ST = schema_type::other, + bool fund = fundamental_p<T>::r> + class list; + + + // + // + template <typename T, typename C, schema_type::value ST> + class list<T, C, ST, false>: public sequence<T> + { + public: + explicit + list (flags f = 0, container* c = 0) + : sequence<T> (f, c) + { + } + + list (typename sequence<T>::size_type n, + const T& x, + container* c = 0) + : sequence<T> (n, x, c) + { + } + + template<typename I> + list (const I& b, const I& e, container* c = 0) + : sequence<T> (b, e, c) + { + } + + template <typename S> + list (istream<S>&, flags = 0, container* c = 0); + + list (const list<T, C, ST, false>& v, flags f = 0, container* c = 0) + : sequence<T> (v, f, c) + { + } + + public: + list (const xercesc::DOMElement&, flags = 0, container* c = 0); + + list (const xercesc::DOMAttr&, flags = 0, container* c = 0); + + list (const std::basic_string<C>&, + const xercesc::DOMElement*, + flags = 0, + container* c = 0); + + private: + void + init (const std::basic_string<C>&, const xercesc::DOMElement*); + }; + + + // + // + template <typename T, typename C, schema_type::value ST> + class list<T, C, ST, true>: public sequence<T> + { + public: + explicit + list (flags f = 0, container* c = 0) + : sequence<T> (f, c) + { + } + + explicit + list (typename sequence<T>::size_type n, const T& x, container* c = 0) + : sequence<T> (n, x, c) + { + } + + template<typename I> + list (const I& b, const I& e, container* c = 0) + : sequence<T> (b, e, c) + { + } + + template <typename S> + list (istream<S>&, flags = 0, container* c = 0); + + list (const list<T, C, ST, true>& s, flags f = 0, container* c = 0) + : sequence<T> (s, f, c) + { + } + + public: + list (const xercesc::DOMElement&, flags = 0, container* c = 0); + + list (const xercesc::DOMAttr&, flags = 0, container* c = 0); + + list (const std::basic_string<C>&, + const xercesc::DOMElement*, + flags = 0, + container* c = 0); + + private: + void + init (const std::basic_string<C>&, const xercesc::DOMElement*); + }; + } + } +} + +#endif // XSD_CXX_TREE_LIST_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/ostream.hxx b/xsd/libxsd/xsd/cxx/tree/ostream.hxx new file mode 100644 index 0000000..cf2d9ee --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/ostream.hxx @@ -0,0 +1,245 @@ +// file : xsd/cxx/tree/ostream.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_OSTREAM_HXX +#define XSD_CXX_TREE_OSTREAM_HXX + +#include <cstddef> // std::size_t + +namespace xsd +{ + namespace cxx + { + namespace tree + { + class ostream_common + { + public: + template <typename T> + struct as_size + { + explicit as_size (T x) : x_ (x) {} + T x_; + }; + + + // 8-bit + // + template <typename T> + struct as_int8 + { + explicit as_int8 (T x) : x_ (x) {} + T x_; + }; + + template <typename T> + struct as_uint8 + { + explicit as_uint8 (T x) : x_ (x) {} + T x_; + }; + + + // 16-bit + // + template <typename T> + struct as_int16 + { + explicit as_int16 (T x) : x_ (x) {} + T x_; + }; + + template <typename T> + struct as_uint16 + { + explicit as_uint16 (T x) : x_ (x) {} + T x_; + }; + + + // 32-bit + // + template <typename T> + struct as_int32 + { + explicit as_int32 (T x) : x_ (x) {} + T x_; + }; + + template <typename T> + struct as_uint32 + { + explicit as_uint32 (T x) : x_ (x) {} + T x_; + }; + + + // 64-bit + // + template <typename T> + struct as_int64 + { + explicit as_int64 (T x) : x_ (x) {} + T x_; + }; + + template <typename T> + struct as_uint64 + { + explicit as_uint64 (T x) : x_ (x) {} + T x_; + }; + + + // Boolean + // + template <typename T> + struct as_bool + { + explicit as_bool (T x) : x_ (x) {} + T x_; + }; + + + // Floating-point + // + template <typename T> + struct as_float32 + { + explicit as_float32 (T x) : x_ (x) {} + T x_; + }; + + template <typename T> + struct as_float64 + { + explicit as_float64 (T x) : x_ (x) {} + T x_; + }; + }; + + template<typename S> + class ostream: public ostream_common + { + public: + explicit + ostream (S& s) + : s_ (s) + { + } + + S& + impl () + { + return s_; + } + + private: + ostream (const ostream&); + ostream& + operator= (const ostream&); + + private: + S& s_; + }; + + + // 8-bit + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, signed char x) + { + return s << ostream_common::as_int8<signed char> (x); + } + + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, unsigned char x) + { + return s << ostream_common::as_uint8<unsigned char> (x); + } + + + // 16-bit + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, short x) + { + return s << ostream_common::as_int16<short> (x); + } + + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, unsigned short x) + { + return s << ostream_common::as_uint16<unsigned short> (x); + } + + + // 32-bit + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, int x) + { + return s << ostream_common::as_int32<int> (x); + } + + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, unsigned int x) + { + return s << ostream_common::as_uint32<unsigned int> (x); + } + + + // 64-bit + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, long long x) + { + return s << ostream_common::as_int64<long long> (x); + } + + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, unsigned long long x) + { + return s << ostream_common::as_uint64<unsigned long long> (x); + } + + // Boolean + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, bool x) + { + return s << ostream_common::as_bool<bool> (x); + } + + + // Floating-point + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, float x) + { + return s << ostream_common::as_float32<float> (x); + } + + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, double x) + { + return s << ostream_common::as_float64<double> (x); + } + } + } +} + +#endif // XSD_CXX_TREE_OSTREAM_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing.hxx b/xsd/libxsd/xsd/cxx/tree/parsing.hxx new file mode 100644 index 0000000..84b3898 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing.hxx @@ -0,0 +1,12 @@ +// file : xsd/cxx/tree/parsing.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_HXX +#define XSD_CXX_TREE_PARSING_HXX + +#include <xsd/cxx/tree/parsing.txx> +#include <xsd/cxx/tree/parsing/date-time.txx> + +#endif // XSD_CXX_TREE_PARSING_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing.txx b/xsd/libxsd/xsd/cxx/tree/parsing.txx new file mode 100644 index 0000000..db50775 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing.txx @@ -0,0 +1,914 @@ +// file : xsd/cxx/tree/parsing.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string> + +#include <xsd/cxx/ro-string.hxx> // trim + +#include <xsd/cxx/xml/string.hxx> // xml::{string, transcode} +#include <xsd/cxx/xml/elements.hxx> // xml::{prefix, uq_name} +#include <xsd/cxx/xml/bits/literals.hxx> // xml::bits::{xml_prefix, + // xml_namespace} + +#include <xsd/cxx/tree/exceptions.hxx> // no_prefix_mapping +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/list.hxx> +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Note that most of the types implemented here (except string, + // (normalizedString, and base64Binary) cannot have whitespaces + // in the value. As result we don't need to waste time collapsing + // whitespaces. All we need to do is trim the string representation + // which can be done without copying. + // + + // type + // + inline _type:: + _type (const xercesc::DOMElement& e, flags f, container* c) + : dom_info_ (0), container_ (c) + { + if (f & flags::keep_dom) + { + std::auto_ptr<dom_info> r ( + dom_info_factory::create (e, *this, c == 0)); + dom_info_ = r; + } + } + + inline _type:: + _type (const xercesc::DOMAttr& a, flags f, container* c) + : dom_info_ (0), container_ (c) + { + if (f & flags::keep_dom) + { + std::auto_ptr<dom_info> r (dom_info_factory::create (a, *this)); + dom_info_ = r; + } + } + + template <typename C> + inline _type:: + _type (const std::basic_string<C>&, + const xercesc::DOMElement*, + flags, + container* c) + : dom_info_ (0), // List elements don't have associated DOM nodes. + container_ (c) + { + } + + // simple_type + // + template <typename B> + inline simple_type<B>:: + simple_type (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + } + + template <typename B> + inline simple_type<B>:: + simple_type (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + } + + template <typename B> + template <typename C> + inline simple_type<B>:: + simple_type (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + } + + // fundamental_base + // + template <typename T, typename C, typename B, schema_type::value ST> + fundamental_base<T, C, B, ST>:: + fundamental_base (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), + facet_table_ (0), + x_ (traits<T, C, ST>::create (e, f, c)) + { + } + + template <typename T, typename C, typename B, schema_type::value ST> + fundamental_base<T, C, B, ST>:: + fundamental_base (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), + facet_table_ (0), + x_ (traits<T, C, ST>::create (a, f, c)) + { + } + + template <typename T, typename C, typename B, schema_type::value ST> + fundamental_base<T, C, B, ST>:: + fundamental_base (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), + facet_table_ (0), + x_ (traits<T, C, ST>::create (s, e, f, c)) + { + } + + + // Parsing c-tors for list. + // + + namespace bits + { + // Find first non-space character. + // + template <typename C> + typename std::basic_string<C>::size_type + find_ns (const C* s, + typename std::basic_string<C>::size_type size, + typename std::basic_string<C>::size_type pos) + { + while (pos < size && + (s[pos] == C (0x20) || // space + s[pos] == C (0x0D) || // carriage return + s[pos] == C (0x09) || // tab + s[pos] == C (0x0A))) + ++pos; + + return pos < size ? pos : std::basic_string<C>::npos; + } + + // Find first space character. + // + template <typename C> + typename std::basic_string<C>::size_type + find_s (const C* s, + typename std::basic_string<C>::size_type size, + typename std::basic_string<C>::size_type pos) + { + while (pos < size && + s[pos] != C (0x20) && // space + s[pos] != C (0x0D) && // carriage return + s[pos] != C (0x09) && // tab + s[pos] != C (0x0A)) + ++pos; + + return pos < size ? pos : std::basic_string<C>::npos; + } + } + + // Individual items of the list have no DOM association. Therefore + // I clear keep_dom from flags. + // + + template <typename T, typename C, schema_type::value ST> + list<T, C, ST, false>:: + list (const xercesc::DOMElement& e, flags f, container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (text_content<C> (e), &e); + } + + template <typename T, typename C, schema_type::value ST> + list<T, C, ST, false>:: + list (const xercesc::DOMAttr& a, flags f, container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); + } + + template <typename T, typename C, schema_type::value ST> + list<T, C, ST, false>:: + list (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (s, e); + } + + template <typename T, typename C, schema_type::value ST> + void list<T, C, ST, false>:: + init (const std::basic_string<C>& s, const xercesc::DOMElement* parent) + { + if (s.size () == 0) + return; + + using std::basic_string; + typedef typename sequence<T>::ptr ptr; + typedef typename basic_string<C>::size_type size_type; + + const C* data (s.c_str ()); + size_type size (s.size ()); + + // Traverse the data while logically collapsing spaces. + // + for (size_type i (bits::find_ns<C> (data, size, 0)); + i != basic_string<C>::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != basic_string<C>::npos) + { + ptr r ( + new T (basic_string<C> (data + i, j - i), + parent, + this->flags_, + this->container_)); + + this->v_.push_back (r); + + i = bits::find_ns (data, size, j); + } + else + { + // Last element. + // + ptr r ( + new T (basic_string<C> (data + i, size - i), + parent, + this->flags_, + this->container_)); + + this->v_.push_back (r); + + break; + } + } + } + + template <typename T, typename C, schema_type::value ST> + list<T, C, ST, true>:: + list (const xercesc::DOMElement& e, flags f, container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (text_content<C> (e), &e); + } + + template <typename T, typename C, schema_type::value ST> + inline list<T, C, ST, true>:: + list (const xercesc::DOMAttr& a, flags f, container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); + } + + template <typename T, typename C, schema_type::value ST> + inline list<T, C, ST, true>:: + list (const std::basic_string<C>& s, + const xercesc::DOMElement* parent, + flags f, + container* c) + : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + { + init (s, parent); + } + + template <typename T, typename C, schema_type::value ST> + inline void list<T, C, ST, true>:: + init (const std::basic_string<C>& s, const xercesc::DOMElement* parent) + { + if (s.size () == 0) + return; + + using std::basic_string; + typedef typename basic_string<C>::size_type size_type; + + const C* data (s.c_str ()); + size_type size (s.size ()); + + // Traverse the data while logically collapsing spaces. + // + for (size_type i (bits::find_ns<C> (data, size, 0)); + i != basic_string<C>::npos;) + { + size_type j (bits::find_s (data, size, i)); + + if (j != basic_string<C>::npos) + { + this->push_back ( + traits<T, C, ST>::create ( + basic_string<C> (data + i, j - i), parent, 0, 0)); + + i = bits::find_ns (data, size, j); + } + else + { + // Last element. + // + this->push_back ( + traits<T, C, ST>::create ( + basic_string<C> (data + i, size - i), parent, 0, 0)); + + break; + } + } + } + + + // Parsing c-tors for built-in types. + // + + + // string + // + template <typename C, typename B> + string<C, B>:: + string (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), + base_type (text_content<C> (e)) + { + } + + template <typename C, typename B> + string<C, B>:: + string (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), + base_type (xml::transcode<C> (a.getValue ())) + { + } + + template <typename C, typename B> + string<C, B>:: + string (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), base_type (s) + { + } + + + // normalized_string + // + template <typename C, typename B> + normalized_string<C, B>:: + normalized_string (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + normalize (); + } + + template <typename C, typename B> + normalized_string<C, B>:: + normalized_string (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + normalize (); + } + + template <typename C, typename B> + normalized_string<C, B>:: + normalized_string (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + normalize (); + } + + template <typename C, typename B> + void normalized_string<C, B>:: + normalize () + { + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (this->size ()); + + for (size_type i (0); i < size; ++i) + { + C& c ((*this)[i]); + + if (c == C (0x0D) || // carriage return + c == C (0x09) || // tab + c == C (0x0A)) + c = C (0x20); + } + } + + + // token + // + template <typename C, typename B> + token<C, B>:: + token (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + collapse (); + } + + template <typename C, typename B> + token<C, B>:: + token (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + collapse (); + } + + template <typename C, typename B> + token<C, B>:: + token (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + collapse (); + } + + template <typename C, typename B> + void token<C, B>:: + collapse () + { + // We have all whitespace normilized by our base. We just + // need to collapse them. + // + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (this->size ()), j (0); + bool subs (false), trim (true); + + for (size_type i (0); i < size; ++i) + { + C c ((*this)[i]); + + if (c == C (0x20)) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + + if (!trim) + (*this)[j++] = C (0x20); + } + + if (trim) + trim = false; + + (*this)[j++] = c; + } + } + + this->resize (j); + } + + + // nmtoken + // + template <typename C, typename B> + nmtoken<C, B>:: + nmtoken (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + } + + template <typename C, typename B> + nmtoken<C, B>:: + nmtoken (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + } + + template <typename C, typename B> + nmtoken<C, B>:: + nmtoken (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + } + + + // nmtokens + // + template <typename C, typename B, typename nmtoken> + nmtokens<C, B, nmtoken>:: + nmtokens (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), base_type (e, f, this) + { + } + + template <typename C, typename B, typename nmtoken> + nmtokens<C, B, nmtoken>:: + nmtokens (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), base_type (a, f, this) + { + } + + template <typename C, typename B, typename nmtoken> + nmtokens<C, B, nmtoken>:: + nmtokens (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), base_type (s, e, f, this) + { + } + + + // name + // + template <typename C, typename B> + name<C, B>:: + name (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + } + + template <typename C, typename B> + name<C, B>:: + name (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + } + + template <typename C, typename B> + name<C, B>:: + name (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + } + + + // ncname + // + template <typename C, typename B> + ncname<C, B>:: + ncname (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + } + + template <typename C, typename B> + ncname<C, B>:: + ncname (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + } + + template <typename C, typename B> + ncname<C, B>:: + ncname (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + } + + + // language + // + template <typename C, typename B> + language<C, B>:: + language (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + } + + template <typename C, typename B> + language<C, B>:: + language (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + } + + template <typename C, typename B> + language<C, B>:: + language (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + } + + + // id + // + template <typename C, typename B> + id<C, B>:: + id (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c), identity_ (*this) + { + register_id (); + } + + template <typename C, typename B> + id<C, B>:: + id (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c), identity_ (*this) + { + register_id (); + } + + template <typename C, typename B> + id<C, B>:: + id (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c), identity_ (*this) + { + register_id (); + } + + + // idref + // + template <typename C, typename B, typename T> + idref<C, B, T>:: + idref (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c), identity_ (*this) + { + } + + template <typename C, typename B, typename T> + idref<C, B, T>:: + idref (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f , c), identity_ (*this) + { + } + + template <typename C, typename B, typename T> + idref<C, B, T>:: + idref (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c), identity_ (*this) + { + } + + + // idrefs + // + template <typename C, typename B, typename idref> + idrefs<C, B, idref>:: + idrefs (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), base_type (e, f, this) + { + } + + template <typename C, typename B, typename idref> + idrefs<C, B, idref>:: + idrefs (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), base_type (a, f, this) + { + } + + template <typename C, typename B, typename idref> + idrefs<C, B, idref>:: + idrefs (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), base_type (s, e, f, this) + { + } + + + // uri + // + template <typename C, typename B> + uri<C, B>:: + uri (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), + base_type (trim (text_content<C> (e))) + { + } + + template <typename C, typename B> + uri<C, B>:: + uri (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), + base_type (trim (xml::transcode<C> (a.getValue ()))) + { + } + + template <typename C, typename B> + uri<C, B>:: + uri (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), base_type (trim (s)) + { + } + + + // qname + // + template <typename C, typename B, typename uri, typename ncname> + qname<C, B, uri, ncname>:: + qname (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + std::basic_string<C> v (trim (text_content<C> (e))); + ns_ = resolve (v, &e); + name_ = xml::uq_name (v); + } + + template <typename C, typename B, typename uri, typename ncname> + qname<C, B, uri, ncname>:: + qname (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + std::basic_string<C> v (trim (xml::transcode<C> (a.getValue ()))); + ns_ = resolve (v, a.getOwnerElement ()); + name_ = xml::uq_name (v); + } + + template <typename C, typename B, typename uri, typename ncname> + qname<C, B, uri, ncname>:: + qname (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + std::basic_string<C> v (trim (s)); + ns_ = resolve (v, e); + name_ = xml::uq_name (v); + } + + template <typename C, typename B, typename uri, typename ncname> + uri qname<C, B, uri, ncname>:: + resolve (const std::basic_string<C>& s, const xercesc::DOMElement* e) + { + std::basic_string<C> p (xml::prefix (s)); + + if (e) + { + // This code is copied verbatim from xml/dom/elements.hxx. + // + + // 'xml' prefix requires special handling and Xerces folks refuse + // to handle this in DOM so I have to do it myself. + // + if (p == xml::bits::xml_prefix<C> ()) + return xml::bits::xml_namespace<C> (); + + const XMLCh* xns ( + e->lookupNamespaceURI ( + p.empty () ? 0 : xml::string (p).c_str ())); + + if (xns != 0) + return xml::transcode<C> (xns); + else if (p.empty ()) + return std::basic_string<C> (); + } + + throw no_prefix_mapping<C> (p); + } + + + // base64_binary + // + // We are not doing whitespace collapsing since the decode + // functions can handle it like this. + // + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + // This implementation is not optimal. + // + std::basic_string<C> str (trim (text_content<C> (e))); + decode (xml::string (str).c_str ()); + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + std::basic_string<C> str (trim (xml::transcode<C> (a.getValue ()))); + decode (xml::string (str).c_str ()); + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + std::basic_string<C> str (trim (s)); + decode (xml::string (str).c_str ()); + } + + + // hex_binary + // + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + // This implementation is not optimal. + // + std::basic_string<C> str (trim (text_content<C> (e))); + decode (xml::string (str).c_str ()); + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + std::basic_string<C> str (trim (xml::transcode<C> (a.getValue ()))); + decode (xml::string (str).c_str ()); + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + std::basic_string<C> str (trim (s)); + decode (xml::string (str).c_str ()); + } + + // entity + // + template <typename C, typename B> + entity<C, B>:: + entity (const xercesc::DOMElement& e, flags f, container* c) + : base_type (e, f, c) + { + } + + template <typename C, typename B> + entity<C, B>:: + entity (const xercesc::DOMAttr& a, flags f, container* c) + : base_type (a, f, c) + { + } + + template <typename C, typename B> + entity<C, B>:: + entity (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : base_type (s, e, f, c) + { + } + + + // entities + // + template <typename C, typename B, typename entity> + entities<C, B, entity>:: + entities (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c), base_type (e, f, this) + { + } + + template <typename C, typename B, typename entity> + entities<C, B, entity>:: + entities (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c), base_type (a, f, this) + { + } + + template <typename C, typename B, typename entity> + entities<C, B, entity>:: + entities (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c), base_type (s, e, f, this) + { + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx new file mode 100644 index 0000000..3dafdaa --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx @@ -0,0 +1,76 @@ +// file : xsd/cxx/tree/parsing/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_BOOLEAN_HXX +#define XSD_CXX_TREE_PARSING_BOOLEAN_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<bool, C, schema_type::other> + { + typedef bool type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + bool traits<bool, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + bool traits<bool, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + bool traits<bool, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + return tmp == bits::true_<C> () || tmp == bits::one<C> (); + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_BOOLEAN_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx new file mode 100644 index 0000000..0a127c9 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_BYTE_HXX +#define XSD_CXX_TREE_PARSING_BYTE_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<signed char, C, schema_type::other> + { + typedef signed char type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + signed char traits<signed char, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + signed char traits<signed char, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + signed char traits<signed char, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + short t; + is >> t; + + return static_cast<type> (t); + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_BYTE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx b/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx new file mode 100644 index 0000000..913786c --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx @@ -0,0 +1,702 @@ +// file : xsd/cxx/tree/parsing/date-time.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + template <typename C> + void time_zone:: + zone_parse (const C* s, std::size_t n) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return; + } + else if (s[0] == C ('Z')) + { + hours_ = 0; + minutes_ = 0; + present_ = true; + } + else if (n == 6) + { + // Parse hours. + // + hours_ = 10 * (s[1] - C ('0')) + (s[2] - C ('0')); + + // Parse minutes. + // + minutes_ = 10 * (s[4] - C ('0')) + (s[5] - C ('0')); + + if (s[0] == C ('-')) + { + hours_ = -hours_; + minutes_ = -minutes_; + } + present_ = true; + } + } + + // gday + // + template <typename C, typename B> + gday<C, B>:: + gday (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + gday<C, B>:: + gday (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + gday<C, B>:: + gday (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void gday<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (n >= 5) + { + day_ = 10 * (s[3] - C ('0')) + (s[4] - C ('0')); + + if (n > 5) + zone_parse (s + 5, n - 5); + } + } + + // gmonth + // + template <typename C, typename B> + gmonth<C, B>:: + gmonth (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + gmonth<C, B>:: + gmonth (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + gmonth<C, B>:: + gmonth (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void gmonth<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (n >= 4) + { + month_ = 10 * (s[2] - C ('0')) + (s[3] - C ('0')); + + if (n > 4) + zone_parse (s + 4, n - 4); + } + } + + // gyear + // + template <typename C, typename B> + gyear<C, B>:: + gyear (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + gyear<C, B>:: + gyear (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + gyear<C, B>:: + gyear (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void gyear<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + if (n >= 4) + { + // Find the end of the year token. + // + size_type pos (4); + for (; pos < n; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string<C> year_fragment (s, pos); + zc_istream<C> is (year_fragment); + is >> year_; + + if (pos < n) + zone_parse (s + pos, n - pos); + } + } + + // gmonth_day + // + template <typename C, typename B> + gmonth_day<C, B>:: + gmonth_day (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + gmonth_day<C, B>:: + gmonth_day (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + gmonth_day<C, B>:: + gmonth_day (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void gmonth_day<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (n >= 7) + { + month_ = 10 * (s[2] - C ('0')) + (s[3] - C ('0')); + day_ = 10 * (s[5] - C ('0')) + (s[6] - C ('0')); + + if (n > 7) + zone_parse (s + 7, n - 7); + } + } + + // gyear_month + // + template <typename C, typename B> + gyear_month<C, B>:: + gyear_month (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + gyear_month<C, B>:: + gyear_month (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + gyear_month<C, B>:: + gyear_month (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void gyear_month<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (n >= 7) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string<C>::npos && (n - pos - 1) >= 2) + { + ro_string<C> year_fragment (s, pos); + zc_istream<C> is (year_fragment); + is >> year_; + + month_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + + pos += 3; + + if (pos < n) + zone_parse (s + pos, n - pos); + } + } + } + + // date + // + template <typename C, typename B> + date<C, B>:: + date (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + date<C, B>:: + date (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + date<C, B>:: + date (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void date<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (n >= 10) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string<C>::npos && (n - pos - 1) >= 5) + { + ro_string<C> year_fragment (s, pos); + zc_istream<C> is (year_fragment); + is >> year_; + + month_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + day_ = 10 * (s[pos + 4] - C ('0')) + (s[pos + 5] - C ('0')); + + pos += 6; + + if (pos < n) + zone_parse (s + pos, n - pos); + } + } + } + + // time + // + template <typename C, typename B> + time<C, B>:: + time (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + time<C, B>:: + time (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + time<C, B>:: + time (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void time<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n >= 8) + { + hours_ = 10 * (s[0] - '0') + (s[1] - '0'); + minutes_ = 10 * (s[3] - '0') + (s[4] - '0'); + + // Find the end of the seconds fragment. + // + size_type pos (8); + for (; pos < n; ++pos) + { + C c (s[pos]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string<C> seconds_fragment (s + 6, pos - 6); + zc_istream<C> is (seconds_fragment); + is >> seconds_; + + if (pos < n) + zone_parse (s + pos, n - pos); + } + } + + // date_time + // + template <typename C, typename B> + date_time<C, B>:: + date_time (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + date_time<C, B>:: + date_time (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + date_time<C, B>:: + date_time (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + template <typename C, typename B> + void date_time<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n >= 19) + { + // Find the end of the year token. + // + size_type pos (tmp.find (C ('-'), 4)); + + if (pos != ro_string<C>::npos && (n - pos - 1) >= 14) + { + ro_string<C> year_fragment (s, pos); + zc_istream<C> yis (year_fragment); + yis >> year_; + + month_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + pos += 3; + + day_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + pos += 3; + + hours_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + pos += 3; + + minutes_ = 10 * (s[pos + 1] - C ('0')) + (s[pos + 2] - C ('0')); + pos += 4; // Point to the first S. + + // Find the end of the seconds fragment. + // + size_type sec_end (pos + 2); + for (; sec_end < n; ++sec_end) + { + C c (s[sec_end]); + + if (c == C ('Z') || c == C ('+') || c == C ('-')) + break; + } + + ro_string<C> seconds_fragment (s + pos, sec_end - pos); + zc_istream<C> sis (seconds_fragment); + sis >> seconds_; + + if (sec_end < n) + zone_parse (s + sec_end, n - sec_end); + } + } + } + + // duration + // + template <typename C, typename B> + duration<C, B>:: + duration (const xercesc::DOMElement& e, flags f, container* c) + : B (e, f, c) + { + parse (text_content<C> (e)); + } + + template <typename C, typename B> + duration<C, B>:: + duration (const xercesc::DOMAttr& a, flags f, container* c) + : B (a, f, c) + { + parse (xml::transcode<C> (a.getValue ())); + } + + template <typename C, typename B> + duration<C, B>:: + duration (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + : B (s, e, f, c) + { + parse (s); + } + + namespace bits + { + template <typename C> + inline typename ro_string<C>::size_type + duration_delim (const C* s, + typename ro_string<C>::size_type pos, + typename ro_string<C>::size_type size) + { + const C* p (s + pos); + for (; p < (s + size); ++p) + { + if (*p == C ('Y') || *p == C ('D') || *p == C ('M') || + *p == C ('H') || *p == C ('M') || *p == C ('S') || + *p == C ('T')) + break; + } + + return p - s; + } + } + + template <typename C, typename B> + void duration<C, B>:: + parse (const std::basic_string<C>& str) + { + typedef typename ro_string<C>::size_type size_type; + + ro_string<C> tmp (str); + size_type n (trim (tmp)); + const C* s (tmp.data ()); + + // Set all the fields since some of them may not be specified. + // + years_ = months_ = days_ = hours_ = minutes_ = 0; + seconds_ = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + if (n >= 3) + { + size_type pos (0); + + if (s[0] == C ('-')) + { + negative_ = true; + pos++; + } + else + negative_ = false; + + pos++; // Skip 'P'. + + size_type del (bits::duration_delim (s, pos, n)); + + if (del != n && s[del] == C ('Y')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> years_; + + pos = del + 1; + del = bits::duration_delim (s, pos, n); + } + + if (del != n && s[del] == C ('M')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> months_; + + pos = del + 1; + del = bits::duration_delim (s, pos, n); + } + + if (del != n && s[del] == C ('D')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> days_; + + pos = del + 1; + del = bits::duration_delim (s, pos, n); + } + + if (del != n && s[del] == C ('T')) + { + pos = del + 1; + del = bits::duration_delim (s, pos, n); + + if (del != n && s[del] == C ('H')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> hours_; + + pos = del + 1; + del = bits::duration_delim (s, pos, n); + } + + if (del != n && s[del] == C ('M')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> minutes_; + + pos = del + 1; + del = bits::duration_delim (s, pos, n); + } + + if (del != n && s[del] == C ('S')) + { + ro_string<C> fragment (s + pos, del - pos); + zc_istream<C> is (fragment); + is >> seconds_; + } + } + } + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx new file mode 100644 index 0000000..636c0f5 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx @@ -0,0 +1,85 @@ +// file : xsd/cxx/tree/parsing/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_DECIMAL_HXX +#define XSD_CXX_TREE_PARSING_DECIMAL_HXX + +#include <limits> +#include <locale> + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<double, C, schema_type::decimal> + { + typedef double type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::decimal>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + is.imbue (std::locale::classic ()); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_DECIMAL_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx new file mode 100644 index 0000000..1507ccf --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx @@ -0,0 +1,94 @@ +// file : xsd/cxx/tree/parsing/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_DOUBLE_HXX +#define XSD_CXX_TREE_PARSING_DOUBLE_HXX + +#include <limits> +#include <locale> + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<double, C, schema_type::double_> + { + typedef double type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + double traits<double, C, schema_type::double_>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::double_>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + double traits<double, C, schema_type::double_>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + if (tmp == bits::positive_inf<C> ()) + return std::numeric_limits<double>::infinity (); + + if (tmp == bits::negative_inf<C> ()) + return -std::numeric_limits<double>::infinity (); + + if (tmp == bits::nan<C> ()) + return std::numeric_limits<double>::quiet_NaN (); + + zc_istream<C> is (tmp); + is.imbue (std::locale::classic ()); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_DOUBLE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx b/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx new file mode 100644 index 0000000..bb9a4c6 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx @@ -0,0 +1,42 @@ +// file : xsd/cxx/tree/parsing/element-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_ELEMENT_MAP_TXX +#define XSD_CXX_TREE_PARSING_ELEMENT_MAP_TXX + +#include <xsd/cxx/xml/dom/elements.hxx> + +#include <xsd/cxx/tree/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C, typename T> + std::auto_ptr<element_type<C, T> > element_map<C, T>:: + parse (const xercesc::DOMElement& e, flags f) + { + const qualified_name n (xml::dom::name<C> (e)); + typename map::const_iterator i (map_->find (n)); + + if (i != map_->end () && i->second.parser_ != 0) + return (i->second.parser_) (e, f); + else + throw no_element_info<C> (n.name (), n.namespace_ ()); + } + + template<typename T, typename C, typename B> + std::auto_ptr<element_type<C, B> > + parser_impl (const xercesc::DOMElement& e, flags f) + { + return std::auto_ptr<element_type<C, B> > (new T (e, f)); + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_ELEMENT_MAP_TXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx new file mode 100644 index 0000000..3e34f93 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx @@ -0,0 +1,94 @@ +// file : xsd/cxx/tree/parsing/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_FLOAT_HXX +#define XSD_CXX_TREE_PARSING_FLOAT_HXX + +#include <limits> +#include <locale> + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<float, C, schema_type::other> + { + typedef float type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + float traits<float, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + float traits<float, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + float traits<float, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + if (tmp == bits::positive_inf<C> ()) + return std::numeric_limits<float>::infinity (); + + if (tmp == bits::negative_inf<C> ()) + return -std::numeric_limits<float>::infinity (); + + if (tmp == bits::nan<C> ()) + return std::numeric_limits<float>::quiet_NaN (); + + zc_istream<C> is (tmp); + is.imbue (std::locale::classic ()); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_FLOAT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx new file mode 100644 index 0000000..d996d3a --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_INT_HXX +#define XSD_CXX_TREE_PARSING_INT_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<int, C, schema_type::other> + { + typedef int type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + int traits<int, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + int traits<int, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + int traits<int, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_INT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx new file mode 100644 index 0000000..742ade1 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_LONG_HXX +#define XSD_CXX_TREE_PARSING_LONG_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<long long, C, schema_type::other> + { + typedef long long type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + long long traits<long long, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + long long traits<long long, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + long long traits<long long, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_LONG_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx new file mode 100644 index 0000000..3a7ead8 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_SHORT_HXX +#define XSD_CXX_TREE_PARSING_SHORT_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<short, C, schema_type::other> + { + typedef short type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + short traits<short, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + short traits<short, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + short traits<short, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_SHORT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx new file mode 100644 index 0000000..ce336be --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_UNSIGNED_BYTE_HXX +#define XSD_CXX_TREE_PARSING_UNSIGNED_BYTE_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<unsigned char, C, schema_type::other> + { + typedef unsigned char type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + unsigned char traits<unsigned char, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + unsigned char traits<unsigned char, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + unsigned char traits<unsigned char, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + unsigned short t; + is >> t; + + return static_cast<type> (t); + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_UNSIGNED_BYTE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx new file mode 100644 index 0000000..e908dd0 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_UNSIGNED_INT_HXX +#define XSD_CXX_TREE_PARSING_UNSIGNED_INT_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<unsigned int, C, schema_type::other> + { + typedef unsigned int type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + unsigned int traits<unsigned int, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + unsigned int traits<unsigned int, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + unsigned int traits<unsigned int, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_UNSIGNED_INT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx new file mode 100644 index 0000000..647b8dd --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_UNSIGNED_LONG_HXX +#define XSD_CXX_TREE_PARSING_UNSIGNED_LONG_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<unsigned long long, C, schema_type::other> + { + typedef unsigned long long type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + unsigned long long traits<unsigned long long, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + unsigned long long traits<unsigned long long, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + unsigned long long traits<unsigned long long, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_UNSIGNED_LONG_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx new file mode 100644 index 0000000..f53c724 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx @@ -0,0 +1,80 @@ +// file : xsd/cxx/tree/parsing/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_PARSING_UNSIGNED_SHORT_HXX +#define XSD_CXX_TREE_PARSING_UNSIGNED_SHORT_HXX + +#include <xsd/cxx/ro-string.hxx> +#include <xsd/cxx/zc-istream.hxx> + +#include <xsd/cxx/xml/string.hxx> // xml::transcode + +#include <xsd/cxx/tree/text.hxx> // text_content + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct traits<unsigned short, C, schema_type::other> + { + typedef unsigned short type; + + static type + create (const xercesc::DOMElement& e, flags f, container* c); + + static type + create (const xercesc::DOMAttr& a, flags f, container* c); + + static type + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*); + }; + + template <typename C> + unsigned short traits<unsigned short, C, schema_type::other>:: + create (const xercesc::DOMElement& e, flags f, container* c) + { + return create (text_content<C> (e), 0, f, c); + } + + template <typename C> + unsigned short traits<unsigned short, C, schema_type::other>:: + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return create (xml::transcode<C> (a.getValue ()), 0, f, c); + } + + template <typename C> + unsigned short traits<unsigned short, C, schema_type::other>:: + create (const std::basic_string<C>& s, + const xercesc::DOMElement*, + flags, + container*) + { + // This type cannot have whitespaces in its values. As result we + // don't need to waste time collapsing whitespaces. All we need to + // do is trim the string representation which can be done without + // copying. + // + ro_string<C> tmp (s); + trim (tmp); + + zc_istream<C> is (tmp); + + type t; + is >> t; + + return t; + } + } + } +} + +#endif // XSD_CXX_TREE_PARSING_UNSIGNED_SHORT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization.hxx b/xsd/libxsd/xsd/cxx/tree/serialization.hxx new file mode 100644 index 0000000..612185f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization.hxx @@ -0,0 +1,66 @@ +// file : xsd/cxx/tree/serialization.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_HXX +#define XSD_CXX_TREE_SERIALIZATION_HXX + +#include <sstream> + +#include <xercesc/dom/DOMElement.hpp> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // + // + template <typename C> + class list_stream + { + public: + list_stream (std::basic_ostringstream<C>& os, + xercesc::DOMElement& parent) + : os_ (os), parent_ (parent) + { + } + + std::basic_ostringstream<C>& os_; + xercesc::DOMElement& parent_; + }; + + template <typename T> + class as_double + { + public: + as_double (const T& v) + : x (v) + { + } + + const T& x; + }; + + template <typename T> + class as_decimal + { + public: + as_decimal (const T& v, const facet* f = 0) + : x (v), facets (f) + { + } + + const T& x; + const facet* facets; + }; + } + } +} + +#include <xsd/cxx/tree/serialization.txx> +#include <xsd/cxx/tree/serialization/date-time.txx> + +#endif // XSD_CXX_TREE_SERIALIZATION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization.txx b/xsd/libxsd/xsd/cxx/tree/serialization.txx new file mode 100644 index 0000000..29364f4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization.txx @@ -0,0 +1,764 @@ +// file : xsd/cxx/tree/serialization.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string> +#include <sstream> + +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/xml/string.hxx> // xml::{string, transcode} +#include <xsd/cxx/xml/dom/serialization-header.hxx> // dom::{prefix, clear} + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/list.hxx> + +// The only way to make the following serialization operators +// for fundamental types work is to defined them in the xercesc +// namespace so that they can be found by ADL. Placing them into +// the global namespace does not work. +// + +namespace XERCES_CPP_NAMESPACE +{ + // Serialization of std::basic_string and C string. Used in other + // serializers. Also used to serialize enumerators. + // + template <typename C> + void + operator<< (xercesc::DOMElement& e, const C* s) + { + xsd::cxx::xml::dom::clear<char> (e); + + if (*s != C (0)) + e.setTextContent (xsd::cxx::xml::string (s).c_str ()); + } + + template <typename C> + void + operator<< (xercesc::DOMAttr& a, const C* s) + { + a.setValue (xsd::cxx::xml::string (s).c_str ()); + } + + // We duplicate the code above instead of delegating in order to + // allow the xml::string type to take advantage of cached string + // sizes. + // + template <typename C> + void + operator<< (xercesc::DOMElement& e, const std::basic_string<C>& s) + { + xsd::cxx::xml::dom::clear<char> (e); + + if (!s.empty ()) + e.setTextContent (xsd::cxx::xml::string (s).c_str ()); + } + + template <typename C> + void + operator<< (xercesc::DOMAttr& a, const std::basic_string<C>& s) + { + a.setValue (xsd::cxx::xml::string (s).c_str ()); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // List serialization operators for std::basic_string and C string. + // + + template <typename C> + void + operator<< (list_stream<C>& ls, const C* s) + { + ls.os_ << s; + } + + template <typename C> + void + operator<< (list_stream<C>& ls, const std::basic_string<C>& s) + { + ls.os_ << s; + } + + // Insertion operators for type. + // + inline void + operator<< (xercesc::DOMElement& e, const type&) + { + xml::dom::clear<char> (e); + } + + inline void + operator<< (xercesc::DOMAttr&, const type&) + { + } + + template <typename C> + inline void + operator<< (list_stream<C>&, const type&) + { + } + + // Insertion operators for simple_type. + // + template <typename B> + inline void + operator<< (xercesc::DOMElement& e, const simple_type<B>&) + { + xml::dom::clear<char> (e); + } + + template <typename B> + inline void + operator<< (xercesc::DOMAttr&, const simple_type<B>&) + { + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>&, const simple_type<B>&) + { + } + + // Insertion operators for list. + // + template <typename C, typename T, schema_type::value ST, bool fund> + void + operator<< (xercesc::DOMElement& e, const list<T, C, ST, fund>& v) + { + std::basic_ostringstream<C> os; + list_stream<C> ls (os, e); + + ls << v; + + e << os.str (); + } + + template <typename C, typename T, schema_type::value ST, bool fund> + void + operator<< (xercesc::DOMAttr& a, const list<T, C, ST, fund>& v) + { + std::basic_ostringstream<C> os; + list_stream<C> ls (os, *a.getOwnerElement ()); + + ls << v; + + a << os.str (); + } + + template <typename C, typename T, schema_type::value ST, bool fund> + void + operator<< (list_stream<C>& ls, const list<T, C, ST, fund>& v) + { + for (typename list<T, C, ST, fund>::const_iterator + b (v.begin ()), e (v.end ()), i (b); i != e; ++i) + { + if (i != b) + ls.os_ << C (' '); + + ls << *i; + } + } + + // Specializations for double and decimal. + // + template <typename C, typename T, bool fund> + void + operator<< (list_stream<C>& ls, + const list<T, C, schema_type::double_, fund>& v) + { + for (typename list<T, C, schema_type::double_, fund>::const_iterator + b (v.begin ()), e (v.end ()), i (b); i != e; ++i) + { + if (i != b) + ls.os_ << C (' '); + + ls << as_double<T> (*i); + } + } + + template <typename C, typename T, bool fund> + void + operator<< (list_stream<C>& ls, + const list<T, C, schema_type::decimal, fund>& v) + { + for (typename list<T, C, schema_type::decimal, fund>::const_iterator + b (v.begin ()), e (v.end ()), i (b); i != e; ++i) + { + if (i != b) + ls.os_ << C (' '); + + ls << as_decimal<T> (*i); + } + } + + + // Insertion operators for fundamental_base. + // + template <typename T, typename C, typename B, schema_type::value ST> + void + operator<< (xercesc::DOMElement& e, + const fundamental_base<T, C, B, ST>& x) + { + const T& r (x); + e << r; + } + + template <typename T, typename C, typename B, schema_type::value ST> + void + operator<< (xercesc::DOMAttr& a, const fundamental_base<T, C, B, ST>& x) + { + const T& r (x); + a << r; + } + + template <typename T, typename C, typename B, schema_type::value ST> + void + operator<< (list_stream<C>& ls, const fundamental_base<T, C, B, ST>& x) + { + const T& r (x); + ls << r; + } + + // Specializations for double. + // + template <typename T, typename C, typename B> + void + operator<< ( + xercesc::DOMElement& e, + const fundamental_base<T, C, B, schema_type::double_>& x) + { + e << as_double<T> (x); + } + + template <typename T, typename C, typename B> + void + operator<< ( + xercesc::DOMAttr& a, + const fundamental_base<T, C, B, schema_type::double_>& x) + { + a << as_double<T> (x); + } + + template <typename T, typename C, typename B> + void + operator<< ( + list_stream<C>& ls, + const fundamental_base<T, C, B, schema_type::double_>& x) + { + ls << as_double<T> (x); + } + + // Specializations for decimal. + // + template <typename T, typename C, typename B> + void + operator<< ( + xercesc::DOMElement& e, + const fundamental_base<T, C, B, schema_type::decimal>& x) + { + e << as_decimal<T> (x, x._facet_table ()); + } + + template <typename T, typename C, typename B> + void + operator<< ( + xercesc::DOMAttr& a, + const fundamental_base<T, C, B, schema_type::decimal>& x) + { + a << as_decimal<T> (x, x._facet_table ()); + } + + template <typename T, typename C, typename B> + void + operator<< ( + list_stream<C>& ls, + const fundamental_base<T, C, B, schema_type::decimal>& x) + { + ls << as_decimal<T> (x, x._facet_table ()); + } + + // Insertion operators for built-in types. + // + + namespace bits + { + template <typename C, typename T> + void + insert (xercesc::DOMElement& e, const T& x) + { + std::basic_ostringstream<C> os; + os << x; + e << os.str (); + } + + template <typename C, typename T> + void + insert (xercesc::DOMAttr& a, const T& x) + { + std::basic_ostringstream<C> os; + os << x; + a << os.str (); + } + } + + + // string + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const string<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const string<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const string<C, B>& x) + { + ls.os_ << x; + } + + + // normalized_string + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const normalized_string<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const normalized_string<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const normalized_string<C, B>& x) + { + ls.os_ << x; + } + + + // token + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const token<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const token<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const token<C, B>& x) + { + ls.os_ << x; + } + + + // nmtoken + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const nmtoken<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const nmtoken<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const nmtoken<C, B>& x) + { + ls.os_ << x; + } + + + // nmtokens + // + template <typename C, typename B, typename nmtoken> + inline void + operator<< (xercesc::DOMElement& e, const nmtokens<C, B, nmtoken>& v) + { + const list<nmtoken, C>& r (v); + e << r; + } + + template <typename C, typename B, typename nmtoken> + inline void + operator<< (xercesc::DOMAttr& a, const nmtokens<C, B, nmtoken>& v) + { + const list<nmtoken, C>& r (v); + a << r; + } + + template <typename C, typename B, typename nmtoken> + inline void + operator<< (list_stream<C>& ls, const nmtokens<C, B, nmtoken>& v) + { + const list<nmtoken, C>& r (v); + ls << r; + } + + + // name + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const name<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const name<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const name<C, B>& x) + { + ls.os_ << x; + } + + + // ncname + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const ncname<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const ncname<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const ncname<C, B>& x) + { + ls.os_ << x; + } + + + // language + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const language<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const language<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const language<C, B>& x) + { + ls.os_ << x; + } + + + // id + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const id<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const id<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const id<C, B>& x) + { + ls.os_ << x; + } + + + // idref + // + template <typename C, typename B, typename T> + inline void + operator<< (xercesc::DOMElement& e, const idref<C, B, T>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B, typename T> + inline void + operator<< (xercesc::DOMAttr& a, const idref<C, B, T>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B, typename T> + inline void + operator<< (list_stream<C>& ls, const idref<C, B, T>& x) + { + ls.os_ << x; + } + + + // idrefs + // + template <typename C, typename B, typename idref> + inline void + operator<< (xercesc::DOMElement& e, const idrefs<C, B, idref>& v) + { + const list<idref, C>& r (v); + e << r; + } + + template <typename C, typename B, typename idref> + inline void + operator<< (xercesc::DOMAttr& a, const idrefs<C, B, idref>& v) + { + const list<idref, C>& r (v); + a << r; + } + + template <typename C, typename B, typename idref> + inline void + operator<< (list_stream<C>& ls, const idrefs<C, B, idref>& v) + { + const list<idref, C>& r (v); + ls << r; + } + + + // uri + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const uri<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const uri<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const uri<C, B>& x) + { + ls.os_ << x; + } + + + // qname + // + template <typename C, typename B, typename uri, typename ncname> + void + operator<< (xercesc::DOMElement& e, const qname<C, B, uri, ncname>& x) + { + std::basic_ostringstream<C> os; + + if (x.qualified ()) + { + std::basic_string<C> p (xml::dom::prefix (x.namespace_ (), e)); + + if (!p.empty ()) + os << p << C (':'); + } + + os << x.name (); + e << os.str (); + } + + template <typename C, typename B, typename uri, typename ncname> + void + operator<< (xercesc::DOMAttr& a, const qname<C, B, uri, ncname>& x) + { + std::basic_ostringstream<C> os; + + if (x.qualified ()) + { + std::basic_string<C> p ( + xml::dom::prefix (x.namespace_ (), *a.getOwnerElement ())); + + if (!p.empty ()) + os << p << C (':'); + } + + os << x.name (); + a << os.str (); + } + + template <typename C, typename B, typename uri, typename ncname> + void + operator<< (list_stream<C>& ls, const qname<C, B, uri, ncname>& x) + { + if (x.qualified ()) + { + std::basic_string<C> p ( + xml::dom::prefix (x.namespace_ (), ls.parent_)); + + if (!p.empty ()) + ls.os_ << p << C (':'); + } + + ls.os_ << x.name (); + } + + + // base64_binary + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const base64_binary<C, B>& x) + { + e << x.encode (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const base64_binary<C, B>& x) + { + a << x.encode (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const base64_binary<C, B>& x) + { + ls.os_ << x.encode (); + } + + + // hex_binary + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const hex_binary<C, B>& x) + { + e << x.encode (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const hex_binary<C, B>& x) + { + a << x.encode (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const hex_binary<C, B>& x) + { + ls.os_ << x.encode (); + } + + + // entity + // + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const entity<C, B>& x) + { + bits::insert<C> (e, x); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const entity<C, B>& x) + { + bits::insert<C> (a, x); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const entity<C, B>& x) + { + ls.os_ << x; + } + + + // entities + // + template <typename C, typename B, typename entity> + inline void + operator<< (xercesc::DOMElement& e, const entities<C, B, entity>& v) + { + const list<entity, C>& r (v); + e << r; + } + + template <typename C, typename B, typename entity> + inline void + operator<< (xercesc::DOMAttr& a, const entities<C, B, entity>& v) + { + const list<entity, C>& r (v); + a << r; + } + + template <typename C, typename B, typename entity> + inline void + operator<< (list_stream<C>& ls, const entities<C, B, entity>& v) + { + const list<entity, C>& r (v); + ls << r; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx new file mode 100644 index 0000000..ce34560 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx @@ -0,0 +1,52 @@ +// file : xsd/cxx/tree/serialization/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_BOOLEAN_HXX +#define XSD_CXX_TREE_SERIALIZATION_BOOLEAN_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, bool b) + { + std::basic_ostringstream<char> os; + os.setf (std::ios_base::boolalpha); + os << b; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, bool b) + { + std::basic_ostringstream<char> os; + os.setf (std::ios_base::boolalpha); + os << b; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, bool b) + { + // We don't need to restore the original bool format flag + // since items in the list are all of the same type. + // + ls.os_.setf (std::ios_base::boolalpha); + ls.os_ << b; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_BOOLEAN_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/byte.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/byte.hxx new file mode 100644 index 0000000..583eda9 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/byte.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_BYTE_HXX +#define XSD_CXX_TREE_SERIALIZATION_BYTE_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, signed char c) + { + std::basic_ostringstream<char> os; + os << static_cast<short> (c); + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, signed char c) + { + std::basic_ostringstream<char> os; + os << static_cast<short> (c); + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, signed char c) + { + ls.os_ << static_cast<short> (c); + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_BYTE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/date-time.txx b/xsd/libxsd/xsd/cxx/tree/serialization/date-time.txx new file mode 100644 index 0000000..1180e1c --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/date-time.txx @@ -0,0 +1,620 @@ +// file : xsd/cxx/tree/serialization/date-time.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <locale> +#include <string> +#include <ostream> +#include <sstream> + +#include <xsd/cxx/tree/bits/literals.hxx> // bits::{gday_prefix,gmonth_prefix} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // time_zone + // + namespace bits + { + // Assumes the fill character is set to '0'. + // + template <typename C> + void + zone_insert (std::basic_ostream<C>& os, const time_zone& z) + { + // time-zone := Z|(+|-)HH:MM + // + short h = z.zone_hours (); + short m = z.zone_minutes (); + + if (h == 0 && m == 0) + { + os << C ('Z'); + } + else + { + if (h < 0 || m < 0) + { + h = -h; + m = -m; + os << C ('-'); + } + else + os << C ('+'); + + if (h >= 0 && h <= 14 && m >= 0 && m <= 59) + { + os.width (2); + os << h << C (':'); + os.width (2); + os << m; + } + } + } + } + + // gday + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::gday<C, B>& x) + { + if (x.day () < 32) + { + // Save some time and space by not restoring the fill character + // since it is the same in case of a list. + // + os.fill (C ('0')); + os << bits::gday_prefix<C> (); + os.width (2); + os << x.day (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const gday<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const gday<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const gday<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // gmonth + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::gmonth<C, B>& x) + { + if (x.month () < 13) + { + os.fill (C ('0')); + os << bits::gmonth_prefix<C> (); + os.width (2); + os << x.month (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const gmonth<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const gmonth<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const gmonth<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // gyear + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::gyear<C, B>& x) + { + os.fill (C ('0')); + os.width (4); + os << x.year (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const gyear<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const gyear<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const gyear<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // gmonth_day + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::gmonth_day<C, B>& x) + { + if (x.month () < 13 && x.day () < 32) + { + os.fill (C ('0')); + os << bits::gmonth_prefix<C> (); + os.width (2); + os << x.month () << C ('-'); + os.width (2); + os << x.day (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const gmonth_day<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const gmonth_day<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const gmonth_day<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // gyear_month + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::gyear_month<C, B>& x) + { + if (x.month () < 13) + { + os.fill (C ('0')); + os.width (4); + os << x.year () << C ('-'); + os.width (2); + os << x.month (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const gyear_month<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const gyear_month<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const gyear_month<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // date + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::date<C, B>& x) + { + if (x.month () < 13 && x.day () < 32) + { + os.fill (C ('0')); + os.width (4); + os << x.year () << C ('-'); + os.width (2); + os << x.month () << C ('-'); + os.width (2); + os << x.day (); + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const date<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const date<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const date<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // time + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::time<C, B>& x) + { + if (x.hours () <= 24 && + x.minutes () <= 59 && + x.seconds () >= 0.0 && + x.seconds () < 60.0) + { + os.fill (C ('0')); + os.width (2); + os << x.hours () << C (':'); + + os.width (2); + os << x.minutes () << C (':'); + + std::basic_ostringstream<C> ostr; + ostr.imbue (std::locale::classic ()); + ostr.width (9); + ostr.fill (C ('0')); + ostr << std::fixed << x.seconds (); + + std::basic_string<C> s (ostr.str ()); + + // Remove the trailing zeros and the decimal point if necessary. + // + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (s.size ()), n (size); + + for (; n > 0 && s[n - 1] == C ('0'); --n)/*noop*/; + + if (n > 0 && s[n - 1] == C ('.')) + --n; + + if (n != size) + s.resize (n); + + os << s; + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const time<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const time<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const time<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // date_time + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::date_time<C, B>& x) + { + if (x.month () <= 12 && + x.day () <= 31 && + x.hours () <= 24 && + x.minutes () <= 59 && + x.seconds () >= 0.0 && + x.seconds () < 60.0) + { + os.fill (C ('0')); + os.width (4); + os << x.year () << C ('-'); + + os.width (2); + os << x.month () << C ('-'); + + os.width (2); + os << x.day () << C ('T'); + + os.width (2); + os << x.hours () << C (':'); + + os.width (2); + os << x.minutes () << C (':'); + + std::basic_ostringstream<C> ostr; + ostr.imbue (std::locale::classic ()); + ostr.width (9); + ostr.fill (C ('0')); + ostr << std::fixed << x.seconds (); + + std::basic_string<C> s (ostr.str ()); + + // Remove the trailing zeros and the decimal point if necessary. + // + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (s.size ()), n (size); + + for (; n > 0 && s[n - 1] == C ('0'); --n)/*noop*/; + + if (n > 0 && s[n - 1] == C ('.')) + --n; + + if (n != size) + s.resize (n); + + os << s; + + if (x.zone_present ()) + zone_insert (os, x); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const date_time<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const date_time<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const date_time<C, B>& x) + { + bits::insert (ls.os_, x); + } + + // duration + // + namespace bits + { + template <typename C, typename B> + void + insert (std::basic_ostream<C>& os, const tree::duration<C, B>& x) + { + if (x.negative ()) + os << C ('-'); + + os << C ('P'); + + // years + // + // In case it is 0-duration, use the years field to handle + // this case. + // + if (x.years () != 0 || + (x.months () == 0 && + x.days () == 0 && + x.hours () == 0 && + x.minutes () == 0 && + x.seconds () == 0.0)) + { + os << x.years () << C ('Y'); + } + + // months + // + if (x.months () != 0) + { + os << x.months () << C ('M'); + } + + // days + // + if (x.days () != 0) + { + os << x.days () << C ('D'); + } + + // Figure out if we need the 'T' delimiter. + // + if (x.hours () != 0 || + x.minutes () != 0 || + x.seconds () != 0.0) + os << C ('T'); + + // hours + // + if (x.hours () != 0) + { + os << x.hours () << C ('H'); + } + + // minutes + // + if (x.minutes () != 0) + { + os << x.minutes () << C ('M'); + } + + // seconds + // + if (x.seconds () > 0.0) + { + std::basic_ostringstream<C> ostr; + ostr.imbue (std::locale::classic ()); + ostr << std::fixed << x.seconds (); + + std::basic_string<C> s (ostr.str ()); + + // Remove the trailing zeros and the decimal point if necessary. + // + typedef typename std::basic_string<C>::size_type size_type; + + size_type size (s.size ()), n (size); + + for (; n > 0 && s[n - 1] == C ('0'); --n)/*noop*/; + + if (n > 0 && s[n - 1] == C ('.')) + --n; + + if (n != size) + s.resize (n); + + os << s << C ('S'); + } + } + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMElement& e, const duration<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + e << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (xercesc::DOMAttr& a, const duration<C, B>& x) + { + std::basic_ostringstream<C> os; + bits::insert (os, x); + a << os.str (); + } + + template <typename C, typename B> + inline void + operator<< (list_stream<C>& ls, const duration<C, B>& x) + { + bits::insert (ls.os_, x); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx new file mode 100644 index 0000000..971622f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx @@ -0,0 +1,126 @@ +// file : xsd/cxx/tree/serialization/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_DECIMAL_HXX +#define XSD_CXX_TREE_SERIALIZATION_DECIMAL_HXX + +#include <limits> // std::numeric_limits +#include <locale> +#include <sstream> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // The formula for the number of decimla digits required is given in: + // + // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf + // + template <typename C> + std::basic_string<C> + insert (const as_decimal<double>& d) + { + std::basic_ostringstream<C> os; + os.imbue (std::locale::classic ()); + std::streamsize prec; + + const facet* f = d.facets ? + facet::find (d.facets, facet::fraction_digits) : 0; + + if (f) + prec = static_cast<std::streamsize> (f->value); + else + { + // Precision. + // +#if defined (XSD_CXX_TREE_DECIMAL_PRECISION_MAX) + prec = 2 + std::numeric_limits<double>::digits * 301/1000; +#elif defined (XSD_CXX_TREE_DECIMAL_PRECISION) + prec = XSD_CXX_TREE_DECIMAL_PRECISION; +#else + prec = std::numeric_limits<double>::digits10; +#endif + } + + os.precision (prec); + os << std::fixed << d.x; + std::basic_string<C> r (os.str ()); + const C* cr (r.c_str ()); + + // Remove the trailing zeros and the decimal point if necessary. + // + typename std::basic_string<C>::size_type size (r.size ()), n (size); + + if (prec != 0) + { + for (; n > 0 && cr[n - 1] == '0'; --n)/*noop*/; + + if (n > 0 && cr[n - 1] == '.') + --n; + } + + // See if we have a restriction on total digits. + // + f = d.facets ? facet::find (d.facets, facet::total_digits) : 0; + + if (f && n > f->value) + { + // Point and sign do not count so figure out if we have them. + // + typename std::basic_string<C>::size_type extra ( + cr[0] == '-' ? 1 : 0); + + if (r.find ('.') < n) + extra++; + + // Unless we have a point and the size difference is one, + // remove some digits. + // + if ((n - extra) > f->value) + n -= (n - extra - f->value); + + if (n > 0 && cr[n - 1] == '.') + --n; + } + + if (n != size) + r.resize (n); + + return r; + } + } + + template <typename C> + inline void + operator<< (list_stream<C>& ls, const as_decimal<double>& d) + { + ls.os_ << bits::insert<C> (d); + } + } + } +} + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, + const xsd::cxx::tree::as_decimal<double>& d) + { + e << xsd::cxx::tree::bits::insert<char> (d); + } + + inline void + operator<< (xercesc::DOMAttr& a, + const xsd::cxx::tree::as_decimal<double>& d) + { + a << xsd::cxx::tree::bits::insert<char> (d); + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_DECIMAL_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/double.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/double.hxx new file mode 100644 index 0000000..6d21536 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/double.hxx @@ -0,0 +1,96 @@ +// file : xsd/cxx/tree/serialization/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_DOUBLE_HXX +#define XSD_CXX_TREE_SERIALIZATION_DOUBLE_HXX + +#include <limits> // std::numeric_limits +#include <locale> +#include <sstream> + +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // The formula for the number of decimla digits required is given in: + // + // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf + // + template <typename C> + std::basic_string<C> + insert (const as_double<double>& d) + { + std::basic_string<C> r; + + if (d.x == std::numeric_limits<double>::infinity ()) + r = bits::positive_inf<C> (); + else if (d.x == -std::numeric_limits<double>::infinity ()) + r = bits::negative_inf<C> (); + else if (!(d.x == d.x)) + r = bits::nan<C> (); + else + { + std::basic_ostringstream<C> os; + os.imbue (std::locale::classic ()); + + // Precision. + // +#if defined (XSD_CXX_TREE_DOUBLE_PRECISION_MAX) + os.precision (2 + std::numeric_limits<double>::digits * 301/1000); +#elif defined (XSD_CXX_TREE_DOUBLE_PRECISION) + os.precision (XSD_CXX_TREE_DOUBLE_PRECISION); +#else + os.precision (std::numeric_limits<double>::digits10); +#endif + // Format. + // +#if defined (XSD_CXX_TREE_DOUBLE_FIXED) + os << std::fixed << d.x; +#elif defined (XSD_CXX_TREE_DOUBLE_SCIENTIFIC) + os << std::scientific << d.x; +#else + os << d.x; +#endif + r = os.str (); + } + + return r; + } + } + + template <typename C> + inline void + operator<< (list_stream<C>& ls, const as_double<double>& d) + { + ls.os_ << bits::insert<C> (d); + } + } + } +} + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, + const xsd::cxx::tree::as_double<double>& d) + { + e << xsd::cxx::tree::bits::insert<char> (d); + } + + inline void + operator<< (xercesc::DOMAttr& a, + const xsd::cxx::tree::as_double<double>& d) + { + a << xsd::cxx::tree::bits::insert<char> (d); + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_DOUBLE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/element-map.txx b/xsd/libxsd/xsd/cxx/tree/serialization/element-map.txx new file mode 100644 index 0000000..9870ff2 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/element-map.txx @@ -0,0 +1,40 @@ +// file : xsd/cxx/tree/serialization/element-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_ELEMENT_MAP_TXX +#define XSD_CXX_TREE_SERIALIZATION_ELEMENT_MAP_TXX + +#include <xsd/cxx/tree/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C, typename T> + void element_map<C, T>:: + serialize (xercesc::DOMElement& e, const element_type& x) + { + const qualified_name n (x._name (), x._namespace ()); + typename map::const_iterator i (map_->find (n)); + + if (i != map_->end () && i->second.serializer_ != 0) + return (i->second.serializer_) (e, x); + else + throw no_element_info<C> (n.name (), n.namespace_ ()); + } + + template<typename T, typename C, typename B> + void + serializer_impl (xercesc::DOMElement& e, const element_type<C, B>& x) + { + e << static_cast<const T&> (x); + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_ELEMENT_MAP_TXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/float.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/float.hxx new file mode 100644 index 0000000..2d37ae6 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/float.hxx @@ -0,0 +1,94 @@ +// file : xsd/cxx/tree/serialization/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_FLOAT_HXX +#define XSD_CXX_TREE_SERIALIZATION_FLOAT_HXX + +#include <limits> // std::numeric_limits +#include <locale> +#include <sstream> + +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // The formula for the number of decimla digits required is given in: + // + // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf + // + template <typename C> + std::basic_string<C> + insert (float f) + { + std::basic_string<C> r; + + if (f == std::numeric_limits<float>::infinity ()) + r = bits::positive_inf<C> (); + else if (f == -std::numeric_limits<float>::infinity ()) + r = bits::negative_inf<C> (); + else if (!(f == f)) + r = bits::nan<C> (); + else + { + std::basic_ostringstream<C> os; + os.imbue (std::locale::classic ()); + + // Precision. + // +#if defined (XSD_CXX_TREE_FLOAT_PRECISION_MAX) + os.precision (2 + std::numeric_limits<float>::digits * 301/1000); +#elif defined (XSD_CXX_TREE_FLOAT_PRECISION) + os.precision (XSD_CXX_TREE_FLOAT_PRECISION); +#else + os.precision (std::numeric_limits<float>::digits10); +#endif + // Format. + // +#if defined (XSD_CXX_TREE_FLOAT_FIXED) + os << std::fixed << f; +#elif defined (XSD_CXX_TREE_FLOAT_SCIENTIFIC) + os << std::scientific << f; +#else + os << f; +#endif + r = os.str (); + } + + return r; + } + } + + template <typename C> + inline void + operator<< (list_stream<C>& ls, float f) + { + ls.os_ << bits::insert<C> (f); + } + } + } +} + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, float f) + { + e << xsd::cxx::tree::bits::insert<char> (f); + } + + inline void + operator<< (xercesc::DOMAttr& a, float f) + { + a << xsd::cxx::tree::bits::insert<char> (f); + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_FLOAT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/int.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/int.hxx new file mode 100644 index 0000000..f88d6b8 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/int.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_INT_HXX +#define XSD_CXX_TREE_SERIALIZATION_INT_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, int i) + { + std::basic_ostringstream<char> os; + os << i; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, int i) + { + std::basic_ostringstream<char> os; + os << i; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, int i) + { + ls.os_ << i; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_INT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/long.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/long.hxx new file mode 100644 index 0000000..c37338b --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/long.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_LONG_HXX +#define XSD_CXX_TREE_SERIALIZATION_LONG_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, long long l) + { + std::basic_ostringstream<char> os; + os << l; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, long long l) + { + std::basic_ostringstream<char> os; + os << l; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, long long l) + { + ls.os_ << l; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_LONG_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/short.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/short.hxx new file mode 100644 index 0000000..7d885c1 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/short.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_SHORT_HXX +#define XSD_CXX_TREE_SERIALIZATION_SHORT_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, short s) + { + std::basic_ostringstream<char> os; + os << s; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, short s) + { + std::basic_ostringstream<char> os; + os << s; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, short s) + { + ls.os_ << s; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_SHORT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx new file mode 100644 index 0000000..114f1a1 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_UNSIGNED_BYTE_HXX +#define XSD_CXX_TREE_SERIALIZATION_UNSIGNED_BYTE_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, unsigned char c) + { + std::basic_ostringstream<char> os; + os << static_cast<unsigned short> (c); + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, unsigned char c) + { + std::basic_ostringstream<char> os; + os << static_cast<unsigned short> (c); + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, unsigned char c) + { + ls.os_ << static_cast<unsigned short> (c); + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_UNSIGNED_BYTE_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx new file mode 100644 index 0000000..f91fe21 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_UNSIGNED_INT_HXX +#define XSD_CXX_TREE_SERIALIZATION_UNSIGNED_INT_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, unsigned int i) + { + std::basic_ostringstream<char> os; + os << i; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, unsigned int i) + { + std::basic_ostringstream<char> os; + os << i; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, unsigned int i) + { + ls.os_ << i; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_UNSIGNED_INT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx new file mode 100644 index 0000000..f5f12f3 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_UNSIGNED_LONG_HXX +#define XSD_CXX_TREE_SERIALIZATION_UNSIGNED_LONG_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, unsigned long long l) + { + std::basic_ostringstream<char> os; + os << l; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, unsigned long long l) + { + std::basic_ostringstream<char> os; + os << l; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, unsigned long long l) + { + ls.os_ << l; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_UNSIGNED_LONG_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx new file mode 100644 index 0000000..52437e0 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx @@ -0,0 +1,46 @@ +// file : xsd/cxx/tree/serialization/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_SERIALIZATION_UNSIGNED_SHORT_HXX +#define XSD_CXX_TREE_SERIALIZATION_UNSIGNED_SHORT_HXX + +#include <sstream> + +namespace XERCES_CPP_NAMESPACE +{ + inline void + operator<< (xercesc::DOMElement& e, unsigned short s) + { + std::basic_ostringstream<char> os; + os << s; + e << os.str (); + } + + inline void + operator<< (xercesc::DOMAttr& a, unsigned short s) + { + std::basic_ostringstream<char> os; + os << s; + a << os.str (); + } +} + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + inline void + operator<< (list_stream<C>& ls, unsigned short s) + { + ls.os_ << s; + } + } + } +} + +#endif // XSD_CXX_TREE_SERIALIZATION_UNSIGNED_SHORT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx new file mode 100644 index 0000000..28619a5 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx @@ -0,0 +1,114 @@ +// file : xsd/cxx/tree/std-ostream-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STD_OSTREAM_MAP_HXX +#define XSD_CXX_TREE_STD_OSTREAM_MAP_HXX + +#include <map> +#include <cstddef> // std::size_t +#include <ostream> +#include <typeinfo> + +#include <xsd/cxx/tree/elements.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct std_ostream_map + { + typedef std::type_info type_id; + typedef void (*inserter) (std::basic_ostream<C>&, const type&); + + std_ostream_map (); + + void + register_type (const type_id&, inserter, bool override = true); + + void + unregister_type (const type_id&); + + void + insert (std::basic_ostream<C>&, const type&); + + public: + inserter + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map<const type_id*, inserter, type_id_comparator> + type_map; + + type_map type_map_; + }; + + // + // + template<unsigned long id, typename C> + struct std_ostream_plate + { + static std_ostream_map<C>* map; + static std::size_t count; + + std_ostream_plate (); + ~std_ostream_plate (); + }; + + template<unsigned long id, typename C> + std_ostream_map<C>* std_ostream_plate<id, C>::map = 0; + + template<unsigned long id, typename C> + std::size_t std_ostream_plate<id, C>::count = 0; + + + // + // + template<unsigned long id, typename C> + inline std_ostream_map<C>& + std_ostream_map_instance () + { + return *std_ostream_plate<id, C>::map; + } + + // + // + template<typename C, typename T> + void + inserter_impl (std::basic_ostream<C>&, const type&); + + template<unsigned long id, typename C, typename T> + struct std_ostream_initializer + { + std_ostream_initializer (); + ~std_ostream_initializer (); + }; + } + } +} + +#include <xsd/cxx/tree/std-ostream-map.txx> + +#endif // XSD_CXX_TREE_STD_OSTREAM_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx new file mode 100644 index 0000000..6a748ec --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx @@ -0,0 +1,293 @@ +// file : xsd/cxx/tree/std-ostream-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/std-ostream-operators.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // std_ostream_map + // + template <typename C> + std_ostream_map<C>:: + std_ostream_map () + { + // anyType and anySimpleType. + // + register_type ( + typeid (type), + &inserter_impl<C, type>, + false); + + typedef simple_type<type> simple_type; + register_type ( + typeid (simple_type), + &inserter_impl<C, simple_type>, + false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + typeid (string), + &inserter_impl<C, string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + typeid (normalized_string), + &inserter_impl<C, normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + typeid (token), + &inserter_impl<C, token>, + false); + + typedef name<C, token> name; + register_type ( + typeid (name), + &inserter_impl<C, name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + typeid (nmtoken), + &inserter_impl<C, nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + typeid (nmtokens), + &inserter_impl<C, nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + typeid (ncname), + &inserter_impl<C, ncname>, + false); + + typedef language<C, token> language; + register_type ( + typeid (language), + &inserter_impl<C, language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + typeid (id), + &inserter_impl<C, id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + typeid (idref), + &inserter_impl<C, idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + typeid (idrefs), + &inserter_impl<C, idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + typeid (uri), + &inserter_impl<C, uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + typeid (qname), + &inserter_impl<C, qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + typeid (base64_binary), + &inserter_impl<C, base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + typeid (hex_binary), + &inserter_impl<C, hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + typeid (gday), + &inserter_impl<C, gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + typeid (gmonth), + &inserter_impl<C, gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + typeid (gyear), + &inserter_impl<C, gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + typeid (gmonth_day), + &inserter_impl<C, gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + typeid (gyear_month), + &inserter_impl<C, gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + typeid (date), + &inserter_impl<C, date>, + false); + + typedef time<C, simple_type> time; + register_type ( + typeid (time), + &inserter_impl<C, time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + typeid (date_time), + &inserter_impl<C, date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + typeid (duration), + &inserter_impl<C, duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + typeid (entity), + &inserter_impl<C, entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + typeid (entities), + &inserter_impl<C, entities>, + false); + } + + template <typename C> + void std_ostream_map<C>:: + register_type (const type_id& tid, inserter i, bool override) + { + if (override || type_map_.find (&tid) == type_map_.end ()) + type_map_[&tid] = i; + } + + template <typename C> + void std_ostream_map<C>:: + unregister_type (const type_id& tid) + { + type_map_.erase (&tid); + } + + template <typename C> + void std_ostream_map<C>:: + insert (std::basic_ostream<C>& os, const type& x) + { + if (inserter i = find (typeid (x))) + i (os, x); + else + throw no_type_info<C> (std::basic_string<C> (), + std::basic_string<C> ()); // @@ TODO + } + + template <typename C> + typename std_ostream_map<C>::inserter std_ostream_map<C>:: + find (const type_id& tid) const + { + typename type_map::const_iterator i (type_map_.find (&tid)); + return i == type_map_.end () ? 0 : i->second; + } + + // std_ostream_plate + // + template<unsigned long id, typename C> + std_ostream_plate<id, C>:: + std_ostream_plate () + { + if (count == 0) + map = new std_ostream_map<C>; + + ++count; + } + + template<unsigned long id, typename C> + std_ostream_plate<id, C>:: + ~std_ostream_plate () + { + if (--count == 0) + delete map; + } + + // + // + template<typename C, typename T> + void + inserter_impl (std::basic_ostream<C>& os, const type& x) + { + os << static_cast<const T&> (x); + } + + // std_ostream_initializer + // + template<unsigned long id, typename C, typename T> + std_ostream_initializer<id, C, T>:: + std_ostream_initializer () + { + std_ostream_map_instance<id, C> ().register_type ( + typeid (T), &inserter_impl<C, T>); + } + + template<unsigned long id, typename C, typename T> + std_ostream_initializer<id, C, T>:: + ~std_ostream_initializer () + { + std_ostream_map_instance<id, C> ().unregister_type (typeid (T)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx b/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx new file mode 100644 index 0000000..a7ab357 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx @@ -0,0 +1,274 @@ +// file : xsd/cxx/tree/std-ostream-operators.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX +#define XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX + +#include <ostream> + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/containers.hxx> +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/list.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // type + // + template <typename C> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const type&) + { + return os; + } + + + // simple_type + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const simple_type<B>&) + { + return os; + } + + + // fundamental_base + // + template <typename T, typename C, typename B, schema_type::value ST> + inline + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, fundamental_base<T, C, B, ST> x) + { + T& r (x); + return os << r; + } + + // optional: see containers.hxx + // + + // list + // + + // This is an xsd:list-style format (space-separated). + // + template <typename C, typename T, schema_type::value ST, bool fund> + std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const list<T, C, ST, fund>& v) + { + for (typename list<T, C, ST, fund>::const_iterator + b (v.begin ()), e (v.end ()), i (b); i != e; ++i) + { + if (i != b) + os << C (' '); + + os << *i; + } + + return os; + } + + + // Operators for built-in types. + // + + + // string + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const string<C, B>& v) + { + const std::basic_string<C>& r (v); + return os << r; + } + + + // normalized_string + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const normalized_string<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // token + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const token<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // nmtoken + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const nmtoken<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // nmtokens + // + template <typename C, typename B, typename nmtoken> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const nmtokens<C, B, nmtoken>& v) + { + const list<nmtoken, C>& r (v); + return os << r; + } + + + // name + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const name<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // ncname + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const ncname<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // language + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const language<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // id + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const id<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // idref + // + template <typename C, typename B, typename T> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const idref<C, B, T>& v) + { + const B& r (v); + return os << r; + } + + + // idrefs + // + template <typename C, typename B, typename idref> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const idrefs<C, B, idref>& v) + { + const list<idref, C>& r (v); + return os << r; + } + + + // uri + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const uri<C, B>& v) + { + const std::basic_string<C>& r (v); + return os << r; + } + + + // qname + // + template <typename C, typename B, typename uri, typename ncname> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, + const qname<C, B, uri, ncname>& n) + { + if (n.qualified ()) + os << n.namespace_ () << C ('#'); + + return os << n.name (); + } + + + // base64_binary + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const base64_binary<C, B>& v) + { + return os << v.encode (); + } + + + // hex_binary + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const hex_binary<C, B>& v) + { + return os << v.encode (); + } + + + // entity + // + template <typename C, typename B> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const entity<C, B>& v) + { + const B& r (v); + return os << r; + } + + + // entities + // + template <typename C, typename B, typename entity> + inline std::basic_ostream<C>& + operator<< (std::basic_ostream<C>& os, const entities<C, B, entity>& v) + { + const list<entity, C>& r (v); + return os << r; + } + } + } +} + +#include <xsd/cxx/tree/date-time-ostream.txx> + +#endif // XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx new file mode 100644 index 0000000..dd4c79a --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx @@ -0,0 +1,105 @@ +// file : xsd/cxx/tree/stream-extraction-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX +#define XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX + +#include <map> +#include <memory> // std::auto_ptr +#include <cstddef> // std::size_t + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/istream.hxx> +#include <xsd/cxx/xml/qualified-name.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename S, typename C> + struct stream_extraction_map + { + typedef xml::qualified_name<C> qualified_name; + typedef std::auto_ptr<type> (*extractor) ( + istream<S>&, flags, container*); + + public: + stream_extraction_map (); + + void + register_type (const qualified_name& name, + extractor, + bool override = true); + + void + unregister_type (const qualified_name& name); + + std::auto_ptr<type> + extract (istream<S>&, flags, container*); + + public: + extractor + find (const qualified_name& name) const; + + private: + typedef std::map<qualified_name, extractor> type_map; + + type_map type_map_; + }; + + // + // + template<unsigned long id, typename S, typename C> + struct stream_extraction_plate + { + static stream_extraction_map<S, C>* map; + static std::size_t count; + + stream_extraction_plate (); + ~stream_extraction_plate (); + }; + + template<unsigned long id, typename S, typename C> + stream_extraction_map<S, C>* stream_extraction_plate<id, S, C>::map = 0; + + template<unsigned long id, typename S, typename C> + std::size_t stream_extraction_plate<id, S, C>::count = 0; + + + // + // + template<unsigned long id, typename S, typename C> + inline stream_extraction_map<S, C>& + stream_extraction_map_instance () + { + return *stream_extraction_plate<id, S, C>::map; + } + + // + // + template<typename S, typename T> + std::auto_ptr<type> + extractor_impl (istream<S>&, flags, container*); + + + template<unsigned long id, typename S, typename C, typename T> + struct stream_extraction_initializer + { + stream_extraction_initializer (const C* name, const C* ns); + ~stream_extraction_initializer (); + + private: + const C* name_; + const C* ns_; + }; + } + } +} + +#include <xsd/cxx/tree/stream-extraction-map.txx> + +#endif // XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx new file mode 100644 index 0000000..a4e429e --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx @@ -0,0 +1,310 @@ +// file : xsd/cxx/tree/stream-extraction-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/stream-extraction.hxx> +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // stream_extraction_map + // + template <typename S, typename C> + stream_extraction_map<S, C>:: + stream_extraction_map () + { + // Register extractors for built-in non-fundamental types. + // + std::basic_string<C> xsd (bits::xml_schema<C> ()); + + + // anyType and anySimpleType. + // + register_type ( + qualified_name (bits::any_type<C> (), xsd), + &extractor_impl<S, type>, + false); + + typedef simple_type<type> simple_type; + register_type ( + qualified_name (bits::any_simple_type<C> (), xsd), + &extractor_impl<S, simple_type>, + false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + qualified_name (bits::string<C> (), xsd), + &extractor_impl<S, string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + qualified_name (bits::normalized_string<C> (), xsd), + &extractor_impl<S, normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + qualified_name (bits::token<C> (), xsd), + &extractor_impl<S, token>, + false); + + typedef name<C, token> name; + register_type ( + qualified_name (bits::name<C> (), xsd), + &extractor_impl<S, name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + qualified_name (bits::nmtoken<C> (), xsd), + &extractor_impl<S, nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + qualified_name (bits::nmtokens<C> (), xsd), + &extractor_impl<S, nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + qualified_name (bits::ncname<C> (), xsd), + &extractor_impl<S, ncname>, + false); + + typedef language<C, token> language; + register_type ( + qualified_name (bits::language<C> (), xsd), + &extractor_impl<S, language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + qualified_name (bits::id<C> (), xsd), + &extractor_impl<S, id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + qualified_name (bits::idref<C> (), xsd), + &extractor_impl<S, idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + qualified_name (bits::idrefs<C> (), xsd), + &extractor_impl<S, idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + qualified_name (bits::any_uri<C> (), xsd), + &extractor_impl<S, uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + qualified_name (bits::qname<C> (), xsd), + &extractor_impl<S, qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + qualified_name (bits::base64_binary<C> (), xsd), + &extractor_impl<S, base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + qualified_name (bits::hex_binary<C> (), xsd), + &extractor_impl<S, hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + qualified_name (bits::gday<C> (), xsd), + &extractor_impl<S, gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + qualified_name (bits::gmonth<C> (), xsd), + &extractor_impl<S, gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + qualified_name (bits::gyear<C> (), xsd), + &extractor_impl<S, gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + qualified_name (bits::gmonth_day<C> (), xsd), + &extractor_impl<S, gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + qualified_name (bits::gyear_month<C> (), xsd), + &extractor_impl<S, gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + qualified_name (bits::date<C> (), xsd), + &extractor_impl<S, date>, + false); + + typedef time<C, simple_type> time; + register_type ( + qualified_name (bits::time<C> (), xsd), + &extractor_impl<S, time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + qualified_name (bits::date_time<C> (), xsd), + &extractor_impl<S, date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + qualified_name (bits::duration<C> (), xsd), + &extractor_impl<S, duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + qualified_name (bits::entity<C> (), xsd), + &extractor_impl<S, entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + qualified_name (bits::entities<C> (), xsd), + &extractor_impl<S, entities>, + false); + } + + template <typename S, typename C> + void stream_extraction_map<S, C>:: + register_type (const qualified_name& name, + extractor e, + bool override) + { + if (override || type_map_.find (name) == type_map_.end ()) + type_map_[name] = e; + } + + template <typename S, typename C> + void stream_extraction_map<S, C>:: + unregister_type (const qualified_name& name) + { + type_map_.erase (name); + } + + template <typename S, typename C> + std::auto_ptr<type> stream_extraction_map<S, C>:: + extract (istream<S>& s, flags f, container* c) + { + std::basic_string<C> name, ns; + s >> ns >> name; + + if (extractor e = find (qualified_name (name, ns))) + { + return e (s, f, c); + } + else + throw no_type_info<C> (name, ns); + } + + template <typename S, typename C> + typename stream_extraction_map<S, C>::extractor + stream_extraction_map<S, C>:: + find (const qualified_name& name) const + { + typename type_map::const_iterator i (type_map_.find (name)); + return i == type_map_.end () ? 0 : i->second; + } + + + // stream_extraction_plate + // + template<unsigned long id, typename S, typename C> + stream_extraction_plate<id, S, C>:: + stream_extraction_plate () + { + if (count == 0) + map = new stream_extraction_map<S, C>; + + ++count; + } + + template<unsigned long id, typename S, typename C> + stream_extraction_plate<id, S, C>:: + ~stream_extraction_plate () + { + if (--count == 0) + delete map; + } + + // + // + template<typename S, typename T> + std::auto_ptr<type> + extractor_impl (istream<S>& s, flags f, container* c) + { + return std::auto_ptr<type> (new T (s, f, c)); + } + + + // stream_extraction_initializer + // + template<unsigned long id, typename S, typename C, typename T> + stream_extraction_initializer<id, S, C, T>:: + stream_extraction_initializer (const C* name, const C* ns) + : name_ (name), ns_ (ns) + { + stream_extraction_map_instance<id, S, C> ().register_type ( + xml::qualified_name<C> (name, ns), &extractor_impl<S, T>); + } + + template<unsigned long id, typename S, typename C, typename T> + stream_extraction_initializer<id, S, C, T>:: + ~stream_extraction_initializer () + { + stream_extraction_map_instance<id, S, C> ().unregister_type ( + xml::qualified_name<C> (name_, ns_)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx b/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx new file mode 100644 index 0000000..f82042f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx @@ -0,0 +1,303 @@ +// file : xsd/cxx/tree/stream-extraction.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STREAM_EXTRACTION_HXX +#define XSD_CXX_TREE_STREAM_EXTRACTION_HXX + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/list.hxx> + +#include <xsd/cxx/tree/istream.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // type + // + template <typename S> + inline _type:: + _type (istream<S>&, flags, container* c) + : container_ (c) + { + } + + // simple_type + // + template <typename B> + template <typename S> + inline simple_type<B>:: + simple_type (istream<S>& s, flags f, container* c) + : type (s, f, c) + { + } + + // fundamental_base + // + template <typename T, typename C, typename B, schema_type::value ST> + template <typename S> + inline fundamental_base<T, C, B, ST>:: + fundamental_base (istream<S>& s, flags f, container* c) + : B (s, f, c), facet_table_ (0) + { + T& r (*this); + s >> r; + } + + // list + // + template <typename T, typename C, schema_type::value ST> + template <typename S> + list<T, C, ST, false>:: + list (istream<S>& s, flags f, container* c) + : sequence<T> (f, c) + { + std::size_t size; + istream_common::as_size<std::size_t> as_size (size); + s >> as_size; + + if (size > 0) + { + this->reserve (size); + + while (size--) + { + std::auto_ptr<T> p (new T (s, f, c)); + this->push_back (p); + } + } + } + + template <typename T, typename C, schema_type::value ST> + template <typename S> + list<T, C, ST, true>:: + list (istream<S>& s, flags f, container* c) + : sequence<T> (f, c) + { + std::size_t size; + istream_common::as_size<std::size_t> as_size (size); + s >> as_size; + + if (size > 0) + { + this->reserve (size); + + while (size--) + { + T x; + s >> x; + this->push_back (x); + } + } + } + + // Extraction operators for built-in types. + // + + + // string + // + template <typename C, typename B> + template <typename S> + inline string<C, B>:: + string (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + std::basic_string<C>& r (*this); + s >> r; + } + + + // normalized_string + // + template <typename C, typename B> + template <typename S> + inline normalized_string<C, B>:: + normalized_string (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // token + // + template <typename C, typename B> + template <typename S> + inline token<C, B>:: + token (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // nmtoken + // + template <typename C, typename B> + template <typename S> + inline nmtoken<C, B>:: + nmtoken (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // nmtokens + // + template <typename C, typename B, typename nmtoken> + template <typename S> + inline nmtokens<C, B, nmtoken>:: + nmtokens (istream<S>& s, flags f, container* c) + : B (s, f, c), base_type (s, f, this) + { + } + + + // name + // + template <typename C, typename B> + template <typename S> + inline name<C, B>:: + name (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // ncname + // + template <typename C, typename B> + template <typename S> + inline ncname<C, B>:: + ncname (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // language + // + template <typename C, typename B> + template <typename S> + inline language<C, B>:: + language (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // id + // + template <typename C, typename B> + template <typename S> + inline id<C, B>:: + id (istream<S>& s, flags f, container* c) + : B (s, f, c), identity_ (*this) + { + register_id (); + } + + + // idref + // + template <typename C, typename B, typename T> + template <typename S> + inline idref<C, B, T>:: + idref (istream<S>& s, flags f, container* c) + : B (s, f, c), identity_ (*this) + { + } + + + // idrefs + // + template <typename C, typename B, typename idref> + template <typename S> + inline idrefs<C, B, idref>:: + idrefs (istream<S>& s, flags f, container* c) + : B (s, f, c), base_type (s, f, this) + { + } + + + // uri + // + template <typename C, typename B> + template <typename S> + inline uri<C, B>:: + uri (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + std::basic_string<C>& r (*this); + s >> r; + } + + + // qname + // + template <typename C, typename B, typename uri, typename ncname> + template <typename S> + inline qname<C, B, uri, ncname>:: + qname (istream<S>& s, flags f, container* c) + : B (s, f, c), ns_ (s), name_ (s) + { + } + + + // base64_binary + // + template <typename C, typename B> + template <typename S> + inline base64_binary<C, B>:: + base64_binary (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + buffer<C>& r (*this); + s >> r; + } + + + // hex_binary + // + template <typename C, typename B> + template <typename S> + inline hex_binary<C, B>:: + hex_binary (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + buffer<C>& r (*this); + s >> r; + } + + + // entity + // + template <typename C, typename B> + template <typename S> + inline entity<C, B>:: + entity (istream<S>& s, flags f, container* c) + : B (s, f, c) + { + } + + + // entities + // + template <typename C, typename B, typename entity> + template <typename S> + inline entities<C, B, entity>:: + entities (istream<S>& s, flags f, container* c) + : B (s, f, c), base_type (s, f, this) + { + } + } + } +} + +#include <xsd/cxx/tree/date-time-extraction.txx> + +#endif // XSD_CXX_TREE_STREAM_EXTRACTION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx new file mode 100644 index 0000000..e26a3da --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx @@ -0,0 +1,154 @@ +// file : xsd/cxx/tree/stream-insertion-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STREAM_INSERTION_MAP_HXX +#define XSD_CXX_TREE_STREAM_INSERTION_MAP_HXX + +#include <map> +#include <string> +#include <cstddef> // std::size_t +#include <typeinfo> + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/ostream.hxx> +#include <xsd/cxx/xml/qualified-name.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename S, typename C> + struct stream_insertion_map + { + typedef std::type_info type_id; + typedef xml::qualified_name<C> qualified_name; + typedef void (*inserter) (ostream<S>&, const type&); + + stream_insertion_map (); + + void + register_type (const type_id&, + const qualified_name& name, + inserter, + bool override = true); + + void + unregister_type (const type_id&); + + void + insert (ostream<S>&, const type&); + + public: + struct type_info + { + type_info (const qualified_name& name, + typename stream_insertion_map::inserter inserter) + : name_ (name), inserter_ (inserter) + { + } + + const qualified_name& + name () const + { + return name_; + } + + typename stream_insertion_map::inserter + inserter () const + { + return inserter_; + } + + // For std::map. + // + type_info () + : name_ (std::basic_string<C> (), std::basic_string<C> ()), + inserter_ (0) + { + } + + private: + qualified_name name_; + typename stream_insertion_map::inserter inserter_; + }; + + public: + const type_info* + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map<const type_id*, type_info, type_id_comparator> + type_map; + + type_map type_map_; + }; + + // + // + template<unsigned long id, typename S, typename C> + struct stream_insertion_plate + { + static stream_insertion_map<S, C>* map; + static std::size_t count; + + stream_insertion_plate (); + ~stream_insertion_plate (); + }; + + template<unsigned long id, typename S, typename C> + stream_insertion_map<S, C>* stream_insertion_plate<id, S, C>::map = 0; + + template<unsigned long id, typename S, typename C> + std::size_t stream_insertion_plate<id, S, C>::count = 0; + + + // + // + template<unsigned long id, typename S, typename C> + inline stream_insertion_map<S, C>& + stream_insertion_map_instance () + { + return *stream_insertion_plate<id, S, C>::map; + } + + // + // + template<typename S, typename T> + void + inserter_impl (ostream<S>&, const type&); + + template<unsigned long id, typename S, typename C, typename T> + struct stream_insertion_initializer + { + stream_insertion_initializer (const C* name, const C* ns); + ~stream_insertion_initializer (); + }; + } + } +} + +#include <xsd/cxx/tree/stream-insertion-map.txx> + +#endif // XSD_CXX_TREE_STREAM_INSERTION_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx new file mode 100644 index 0000000..07bfa8b --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx @@ -0,0 +1,340 @@ +// file : xsd/cxx/tree/stream-insertion-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/stream-insertion.hxx> +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // stream_insertion_map + // + template <typename S, typename C> + stream_insertion_map<S, C>:: + stream_insertion_map () + { + // Register inserters for built-in non-fundamental types. + // + std::basic_string<C> xsd (bits::xml_schema<C> ()); + + + // anyType and anySimpleType. + // + register_type ( + typeid (type), + qualified_name (bits::any_type<C> (), xsd), + &inserter_impl<S, type>, + false); + + typedef simple_type<type> simple_type; + register_type ( + typeid (simple_type), + qualified_name (bits::any_simple_type<C> (), xsd), + &inserter_impl<S, simple_type>, + false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + typeid (string), + qualified_name (bits::string<C> (), xsd), + &inserter_impl<S, string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + typeid (normalized_string), + qualified_name (bits::normalized_string<C> (), xsd), + &inserter_impl<S, normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + typeid (token), + qualified_name (bits::token<C> (), xsd), + &inserter_impl<S, token>, + false); + + typedef name<C, token> name; + register_type ( + typeid (name), + qualified_name (bits::name<C> (), xsd), + &inserter_impl<S, name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + typeid (nmtoken), + qualified_name (bits::nmtoken<C> (), xsd), + &inserter_impl<S, nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + typeid (nmtokens), + qualified_name (bits::nmtokens<C> (), xsd), + &inserter_impl<S, nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + typeid (ncname), + qualified_name (bits::ncname<C> (), xsd), + &inserter_impl<S, ncname>, + false); + + typedef language<C, token> language; + register_type ( + typeid (language), + qualified_name (bits::language<C> (), xsd), + &inserter_impl<S, language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + typeid (id), + qualified_name (bits::id<C> (), xsd), + &inserter_impl<S, id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + typeid (idref), + qualified_name (bits::idref<C> (), xsd), + &inserter_impl<S, idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + typeid (idrefs), + qualified_name (bits::idrefs<C> (), xsd), + &inserter_impl<S, idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + typeid (uri), + qualified_name (bits::any_uri<C> (), xsd), + &inserter_impl<S, uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + typeid (qname), + qualified_name (bits::qname<C> (), xsd), + &inserter_impl<S, qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + typeid (base64_binary), + qualified_name (bits::base64_binary<C> (), xsd), + &inserter_impl<S, base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + typeid (hex_binary), + qualified_name (bits::hex_binary<C> (), xsd), + &inserter_impl<S, hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + typeid (gday), + qualified_name (bits::gday<C> (), xsd), + &inserter_impl<S, gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + typeid (gmonth), + qualified_name (bits::gmonth<C> (), xsd), + &inserter_impl<S, gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + typeid (gyear), + qualified_name (bits::gyear<C> (), xsd), + &inserter_impl<S, gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + typeid (gmonth_day), + qualified_name (bits::gmonth_day<C> (), xsd), + &inserter_impl<S, gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + typeid (gyear_month), + qualified_name (bits::gyear_month<C> (), xsd), + &inserter_impl<S, gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + typeid (date), + qualified_name (bits::date<C> (), xsd), + &inserter_impl<S, date>, + false); + + typedef time<C, simple_type> time; + register_type ( + typeid (time), + qualified_name (bits::time<C> (), xsd), + &inserter_impl<S, time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + typeid (date_time), + qualified_name (bits::date_time<C> (), xsd), + &inserter_impl<S, date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + typeid (duration), + qualified_name (bits::duration<C> (), xsd), + &inserter_impl<S, duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + typeid (entity), + qualified_name (bits::entity<C> (), xsd), + &inserter_impl<S, entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + typeid (entities), + qualified_name (bits::entities<C> (), xsd), + &inserter_impl<S, entities>, + false); + } + + template <typename S, typename C> + void stream_insertion_map<S, C>:: + register_type (const type_id& tid, + const qualified_name& name, + inserter i, + bool override) + { + if (override || type_map_.find (&tid) == type_map_.end ()) + type_map_[&tid] = type_info (name, i); + } + + template <typename S, typename C> + void stream_insertion_map<S, C>:: + unregister_type (const type_id& tid) + { + type_map_.erase (&tid); + } + + template <typename S, typename C> + void stream_insertion_map<S, C>:: + insert (ostream<S>& s, const type& x) + { + if (const type_info* ti = find (typeid (x))) + { + const qualified_name& qn (ti->name ()); + + s << qn.namespace_ () << qn.name (); + ti->inserter () (s, x); + } + else + throw no_type_info<C> (std::basic_string<C> (), + std::basic_string<C> ()); // @@ TODO + } + + template <typename S, typename C> + const typename stream_insertion_map<S, C>::type_info* + stream_insertion_map<S, C>:: + find (const type_id& tid) const + { + typename type_map::const_iterator i (type_map_.find (&tid)); + return i == type_map_.end () ? 0 : &i->second; + } + + + // stream_insertion_plate + // + template<unsigned long id, typename S, typename C> + stream_insertion_plate<id, S, C>:: + stream_insertion_plate () + { + if (count == 0) + map = new stream_insertion_map<S, C>; + + ++count; + } + + template<unsigned long id, typename S, typename C> + stream_insertion_plate<id, S, C>:: + ~stream_insertion_plate () + { + if (--count == 0) + delete map; + } + + // + // + template<typename S, typename T> + void + inserter_impl (ostream<S>& s, const type& x) + { + s << static_cast<const T&> (x); + } + + // stream_insertion_initializer + // + template<unsigned long id, typename S, typename C, typename T> + stream_insertion_initializer<id, S, C, T>:: + stream_insertion_initializer (const C* name, const C* ns) + { + stream_insertion_map_instance<id, S, C> ().register_type ( + typeid (T), + xml::qualified_name<C> (name, ns), + &inserter_impl<S, T>); + } + + template<unsigned long id, typename S, typename C, typename T> + stream_insertion_initializer<id, S, C, T>:: + ~stream_insertion_initializer () + { + stream_insertion_map_instance<id, S, C> ().unregister_type ( + typeid (T)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx new file mode 100644 index 0000000..c345e80 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx @@ -0,0 +1,273 @@ +// file : xsd/cxx/tree/stream-insertion.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_STREAM_INSERTION_HXX +#define XSD_CXX_TREE_STREAM_INSERTION_HXX + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/list.hxx> + +#include <xsd/cxx/tree/ostream.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // type + // + template <typename S> + inline ostream<S>& + operator<< (ostream<S>& s, const type&) + { + return s; + } + + // simple_type + // + template <typename S, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const simple_type<B>&) + { + return s; + } + + // fundamental_base + // + template <typename S, + typename T, + typename C, + typename B, + schema_type::value ST> + inline ostream<S>& + operator<< (ostream<S>& s, const fundamental_base<T, C, B, ST>& x) + { + const T& r (x); + return s << r; + } + + // list + // + template <typename S, + typename T, + typename C, + schema_type::value ST, + bool fund> + ostream<S>& + operator<< (ostream<S>& s, const list<T, C, ST, fund>& x) + { + s << ostream_common::as_size<std::size_t> (x.size ()); + + for (typename list<T, C, ST, fund>::const_iterator + i (x.begin ()), e (x.end ()); i != e; ++i) + { + s << *i; + } + + return s; + } + + + // Insertion operators for built-in types. + // + + + // string + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const string<C, B>& x) + { + const std::basic_string<C>& r (x); + return s << r; + } + + + // normalized_string + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const normalized_string<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // token + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const token<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // nmtoken + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const nmtoken<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // nmtokens + // + template <typename S, typename C, typename B, typename nmtoken> + inline ostream<S>& + operator<< (ostream<S>& s, const nmtokens<C, B, nmtoken>& x) + { + const list<nmtoken, C>& r (x); + return s << r; + } + + + // name + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const name<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // ncname + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const ncname<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // language + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const language<C, B>& x) + { + const std::basic_string<C>& r (x); + return s << r; + } + + + // id + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const id<C, B>& x) + { + const std::basic_string<C>& r (x); + return s << r; + } + + + // idref + // + template <typename S, typename C, typename B, typename T> + inline ostream<S>& + operator<< (ostream<S>& s, const idref<C, B, T>& x) + { + const B& r (x); + return s << r; + } + + + // idrefs + // + template <typename S, typename C, typename B, typename idref> + inline ostream<S>& + operator<< (ostream<S>& s, const idrefs<C, B, idref>& x) + { + const list<idref, C>& r (x); + return s << r; + } + + + // uri + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const uri<C, B>& x) + { + const std::basic_string<C>& r (x); + return s << r; + } + + + // qname + // + template <typename S, + typename C, + typename B, + typename uri, + typename ncname> + inline ostream<S>& + operator<< (ostream<S>& s, const qname<C, B, uri, ncname>& x) + { + return s << x.namespace_ () << x.name (); + } + + + // base64_binary + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const base64_binary<C, B>& x) + { + const buffer<C>& r (x); + return s << r; + } + + + // hex_binary + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const hex_binary<C, B>& x) + { + const buffer<C>& r (x); + return s << r; + } + + + // entity + // + template <typename S, typename C, typename B> + inline ostream<S>& + operator<< (ostream<S>& s, const entity<C, B>& x) + { + const B& r (x); + return s << r; + } + + + // entities + // + template <typename S, typename C, typename B, typename entity> + inline ostream<S>& + operator<< (ostream<S>& s, const entities<C, B, entity>& x) + { + const list<entity, C>& r (x); + return s << r; + } + } + } +} + +#include <xsd/cxx/tree/date-time-insertion.txx> + +#endif // XSD_CXX_TREE_STREAM_INSERTION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/text.hxx b/xsd/libxsd/xsd/cxx/tree/text.hxx new file mode 100644 index 0000000..15f12dc --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/text.hxx @@ -0,0 +1,30 @@ +// file : xsd/cxx/tree/text.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_TEXT_HXX +#define XSD_CXX_TREE_TEXT_HXX + +#include <string> + +#include <xercesc/dom/DOMElement.hpp> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Throws expected_text_content. + // + template <typename C> + std::basic_string<C> + text_content (const xercesc::DOMElement&); + } + } +} + +#include <xsd/cxx/tree/text.txx> + +#endif // XSD_CXX_TREE_TEXT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/text.txx b/xsd/libxsd/xsd/cxx/tree/text.txx new file mode 100644 index 0000000..2d83c71 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/text.txx @@ -0,0 +1,77 @@ +// file : xsd/cxx/tree/text.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xercesc/dom/DOMText.hpp> + +#include <xsd/cxx/xml/string.hxx> + +#include <xsd/cxx/tree/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + std::basic_string<C> + text_content (const xercesc::DOMElement& e) + { + using xercesc::DOMNode; + using xercesc::DOMText; + + DOMNode* n (e.getFirstChild ()); + + // Fast path. + // + if (n != 0 && + n->getNodeType () == DOMNode::TEXT_NODE && + n->getNextSibling () == 0) + { + DOMText* t (static_cast<DOMText*> (n)); + + // Berkeley DB XML DOM does not implement getLength(). + // +#ifndef DBXML_DOM + return xml::transcode<C> (t->getData (), t->getLength ()); +#else + return xml::transcode<C> (t->getData ()); +#endif + } + + std::basic_string<C> r; + + for (; n != 0; n = n->getNextSibling ()) + { + switch (n->getNodeType ()) + { + case DOMNode::TEXT_NODE: + case DOMNode::CDATA_SECTION_NODE: + { + DOMText* t (static_cast<DOMText*> (n)); + + // Berkeley DB XML DOM does not implement getLength(). + // +#ifndef DBXML_DOM + r += xml::transcode<C> (t->getData (), t->getLength ()); +#else + r += xml::transcode<C> (t->getData ()); +#endif + break; + } + case DOMNode::ELEMENT_NODE: + { + throw expected_text_content<C> (); + } + default: + break; // ignore + } + } + + return r; + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx b/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx new file mode 100644 index 0000000..7e849db --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx @@ -0,0 +1,173 @@ +// file : xsd/cxx/tree/type-factory-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX +#define XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX + +#include <map> +#include <string> +#include <memory> // std::auto_ptr +#include <cstddef> // std::size_t + +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/xml/qualified-name.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct type_factory_map + { + typedef xml::qualified_name<C> qualified_name; + typedef std::auto_ptr<type> (*factory) (const xercesc::DOMElement&, + flags, + container*); + public: + type_factory_map (); + + void + register_type (const qualified_name& name, + factory, + bool override = true); + + void + unregister_type (const qualified_name& name); + + void + register_element (const qualified_name& root, + const qualified_name& subst, + factory); + + void + unregister_element (const qualified_name& root, + const qualified_name& subst); + + std::auto_ptr<type> + create (const C* name, // element name + const C* ns, // element namespace + factory static_type, + bool global, + bool qualified, + const xercesc::DOMElement&, + const qualified_name&, + flags, + container*) const; + + public: + factory + find (const qualified_name& name) const; + + private: + template <typename T> + static std::auto_ptr<type> + traits_adapter (const xercesc::DOMElement&, flags, container*); + + private: + typedef + std::map<qualified_name, factory> + type_map; + + // Map of (root-element to map of (subst-element to factory)). + // + typedef + std::map<qualified_name, factory> + subst_map; + + typedef + std::map<qualified_name, subst_map> + element_map; + + type_map type_map_; + element_map element_map_; + + private: + factory + find_substitution (const subst_map& start, + const qualified_name& name) const; + + // The name argument is as specified in xsi:type. + // + factory + find_type (const std::basic_string<C>& name, + const xercesc::DOMElement&) const; + }; + + + // + // + template<unsigned long id, typename C> + struct type_factory_plate + { + static type_factory_map<C>* map; + static std::size_t count; + + type_factory_plate (); + ~type_factory_plate (); + }; + + template<unsigned long id, typename C> + type_factory_map<C>* type_factory_plate<id, C>::map = 0; + + template<unsigned long id, typename C> + std::size_t type_factory_plate<id, C>::count = 0; + + + // + // + template<unsigned long id, typename C> + inline type_factory_map<C>& + type_factory_map_instance () + { + return *type_factory_plate<id, C>::map; + } + + + // + // + template<typename T> + std::auto_ptr<type> + factory_impl (const xercesc::DOMElement&, flags, container*); + + // + // + template<unsigned long id, typename C, typename T> + struct type_factory_initializer + { + type_factory_initializer (const C* name, const C* ns); + ~type_factory_initializer (); + + private: + const C* name_; + const C* ns_; + }; + + // + // + template<unsigned long id, typename C, typename T> + struct element_factory_initializer + { + element_factory_initializer (const C* root_name, const C* root_ns, + const C* subst_name, const C* subst_ns); + + ~element_factory_initializer (); + + private: + const C* root_name_; + const C* root_ns_; + const C* subst_name_; + const C* subst_ns_; + }; + } + } +} + +#include <xsd/cxx/tree/type-factory-map.txx> + +#endif // XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx b/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx new file mode 100644 index 0000000..b9e0a06 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx @@ -0,0 +1,481 @@ +// file : xsd/cxx/tree/type-factory-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xercesc/validators/schema/SchemaSymbols.hpp> + +#include <xsd/cxx/xml/string.hxx> // xml::{string, transcode} +#include <xsd/cxx/xml/elements.hxx> // xml::{prefix, uq_name} +#include <xsd/cxx/xml/bits/literals.hxx> // xml::bits::{xml_namespace, etc} + +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/bits/literals.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // type_factory_map + // + template <typename C> + type_factory_map<C>:: + type_factory_map () + { + // Register factories for default instantiations of built-in, + // non-fundamental types. + // + + std::basic_string<C> xsd (bits::xml_schema<C> ()); + + + // anyType and anySimpleType. + // + register_type ( + qualified_name (bits::any_type<C> (), xsd), + &factory_impl<type>, + false); + + typedef simple_type<type> simple_type; + register_type ( + qualified_name (bits::any_simple_type<C> (), xsd), + &factory_impl<simple_type>, + false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + qualified_name (bits::string<C> (), xsd), + &factory_impl<string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + qualified_name (bits::normalized_string<C> (), xsd), + &factory_impl<normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + qualified_name (bits::token<C> (), xsd), + &factory_impl<token>, + false); + + typedef name<C, token> name; + register_type ( + qualified_name (bits::name<C> (), xsd), + &factory_impl<name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + qualified_name (bits::nmtoken<C> (), xsd), + &factory_impl<nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + qualified_name (bits::nmtokens<C> (), xsd), + &factory_impl<nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + qualified_name (bits::ncname<C> (), xsd), + &factory_impl<ncname>, + false); + + typedef language<C, token> language; + register_type ( + qualified_name (bits::language<C> (), xsd), + &factory_impl<language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + qualified_name (bits::id<C> (), xsd), + &factory_impl<id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + qualified_name (bits::idref<C> (), xsd), + &factory_impl<idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + qualified_name (bits::idrefs<C> (), xsd), + &factory_impl<idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + qualified_name (bits::any_uri<C> (), xsd), + &factory_impl<uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + qualified_name (bits::qname<C> (), xsd), + &factory_impl<qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + qualified_name (bits::base64_binary<C> (), xsd), + &factory_impl<base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + qualified_name (bits::hex_binary<C> (), xsd), + &factory_impl<hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + qualified_name (bits::gday<C> (), xsd), + &factory_impl<gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + qualified_name (bits::gmonth<C> (), xsd), + &factory_impl<gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + qualified_name (bits::gyear<C> (), xsd), + &factory_impl<gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + qualified_name (bits::gmonth_day<C> (), xsd), + &factory_impl<gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + qualified_name (bits::gyear_month<C> (), xsd), + &factory_impl<gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + qualified_name (bits::date<C> (), xsd), + &factory_impl<date>, + false); + + typedef time<C, simple_type> time; + register_type ( + qualified_name (bits::time<C> (), xsd), + &factory_impl<time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + qualified_name (bits::date_time<C> (), xsd), + &factory_impl<date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + qualified_name (bits::duration<C> (), xsd), + &factory_impl<duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + qualified_name (bits::entity<C> (), xsd), + &factory_impl<entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + qualified_name (bits::entities<C> (), xsd), + &factory_impl<entities>, + false); + } + + template <typename C> + void type_factory_map<C>:: + register_type (const qualified_name& name, + factory f, + bool override) + { + if (override || type_map_.find (name) == type_map_.end ()) + type_map_[name] = f; + } + + template <typename C> + void type_factory_map<C>:: + unregister_type (const qualified_name& name) + { + type_map_.erase (name); + } + + template <typename C> + void type_factory_map<C>:: + register_element (const qualified_name& root, + const qualified_name& subst, + factory f) + { + element_map_[root][subst] = f; + } + + template <typename C> + void type_factory_map<C>:: + unregister_element (const qualified_name& root, + const qualified_name& subst) + { + typename element_map::iterator i (element_map_.find (root)); + + if (i != element_map_.end ()) + { + i->second.erase (subst); + + if (i->second.empty ()) + element_map_.erase (i); + } + } + + template <typename C> + typename type_factory_map<C>::factory type_factory_map<C>:: + find (const qualified_name& name) const + { + typename type_map::const_iterator i (type_map_.find (name)); + return i == type_map_.end () ? 0 : i->second; + } + + template <typename C> + std::auto_ptr<type> type_factory_map<C>:: + create (const C* name, + const C* ns, + factory static_type, + bool global, + bool qualified, + const xercesc::DOMElement& e, + const qualified_name& qn, + tree::flags flags, + container* c) const + { + factory f = 0; + + // See if we've got a straight match. + // + if (qn.name () == name && + (qualified ? qn.namespace_ () == ns : ns[0] == C ('\0'))) + { + f = static_type; + } + else if (global) + { + // See if we have a substitution. + // + typename element_map::const_iterator i ( + element_map_.find (qualified_name (name, ns))); + + if (i != element_map_.end ()) + { + f = find_substitution (i->second, qn); + } + } + + if (f == 0) + return std::auto_ptr<type> (0); // No match. + + // Check for xsi:type + // + { + const XMLCh* v ( + e.getAttributeNS ( + xercesc::SchemaSymbols::fgURI_XSI, + xercesc::SchemaSymbols::fgXSI_TYPE)); + + if (v != 0 && v[0] != XMLCh (0)) + f = find_type (xml::transcode<C> (v), e); + } + + return f (e, flags, c); + } + + template <typename C> + template <typename T> + std::auto_ptr<type> type_factory_map<C>:: + traits_adapter (const xercesc::DOMElement& e, flags f, container* c) + { + std::auto_ptr<T> r (traits<T, C>::create (e, f, c)); + return std::auto_ptr<type> (r.release ()); + } + + template <typename C> + typename type_factory_map<C>::factory type_factory_map<C>:: + find_substitution (const subst_map& start, + const qualified_name& name) const + { + typename subst_map::const_iterator i (start.find (name)); + + if (i != start.end ()) + return i->second; + else + { + for (i = start.begin (); i != start.end (); ++i) + { + typename element_map::const_iterator j ( + element_map_.find (i->first)); + + if (j != element_map_.end ()) + { + if (factory f = find_substitution (j->second, name)) + return f; + } + } + } + + return 0; + } + + template <typename C> + typename type_factory_map<C>::factory type_factory_map<C>:: + find_type (const std::basic_string<C>& name, + const xercesc::DOMElement& e) const + { + using std::basic_string; + + basic_string<C> ns_name, uq_name (xml::uq_name (name)); + + // Copied with modifications from xml/dom/elements.hxx. + // + std::basic_string<C> p (xml::prefix (name)); + + // 'xml' prefix requires special handling and Xerces folks refuse + // to handle this in DOM so I have to do it myself. + // + if (p == xml::bits::xml_prefix<C> ()) + ns_name = xml::bits::xml_namespace<C> (); + else + { + const XMLCh* xns ( + e.lookupNamespaceURI ( + p.empty () ? 0 : xml::string (p).c_str ())); + + if (xns != 0) + ns_name = xml::transcode<C> (xns); + else + { + // See if we've got any no-namespace types. + // + if (!p.empty ()) + throw no_prefix_mapping<C> (p); + } + } + + factory f (find (qualified_name (uq_name, ns_name))); + + if (f == 0) + throw no_type_info<C> (uq_name, ns_name); + + return f; + } + + + // type_factory_plate + // + template<unsigned long id, typename C> + type_factory_plate<id, C>:: + type_factory_plate () + { + if (count == 0) + map = new type_factory_map<C>; + + ++count; + } + + template<unsigned long id, typename C> + type_factory_plate<id, C>:: + ~type_factory_plate () + { + if (--count == 0) + delete map; + } + + + // + // + template<typename T> + std::auto_ptr<type> + factory_impl (const xercesc::DOMElement& e, flags f, container* c) + { + return std::auto_ptr<type> (new T (e, f, c)); + } + + // + // + template<unsigned long id, typename C, typename T> + type_factory_initializer<id, C, T>:: + type_factory_initializer (const C* name, const C* ns) + : name_ (name), ns_ (ns) + { + type_factory_map_instance<id, C> ().register_type ( + xml::qualified_name<C> (name, ns), &factory_impl<T>); + } + + template<unsigned long id, typename C, typename T> + type_factory_initializer<id, C, T>:: + ~type_factory_initializer () + { + type_factory_map_instance<id, C> ().unregister_type ( + xml::qualified_name<C> (name_, ns_)); + } + + // + // + template<unsigned long id, typename C, typename T> + element_factory_initializer<id, C, T>:: + element_factory_initializer (const C* root_name, const C* root_ns, + const C* subst_name, const C* subst_ns) + : root_name_ (root_name), root_ns_ (root_ns), + subst_name_ (subst_name), subst_ns_ (subst_ns) + { + type_factory_map_instance<id, C> ().register_element ( + xml::qualified_name<C> (root_name, root_ns), + xml::qualified_name<C> (subst_name, subst_ns), + &factory_impl<T>); + } + + template<unsigned long id, typename C, typename T> + element_factory_initializer<id, C, T>:: + ~element_factory_initializer () + { + type_factory_map_instance<id, C> ().unregister_element ( + xml::qualified_name<C> (root_name_, root_ns_), + xml::qualified_name<C> (subst_name_, subst_ns_)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx new file mode 100644 index 0000000..491ad3b --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx @@ -0,0 +1,235 @@ +// file : xsd/cxx/tree/type-serializer-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_TYPE_SERIALIZER_MAP_HXX +#define XSD_CXX_TREE_TYPE_SERIALIZER_MAP_HXX + +#include <map> +#include <string> +#include <cstddef> // std::size_t +#include <typeinfo> + +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/tree/elements.hxx> + +#include <xsd/cxx/xml/qualified-name.hxx> +#include <xsd/cxx/xml/dom/serialization-header.hxx> // namespace_infomap + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template <typename C> + struct type_serializer_map + { + typedef std::type_info type_id; + typedef xml::qualified_name<C> qualified_name; + typedef void (*serializer) (xercesc::DOMElement&, const type&); + + void + register_type (const type_id&, + const qualified_name& name, + serializer, + bool override = true); + + void + unregister_type (const type_id&); + + void + register_element (const qualified_name& root, + const qualified_name& subst, + const type_id&, + serializer); + + void + unregister_element (const qualified_name& root, const type_id&); + + public: + void + serialize (const C* name, // element name + const C* ns, // element namespace + bool global, + bool qualified, + xercesc::DOMElement& parent, + const type&) const; + + // Serialize into existing element. + // + void + serialize (const C* static_name, + const C* static_ns, + xercesc::DOMElement&, + const qualified_name&, + const type&) const; + + // Create DOMDocument with root element suitable for serializing + // x into it. + // + xml::dom::auto_ptr<xercesc::DOMDocument> + serialize (const C* name, // element name + const C* ns, // element namespace + const xml::dom::namespace_infomap<C>&, + const type& x, + unsigned long flags) const; + + public: + type_serializer_map (); + + public: + struct type_info + { + type_info (const qualified_name& name, + typename type_serializer_map::serializer serializer) + : name_ (name), serializer_ (serializer) + { + } + + const qualified_name& + name () const + { + return name_; + } + + typename type_serializer_map::serializer + serializer () const + { + return serializer_; + } + + // For std::map. + // + type_info () + : name_ (std::basic_string<C> (), std::basic_string<C> ()), + serializer_ (0) + { + } + + private: + qualified_name name_; + typename type_serializer_map::serializer serializer_; + }; + + public: + const type_info* + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map<const type_id*, type_info, type_id_comparator> + type_map; + + // Map of (root-element to map of (type_id to type_info)). + // Note that here type_info::name is element name. + // + typedef + std::map<const type_id*, type_info, type_id_comparator> + subst_map; + + typedef + std::map<qualified_name, subst_map> + element_map; + + type_map type_map_; + element_map element_map_; + + private: + const type_info* + find_substitution (const subst_map& start, const type_id&) const; + + // Sets an xsi:type attribute corresponding to the type_info. + // + void + set_xsi_type (xercesc::DOMElement& parent, + xercesc::DOMElement&, + const type_info&) const; + }; + + + // + // + template<unsigned long id, typename C> + struct type_serializer_plate + { + static type_serializer_map<C>* map; + static std::size_t count; + + type_serializer_plate (); + ~type_serializer_plate (); + }; + + template<unsigned long id, typename C> + type_serializer_map<C>* type_serializer_plate<id, C>::map = 0; + + template<unsigned long id, typename C> + std::size_t type_serializer_plate<id, C>::count = 0; + + + // + // + template<unsigned long id, typename C> + inline type_serializer_map<C>& + type_serializer_map_instance () + { + return *type_serializer_plate<id, C>::map; + } + + // + // + template<typename T> + void + serializer_impl (xercesc::DOMElement&, const type&); + + + // + // + template<unsigned long id, typename C, typename T> + struct type_serializer_initializer + { + type_serializer_initializer (const C* name, const C* ns); + ~type_serializer_initializer (); + }; + + + // + // + template<unsigned long id, typename C, typename T> + struct element_serializer_initializer + { + element_serializer_initializer (const C* root_name, const C* root_ns, + const C* subst_name, const C* subst_ns); + + ~element_serializer_initializer (); + + private: + const C* root_name_; + const C* root_ns_; + }; + } + } +} + +#include <xsd/cxx/tree/type-serializer-map.txx> + +#endif // XSD_CXX_TREE_TYPE_SERIALIZER_MAP_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx new file mode 100644 index 0000000..859331f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx @@ -0,0 +1,576 @@ +// file : xsd/cxx/tree/type-serializer-map.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xercesc/util/XMLUni.hpp> +#include <xercesc/validators/schema/SchemaSymbols.hpp> + +#include <xsd/cxx/xml/bits/literals.hxx> // xml::bits::{xsi_namespace, type} +#include <xsd/cxx/xml/dom/serialization-source.hxx> // dom::{create_*, prefix} + +#include <xsd/cxx/tree/types.hxx> +#include <xsd/cxx/tree/bits/literals.hxx> + +#include <iostream> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // type_serializer_map + // + template <typename C> + type_serializer_map<C>:: + type_serializer_map () + { + // Register serializers for built-in non-fundamental types. + // + std::basic_string<C> xsd (bits::xml_schema<C> ()); + + + // anyType and anySimpleType. + // + register_type ( + typeid (type), + qualified_name (bits::any_type<C> (), xsd), + &serializer_impl<type>, + false); + + typedef simple_type<type> simple_type; + register_type ( + typeid (simple_type), + qualified_name (bits::any_simple_type<C> (), xsd), + &serializer_impl<simple_type>, + false); + + + // Strings + // + typedef string<C, simple_type> string; + register_type ( + typeid (string), + qualified_name (bits::string<C> (), xsd), + &serializer_impl<string>, + false); + + typedef normalized_string<C, string> normalized_string; + register_type ( + typeid (normalized_string), + qualified_name (bits::normalized_string<C> (), xsd), + &serializer_impl<normalized_string>, + false); + + typedef token<C, normalized_string> token; + register_type ( + typeid (token), + qualified_name (bits::token<C> (), xsd), + &serializer_impl<token>, + false); + + typedef name<C, token> name; + register_type ( + typeid (name), + qualified_name (bits::name<C> (), xsd), + &serializer_impl<name>, + false); + + typedef nmtoken<C, token> nmtoken; + register_type ( + typeid (nmtoken), + qualified_name (bits::nmtoken<C> (), xsd), + &serializer_impl<nmtoken>, + false); + + typedef nmtokens<C, simple_type, nmtoken> nmtokens; + register_type ( + typeid (nmtokens), + qualified_name (bits::nmtokens<C> (), xsd), + &serializer_impl<nmtokens>, + false); + + typedef ncname<C, name> ncname; + register_type ( + typeid (ncname), + qualified_name (bits::ncname<C> (), xsd), + &serializer_impl<ncname>, + false); + + typedef language<C, token> language; + register_type ( + typeid (language), + qualified_name (bits::language<C> (), xsd), + &serializer_impl<language>, + false); + + + // ID/IDREF. + // + typedef id<C, ncname> id; + register_type ( + typeid (id), + qualified_name (bits::id<C> (), xsd), + &serializer_impl<id>, + false); + + typedef idref<C, ncname, type> idref; + register_type ( + typeid (idref), + qualified_name (bits::idref<C> (), xsd), + &serializer_impl<idref>, + false); + + typedef idrefs<C, simple_type, idref> idrefs; + register_type ( + typeid (idrefs), + qualified_name (bits::idrefs<C> (), xsd), + &serializer_impl<idrefs>, + false); + + + // URI. + // + typedef uri<C, simple_type> uri; + register_type ( + typeid (uri), + qualified_name (bits::any_uri<C> (), xsd), + &serializer_impl<uri>, + false); + + + // Qualified name. + // + typedef qname<C, simple_type, uri, ncname> qname; + register_type ( + typeid (qname), + qualified_name (bits::qname<C> (), xsd), + &serializer_impl<qname>, + false); + + + // Binary. + // + typedef base64_binary<C, simple_type> base64_binary; + register_type ( + typeid (base64_binary), + qualified_name (bits::base64_binary<C> (), xsd), + &serializer_impl<base64_binary>, + false); + + typedef hex_binary<C, simple_type> hex_binary; + register_type ( + typeid (hex_binary), + qualified_name (bits::hex_binary<C> (), xsd), + &serializer_impl<hex_binary>, + false); + + + // Date/time. + // + typedef gday<C, simple_type> gday; + register_type ( + typeid (gday), + qualified_name (bits::gday<C> (), xsd), + &serializer_impl<gday>, + false); + + typedef gmonth<C, simple_type> gmonth; + register_type ( + typeid (gmonth), + qualified_name (bits::gmonth<C> (), xsd), + &serializer_impl<gmonth>, + false); + + typedef gyear<C, simple_type> gyear; + register_type ( + typeid (gyear), + qualified_name (bits::gyear<C> (), xsd), + &serializer_impl<gyear>, + false); + + typedef gmonth_day<C, simple_type> gmonth_day; + register_type ( + typeid (gmonth_day), + qualified_name (bits::gmonth_day<C> (), xsd), + &serializer_impl<gmonth_day>, + false); + + typedef gyear_month<C, simple_type> gyear_month; + register_type ( + typeid (gyear_month), + qualified_name (bits::gyear_month<C> (), xsd), + &serializer_impl<gyear_month>, + false); + + typedef date<C, simple_type> date; + register_type ( + typeid (date), + qualified_name (bits::date<C> (), xsd), + &serializer_impl<date>, + false); + + typedef time<C, simple_type> time; + register_type ( + typeid (time), + qualified_name (bits::time<C> (), xsd), + &serializer_impl<time>, + false); + + typedef date_time<C, simple_type> date_time; + register_type ( + typeid (date_time), + qualified_name (bits::date_time<C> (), xsd), + &serializer_impl<date_time>, + false); + + typedef duration<C, simple_type> duration; + register_type ( + typeid (duration), + qualified_name (bits::duration<C> (), xsd), + &serializer_impl<duration>, + false); + + + // Entity. + // + typedef entity<C, ncname> entity; + register_type ( + typeid (entity), + qualified_name (bits::entity<C> (), xsd), + &serializer_impl<entity>, + false); + + typedef entities<C, simple_type, entity> entities; + register_type ( + typeid (entities), + qualified_name (bits::entities<C> (), xsd), + &serializer_impl<entities>, + false); + } + + template <typename C> + void type_serializer_map<C>:: + register_type (const type_id& tid, + const qualified_name& name, + serializer s, + bool override) + { + if (override || type_map_.find (&tid) == type_map_.end ()) + type_map_[&tid] = type_info (name, s); + } + + template <typename C> + void type_serializer_map<C>:: + unregister_type (const type_id& tid) + { + type_map_.erase (&tid); + } + + template <typename C> + void type_serializer_map<C>:: + register_element (const qualified_name& root, + const qualified_name& subst, + const type_id& tid, + serializer s) + { + element_map_[root][&tid] = type_info (subst, s); + } + + template <typename C> + void type_serializer_map<C>:: + unregister_element (const qualified_name& root, const type_id& tid) + { + typename element_map::iterator i (element_map_.find (root)); + + if (i != element_map_.end ()) + { + i->second.erase (&tid); + + if (i->second.empty ()) + element_map_.erase (root); + } + } + + template <typename C> + void type_serializer_map<C>:: + serialize (const C* name, // element name + const C* ns, // element namespace + bool global, + bool qualified, + xercesc::DOMElement& parent, + const type& x) const + { + const type_id& tid (typeid (x)); + + // First see if we can find a substitution. + // + if (global) + { + typename element_map::const_iterator i ( + element_map_.find (qualified_name (name, ns))); + + if (i != element_map_.end ()) + { + if (const type_info* ti = find_substitution (i->second, tid)) + { + xercesc::DOMElement& e ( + xml::dom::create_element ( + ti->name ().name ().c_str (), + ti->name ().namespace_ ().c_str (), + parent)); + + ti->serializer () (e, x); + return; + } + } + } + + // The last resort is xsi:type. + // + if (const type_info* ti = find (tid)) + { + xercesc::DOMElement& e ( + qualified + ? xml::dom::create_element (name, ns, parent) + : xml::dom::create_element (name, parent)); + + ti->serializer () (e, x); + set_xsi_type (parent, e, *ti); + return; + } + + throw no_type_info<C> (std::basic_string<C> (), + std::basic_string<C> ()); //@@ TODO + } + + template <typename C> + void type_serializer_map<C>:: + serialize (const C* static_name, + const C* static_ns, + xercesc::DOMElement& e, + const qualified_name& qn, + const type& x) const + { + const type_id& tid (typeid (x)); + + // First see if this is a substitution. + // + if (qn.name () != static_name || qn.namespace_ () != static_ns) + { + typename element_map::const_iterator i ( + element_map_.find (qualified_name (static_name, static_ns))); + + if (i != element_map_.end ()) + { + if (const type_info* ti = find_substitution (i->second, tid)) + { + if (ti->name ().name () != qn.name () || + ti->name ().namespace_ () != qn.namespace_ ()) + { + throw unexpected_element<C> ( + qn.name (), qn.namespace_ (), + ti->name ().name (), ti->name ().namespace_ ()); + } + + ti->serializer () (e, x); + return; + } + } + + // This is not a valid substitution. + // + throw unexpected_element<C> (qn.name (), qn.namespace_ (), + static_name, static_ns); + } + + // The last resort is xsi:type. + // + if (const type_info* ti = find (tid)) + { + ti->serializer () (e, x); + set_xsi_type (e, e, *ti); + return; + } + + throw no_type_info<C> (std::basic_string<C> (), + std::basic_string<C> ()); //@@ TODO + } + + template <typename C> + xml::dom::auto_ptr<xercesc::DOMDocument> type_serializer_map<C>:: + serialize (const C* name, + const C* ns, + const xml::dom::namespace_infomap<C>& m, + const type& x, + unsigned long flags) const + { + const type_id& tid (typeid (x)); + + // See if we can find a substitution. + // + { + typename element_map::const_iterator i ( + element_map_.find (qualified_name (name, ns))); + + if (i != element_map_.end ()) + { + if (const type_info* ti = find_substitution (i->second, tid)) + { + return xml::dom::serialize<C> ( + ti->name ().name (), ti->name ().namespace_ (), m, flags); + } + } + } + + // If there is no substitution then serialize() will have to + // find suitable xsi:type. + // + return xml::dom::serialize<C> (name, ns, m, flags); + } + + template <typename C> + const typename type_serializer_map<C>::type_info* + type_serializer_map<C>:: + find (const type_id& tid) const + { + typename type_map::const_iterator i (type_map_.find (&tid)); + return i == type_map_.end () ? 0 : &i->second; + } + + template <typename C> + const typename type_serializer_map<C>::type_info* + type_serializer_map<C>:: + find_substitution (const subst_map& start, const type_id& tid) const + { + typename subst_map::const_iterator i (start.find (&tid)); + + if (i != start.end ()) + return &i->second; + else + { + for (i = start.begin (); i != start.end (); ++i) + { + typename element_map::const_iterator j ( + element_map_.find (i->second.name ())); + + if (j != element_map_.end ()) + { + if (const type_info* ti = find_substitution (j->second, tid)) + return ti; + } + } + } + + return 0; + } + + template <typename C> + void type_serializer_map<C>:: + set_xsi_type (xercesc::DOMElement& parent, + xercesc::DOMElement& e, + const type_info& ti) const + { + std::basic_string<C> id; + const std::basic_string<C>& ns (ti.name ().namespace_ ()); + + if (!ns.empty ()) + { + id = xml::dom::prefix (ns, e); + + if (!id.empty ()) + id += C (':'); + } + + id += ti.name ().name (); + + std::basic_string<C> name = xml::dom::prefix ( + xml::bits::xsi_namespace<C> (), parent, xml::bits::xsi_prefix<C> ()); + + if (!name.empty ()) + name += C (':'); + + name += xml::bits::type<C> (); + + e.setAttributeNS ( + xercesc::SchemaSymbols::fgURI_XSI, + xml::string (name).c_str (), + xml::string (id).c_str ()); + } + + + // type_serializer_plate + // + template<unsigned long id, typename C> + type_serializer_plate<id, C>:: + type_serializer_plate () + { + if (count == 0) + map = new type_serializer_map<C>; + + ++count; + } + + template<unsigned long id, typename C> + type_serializer_plate<id, C>:: + ~type_serializer_plate () + { + if (--count == 0) + delete map; + } + + + // + // + template<typename T> + void + serializer_impl (xercesc::DOMElement& e, const type& x) + { + e << static_cast<const T&> (x); + } + + // type_serializer_initializer + // + template<unsigned long id, typename C, typename T> + type_serializer_initializer<id, C, T>:: + type_serializer_initializer (const C* name, const C* ns) + { + type_serializer_map_instance<id, C> ().register_type ( + typeid (T), + xml::qualified_name<C> (name, ns), + &serializer_impl<T>); + } + + template<unsigned long id, typename C, typename T> + type_serializer_initializer<id, C, T>:: + ~type_serializer_initializer () + { + type_serializer_map_instance<id, C> ().unregister_type (typeid (T)); + } + + // element_serializer_initializer + // + template<unsigned long id, typename C, typename T> + element_serializer_initializer<id, C, T>:: + element_serializer_initializer (const C* root_name, const C* root_ns, + const C* subst_name, const C* subst_ns) + : root_name_ (root_name), root_ns_ (root_ns) + { + type_serializer_map_instance<id, C> ().register_element ( + xml::qualified_name<C> (root_name, root_ns), + xml::qualified_name<C> (subst_name, subst_ns), + typeid (T), + &serializer_impl<T>); + } + + template<unsigned long id, typename C, typename T> + element_serializer_initializer<id, C, T>:: + ~element_serializer_initializer () + { + type_serializer_map_instance<id, C> ().unregister_element ( + xml::qualified_name<C> (root_name_, root_ns_), typeid (T)); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/types.hxx b/xsd/libxsd/xsd/cxx/tree/types.hxx new file mode 100644 index 0000000..299824f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/types.hxx @@ -0,0 +1,3791 @@ +// file : xsd/cxx/tree/types.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains C++ class definitions for XML Schema built-in types. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef XSD_CXX_TREE_TYPES_HXX +#define XSD_CXX_TREE_TYPES_HXX + +#include <string> +#include <cstddef> // std::size_t + +#include <xercesc/dom/DOMAttr.hpp> +#include <xercesc/dom/DOMElement.hpp> + +#include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/list.hxx> +#include <xsd/cxx/tree/buffer.hxx> +#include <xsd/cxx/tree/istream-fwd.hxx> + +#include <xsd/cxx/tree/date-time.hxx> + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + /** + * @brief Class corresponding to the XML Schema %string built-in + * type. + * + * The %string class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class string: public B, public std::basic_string<C> + { + typedef std::basic_string<C> base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates an empty %string. + */ + string () + { + } + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + string (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + string (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + string (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + string (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + string (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + string (const string& x, flags f = 0, container* c = 0) + : B (x, f, c), base_type (x) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual string* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + string (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + string (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + string (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + string (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %string has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + string& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %string contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + string& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %string contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + string& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + string& + operator= (const string& x) + { + base () = x; + return *this; + } + }; + + + /** + * @brief Class corresponding to the XML Schema normalizedString + * built-in type. + * + * The %normalized_string class publicly inherits from and has + * the same set of constructors as @c std::basic_string. It + * therefore can be used as @c std::string (or @c std::wstring + * if you are using @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class normalized_string: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates an empty %normalized_string. + */ + normalized_string () + { + } + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + normalized_string (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + normalized_string (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + normalized_string (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + normalized_string (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + normalized_string (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + normalized_string (const normalized_string& x, + flags f = 0, + container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual normalized_string* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + normalized_string (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + normalized_string (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + normalized_string (const xercesc::DOMAttr& a, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + normalized_string (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %normalized_string has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + normalized_string& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %normalized_string contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + normalized_string& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %normalized_string contains a copy of the standard + * %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + normalized_string& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + normalized_string& + operator= (const normalized_string& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + void + normalize (); + + //@endcond + }; + + + /** + * @brief Class corresponding to the XML Schema %token built-in + * type. + * + * The %token class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class token: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates an empty %token. + */ + token () + { + } + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + token (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + token (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + token (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + token (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + token (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + token (const token& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual token* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + token (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + token (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + token (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + token (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %token has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + token& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %token contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + token& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %token contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + token& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + token& + operator= (const token& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + void + collapse (); + + //@endcond + }; + + + /** + * @brief Class corresponding to the XML Schema NMTOKEN built-in + * type. + * + * The %nmtoken class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class nmtoken: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + nmtoken (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + nmtoken (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + nmtoken (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + nmtoken (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + nmtoken (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + nmtoken (const nmtoken& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual nmtoken* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + nmtoken (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtoken (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtoken (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtoken (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %nmtoken has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + nmtoken& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %nmtoken contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + nmtoken& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %nmtoken contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + nmtoken& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + nmtoken& + operator= (const nmtoken& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + nmtoken () + : base_type () + { + } + + //@endcond + }; + + + /** + * @brief Class corresponding to the XML Schema NMTOKENS built-in + * type. + * + * The %nmtokens class is a vector (or %list in XML Schema terminology) + * of nmtoken elements. It is implemented in terms of the list class + * template. + * + * @nosubgrouping + */ + template <typename C, typename B, typename nmtoken> + class nmtokens: public B, public list<nmtoken, C> + { + typedef list<nmtoken, C> base_type; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates no elements. + */ + nmtokens () + : base_type (0, this) + { + } + + /** + * @brief Initialize the instance with copies of an exemplar elements. + * + * @param n A number of elements to copy. + * @param x An exemplar element to copy. + */ + nmtokens (typename base_type::size_type n, const nmtoken& x) + : base_type (n, x, this) + { + } + + /** + * @brief Initialize the instance with copies of elements from an + * iterator range. + * + * @param begin An iterator pointing to the first element. + * @param end An iterator pointing to the one past the last element. + */ + template <typename I> + nmtokens (const I& begin, const I& end) + : base_type (begin, end, this) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + nmtokens (const nmtokens& x, flags f, container* c = 0) + : B (x, f, c), base_type (x, f, this) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual nmtokens* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + nmtokens (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtokens (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtokens (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + nmtokens (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + }; + + + /** + * @brief Class corresponding to the XML Schema Name built-in + * type. + * + * The %name class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class name: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + name (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + name (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + name (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + name (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + name (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + name (const name& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual name* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + name (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + name (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + name (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + name (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %name has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + name& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %name contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + name& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %name contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + name& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + name& + operator= (const name& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + name () + : base_type () + { + } + + //@endcond + }; + + + // Forward declaration for Sun CC. + // + template <typename C, typename B, typename uri, typename ncname> + class qname; + + + /** + * @brief Class corresponding to the XML Schema NCame built-in + * type. + * + * The %ncname class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class ncname: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + ncname (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + ncname (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + ncname (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + ncname (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + ncname (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + ncname (const ncname& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual ncname* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + ncname (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + ncname (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + ncname (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + ncname (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %ncname has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + ncname& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %ncname contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + ncname& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %ncname contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + ncname& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + ncname& + operator= (const ncname& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + ncname () + : base_type () + { + } + + //@endcond + + template <typename, typename, typename, typename> + friend class qname; + }; + + + /** + * @brief Class corresponding to the XML Schema %language built-in + * type. + * + * The %language class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class language: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + language (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + language (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + language (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + language (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + language (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + language (const language& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual language* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + language (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + language (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + language (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + language (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %language has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + language& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %language contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + language& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %language contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + language& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + language& + operator= (const language& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + language () + : base_type () + { + } + + //@endcond + }; + + + //@cond + + template <typename C, typename ncname> + struct identity_impl: identity + { + identity_impl (const ncname& id) + : id_ (id) + { + } + + virtual bool + before (const identity& y) const; + + virtual void + throw_duplicate_id () const; + + private: + const ncname& id_; + }; + + //@endcond + + + /** + * @brief Class corresponding to the XML Schema ID built-in + * type. + * + * The %id class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class id: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + ~id() + { + unregister_id (); + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + id (const C* s) + : base_type (s), identity_ (*this) + { + register_id (); + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + id (const C* s, std::size_t n) + : base_type (s, n), identity_ (*this) + { + register_id (); + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + id (std::size_t n, C c) + : base_type (n, c), identity_ (*this) + { + register_id (); + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + id (const std::basic_string<C>& s) + : base_type (s), identity_ (*this) + { + register_id (); + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + id (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n), identity_ (*this) + { + register_id (); + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + id (const id& x, flags f = 0, container* c = 0) + : base_type (x, f, c), identity_ (*this) + { + register_id (); + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual id* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + id (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + id (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + id (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + id (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %id has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + id& + operator= (C c); + + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %id contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + id& + operator= (const C* s); + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %id contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + id& + operator= (const std::basic_string<C>& s); + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + id& + operator= (const id& x); + + public: + //@cond + + virtual void + _container (container*); + + // The above override also hides other _container versions. We + // also cannot do using-declarations because of bugs in HP aCC3. + // + const container* + _container () const + { + return B::_container (); + } + + container* + _container () + { + return B::_container (); + } + + //@endcond + + protected: + //@cond + + id () + : base_type (), identity_ (*this) + { + register_id (); + } + + //@endcond + + private: + void + register_id (); + + void + unregister_id (); + + private: + identity_impl<C, B> identity_; + }; + + + /** + * @brief Class corresponding to the XML Schema IDREF built-in + * type. + * + * The %idref class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * The %idref class also provides an autopointer-like interface + * for resolving referenced objects. By default the object is + * returned as type (mapping for anyType) but statically-typed + * %idref can be created using the XML Schema extension. See the + * C++/Tree Mapping User Manual for more information. + * + * @nosubgrouping + */ + template <typename C, typename B, typename T> + class idref: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @brief Referenced type. + */ + typedef T ref_type; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + idref (const C* s) + : base_type (s), identity_ (*this) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + idref (const C* s, std::size_t n) + : base_type (s, n), identity_ (*this) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + idref (std::size_t n, C c) + : base_type (n, c), identity_ (*this) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + idref (const std::basic_string<C>& s) + : base_type (s), identity_ (*this) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + idref (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n), identity_ (*this) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + idref (const idref& x, flags f = 0, container* c = 0) + : base_type (x, f, c), identity_ (*this) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual idref* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + idref (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idref (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idref (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idref (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %idref has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + idref& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %idref contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + idref& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %idref contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + idref& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + idref& + operator= (const idref& x) + { + base () = x; + return *this; + } + + public: + /** + * @brief Call referenced object. + * + * @return A constant pointer to the referenced object. + */ + const ref_type* + operator-> () const + { + return get (); + } + + /** + * @brief Call referenced object. + * + * @return A pointer to the referenced object. + */ + ref_type* + operator-> () + { + return get (); + } + + /** + * @brief Dereference referenced object. + * + * @return A constant C++ reference to the referenced object. + */ + const ref_type& + operator* () const + { + return *(get ()); + } + + /** + * @brief Dereference referenced object. + * + * @return A C++ reference to the referenced object. + */ + ref_type& + operator* () + { + return *(get ()); + } + + /** + * @brief Get a constant pointer to the referenced object. + * + * @return A constant pointer to the referenced object or 0 if + * the object is not found. + */ + const ref_type* + get () const + { + return dynamic_cast<const ref_type*> (get_ ()); + } + + /** + * @brief Get a pointer to the referenced object. + * + * @return A pointer to the referenced object or 0 if the object + * is not found. + */ + ref_type* + get () + { + return dynamic_cast<ref_type*> (get_ ()); + } + + /** + * @brief Opaque type that can be evaluated as true or false. + */ + typedef void (idref::*bool_convertible)(); + + /** + * @brief Implicit conversion to boolean type. + * + * @return True if the referenced object is found, false otherwise. + */ + operator bool_convertible () const + { + return get_ () ? &idref::true_ : 0; + } + + protected: + //@cond + + idref () + : base_type (), identity_ (*this) + { + } + + //@endcond + + private: + const _type* + get_ () const; + + _type* + get_ (); + + void + true_ (); + + private: + identity_impl<C, B> identity_; + }; + + + /** + * @brief Class corresponding to the XML Schema IDREFS built-in + * type. + * + * The %idrefs class is a vector (or %list in XML Schema terminology) + * of idref elements. It is implemented in terms of the list class + * template. + * + * @nosubgrouping + */ + template <typename C, typename B, typename idref> + class idrefs: public B, public list<idref, C> + { + typedef list<idref, C> base_type; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates no elements. + */ + idrefs () + : base_type (0, this) + { + } + + /** + * @brief Initialize the instance with copies of an exemplar elements. + * + * @param n A number of elements to copy. + * @param x An exemplar element to copy. + */ + idrefs (typename base_type::size_type n, const idref& x) + : base_type (n, x, this) + { + } + + /** + * @brief Initialize the instance with copies of elements from an + * iterator range. + * + * @param begin An iterator pointing to the first element. + * @param end An iterator pointing to the one past the last element. + */ + template <typename I> + idrefs (const I& begin, const I& end) + : base_type (begin, end, this) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + idrefs (const idrefs& x, flags f = 0, container* c = 0) + : B (x, f, c), base_type (x, f, this) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual idrefs* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + idrefs (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idrefs (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idrefs (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + idrefs (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + }; + + + /** + * @brief Class corresponding to the XML Schema anyURI built-in + * type. + * + * The %uri class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class uri: public B, public std::basic_string<C> + { + typedef std::basic_string<C> base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + uri (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + uri (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + uri (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + uri (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + uri (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + uri (const uri& x, flags f = 0, container* c = 0) + : B (x, f, c), base_type (x) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual uri* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + uri (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + uri (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + uri (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + uri (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %uri has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + uri& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %uri contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + uri& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %uri contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + uri& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + uri& + operator= (const uri& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + uri () + : base_type () + { + } + + //@endcond + + template <typename, typename, typename, typename> + friend class qname; + }; + + + /** + * @brief Class corresponding to the XML Schema QName built-in + * type. + * + * The %qname class represents a potentially namespace-qualified + * XML %name. + * + * @nosubgrouping + */ + template <typename C, typename B, typename uri, typename ncname> + class qname: public B + { + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a %name only. + * + * The resulting %qname is unqualified. + * + * @param n An XML %name (ncname). + */ + qname (const ncname& n) + : ns_ (), name_ (n) + { + } + + /** + * @brief Initialize an instance with a %name and a namespace. + * + * The resulting %qname is qualified. + * + * @param ns An XML namespace (uri). + * @param n An XML %name (ncname). + */ + qname (const uri& ns, const ncname& n) + : ns_ (ns), name_ (n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + qname (const qname& x, flags f = 0, container* c = 0) + : B (x, f, c), + ns_ (x.ns_), + name_ (x.name_) + { + // Note that ns_ and name_ have no DOM association. + // + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual qname* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + qname (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + qname (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + qname (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + qname (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Determine if the %name is qualified. + * + * @return True if the %name is qualified, false otherwise. + */ + bool + qualified () const + { + return !ns_.empty (); + } + + /** + * @brief Get XML namespace. + * + * @return A constant reference to qualifying XML namespace. + */ + const uri& + namespace_ () const + { + return ns_; + } + + /** + * @brief Get XML %name. + * + * @return A constant reference to unqualified XML %name. + */ + const ncname& + name () const + { + return name_; + } + + protected: + //@cond + + qname () + : ns_ (), name_ () + { + } + + //@endcond + + private: + static uri + resolve (const std::basic_string<C>&, const xercesc::DOMElement*); + + private: + uri ns_; + ncname name_; + }; + + /** + * @brief %qname comparison operator. + * + * @return True if the names are equal, false otherwise. + */ + template <typename C, typename B, typename uri, typename ncname> + inline bool + operator== (const qname<C, B, uri, ncname>& a, + const qname<C, B, uri, ncname>& b) + { + return a.name () == b.name () && a.namespace_ () == b.namespace_ (); + } + + /** + * @brief %qname comparison operator. + * + * @return True if the names are not equal, false otherwise. + */ + template <typename C, typename B, typename uri, typename ncname> + inline bool + operator!= (const qname<C, B, uri, ncname>& a, + const qname<C, B, uri, ncname>& b) + { + return !(a == b); + } + + + /** + * @brief Class corresponding to the XML Schema base64Binary + * built-in type. + * + * The %base64_binary class is a binary %buffer abstraction with + * base64-encoded representation in XML. It publicly inherits from + * the buffer class which provides the %buffer functionality. + * + * @nosubgrouping + */ + template <typename C, typename B> + class base64_binary: public B, public buffer<C> + { + public: + typedef typename buffer<C>::size_t size_t; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Allocate a %buffer of the specified size. + * + * The resulting %buffer has the same size and capacity. + * + * @param size A %buffer size in bytes. + */ + explicit + base64_binary (size_t size = 0); + + /** + * @brief Allocate a %buffer of the specified size and capacity. + * + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + base64_binary (size_t size, size_t capacity); + + /** + * @brief Allocate a %buffer of the specified size and copy + * the data. + * + * The resulting %buffer has the same size and capacity with + * @a size bytes copied from @a data. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + */ + base64_binary (const void* data, size_t size); + + /** + * @brief Allocate a %buffer of the specified size and capacity + * and copy the data. + * + * @a size bytes are copied from @a data to the resulting + * %buffer. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + base64_binary (const void* data, size_t size, size_t capacity); + + /** + * @brief Reuse an existing %buffer. + * + * If the @a assume_ownership argument is true, the %buffer will + * assume ownership of @a data and will release the memory + * by calling @c operator @c delete(). + * + * @param data A %buffer to reuse. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @param assume_ownership A boolean value indication whether to + * assume ownership. + * @throw bounds If @a size exceeds @a capacity + */ + base64_binary (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + base64_binary (const base64_binary& x, + flags f = 0, + container* c = 0) + : B (x, f, c), buffer<C> (x) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual base64_binary* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + base64_binary (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + base64_binary (const xercesc::DOMElement& e, + flags f = 0, + container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + base64_binary (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + base64_binary (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + base64_binary& + operator= (const base64_binary& x) + { + buffer<C>& b (*this); + b = x; + return *this; + } + + public: + /** + * @brief Encode the %buffer in base64 encoding. + * + * @return A %string with base64-encoded data. + */ + std::basic_string<C> + encode () const; + + private: + void + decode (const XMLCh*); + }; + + + /** + * @brief Class corresponding to the XML Schema hexBinary + * built-in type. + * + * The %hex_binary class is a binary %buffer abstraction with + * hex-encoded representation in XML. It publicly inherits from + * the buffer class which provides the %buffer functionality. + * + * @nosubgrouping + */ + template <typename C, typename B> + class hex_binary: public B, public buffer<C> + { + public: + typedef typename buffer<C>::size_t size_t; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Allocate a %buffer of the specified size. + * + * The resulting %buffer has the same size and capacity. + * + * @param size A %buffer size in bytes. + */ + explicit + hex_binary (size_t size = 0); + + /** + * @brief Allocate a %buffer of the specified size and capacity. + * + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + hex_binary (size_t size, size_t capacity); + + /** + * @brief Allocate a %buffer of the specified size and copy + * the data. + * + * The resulting %buffer has the same size and capacity with + * @a size bytes copied from @a data. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + */ + hex_binary (const void* data, size_t size); + + /** + * @brief Allocate a %buffer of the specified size and capacity + * and copy the data. + * + * @a size bytes are copied from @a data to the resulting + * %buffer. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + hex_binary (const void* data, size_t size, size_t capacity); + + /** + * @brief Reuse an existing %buffer.. + * + * If the @a assume_ownership argument is true, the %buffer will + * assume ownership of @a data and will release the memory + * by calling @c operator @c delete(). + * + * @param data A %buffer to reuse. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @param assume_ownership A boolean value indication whether to + * assume ownership. + * @throw bounds If @a size exceeds @a capacity + */ + hex_binary (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + hex_binary (const hex_binary& x, flags f = 0, container* c = 0) + : B (x, f, c), buffer<C> (x) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual hex_binary* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + hex_binary (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + hex_binary (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + hex_binary (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + hex_binary (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + hex_binary& + operator= (const hex_binary& x) + { + buffer<C>& b (*this); + b = x; + return *this; + } + + public: + /** + * @brief Encode the %buffer in hex encoding. + * + * @return A %string with hex-encoded data. + */ + std::basic_string<C> + encode () const; + + private: + void + decode (const XMLCh*); + }; + + + /** + * @brief Class corresponding to the XML Schema ENTITY built-in + * type. + * + * The %entity class publicly inherits from and has the same set + * of constructors as @c std::basic_string. It therefore can be + * used as @c std::string (or @c std::wstring if you are using + * @c wchar_t as the character type). + * + * @nosubgrouping + */ + template <typename C, typename B> + class entity: public B + { + typedef B base_type; + + base_type& + base () + { + return *this; + } + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Initialize an instance with a copy of a C %string. + * + * @param s A C %string to copy. + */ + entity (const C* s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a character array. + * + * @param s A character array to copy. + * @param n A number of character to copy. + */ + entity (const C* s, std::size_t n) + : base_type (s, n) + { + } + + /** + * @brief Initialize an instance with multiple copies of the same + * character. + * + * @param n A number of copies to create. + * @param c A character to copy. + */ + entity (std::size_t n, C c) + : base_type (n, c) + { + } + + /** + * @brief Initialize an instance with a copy of a standard %string. + * + * @param s A standard %string to copy. + */ + entity (const std::basic_string<C>& s) + : base_type (s) + { + } + + /** + * @brief Initialize an instance with a copy of a substring. + * + * @param s A standard %string to copy the substring from. + * @param pos An index of the first character to copy from. + * @param n A number of characters to copy. + */ + entity (const std::basic_string<C>& s, + std::size_t pos, + std::size_t n = std::basic_string<C>::npos) + : base_type (s, pos, n) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + entity (const entity& x, flags f = 0, container* c = 0) + : base_type (x, f, c) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual entity* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + entity (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entity (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entity (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entity (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + + public: + /** + * @brief Assign a character to the instance. + * + * The resulting %entity has only one character. + * + * @param c A character to assign. + * @return A reference to the instance. + */ + entity& + operator= (C c) + { + base () = c; + return *this; + } + + /** + * @brief Assign a C %string to the instance. + * + * The resulting %entity contains a copy of the C %string. + * + * @param s A C %string to assign. + * @return A reference to the instance. + */ + entity& + operator= (const C* s) + { + base () = s; + return *this; + } + + /** + * @brief Assign a standard %string to the instance. + * + * The resulting %entity contains a copy of the standard %string. + * + * @param s A standard %string to assign. + * @return A reference to the instance. + */ + entity& + operator= (const std::basic_string<C>& s) + { + base () = s; + return *this; + } + + /** + * @brief Copy assignment operator. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + entity& + operator= (const entity& x) + { + base () = x; + return *this; + } + + protected: + //@cond + + entity () + : base_type () + { + } + + //@endcond + }; + + + /** + * @brief Class corresponding to the XML Schema ENTITIES built-in + * type. + * + * The %entities class is a vector (or %list in XML Schema terminology) + * of entity elements. It is implemented in terms of the list class + * template. + * + * @nosubgrouping + */ + template <typename C, typename B, typename entity> + class entities: public B, public list<entity, C> + { + typedef list<entity, C> base_type; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Default constructor creates no elements. + */ + entities () + : base_type (0, this) + { + } + + /** + * @brief Initialize the instance with copies of an exemplar elements. + * + * @param n A number of elements to copy. + * @param x An exemplar element to copy. + */ + entities (typename base_type::size_type n, const entity& x) + : base_type (n, x, this) + { + } + + /** + * @brief Initialize the instance with copies of elements from an + * iterator range. + * + * @param begin An iterator pointing to the first element. + * @param end An iterator pointing to the one past the last element. + */ + template <typename I> + entities (const I& begin, const I& end) + : base_type (begin, end, this) + { + } + + public: + /** + * @brief Copy constructor. + * + * @param x An instance to make a copy of. + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * + * For polymorphic object models use the @c _clone function instead. + */ + entities (const entities& x, flags f = 0, container* c = 0) + : B (x, f, c), base_type (x, f, this) + { + } + + /** + * @brief Copy the instance polymorphically. + * + * @param f Flags to create the copy with. + * @param c A pointer to the object that will contain the copy. + * @return A pointer to the dynamically allocated copy. + * + * This function ensures that the dynamic type of the instance + * is used for copying and should be used for polymorphic object + * models instead of the copy constructor. + */ + virtual entities* + _clone (flags f = 0, container* c = 0) const; + + public: + /** + * @brief Create an instance from a data representation + * stream. + * + * @param s A stream to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + template <typename S> + entities (istream<S>& s, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM element. + * + * @param e A DOM element to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entities (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a DOM Attribute. + * + * @param a A DOM attribute to extract the data from. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entities (const xercesc::DOMAttr& a, flags f = 0, container* c = 0); + + /** + * @brief Create an instance from a %string fragment. + * + * @param s A %string fragment to extract the data from. + * @param e A pointer to DOM element containing the %string fragment. + * @param f Flags to create the new instance with. + * @param c A pointer to the object that will contain the new + * instance. + */ + entities (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f = 0, + container* c = 0); + //@} + }; + } + } +} + +#include <xsd/cxx/tree/types.txx> + +#endif // XSD_CXX_TREE_TYPES_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/types.txx b/xsd/libxsd/xsd/cxx/tree/types.txx new file mode 100644 index 0000000..8d6d79f --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/types.txx @@ -0,0 +1,598 @@ +// file : xsd/cxx/tree/types.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xercesc/util/Base64.hpp> +#include <xercesc/util/XMLString.hpp> +#include <xercesc/util/XercesVersion.hpp> + +#include <xsd/cxx/auto-array.hxx> + +#include <xsd/cxx/xml/std-memory-manager.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + + // string + // + template <typename C, typename B> + string<C, B>* string<C, B>:: + _clone (flags f, container* c) const + { + return new string (*this, f, c); + } + + + // normalized_string + // + template <typename C, typename B> + normalized_string<C, B>* normalized_string<C, B>:: + _clone (flags f, container* c) const + { + return new normalized_string (*this, f, c); + } + + + // token + // + template <typename C, typename B> + token<C, B>* token<C, B>:: + _clone (flags f, container* c) const + { + return new token (*this, f, c); + } + + + // nmtoken + // + template <typename C, typename B> + nmtoken<C, B>* nmtoken<C, B>:: + _clone (flags f, container* c) const + { + return new nmtoken (*this, f, c); + } + + + // nmtokens + // + template <typename C, typename B, typename nmtoken> + nmtokens<C, B, nmtoken>* nmtokens<C, B, nmtoken>:: + _clone (flags f, container* c) const + { + return new nmtokens (*this, f, c); + } + + + // name + // + template <typename C, typename B> + name<C, B>* name<C, B>:: + _clone (flags f, container* c) const + { + return new name (*this, f, c); + } + + + // ncname + // + template <typename C, typename B> + ncname<C, B>* ncname<C, B>:: + _clone (flags f, container* c) const + { + return new ncname (*this, f, c); + } + + + // language + // + template <typename C, typename B> + language<C, B>* language<C, B>:: + _clone (flags f, container* c) const + { + return new language (*this, f, c); + } + + + // identity_impl + // + template <typename C, typename ncname> + bool identity_impl<C, ncname>:: + before (const identity& y) const + { + return id_ < static_cast<const identity_impl&> (y).id_; + } + + template <typename C, typename ncname> + void identity_impl<C, ncname>:: + throw_duplicate_id () const + { + throw duplicate_id<C> (id_); + } + + + // id + // + template <typename C, typename B> + id<C, B>* id<C, B>:: + _clone (flags f, container* c) const + { + return new id (*this, f, c); + } + + template <typename C, typename B> + id<C, B>& id<C, B>:: + operator= (C c) + { + unregister_id (); + base () = c; + register_id (); + + return *this; + } + + template <typename C, typename B> + id<C, B>& id<C, B>:: + operator= (const C* s) + { + unregister_id (); + base () = s; + register_id (); + + return *this; + } + + template <typename C, typename B> + id<C, B>& id<C, B>:: + operator= (const std::basic_string<C>& s) + { + unregister_id (); + base () = s; + register_id (); + + return *this; + } + + template <typename C, typename B> + id<C, B>& id<C, B>:: + operator= (const id& x) + { + unregister_id (); + base () = x; + register_id (); + + return *this; + } + + // It would have been cleaner to mention empty and _container + // with the using-declaration but HP aCC3 can't handle it in + // some non-trivial to track down cases. So we are going to use + // the old-n-ugly this-> techniques. + // + template <typename C, typename B> + void id<C, B>:: + _container (container* c) + { + B::_container (c); + register_id (); + } + + template <typename C, typename B> + void id<C, B>:: + register_id () + { + container* r (this->_root ()); + + if (r != 0 && !this->empty ()) + r->_register_id (identity_, this->_container ()); + } + + template <typename C, typename B> + void id<C, B>:: + unregister_id () + { + container* r (this->_root ()); + + if (r != 0 && !this->empty ()) + r->_unregister_id (identity_); + } + + + // idref + // + template <typename C, typename B, typename T> + idref<C, B, T>* idref<C, B, T>:: + _clone (flags f, container* c) const + { + return new idref (*this, f, c); + } + + // It would have been cleaner to mention empty, _root, etc. with + // the using-declaration but HP aCC3 can't handle it in some + // non-trivial to track down cases. So we are going to use the + // old-n-ugly this-> techniques. + // + template <typename C, typename B, typename T> + const _type* idref<C, B, T>:: + get_ () const + { + if (!this->empty () && this->_container () != 0) + { + return this->_root ()->_lookup_id (identity_); + } + else + return 0; + } + + template <typename C, typename B, typename T> + _type* idref<C, B, T>:: + get_ () + { + if (!this->empty () && this->_container () != 0) + { + return this->_root ()->_lookup_id (identity_); + } + else + return 0; + } + + template <typename C, typename B, typename T> + void idref<C, B, T>:: + true_ () + { + } + + + // idrefs + // + template <typename C, typename B, typename idref> + idrefs<C, B, idref>* idrefs<C, B, idref>:: + _clone (flags f, container* c) const + { + return new idrefs (*this, f, c); + } + + + // uri + // + template <typename C, typename B> + uri<C, B>* uri<C, B>:: + _clone (flags f, container* c) const + { + return new uri (*this, f, c); + } + + + // qname + // + template <typename C, typename B, typename uri, typename ncname> + qname<C, B, uri, ncname>* qname<C, B, uri, ncname>:: + _clone (flags f, container* c) const + { + return new qname (*this, f, c); + } + + + // base64_binary + // + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (size_t size) + : buffer<C> (size) + { + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (size_t size, size_t capacity) + : buffer<C> (size, capacity) + { + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (const void* data, size_t size) + : buffer<C> (data, size) + { + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (const void* data, size_t size, size_t capacity) + : buffer<C> (data, size, capacity) + { + } + + template <typename C, typename B> + base64_binary<C, B>:: + base64_binary (void* data, size_t size, size_t capacity, bool own) + : buffer<C> (data, size, capacity, own) + { + } + + template <typename C, typename B> + base64_binary<C, B>* base64_binary<C, B>:: + _clone (flags f, container* c) const + { + return new base64_binary (*this, f, c); + } + + // It would have been cleaner to mention size, and data with the + // using-declaration but HP aCC3 can't handle it in some non- + // trivial to track down cases. So we are going to use the + // old-n- ugly this-> techniques. + // + template <typename C, typename B> + std::basic_string<C> base64_binary<C, B>:: + encode () const + { + // HP aCC3 cannot handle using namespace xercesc; + // + using xercesc::Base64; + std::basic_string<C> str; + +#if _XERCES_VERSION >= 30000 + XMLSize_t n; + + xml::std_memory_manager mm; + auto_array<XMLByte, xml::std_memory_manager> r ( + Base64::encode ( + reinterpret_cast<const XMLByte*> (this->data ()), + static_cast<XMLSize_t> (this->size ()), + &n, + &mm), + mm); + + if (r) + { + str.reserve (n + 1); + str.resize (n); + + for (XMLSize_t i (0); i < n; ++i) + str[i] = C (r[i]); + } + else + { + //@@ throw + } +#else + unsigned int n; + + xml::std_memory_manager mm; + auto_array<XMLByte, xml::std_memory_manager> r ( + Base64::encode ( + reinterpret_cast<const XMLByte*> (this->data ()), + static_cast<unsigned int> (this->size ()), + &n, + &mm), + mm); + + if (r) + { + str.reserve (n + 1); + str.resize (n); + + for (unsigned int i (0); i < n; ++i) + str[i] = C (r[i]); + } + else + { + //@@ throw + } +#endif + + return str; + } + + template <typename C, typename B> + void base64_binary<C, B>:: + decode (const XMLCh* src) + { + // HP aCC3 cannot handle using namespace xercesc; + // + using xercesc::Base64; + + xml::std_memory_manager mm; + + // Xerces 2.6.0 and earlier do not have decodeToXMLByte which + // makes my life harder and your code slower. + // +#if _XERCES_VERSION >= 20700 + +#if _XERCES_VERSION >= 30000 + XMLSize_t size; + auto_array<XMLByte, xml::std_memory_manager> data ( + Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#else + unsigned int size; + auto_array<XMLByte, xml::std_memory_manager> data ( + Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#endif // _XERCES_VERSION >= 30000 + + if (data) + { + buffer<C> tmp (data.get (), size, size, true); + data.release (); + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + else + { + //@@ throw + } +#else + unsigned int size; + +#if _XERCES_VERSION >= 20600 // Xerces 2.5.0 does not have Conf_RFC2045. + auto_array<XMLCh, xml::std_memory_manager> data ( + Base64::decode (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#else + auto_array<XMLCh, xml::std_memory_manager> data ( + Base64::decode (src, &size, &mm), mm); +#endif // _XERCES_VERSION >= 20600 + + if (data) + { + buffer<C> tmp (size); + for (unsigned int i (0); i < size; ++i) + tmp.data ()[i] = static_cast<char> (data[i]); + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + else + { + //@@ throw + } +#endif //_XERCES_VERSION >= 20700 + } + + + // hex_binary + // + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (size_t size) + : buffer<C> (size) + { + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (size_t size, size_t capacity) + : buffer<C> (size, capacity) + { + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (const void* data, size_t size) + : buffer<C> (data, size) + { + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (const void* data, size_t size, size_t capacity) + : buffer<C> (data, size, capacity) + { + } + + template <typename C, typename B> + hex_binary<C, B>:: + hex_binary (void* data, size_t size, size_t capacity, bool own) + : buffer<C> (data, size, capacity, own) + { + } + + template <typename C, typename B> + hex_binary<C, B>* hex_binary<C, B>:: + _clone (flags f, container* c) const + { + return new hex_binary (*this, f, c); + } + + // It would have been cleaner to mention size, and data with the + // using-declaration but HP aCC3 can't handle it in some non- + // trivial to track down cases. So we are going to use the + // old-n-ugly this-> techniques. + // + template <typename C, typename B> + std::basic_string<C> hex_binary<C, B>:: + encode () const + { + std::basic_string<C> str; + + const char tab[] = "0123456789ABCDEF"; + + if (size_t n = this->size ()) + { + str.reserve (2 * n + 1); + str.resize (2 * n); + + for (size_t i (0); i < n; ++i) + { + unsigned char byte ( + static_cast<unsigned char> (*(this->data () + i))); + unsigned char h (byte >> 4); + unsigned char l (byte & 0x0F); + + str[2 * i] = C (tab[h]); + str[2 * i + 1] = C (tab[l]); + } + } + + return str; + } + + namespace bits + { + inline unsigned char + hex_decode (XMLCh c) + { + unsigned char r (0xFF); + + if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast<unsigned char> (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast<unsigned char> (10 + (c - 'a')); + + return r; + } + } + + template <typename C, typename B> + void hex_binary<C, B>:: + decode (const XMLCh* src) + { + size_t src_n (xercesc::XMLString::stringLen (src)); + + if (src_n % 2 != 0) + return; // @@ throw + + size_t n (src_n / 2); + + buffer<C> tmp (n); + + for (size_t i (0); i < n; ++i) + { + unsigned char h (bits::hex_decode (src[2 * i])); + unsigned char l (bits::hex_decode (src[2 * i + 1])); + + if (h == 0xFF || l == 0xFF) + return; //@@ throw + + tmp.data()[i] = (h << 4) | l; + } + + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + + + // entity + // + template <typename C, typename B> + entity<C, B>* entity<C, B>:: + _clone (flags f, container* c) const + { + return new entity (*this, f, c); + } + + + // entities + // + template <typename C, typename B, typename entity> + entities<C, B, entity>* entities<C, B, entity>:: + _clone (flags f, container* c) const + { + return new entities (*this, f, c); + } + } + } +} diff --git a/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx b/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx new file mode 100644 index 0000000..ebc3d22 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx @@ -0,0 +1,26 @@ +// file : xsd/cxx/tree/xdr-stream-common.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_XDR_STREAM_COMMON_HXX +#define XSD_CXX_TREE_XDR_STREAM_COMMON_HXX + +#include <xsd/cxx/exceptions.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Base exception for XDR insertion/extraction exceptions. + // + struct xdr_stream_operation: xsd::cxx::exception + { + }; + } + } +} + +#endif // XSD_CXX_TREE_XDR_STREAM_COMMON_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx b/xsd/libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx new file mode 100644 index 0000000..012c1e4 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx @@ -0,0 +1,295 @@ +// file : xsd/cxx/tree/xdr-stream-extraction.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_XDR_STREAM_EXTRACTION_HXX +#define XSD_CXX_TREE_XDR_STREAM_EXTRACTION_HXX + +#include <rpc/types.h> +#include <rpc/xdr.h> + +#include <string> + +#include <xsd/cxx/tree/buffer.hxx> +#include <xsd/cxx/tree/istream.hxx> +#include <xsd/cxx/tree/xdr-stream-common.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct xdr_stream_extraction: xdr_stream_operation + { + virtual const char* + what () const throw () + { + return "XDR stream extraction operation failed"; + } + }; + + + // as_size + // +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_size<T>& x) + { + uint64_t v; + + if (!xdr_uint64_t (&s.impl (), &v) || v > ~(T (0))) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } +#else + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_size<T>& x) + { + uint32_t v; + + if (!xdr_uint32_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } +#endif + + + // 8-bit + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_int8<T>& x) + { + int8_t v; + + if (!xdr_int8_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_uint8<T>& x) + { + uint8_t v; + + if (!xdr_uint8_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + + // 16-bit + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_int16<T>& x) + { + int16_t v; + + if (!xdr_int16_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_uint16<T>& x) + { + uint16_t v; + + if (!xdr_uint16_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + + // 32-bit + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_int32<T>& x) + { + int32_t v; + + if (!xdr_int32_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_uint32<T>& x) + { + uint32_t v; + + if (!xdr_uint32_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + + // 64-bit + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_int64<T>& x) + { + int64_t v; + + if (!xdr_int64_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_uint64<T>& x) + { + uint64_t v; + + if (!xdr_uint64_t (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + + // Boolean + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_bool<T>& x) + { + bool_t v; + + if (!xdr_bool (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + + // Floating-point + // + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_float32<T>& x) + { + float v; + + if (!xdr_float (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + template <typename T> + inline istream<XDR>& + operator>> (istream<XDR>& s, istream<XDR>::as_float64<T>& x) + { + double v; + + if (!xdr_double (&s.impl (), &v)) + throw xdr_stream_extraction (); + + x.x_ = static_cast<T> (v); + + return s; + } + + // Extraction of std::basic_string. + // + + inline istream<XDR>& + operator>> (istream<XDR>& s, std::basic_string<char>& x) + { + unsigned int n; + + if (!xdr_u_int (&s.impl (), &n)) + throw xdr_stream_extraction (); + + // Dangerous but fast. + // + x.clear (); + + if (n != 0) + { + x.resize (n); + char* p (const_cast<char*> (x.c_str ())); + + if (!xdr_opaque (&s.impl (), p, n)) + throw xdr_stream_extraction (); + } + + return s; + } + + // Wide strings are not supported by XDR. + // + // inline istream<XDR>& + // operator>> (istream<XDR>& s, std::basic_string<wchar_t>& x) + // { + // } + + + // Extraction of a binary buffer. + // + template <typename C> + istream<XDR>& + operator>> (istream<XDR>& s, buffer<C>& x) + { + unsigned int n; + + if (!xdr_u_int (&s.impl (), &n)) + throw xdr_stream_extraction (); + + x.size (n); + + if (!xdr_opaque (&s.impl (), x.data (), n)) + throw xdr_stream_extraction (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_XDR_STREAM_EXTRACTION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx new file mode 100644 index 0000000..00031d2 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx @@ -0,0 +1,259 @@ +// file : xsd/cxx/tree/xdr-stream-insertion.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_XDR_STREAM_INSERTION_HXX +#define XSD_CXX_TREE_XDR_STREAM_INSERTION_HXX + +#include <rpc/types.h> +#include <rpc/xdr.h> + +#include <string> + +#include <xsd/cxx/tree/buffer.hxx> +#include <xsd/cxx/tree/ostream.hxx> +#include <xsd/cxx/tree/xdr-stream-common.hxx> + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct xdr_stream_insertion: xdr_stream_operation + { + virtual const char* + what () const throw () + { + return "XDR stream insertion operation failed"; + } + }; + + // as_size + // +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_size<T> x) + { + uint64_t v (static_cast<uint64_t> (x.x_)); + + if (!xdr_uint64_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } +#else + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_size<T> x) + { + uint32_t v (static_cast<uint32_t> (x.x_)); + + if (x.x_ > ~(uint32_t (0)) || !xdr_uint32_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } +#endif + + + // 8-bit + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_int8<T> x) + { + int8_t v (static_cast<int8_t> (x.x_)); + + if (!xdr_int8_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_uint8<T> x) + { + uint8_t v (static_cast<uint8_t> (x.x_)); + + if (!xdr_uint8_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + + // 16-bit + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_int16<T> x) + { + int16_t v (static_cast<int16_t> (x.x_)); + + if (!xdr_int16_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_uint16<T> x) + { + uint16_t v (static_cast<uint16_t> (x.x_)); + + if (!xdr_uint16_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + + // 32-bit + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_int32<T> x) + { + int32_t v (static_cast<int32_t> (x.x_)); + + if (!xdr_int32_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_uint32<T> x) + { + uint32_t v (static_cast<uint32_t> (x.x_)); + + if (!xdr_uint32_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + + // 64-bit + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_int64<T> x) + { + int64_t v (static_cast<int64_t> (x.x_)); + + if (!xdr_int64_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_uint64<T> x) + { + uint64_t v (static_cast<uint64_t> (x.x_)); + + if (!xdr_uint64_t (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + + // Boolean + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_bool<T> x) + { + bool_t v (static_cast<bool_t> (x.x_)); + + if (!xdr_bool (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + + // Floating-point + // + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_float32<T> x) + { + float v (static_cast<float> (x.x_)); + + if (!xdr_float (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + template <typename T> + inline ostream<XDR>& + operator<< (ostream<XDR>& s, ostream<XDR>::as_float64<T> x) + { + double v (static_cast<double> (x.x_)); + + if (!xdr_double (&s.impl (), &v)) + throw xdr_stream_insertion (); + + return s; + } + + // Insertion of std::basic_string. + // + + inline ostream<XDR>& + operator<< (ostream<XDR>& s, const std::basic_string<char>& x) + { + // XDR strings are hard-wired with a 32 bit (unsigned int) length. + // + char* p (const_cast<char*> (x.c_str ())); + unsigned int n (static_cast<unsigned int> (x.length ())); + + if (x.length () > ~((unsigned int) 0) || + !xdr_u_int (&s.impl (), &n) || + !xdr_opaque (&s.impl (), p, n)) + throw xdr_stream_insertion (); + + return s; + } + + // Wide strings are not supported by XDR. + // + // inline ostream<XDR>& + // operator<< (ostream<XDR>& s, const std::basic_string<wchar_t>& x) + // { + // } + + + // Insertion of a binary buffer. + // + template <typename C> + ostream<XDR>& + operator<< (ostream<XDR>& s, const buffer<C>& x) + { + // It is not possible to write an array with a 64-bit size. + // + unsigned int n (static_cast<unsigned int> (x.size ())); + + if (x.size () > ~((unsigned int) 0) || + !xdr_u_int (&s.impl (), &n) || + !xdr_opaque (&s.impl (), const_cast<char*> (x.data ()), n)) + throw xdr_stream_insertion (); + + return s; + } + } + } +} + +#endif // XSD_CXX_TREE_XDR_STREAM_INSERTION_HXX |