diff options
Diffstat (limited to 'xsd/libxsd/xsd/cxx/tree')
85 files changed, 1936 insertions, 941 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 index 7c3fc96..7a9fbff 100644 --- a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-common.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/ace-cdr-stream-common.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 53e1f6c..b843ffa 100644 --- a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/ace-cdr-stream-extraction.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX @@ -12,7 +11,13 @@ #include <ace/ACE.h> // ACE::strdelete #include <ace/CDR_Stream.h> -#include <xsd/cxx/auto-array.hxx> +#include <xsd/cxx/config.hxx> // XSD_CXX11 + +#ifdef XSD_CXX11 +# include <memory> // std::unique_ptr +#else +# include <xsd/cxx/auto-array.hxx> +#endif #include <xsd/cxx/tree/buffer.hxx> #include <xsd/cxx/tree/istream.hxx> @@ -258,11 +263,11 @@ namespace xsd namespace bits { - template<typename C> - struct ace_str_deallocator + template <typename C> + struct ace_str_deleter { void - deallocate (C* s) + operator() (C* s) const { ACE::strdelete (s); } @@ -272,18 +277,22 @@ namespace xsd inline istream<ACE_InputCDR>& operator>> (istream<ACE_InputCDR>& s, std::basic_string<char>& x) { - typedef bits::ace_str_deallocator<char> deallocator; + typedef bits::ace_str_deleter<char> deleter; - deallocator d; + deleter d; char* r; if (!s.impl ().read_string (r)) throw ace_cdr_stream_extraction (); - auto_array<char, deallocator> ar (r, d); +#ifdef XSD_CXX11 + std::unique_ptr<char[], deleter&> ar ( +#else + auto_array<char, deleter> ar ( +#endif + r, d); x = r; - return s; } @@ -291,18 +300,22 @@ namespace xsd inline istream<ACE_InputCDR>& operator>> (istream<ACE_InputCDR>& s, std::basic_string<wchar_t>& x) { - typedef bits::ace_str_deallocator<wchar_t> deallocator; + typedef bits::ace_str_deleter<wchar_t> deleter; - deallocator d; + deleter d; wchar_t* r; if (!s.impl ().read_wstring (r)) throw ace_cdr_stream_extraction (); - auto_array<wchar_t, deallocator> ar (r, d); +#ifdef XSD_CXX11 + std::unique_ptr<wchar_t[], deleter&> ar ( +#else + auto_array<wchar_t, deleter> ar ( +#endif + r, d); x = r; - return s; } #endif diff --git a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx index 0f723d0..3fa92ad 100644 --- a/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx +++ b/xsd/libxsd/xsd/cxx/tree/ace-cdr-stream-insertion.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/ace-cdr-stream-insertion.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 49ac0ca..a690e76 100644 --- a/xsd/libxsd/xsd/cxx/tree/bits/literals.hxx +++ b/xsd/libxsd/xsd/cxx/tree/bits/literals.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/bits/literals.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_BITS_LITERALS_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx b/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx index 260a9e7..9a27d99 100644 --- a/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx +++ b/xsd/libxsd/xsd/cxx/tree/bits/literals.ixx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/bits/literals.ixx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_BITS_LITERALS_IXX diff --git a/xsd/libxsd/xsd/cxx/tree/buffer.hxx b/xsd/libxsd/xsd/cxx/tree/buffer.hxx index 24da287..9ce568c 100644 --- a/xsd/libxsd/xsd/cxx/tree/buffer.hxx +++ b/xsd/libxsd/xsd/cxx/tree/buffer.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/buffer.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file /** diff --git a/xsd/libxsd/xsd/cxx/tree/buffer.txx b/xsd/libxsd/xsd/cxx/tree/buffer.txx index f88f140..c358e98 100644 --- a/xsd/libxsd/xsd/cxx/tree/buffer.txx +++ b/xsd/libxsd/xsd/cxx/tree/buffer.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/buffer.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx b/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx index b7794f4..a316b21 100644 --- a/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/comparison-map.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/comparison-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_COMPARISON_MAP_HXX @@ -27,7 +26,7 @@ namespace xsd comparison_map (); void - register_type (const type_id&, comparator, bool override = true); + register_type (const type_id&, comparator, bool replace = true); void unregister_type (const type_id&); diff --git a/xsd/libxsd/xsd/cxx/tree/comparison-map.txx b/xsd/libxsd/xsd/cxx/tree/comparison-map.txx index e638ed4..af23d64 100644 --- a/xsd/libxsd/xsd/cxx/tree/comparison-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/comparison-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/comparison-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/tree/types.hxx> @@ -20,18 +19,17 @@ namespace xsd // anyType and anySimpleType. // - //register_type ( - // typeid (type), - // &comparator_impl<type>, - // false); - - typedef simple_type<type> simple_type; + register_type ( + typeid (type), + &comparator_impl<type>, + false); - //register_type ( - // typeid (simple_type), - // &comparator_impl<simple_type>, - // false); + typedef simple_type<C, type> simple_type; + register_type ( + typeid (simple_type), + &comparator_impl<simple_type>, + false); // Strings // @@ -212,9 +210,9 @@ namespace xsd template <typename C> void comparison_map<C>:: - register_type (const type_id& tid, comparator c, bool override) + register_type (const type_id& tid, comparator c, bool replace) { - if (override || type_map_.find (&tid) == type_map_.end ()) + if (replace || type_map_.find (&tid) == type_map_.end ()) type_map_[&tid] = c; } diff --git a/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx b/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx index 5313507..549df73 100644 --- a/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx +++ b/xsd/libxsd/xsd/cxx/tree/containers-wildcard.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/containers-wildcard.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX @@ -16,7 +15,7 @@ #include <xsd/cxx/xml/string.hxx> -#include <xsd/cxx/tree/containers.hxx> // iterator_adapter +#include <xsd/cxx/tree/iterator-adapter.hxx> namespace xsd { @@ -936,7 +935,7 @@ namespace xsd return r < 0 ? true - : (r > 0 ? false : XMLString::compareString (an, bn)); + : (r > 0 ? false : XMLString::compareString (an, bn) < 0); } }; diff --git a/xsd/libxsd/xsd/cxx/tree/containers.hxx b/xsd/libxsd/xsd/cxx/tree/containers.hxx index ba76eae..cafd79d 100644 --- a/xsd/libxsd/xsd/cxx/tree/containers.hxx +++ b/xsd/libxsd/xsd/cxx/tree/containers.hxx @@ -1,20 +1,19 @@ // file : xsd/cxx/tree/containers.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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 <memory> // std::auto_ptr/unique_ptr #include <algorithm> // std::equal, std::lexicographical_compare #include <iosfwd> +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + #include <xsd/cxx/tree/elements.hxx> +#include <xsd/cxx/tree/iterator-adapter.hxx> namespace xsd { @@ -132,11 +131,11 @@ namespace xsd public: ~one (); - one (flags, container*); + one (container*); - one (const T&, flags, container*); + one (const T&, container*); - one (std::auto_ptr<T>, flags, container*); + one (XSD_AUTO_PTR<T>, container*); one (const one&, flags, container*); @@ -157,10 +156,13 @@ namespace xsd } void - set (const T&); + set (const T& x) + { + set (x, 0); + } void - set (std::auto_ptr<T>); + set (XSD_AUTO_PTR<T>); bool present () const @@ -168,18 +170,21 @@ namespace xsd return x_ != 0; } - std::auto_ptr<T> + XSD_AUTO_PTR<T> detach () { T* x (x_); x->_container (0); x_ = 0; - return std::auto_ptr<T> (x); + return XSD_AUTO_PTR<T> (x); } protected: + void + set (const T&, flags); + + protected: T* x_; - flags flags_; container* container_; }; @@ -188,12 +193,12 @@ namespace xsd class one<T, true> { public: - one (flags, container*) + one (container*) : present_ (false) { } - one (const T& x, flags, container*) + one (const T& x, container*) : x_ (x), present_ (true) { } @@ -246,9 +251,6 @@ namespace xsd 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; @@ -259,13 +261,13 @@ namespace xsd ~optional (); explicit - optional (flags = 0, container* = 0); + optional (container* = 0); explicit - optional (const T&, flags = 0, container* = 0); + optional (const T&, container* = 0); explicit - optional (std::auto_ptr<T>, flags = 0, container* = 0); + optional (XSD_AUTO_PTR<T>, container* = 0); optional (const optional&, flags = 0, container* = 0); @@ -332,30 +334,35 @@ namespace xsd } void - set (const T&); + set (const T& x) + { + set (x, 0); + } void - set (std::auto_ptr<T>); + set (XSD_AUTO_PTR<T>); void reset (); - std::auto_ptr<T> + XSD_AUTO_PTR<T> detach () { T* x (x_); x->_container (0); x_ = 0; - return std::auto_ptr<T> (x); + return XSD_AUTO_PTR<T> (x); } - private: + protected: + void + set (const T&, flags); + void true_ (); - private: + protected: T* x_; - flags flags_; container* container_; }; @@ -367,13 +374,13 @@ namespace xsd { public: explicit - optional (flags = 0, container* = 0) + optional (container* = 0) : present_ (false) { } explicit - optional (const T&, flags = 0, container* = 0); + optional (const T&, container* = 0); optional (const optional&, flags = 0, container* = 0); @@ -506,7 +513,7 @@ namespace xsd return !(a < b); } - // Provide an ostream insertion opretaor to prevent confusion from + // Provide an ostream insertion operator to prevent confusion from // the implicit bool conversion. // template <typename C, typename T, bool fund> @@ -516,264 +523,9 @@ namespace xsd // 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 @@ -859,33 +611,33 @@ namespace xsd typedef base_sequence::allocator_type allocator_type; protected: - sequence_common (flags f, container* c) - : flags_ (f), container_ (c) + sequence_common (container* c) + : container_ (c) { } sequence_common (size_type n, const type& x, container* c) - : flags_ (0), container_ (c) + : container_ (c) { assign (n, x); } template <typename I> sequence_common (const I& begin, const I& end, container* c) - : flags_ (0), container_ (c) + : container_ (c) { assign (begin, end); } sequence_common (const sequence_common& v, flags f, container* c) - : flags_ (f), container_ (c) + : 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_)); + ptr p ((**i)._clone (f, container_)); v_.push_back (p); } } @@ -906,7 +658,7 @@ namespace xsd { // We have no ptr_ref. // - ptr p ((**si)._clone (flags_, container_)); + ptr p ((**si)._clone (0, container_)); *di = p; } @@ -958,7 +710,7 @@ namespace xsd for (base_iterator i (v_.begin ()), e (v_.end ()); i != e; ++i) { - ptr p (x._clone (flags_, container_)); + ptr p (x._clone (0, container_)); *i = p; } } @@ -974,7 +726,7 @@ namespace xsd for (I i (begin); i != end; ++i) { - ptr p (i->_clone (flags_, container_)); + ptr p (i->_clone (0, container_)); v_.push_back (p); } } @@ -990,7 +742,7 @@ namespace xsd for (base_iterator i (v_.begin () + old), e (v_.end ()); i != e; ++i) { - ptr p (x._clone (flags_, container_)); + ptr p (x._clone (0, container_)); *i = p; } } @@ -1004,7 +756,7 @@ namespace xsd for (base_iterator i (v_.end () - d); n != 0; --n) { - ptr r (x._clone (flags_, container_)); + ptr r (x._clone (0, container_)); *(--i) = r; } } @@ -1021,7 +773,7 @@ namespace xsd for (I i (end);;) { --i; - ptr r (i->_clone (flags_, container_)); + ptr r (i->_clone (0, container_)); p = v_.insert (p, r); if (i == begin) @@ -1031,7 +783,6 @@ namespace xsd } protected: - flags flags_; container* container_; base_sequence v_; }; @@ -1075,8 +826,8 @@ namespace xsd public: explicit - sequence (flags f = 0, container* c = 0) - : sequence_common (f, c) + sequence (container* c = 0) + : sequence_common (c) { } @@ -1260,11 +1011,11 @@ namespace xsd void push_back (const T& x) { - v_.push_back (ptr (x._clone (flags_, container_))); + v_.push_back (ptr (x._clone (0, container_))); } void - push_back (std::auto_ptr<T> x) + push_back (XSD_AUTO_PTR<T> x) { if (x->_container () != container_) x->_container (container_); @@ -1278,7 +1029,7 @@ namespace xsd v_.pop_back (); } - std::auto_ptr<T> + XSD_AUTO_PTR<T> detach_back (bool pop = true) { ptr& p (v_.back ()); @@ -1288,7 +1039,7 @@ namespace xsd if (pop) v_.pop_back (); - return std::auto_ptr<T> (x); + return XSD_AUTO_PTR<T> (x); } iterator @@ -1296,11 +1047,11 @@ namespace xsd { return iterator ( v_.insert ( - position.base (), ptr (x._clone (flags_, container_)))); + position.base (), ptr (x._clone (0, container_)))); } iterator - insert (iterator position, std::auto_ptr<T> x) + insert (iterator position, XSD_AUTO_PTR<T> x) { if (x->_container () != container_) x->_container (container_); @@ -1334,12 +1085,11 @@ namespace xsd } iterator - detach (iterator position, std::auto_ptr<T>& r, bool erase = true) + detach (iterator position, XSD_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; + r.reset (static_cast<T*> (p.release ())); if (erase) return iterator (v_.erase (position.base ())); @@ -1368,7 +1118,7 @@ namespace xsd public: explicit - sequence (flags = 0, container* = 0) + sequence (container* = 0) { } diff --git a/xsd/libxsd/xsd/cxx/tree/containers.txx b/xsd/libxsd/xsd/cxx/tree/containers.txx index fdc0bfd..2a3573f 100644 --- a/xsd/libxsd/xsd/cxx/tree/containers.txx +++ b/xsd/libxsd/xsd/cxx/tree/containers.txx @@ -1,9 +1,13 @@ // file : xsd/cxx/tree/containers.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <ostream> + +#ifdef XSD_CXX11 +# include <utility> // std::move +#endif + #include <xsd/cxx/tree/bits/literals.hxx> namespace xsd @@ -23,34 +27,38 @@ namespace xsd template<typename T> one<T, false>:: - one (flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + one (container* c) + : x_ (0), container_ (c) { } template<typename T> one<T, false>:: - one (const T& x, flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + one (const T& x, container* c) + : x_ (0), 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) + one (XSD_AUTO_PTR<T> x, container* c) + : x_ (0), container_ (c) { +#ifdef XSD_CXX11 + set (std::move (x)); +#else set (x); +#endif } template<typename T> one<T, false>:: one (const one<T, false>& x, flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + : x_ (0), container_ (c) { if (x.present ()) - set (x.get ()); + set (x.get (), f); } template<typename T> @@ -73,12 +81,12 @@ namespace xsd template<typename T> void one<T, false>:: - set (const T& x) + set (const T& x, flags f) { // We always do a fresh copy because T may not be x's // dynamic type. // - T* r (x._clone (flags_, container_)); + T* r (x._clone (f, container_)); delete x_; x_ = r; @@ -86,7 +94,7 @@ namespace xsd template<typename T> void one<T, false>:: - set (std::auto_ptr<T> x) + set (XSD_AUTO_PTR<T> x) { T* r (0); @@ -113,34 +121,38 @@ namespace xsd template <typename T> optional<T, false>:: - optional (flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + optional (container* c) + : x_ (0), container_ (c) { } template <typename T> optional<T, false>:: - optional (const T& x, flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + optional (const T& x, container* c) + : x_ (0), 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) + optional (XSD_AUTO_PTR<T> x, container* c) + : x_ (0), container_ (c) { +#ifdef XSD_CXX11 + set (std::move (x)); +#else set (x); +#endif } template <typename T> optional<T, false>:: optional (const optional<T, false>& x, flags f, container* c) - : x_ (0), flags_ (f), container_ (c) + : x_ (0), container_ (c) { if (x) - set (*x); + set (*x, f); } template <typename T> @@ -172,12 +184,12 @@ namespace xsd template <typename T> void optional<T, false>:: - set (const T& x) + set (const T& x, flags f) { // We always do a fresh copy because T may not be x's // dynamic type. // - T* r (x._clone (flags_, container_)); + T* r (x._clone (f, container_)); delete x_; x_ = r; @@ -185,7 +197,7 @@ namespace xsd template <typename T> void optional<T, false>:: - set (std::auto_ptr<T> x) + set (XSD_AUTO_PTR<T> x) { T* r (0); @@ -220,7 +232,7 @@ namespace xsd // template <typename T> optional<T, true>:: - optional (const T& y, flags, container*) + optional (const T& y, container*) : present_ (false) { set (y); diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx b/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx index 317b80f..4ada1a0 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx +++ b/xsd/libxsd/xsd/cxx/tree/date-time-extraction.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time-extraction.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx b/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx index db24ae1..b41ffce 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx +++ b/xsd/libxsd/xsd/cxx/tree/date-time-insertion.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time-insertion.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx b/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx index 90073f4..830cd49 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx +++ b/xsd/libxsd/xsd/cxx/tree/date-time-ostream.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time-ostream.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <ostream> diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.hxx b/xsd/libxsd/xsd/cxx/tree/date-time.hxx index abde516..9526f92 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time.hxx +++ b/xsd/libxsd/xsd/cxx/tree/date-time.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file /** diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.ixx b/xsd/libxsd/xsd/cxx/tree/date-time.ixx index 5bc7200..00d7f8c 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time.ixx +++ b/xsd/libxsd/xsd/cxx/tree/date-time.ixx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time.ixx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/date-time.txx b/xsd/libxsd/xsd/cxx/tree/date-time.txx index 34c6c84..f5b9b8e 100644 --- a/xsd/libxsd/xsd/cxx/tree/date-time.txx +++ b/xsd/libxsd/xsd/cxx/tree/date-time.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/date-time.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/element-map.hxx b/xsd/libxsd/xsd/cxx/tree/element-map.hxx index 2f12b0b..0f4883d 100644 --- a/xsd/libxsd/xsd/cxx/tree/element-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/element-map.hxx @@ -1,16 +1,17 @@ // file : xsd/cxx/tree/element-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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 <memory> // std::auto_ptr/unique_ptr #include <cstddef> // std::size_t #include <string> +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + #include <xsd/cxx/xml/qualified-name.hxx> #include <xsd/cxx/tree/elements.hxx> @@ -44,7 +45,7 @@ namespace xsd * @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> + static XSD_AUTO_PTR<element_type> parse (const xercesc::DOMElement& e, flags f = 0); /** @@ -61,7 +62,7 @@ namespace xsd typedef xml::qualified_name<C> qualified_name; - typedef std::auto_ptr<element_type> + typedef XSD_AUTO_PTR<element_type> (*parser) (const xercesc::DOMElement&, flags f); typedef void @@ -113,7 +114,7 @@ namespace xsd // // template<typename T, typename C, typename B> - std::auto_ptr<element_type<C, B> > + XSD_AUTO_PTR<element_type<C, B> > parser_impl (const xercesc::DOMElement&, flags); template<typename T, typename C, typename B> diff --git a/xsd/libxsd/xsd/cxx/tree/element-map.txx b/xsd/libxsd/xsd/cxx/tree/element-map.txx index 0ff5d2a..32fe873 100644 --- a/xsd/libxsd/xsd/cxx/tree/element-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/element-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/element-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/elements.hxx b/xsd/libxsd/xsd/cxx/tree/elements.hxx index 403fdb3..a3bbea4 100644 --- a/xsd/libxsd/xsd/cxx/tree/elements.hxx +++ b/xsd/libxsd/xsd/cxx/tree/elements.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/elements.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file /** @@ -17,25 +16,40 @@ #ifndef XSD_CXX_TREE_ELEMENTS_HXX #define XSD_CXX_TREE_ELEMENTS_HXX +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR, XSD_CXX11 + #include <map> #include <string> -#include <memory> // std::auto_ptr +#include <memory> // std::auto_ptr/unique_ptr +#include <cstddef> // std::size_t #include <istream> #include <sstream> #include <cassert> +#ifdef XSD_CXX11 +# include <utility> // std::move +#endif + #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 <xercesc/util/XercesVersion.hpp> + #include <xsd/cxx/xml/elements.hxx> // xml::properties -#include <xsd/cxx/xml/dom/auto-ptr.hxx> // dom::auto_ptr +#include <xsd/cxx/xml/dom/auto-ptr.hxx> // dom::auto_ptr/unique_ptr +#include <xsd/cxx/xml/dom/wildcard-source.hxx> // dom::create_document() #include <xsd/cxx/tree/facet.hxx> #include <xsd/cxx/tree/exceptions.hxx> #include <xsd/cxx/tree/istream-fwd.hxx> +#include <xsd/cxx/tree/containers-wildcard.hxx> + +#if _XERCES_VERSION < 30000 +# error Xerces-C++ 2-series is not supported +#endif namespace xsd { @@ -77,7 +91,7 @@ namespace xsd * * 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. + * @c dom::auto_ptr/unique_ptr<DOMDocument> argument. * */ static const unsigned long own_dom = 0x00000200UL; @@ -89,6 +103,12 @@ namespace xsd static const unsigned long dont_validate = 0x00000400UL; /** + * @brief Extract XML content for anyType or anySimpleType. + * Normally you don't need to specify this flag explicitly. + */ + static const unsigned long extract_content = 0x00000800UL; + + /** * @brief Do not initialize the Xerces-C++ runtime. */ static const unsigned long dont_initialize = 0x00000001UL; @@ -179,7 +199,6 @@ namespace xsd unsigned long x_; }; - // Parsing properties. Refer to xsd/cxx/xml/elements.hxx for XML- // related properties. // @@ -188,6 +207,44 @@ namespace xsd { }; + /** + * @brief Content order sequence entry. + * + * @nosubgrouping + */ + struct content_order + { + /** + * @brief Initialize an instance with passed id and index. + * + * @param id Content id. + * @param index Content index in the corresponding sequence. + */ + content_order (std::size_t id, std::size_t index = 0) + : id (id), index (index) + { + } + + /** + * @brief Content id. + */ + std::size_t id; + + /** + * @brief Content index. + */ + std::size_t index; + }; + + bool + operator== (const content_order&, const content_order&); + + bool + operator!= (const content_order&, const content_order&); + + bool + operator< (const content_order&, const content_order&); + //@cond // DOM user data keys. @@ -202,12 +259,6 @@ namespace xsd 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 @@ -284,10 +335,20 @@ namespace xsd /** * @brief Default constructor. */ - _type () - : container_ (0) - { - } + _type (); + + /** + * @brief Create an instance from a C string. + * + * @param s A string to initialize the instance with. + * + * Note that this constructor ignores the string and creates an + * empty anyType instance. In particular, it will not convert the + * string into DOM content. The purpose of such a strange constructor + * is to allow statically-initialized default values of anyType type. + */ + template <typename C> + _type (const C* s); public: /** @@ -339,7 +400,9 @@ namespace xsd * @param c A pointer to the object that will contain the new * instance. */ - _type (const xercesc::DOMElement& e, flags f = 0, container* c = 0); + _type (const xercesc::DOMElement& e, + flags f = flags::extract_content, + container* c = 0); /** * @brief Create an instance from a DOM Attribute. @@ -377,10 +440,150 @@ namespace xsd type& operator= (const type& x) { - while (&x == 0) /* unused */; + if (this != &x) + { + if (x.content_.get () == 0) + content_.reset (); + else + content_ = x.content_->clone (); + + // Drop DOM association. + // + dom_info_.reset (); + } + return *this; } + // anyType content API. + // + public: + typedef element_optional dom_content_optional; + + /** + * @brief Return a read-only (constant) reference to the anyType + * DOM content. + * + * @return A constant reference to the optional container. + * + * The DOM content is returned as an optional element container, + * the same container as used for optional element wildcards. + */ + const dom_content_optional& + dom_content () const; + + /** + * @brief Return a read-write reference to the anyType DOM content. + * + * @return A reference to the optional container. + * + * The DOM content is returned as an optional element container, + * the same container as used for optional element wildcards. + */ + dom_content_optional& + dom_content (); + + /** + * @brief Set the anyType DOM content. + * + * @param e A new element to set. + * + * This function makes a copy of its argument and sets it as the + * new DOM content. + */ + void + dom_content (const xercesc::DOMElement& e); + + /** + * @brief Set the anyType DOM content. + * + * @param e A new element to use. + * + * This function will use the passed element directly instead + * of making a copy. For this to work the element should belong + * to the DOM document associated with this anyType instance. + * + * @see dom_content_document + */ + void + dom_content (xercesc::DOMElement* e); + + /** + * @brief Set the anyType DOM content. + * + * @param d An optional container with the new element to set. + * + * If the element is present in @a d then this function makes a + * copy of this element and sets it as the new wildcard content. + * Otherwise the element container is set the 'not present' state. + */ + void + dom_content (const dom_content_optional& d); + + /** + * @brief Return a read-only (constant) reference to the DOM + * document associated with this anyType instance. + * + * @return A constant reference to the DOM document. + * + * The DOM document returned by this function is used to store + * the raw XML content corresponding to the anyType instance. + */ + const xercesc::DOMDocument& + dom_content_document () const; + + /** + * @brief Return a read-write reference to the DOM document + * associated with this anyType instance. + * + * @return A reference to the DOM document. + * + * The DOM document returned by this function is used to store + * the raw XML content corresponding to the anyType instance. + */ + xercesc::DOMDocument& + dom_content_document (); + + /** + * @brief Check for absence of DOM (anyType) and text (anySimpleType) + * content. + * + * @return True if there is no content and false otherwise. + * + * This is an optimization function that allows us to check for the + * lack of content without actually creating its empty representation + * (that is, empty DOM document for DOM or empty string for text). + */ + bool + null_content () const; + + // + // + public: + /** + * @brief Comparison operator. It uses DOM (anyType) or text + * (anySimpleType) content if present. If the content is missing + * then the types are assumed unequal. + * + * @return True if the instances are equal, false otherwise. + */ + friend bool + operator== (const type& x, const type& y) + { + return x.content_.get () != 0 && + x.content_->compare (y.content_.get ()); + } + + /** + * @brief Comparison operator. It uses DOM (anyType) or text + * (anySimpleType) content if present. If the content is missing + * then the types are assumed unequal. + * + * @return True if the instances are not equal, false otherwise. + */ + friend bool + operator!= (const type& x, const type& y) {return !(x == y);} + // Container API. // public: @@ -429,7 +632,7 @@ namespace xsd dr = c; } - std::auto_ptr<map>& m (dr ? dr->map_ : map_); + XSD_AUTO_PTR<map>& m (dr ? dr->map_ : map_); if (container_ == 0) { @@ -440,11 +643,16 @@ namespace xsd if (m.get () != 0) { m->insert (map_->begin (), map_->end ()); - std::auto_ptr<map> tmp (0); - map_ = tmp; + map_.reset (); } else + { +#ifdef XSD_CXX11 + m = std::move (map_); +#else m = map_; +#endif + } } } else @@ -466,10 +674,7 @@ namespace xsd // Part of our subtree. // if (m.get () == 0) - { - std::auto_ptr<map> tmp (new map); - m = tmp; - } + m.reset (new map); m->insert (*i); sr->map_->erase (i++); @@ -548,7 +753,7 @@ namespace xsd * @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. + class bad_dom_node_type: public std::exception //@@ Inherit exception<C>. { public: /** @@ -584,37 +789,31 @@ namespace xsd { 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_ = dom_info_factory::create ( *static_cast<xercesc::DOMElement*> (n), *this, - container_ == 0)); + 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_ = dom_info_factory::create ( *static_cast<xercesc::DOMAttr*> (n), - *this)); + *this); - dom_info_ = r; break; } default: @@ -628,26 +827,23 @@ namespace xsd //@cond void - _register_id (const identity& id, type* t) + _register_id (const identity& i, type* t) { // We should be the root. // assert (container_ == 0); if (map_.get () == 0) - { - std::auto_ptr<map> tmp (new map); - map_ = tmp; - } + map_.reset (new map); if (!map_->insert ( - std::pair<const identity*, type*> (&id, t)).second) + std::pair<const identity*, type*> (&i, t)).second) { - id.throw_duplicate_id (); + i.throw_duplicate_id (); } } - //@@ Does not inherit from exception. + //@@ Does not inherit from exception<C>. // struct not_registered: std::exception { @@ -691,15 +887,11 @@ namespace xsd struct dom_info { virtual - ~dom_info () - { - } + ~dom_info () {} - dom_info () - { - } + dom_info () {} - virtual std::auto_ptr<dom_info> + virtual XSD_AUTO_PTR<dom_info> clone (type& tree_node, container*) const = 0; virtual xercesc::DOMNode* @@ -707,41 +899,41 @@ namespace xsd private: dom_info (const dom_info&); - - dom_info& - operator= (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_ (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. + // The caller should have associated a dom::auto/unique_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>*> ( + XSD_DOM_AUTO_PTR<xercesc::DOMDocument>* pd ( + reinterpret_cast<XSD_DOM_AUTO_PTR<xercesc::DOMDocument>*> ( e.getOwnerDocument ()->getUserData (user_data_keys::node))); assert (pd != 0); assert (pd->get () == e.getOwnerDocument ()); - doc_ = *pd; // Transfer ownership. + // Transfer ownership. +#ifdef XSD_CXX11 + doc_ = std::move (*pd); +#else + doc_ = *pd; +#endif } } - virtual std::auto_ptr<dom_info> + virtual XSD_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) @@ -749,11 +941,10 @@ namespace xsd // 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)); + return XSD_AUTO_PTR<dom_info> ( + doc_.get () == 0 + ? 0 + : new dom_element_info (*doc_, tree_node)); } // Check if our container does not have DOM association (e.g., @@ -764,8 +955,7 @@ namespace xsd DOMNode* cn (c->_node ()); if (cn == 0) - return auto_ptr<dom_info> (0); - + return XSD_AUTO_PTR<dom_info> (); // Now we are going to find the corresponding element in // the new tree. @@ -797,7 +987,7 @@ namespace xsd assert (dn->getNodeType () == DOMNode::ELEMENT_NODE); - return auto_ptr<dom_info> ( + return XSD_AUTO_PTR<dom_info> ( new dom_element_info (static_cast<DOMElement&> (*dn), tree_node, false)); @@ -820,7 +1010,7 @@ namespace xsd } private: - xml::dom::auto_ptr<xercesc::DOMDocument> doc_; + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> doc_; xercesc::DOMElement& e_; }; @@ -833,11 +1023,9 @@ namespace xsd a_.setUserData (user_data_keys::node, &n, 0); } - virtual std::auto_ptr<dom_info> + virtual XSD_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) @@ -845,7 +1033,7 @@ namespace xsd // We preserver DOM associations only in complete // copies from root. // - return auto_ptr<dom_info> (0); + return XSD_AUTO_PTR<dom_info> (); } // Check if our container does not have DOM association (e.g., @@ -856,7 +1044,7 @@ namespace xsd DOMNode* cn (c->_node ()); if (cn == 0) - return auto_ptr<dom_info> (0); + return XSD_AUTO_PTR<dom_info> (); // We are going to find the corresponding attribute in // the new tree. @@ -883,7 +1071,7 @@ namespace xsd DOMNode& n (*cn->getAttributes ()->item (i)); assert (n.getNodeType () == DOMNode::ATTRIBUTE_NODE); - return auto_ptr<dom_info> ( + return XSD_AUTO_PTR<dom_info> ( new dom_attribute_info (static_cast<DOMAttr&> (n), tree_node)); } @@ -904,18 +1092,18 @@ namespace xsd struct dom_info_factory { - static std::auto_ptr<dom_info> + static XSD_AUTO_PTR<dom_info> create (const xercesc::DOMElement& e, type& n, bool root) { - return std::auto_ptr<dom_info> ( + return XSD_AUTO_PTR<dom_info> ( new dom_element_info ( const_cast<xercesc::DOMElement&> (e), n, root)); } - static std::auto_ptr<dom_info> + static XSD_AUTO_PTR<dom_info> create (const xercesc::DOMAttr& a, type& n) { - return std::auto_ptr<dom_info> ( + return XSD_AUTO_PTR<dom_info> ( new dom_attribute_info ( const_cast<xercesc::DOMAttr&> (a), n)); } @@ -923,7 +1111,7 @@ namespace xsd //@endcond - std::auto_ptr<dom_info> dom_info_; + XSD_AUTO_PTR<dom_info> dom_info_; // ID/IDREF map. @@ -946,23 +1134,77 @@ namespace xsd std::map<const identity*, type*, identity_comparator> map; - std::auto_ptr<map> map_; + XSD_AUTO_PTR<map> map_; - private: - container* container_; - }; + // anyType and anySimpleType content. + // + protected: - inline _type:: - _type (const type& x, flags, container* c) - : container_ (c) - { - if (x.dom_info_.get ()) + //@cond + + struct content_type { - std::auto_ptr<dom_info> r (x.dom_info_->clone (*this, c)); - dom_info_ = r; - } - } + virtual + ~content_type () {} + + content_type () {} + virtual XSD_AUTO_PTR<content_type> + clone () const = 0; + + virtual bool + compare (const content_type*) const = 0; + + private: + content_type (const content_type&); + content_type& operator= (const content_type&); + }; + + struct dom_content_type: content_type + { + dom_content_type () + : doc (xml::dom::create_document<char> ()), dom (*doc) {} + + explicit + dom_content_type (const xercesc::DOMElement& e) + : doc (xml::dom::create_document<char> ()), dom (e, *doc) {} + + explicit + dom_content_type (xercesc::DOMElement* e) + : doc (xml::dom::create_document<char> ()), dom (e, *doc) {} + + explicit + dom_content_type (const dom_content_optional& d) + : doc (xml::dom::create_document<char> ()), dom (d, *doc) {} + + virtual XSD_AUTO_PTR<content_type> + clone () const + { + return XSD_AUTO_PTR<content_type> (new dom_content_type (dom)); + } + + virtual bool + compare (const content_type* c) const + { + if (const dom_content_type* dc = + dynamic_cast<const dom_content_type*> (c)) + return dom == dc->dom; + + return false; + } + + public: + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> doc; + dom_content_optional dom; + }; + + //@endcond + + mutable XSD_AUTO_PTR<content_type> content_; + + private: + container* container_; + }; /** * @brief Class corresponding to the XML Schema anySimpleType built-in @@ -970,7 +1212,7 @@ namespace xsd * * @nosubgrouping */ - template <typename B> + template <typename C, typename B> class simple_type: public B { public: @@ -985,13 +1227,19 @@ namespace xsd simple_type (); /** - * @brief Create an instance from a string. + * @brief Create an instance from a C string. * * @param s A string to initialize the instance with. */ - template <typename C> simple_type (const C* s); + /** + * @brief Create an instance from a string. + * + * @param s A string to initialize the instance with. + */ + simple_type (const std::basic_string<C>& s); + public: /** * @brief Copy constructor. @@ -1029,7 +1277,9 @@ namespace xsd * instance. */ template <typename S> - simple_type (istream<S>& s, flags f = 0, container* c = 0); + simple_type (istream<S>& s, + flags f = flags::extract_content, + container* c = 0); /** * @brief Create an instance from a DOM element. @@ -1040,7 +1290,7 @@ namespace xsd * instance. */ simple_type (const xercesc::DOMElement& e, - flags f = 0, + flags f = flags::extract_content, container* c = 0); /** @@ -1052,7 +1302,7 @@ namespace xsd * instance. */ simple_type (const xercesc::DOMAttr& a, - flags f = 0, + flags f = flags::extract_content, container* c = 0); /** @@ -1064,12 +1314,82 @@ namespace xsd * @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, + flags f = flags::extract_content, container* c = 0); //@} + + // anySimpleType content API. + // + public: + /** + * @brief Return a read-only (constant) reference to the anySimpleType + * text content. + * + * @return A constant reference to the text string. + */ + const std::basic_string<C>& + text_content () const; + + /** + * @brief Return a read-write reference to the anySimpleType text + * content. + * + * @return A reference to the text string. + */ + std::basic_string<C>& + text_content (); + + /** + * @brief Set the anySimpleType text content. + * + * @param e A new text string to set. + */ + void + text_content (const std::basic_string<C>& t); + + protected: + //@cond + + typedef typename B::content_type content_type; + + struct text_content_type: content_type + { + text_content_type () {} + + explicit + text_content_type (const std::basic_string<C>& t): text (t) {} + + explicit + text_content_type (const C* t): text (t) {} + + virtual XSD_AUTO_PTR<content_type> + clone () const + { + return XSD_AUTO_PTR<content_type> (new text_content_type (text)); + } + + virtual bool + compare (const content_type* c) const + { + if (const text_content_type* tc = + dynamic_cast<const text_content_type*> (c)) + return text == tc->text; + + return false; + } + + public: + // It would have been more elegant to store text content as DOMText. + // However, that would require Xerces-C++ initialization. Also + // having a separate DOMDocument for each text node seems like + // an overkill. + // + std::basic_string<C> text; + }; + + //@endcond }; @@ -1168,28 +1488,77 @@ namespace xsd { typedef T type; - static std::auto_ptr<T> + static XSD_AUTO_PTR<T> create (const xercesc::DOMElement& e, flags f, container* c) { - return std::auto_ptr<T> (new T (e, f, c)); + return XSD_AUTO_PTR<T> (new T (e, f, c)); } - static std::auto_ptr<T> + static XSD_AUTO_PTR<T> create (const xercesc::DOMAttr& a, flags f, container* c) { - return std::auto_ptr<T> (new T (a, f, c)); + return XSD_AUTO_PTR<T> (new T (a, f, c)); } - static std::auto_ptr<T> + static XSD_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)); + return XSD_AUTO_PTR<T> (new T (s, e, f, c)); + } + + // For now for istream we only go through traits for non- + // fundamental types. + // + template <typename S> + static XSD_AUTO_PTR<T> + create (istream<S>& s, flags f, container* c) + { + return XSD_AUTO_PTR<T> (new T (s, f, c)); } }; + template <typename B, + typename C, + schema_type::value ST> + struct traits<simple_type<C, B>, C, ST> + { + typedef simple_type<C, B> type; + + static XSD_AUTO_PTR<type> + create (const xercesc::DOMElement& e, flags f, container* c) + { + return XSD_AUTO_PTR<type> ( + new type (e, f | flags::extract_content, c)); + } + + static XSD_AUTO_PTR<type> + create (const xercesc::DOMAttr& a, flags f, container* c) + { + return XSD_AUTO_PTR<type> ( + new type (a, f | flags::extract_content, c)); + } + + static XSD_AUTO_PTR<type> + create (const std::basic_string<C>& s, + const xercesc::DOMElement* e, + flags f, + container* c) + { + return XSD_AUTO_PTR<type> ( + new type (s, e, f | flags::extract_content, c)); + } + + template <typename S> + static XSD_AUTO_PTR<type> + create (istream<S>& s, flags f, container* c) + { + return XSD_AUTO_PTR<type> ( + new type (s, f | flags::extract_content, c)); + } + }; //@endcond @@ -1352,8 +1721,7 @@ namespace xsd } // The following extra conversion operators causes problems on - // some compilers (notably VC 7.1 and 9.0) and are disabled by - // default. + // some compilers (notably VC 9.0) and are disabled by default. // #ifdef XSD_TREE_EXTRA_FUND_CONV /** diff --git a/xsd/libxsd/xsd/cxx/tree/elements.ixx b/xsd/libxsd/xsd/cxx/tree/elements.ixx index e4dd60a..844ccf7 100644 --- a/xsd/libxsd/xsd/cxx/tree/elements.ixx +++ b/xsd/libxsd/xsd/cxx/tree/elements.ixx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/elements.ixx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd @@ -9,20 +8,258 @@ namespace xsd { namespace tree { + // content_order_type + // + + inline bool + operator== (const content_order& x, const content_order& y) + { + return x.id == y.id && x.index == y.index; + } + + inline bool + operator!= (const content_order& x, const content_order& y) + { + return !(x == y); + } + + inline bool + operator< (const content_order& x, const content_order& y) + { + return x.id < y.id || (x.id == y.id && x.index < y.index); + } + + // type + // + + inline _type:: + _type () + : container_ (0) + { + } + + template <typename C> + inline _type:: + _type (const C*) + : container_ (0) + { + } + + inline _type:: + _type (const type& x, flags f, container* c) + : container_ (c) + { + if (x.content_.get () != 0) + content_ = x.content_->clone (); + + if (x.dom_info_.get () != 0 && (f & flags::keep_dom)) + { + dom_info_ = x.dom_info_->clone (*this, c); + } + } + + inline const _type::dom_content_optional& _type:: + dom_content () const + { + const content_type* c (content_.get ()); + + if (c == 0) + { + content_.reset (new dom_content_type); + c = content_.get (); + } + + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<const dom_content_type*> (c) != 0); + + return static_cast<const dom_content_type*> (c)->dom; + } + + inline _type::dom_content_optional& _type:: + dom_content () + { + content_type* c (content_.get ()); + + if (c == 0) + { + content_.reset (new dom_content_type); + c = content_.get (); + } + + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<dom_content_type*> (c) != 0); + + return static_cast<dom_content_type*> (c)->dom; + } + + inline void _type:: + dom_content (const xercesc::DOMElement& e) + { + content_type* c (content_.get ()); + + if (c == 0) + content_.reset (new dom_content_type (e)); + else + { + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<dom_content_type*> (c) != 0); + static_cast<dom_content_type*> (c)->dom.set (e); + } + } + + inline void _type:: + dom_content (xercesc::DOMElement* e) + { + content_type* c (content_.get ()); + + if (c == 0) + content_.reset (new dom_content_type (e)); + else + { + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<dom_content_type*> (c) != 0); + static_cast<dom_content_type*> (c)->dom.set (e); + } + } + + inline void _type:: + dom_content (const dom_content_optional& d) + { + content_type* c (content_.get ()); + + if (c == 0) + content_.reset (new dom_content_type (d)); + else + { + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<dom_content_type*> (c) != 0); + static_cast<dom_content_type*> (c)->dom = d; + } + } + + inline const xercesc::DOMDocument& _type:: + dom_content_document () const + { + const content_type* c (content_.get ()); + + if (c == 0) + { + content_.reset (new dom_content_type); + c = content_.get (); + } + + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<const dom_content_type*> (c) != 0); + + return *static_cast<const dom_content_type*> (c)->doc; + } + + inline xercesc::DOMDocument& _type:: + dom_content_document () + { + content_type* c (content_.get ()); + + if (c == 0) + { + content_.reset (new dom_content_type); + c = content_.get (); + } + + // Accessing non-DOM content via the DOM API. + // + assert (dynamic_cast<dom_content_type*> (c) != 0); + + return *static_cast<dom_content_type*> (c)->doc; + } + + inline bool _type:: + null_content () const + { + return content_.get () == 0; + } + // simple_type // - template <typename B> - inline simple_type<B>:: + template <typename C, typename B> + inline simple_type<C, B>:: simple_type () { } - template <typename B> - template <typename C> - inline simple_type<B>:: - simple_type (const C*) + template <typename C, typename B> + inline simple_type<C, B>:: + simple_type (const C* s) + { + this->content_.reset (new text_content_type (s)); + } + + template <typename C, typename B> + inline simple_type<C, B>:: + simple_type (const std::basic_string<C>& s) + { + this->content_.reset (new text_content_type (s)); + } + + template <typename C, typename B> + inline const std::basic_string<C>& simple_type<C, B>:: + text_content () const + { + const content_type* c (this->content_.get ()); + + if (c == 0) + { + this->content_.reset (new text_content_type); + c = this->content_.get (); + } + + // Accessing non-text content via the text API. + // + assert (dynamic_cast<const text_content_type*> (c) != 0); + + return static_cast<const text_content_type*> (c)->text; + } + + template <typename C, typename B> + inline std::basic_string<C>& simple_type<C, B>:: + text_content () + { + content_type* c (this->content_.get ()); + + if (c == 0) + { + this->content_.reset (new text_content_type); + c = this->content_.get (); + } + + // Accessing non-text content via the text API. + // + assert (dynamic_cast<text_content_type*> (c) != 0); + + return static_cast<text_content_type*> (c)->text; + } + + template <typename C, typename B> + inline void simple_type<C, B>:: + text_content (const std::basic_string<C>& t) { + content_type* c (this->content_.get ()); + + if (c == 0) + this->content_.reset (new text_content_type (t)); + else + { + // Accessing non-text content via the text API. + // + assert (dynamic_cast<text_content_type*> (c) != 0); + static_cast<text_content_type*> (c)->text = t; + } } } } diff --git a/xsd/libxsd/xsd/cxx/tree/elements.txx b/xsd/libxsd/xsd/cxx/tree/elements.txx index 084cb56..4a8ca6e 100644 --- a/xsd/libxsd/xsd/cxx/tree/elements.txx +++ b/xsd/libxsd/xsd/cxx/tree/elements.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/elements.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xercesc/util/XMLUniDefs.hpp> @@ -28,8 +27,8 @@ namespace xsd // simple_type // - template <typename B> - simple_type<B>:: + template <typename C, typename B> + simple_type<C, B>:: simple_type (const simple_type& other, flags f, container* c) @@ -37,8 +36,8 @@ namespace xsd { } - template <typename B> - simple_type<B>* simple_type<B>:: + template <typename C, typename B> + simple_type<C, B>* simple_type<C, B>:: _clone (flags f, container* c) const { return new simple_type (*this, f, c); diff --git a/xsd/libxsd/xsd/cxx/tree/error-handler.hxx b/xsd/libxsd/xsd/cxx/tree/error-handler.hxx index 6e4426b..e520cce 100644 --- a/xsd/libxsd/xsd/cxx/tree/error-handler.hxx +++ b/xsd/libxsd/xsd/cxx/tree/error-handler.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/error-handler.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index c19d354..8520856 100644 --- a/xsd/libxsd/xsd/cxx/tree/error-handler.txx +++ b/xsd/libxsd/xsd/cxx/tree/error-handler.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/error-handler.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file namespace xsd diff --git a/xsd/libxsd/xsd/cxx/tree/exceptions.hxx b/xsd/libxsd/xsd/cxx/tree/exceptions.hxx index f6ddb15..d871416 100644 --- a/xsd/libxsd/xsd/cxx/tree/exceptions.hxx +++ b/xsd/libxsd/xsd/cxx/tree/exceptions.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/exceptions.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file /** diff --git a/xsd/libxsd/xsd/cxx/tree/exceptions.txx b/xsd/libxsd/xsd/cxx/tree/exceptions.txx index 8262fce..2544f42 100644 --- a/xsd/libxsd/xsd/cxx/tree/exceptions.txx +++ b/xsd/libxsd/xsd/cxx/tree/exceptions.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/exceptions.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/tree/bits/literals.hxx> diff --git a/xsd/libxsd/xsd/cxx/tree/facet.hxx b/xsd/libxsd/xsd/cxx/tree/facet.hxx index c4fbcbe..e17ead1 100644 --- a/xsd/libxsd/xsd/cxx/tree/facet.hxx +++ b/xsd/libxsd/xsd/cxx/tree/facet.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/facet.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index a523952..bd20fff 100644 --- a/xsd/libxsd/xsd/cxx/tree/istream-fwd.hxx +++ b/xsd/libxsd/xsd/cxx/tree/istream-fwd.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/istream-fwd.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_ISTREAM_FWD_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/istream.hxx b/xsd/libxsd/xsd/cxx/tree/istream.hxx index 2f8f8cb..45e334b 100644 --- a/xsd/libxsd/xsd/cxx/tree/istream.hxx +++ b/xsd/libxsd/xsd/cxx/tree/istream.hxx @@ -1,13 +1,17 @@ // file : xsd/cxx/tree/istream.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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 <map> +#include <string> +#include <memory> // std::auto_ptr/unique_ptr #include <cstddef> // std::size_t +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + #include <xsd/cxx/tree/istream-fwd.hxx> namespace xsd @@ -138,13 +142,102 @@ namespace xsd return s_; } + // Add string to the pool. The application should add every + // potentially pooled string to correctly re-create the pool + // constructed during insertion. + // + template <typename C> + void + pool_add (const std::basic_string<C>& s) + { + typedef pool_impl<C> pool_type; + + if (pool_.get () == 0) + pool_.reset (new pool_type); + + pool_type& p (*static_cast<pool_type*> (pool_.get ())); + p.push_back (s); + } + + // Get string from pool id. We return the result via an argument + // instead of as a return type to avoid difficulties some compilers + // (e.g., GCC) experience with calls like istream<S>::pool_string<C>. + // + template <typename C> + void + pool_string (std::size_t id, std::basic_string<C>& out) + { + typedef pool_impl<C> pool_type; + pool_type& p (*static_cast<pool_type*> (pool_.get ())); + out = p[id - 1]; + } + + public: + // 8-bit + // + signed char + read_char (); + + unsigned char + read_uchar (); + + // 16-bit + // + unsigned short + read_short (); + + unsigned short + read_ushort (); + + // 32-bit + // + unsigned int + read_int (); + + unsigned int + read_uint (); + + // 64-bit + // + unsigned long long + read_ulonglong (); + + unsigned long long + read_longlong (); + + // Boolean + // + bool + read_bool (); + + // Floating-point + // + float + read_float (); + + double + read_double (); + private: istream (const istream&); istream& operator= (const istream&); private: + struct pool + { + virtual + ~pool () {} + }; + + template <typename C> + struct pool_impl: pool, std::vector<std::basic_string<C> > + { + }; + S& s_; + std::size_t seq_; + XSD_AUTO_PTR<pool> pool_; }; @@ -251,6 +344,109 @@ namespace xsd istream_common::as_float64<double> as_float64 (x); return s >> as_float64; } + + // + // read_* functions. + // + + template <typename S> + inline signed char istream<S>:: + read_char () + { + signed char r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned char istream<S>:: + read_uchar () + { + unsigned char r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned short istream<S>:: + read_short () + { + short r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned short istream<S>:: + read_ushort () + { + unsigned short r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned int istream<S>:: + read_int () + { + int r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned int istream<S>:: + read_uint () + { + unsigned int r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned long long istream<S>:: + read_ulonglong () + { + long long r; + *this >> r; + return r; + } + + template <typename S> + inline unsigned long long istream<S>:: + read_longlong () + { + unsigned long long r; + *this >> r; + return r; + } + + template <typename S> + inline bool istream<S>:: + read_bool () + { + bool r; + *this >> r; + return r; + } + + template <typename S> + inline float istream<S>:: + read_float () + { + float r; + *this >> r; + return r; + } + + template <typename S> + inline double istream<S>:: + read_double () + { + double r; + *this >> r; + return r; + } } } } diff --git a/xsd/libxsd/xsd/cxx/tree/iterator-adapter.hxx b/xsd/libxsd/xsd/cxx/tree/iterator-adapter.hxx new file mode 100644 index 0000000..0a54604 --- /dev/null +++ b/xsd/libxsd/xsd/cxx/tree/iterator-adapter.hxx @@ -0,0 +1,270 @@ +// file : xsd/cxx/tree/iterator-adapter.hxx +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ITERATOR_ADAPTER_HXX +#define XSD_CXX_TREE_ITERATOR_ADAPTER_HXX + +#include <cstddef> // std::ptrdiff_t +#include <iterator> // std::iterator_traits + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // 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); + } + } + } +} + +#endif // XSD_CXX_TREE_ITERATOR_ADAPTER_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/list.hxx b/xsd/libxsd/xsd/cxx/tree/list.hxx index 30636e9..d1fe907 100644 --- a/xsd/libxsd/xsd/cxx/tree/list.hxx +++ b/xsd/libxsd/xsd/cxx/tree/list.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/list.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_LIST_HXX @@ -11,7 +10,7 @@ #include <xercesc/dom/DOMAttr.hpp> #include <xercesc/dom/DOMElement.hpp> -#include <xsd/cxx/tree/elements.hxx> // tree::istream +#include <xsd/cxx/tree/elements.hxx> #include <xsd/cxx/tree/istream-fwd.hxx> // tree::istream #include <xsd/cxx/tree/containers.hxx> // fundamental_p, sequence @@ -22,8 +21,7 @@ namespace xsd 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. // template <typename T, typename C, @@ -39,8 +37,8 @@ namespace xsd { public: explicit - list (flags f = 0, container* c = 0) - : sequence<T> (f, c) + list (container* c = 0) + : sequence<T> (c) { } @@ -60,8 +58,8 @@ namespace xsd 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) + list (const list<T, C, ST, false>& l, flags f = 0, container* c = 0) + : sequence<T> (l, f, c) { } @@ -77,7 +75,9 @@ namespace xsd private: void - init (const std::basic_string<C>&, const xercesc::DOMElement*); + init (const std::basic_string<C>&, + const xercesc::DOMElement*, + flags); }; @@ -88,8 +88,8 @@ namespace xsd { public: explicit - list (flags f = 0, container* c = 0) - : sequence<T> (f, c) + list (container* c = 0) + : sequence<T> (c) { } @@ -108,8 +108,8 @@ namespace xsd 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) + list (const list<T, C, ST, true>& l, flags f = 0, container* c = 0) + : sequence<T> (l, f, c) { } diff --git a/xsd/libxsd/xsd/cxx/tree/ostream.hxx b/xsd/libxsd/xsd/cxx/tree/ostream.hxx index cf2d9ee..ec15c51 100644 --- a/xsd/libxsd/xsd/cxx/tree/ostream.hxx +++ b/xsd/libxsd/xsd/cxx/tree/ostream.hxx @@ -1,13 +1,17 @@ // file : xsd/cxx/tree/ostream.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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 <map> +#include <string> +#include <memory> // std::auto_ptr/unique_ptr #include <cstddef> // std::size_t +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + namespace xsd { namespace cxx @@ -126,7 +130,7 @@ namespace xsd public: explicit ostream (S& s) - : s_ (s) + : s_ (s), seq_ (1) { } @@ -136,13 +140,55 @@ namespace xsd return s_; } + // If the string is not in the pool, add it and return 0. Otherwise + // return the string's pool id. In the former case the application + // should serialize the original string. + // + // The returned ids are sequential and start with 1. 0 is reserved + // as a special marker to be used by the application for the first + // encounter of the string. + // + template <typename C> + std::size_t + pool_string (const std::basic_string<C>& s) + { + typedef pool_impl<C> pool_type; + + if (pool_.get () == 0) + pool_.reset (new pool_type); + + pool_type& p (*static_cast<pool_type*> (pool_.get ())); + + std::pair<typename pool_type::iterator, bool> r ( + p.insert (std::pair<std::basic_string<C>, std::size_t> (s, seq_))); + + if (!r.second) + return r.first->second; + + seq_++; + return 0; + } + private: ostream (const ostream&); ostream& operator= (const ostream&); private: + struct pool + { + virtual + ~pool () {} + }; + + template <typename C> + struct pool_impl: pool, std::map<std::basic_string<C>, std::size_t> + { + }; + S& s_; + std::size_t seq_; + XSD_AUTO_PTR<pool> pool_; }; diff --git a/xsd/libxsd/xsd/cxx/tree/parsing.hxx b/xsd/libxsd/xsd/cxx/tree/parsing.hxx index 84b3898..f811788 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/parsing.txx b/xsd/libxsd/xsd/cxx/tree/parsing.txx index db50775..73e06f4 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing.txx +++ b/xsd/libxsd/xsd/cxx/tree/parsing.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <string> @@ -35,25 +34,23 @@ namespace xsd // inline _type:: _type (const xercesc::DOMElement& e, flags f, container* c) - : dom_info_ (0), container_ (c) + : container_ (c) { + if (f & flags::extract_content) + content_.reset (new dom_content_type (e)); + if (f & flags::keep_dom) - { - std::auto_ptr<dom_info> r ( - dom_info_factory::create (e, *this, c == 0)); - dom_info_ = r; - } + dom_info_ = dom_info_factory::create (e, *this, c == 0); } inline _type:: _type (const xercesc::DOMAttr& a, flags f, container* c) - : dom_info_ (0), container_ (c) + : container_ (c) { + // anyType cannot be an attribute type so no content extraction. + if (f & flags::keep_dom) - { - std::auto_ptr<dom_info> r (dom_info_factory::create (a, *this)); - dom_info_ = r; - } + dom_info_ = dom_info_factory::create (a, *this); } template <typename C> @@ -62,36 +59,43 @@ namespace xsd const xercesc::DOMElement*, flags, container* c) - : dom_info_ (0), // List elements don't have associated DOM nodes. - container_ (c) + : container_ (c) // List elements don't have associated DOM nodes. { + // anyType cannot be a list element type so no content extraction. } // simple_type // - template <typename B> - inline simple_type<B>:: + template <typename C, typename B> + inline simple_type<C, B>:: simple_type (const xercesc::DOMElement& e, flags f, container* c) - : B (e, f, c) + : B (e, (f & ~flags::extract_content), c) { + if (f & flags::extract_content) + this->content_.reset ( + new text_content_type (tree::text_content<C> (e))); } - template <typename B> - inline simple_type<B>:: + template <typename C, typename B> + inline simple_type<C, B>:: simple_type (const xercesc::DOMAttr& a, flags f, container* c) - : B (a, f, c) + : B (a, (f & ~flags::extract_content), c) { + if (f & flags::extract_content) + this->content_.reset (new text_content_type ( + xml::transcode<C> (a.getValue ()))); } - template <typename B> - template <typename C> - inline simple_type<B>:: + template <typename C, typename B> + inline simple_type<C, B>:: simple_type (const std::basic_string<C>& s, const xercesc::DOMElement* e, flags f, container* c) - : B (s, e, f, c) + : B (s, e, (f & ~flags::extract_content), c) { + if (f & flags::extract_content) + this->content_.reset (new text_content_type (s)); } // fundamental_base @@ -170,23 +174,25 @@ namespace xsd } // Individual items of the list have no DOM association. Therefore - // I clear keep_dom from flags. + // we 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 + : sequence<T> (c) { - init (text_content<C> (e), &e); + init (tree::text_content<C> (e), &e, f & ~flags::keep_dom); } 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 + : sequence<T> (c) { - init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); + init (xml::transcode<C> (a.getValue ()), + a.getOwnerElement (), + f & ~flags::keep_dom); } template <typename T, typename C, schema_type::value ST> @@ -195,20 +201,21 @@ namespace xsd const xercesc::DOMElement* e, flags f, container* c) - : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + : sequence<T> (c) { - init (s, e); + init (s, e, f & ~flags::keep_dom); } 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) + init (const std::basic_string<C>& s, + const xercesc::DOMElement* parent, + flags f) { 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 ()); @@ -223,13 +230,12 @@ namespace xsd 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); + this->push_back ( + traits<T, C, ST>::create ( + basic_string<C> (data + i, j - i), + parent, + f, + this->container_)); i = bits::find_ns (data, size, j); } @@ -237,13 +243,12 @@ namespace xsd { // Last element. // - ptr r ( - new T (basic_string<C> (data + i, size - i), - parent, - this->flags_, - this->container_)); - - this->v_.push_back (r); + this->push_back ( + traits<T, C, ST>::create ( + basic_string<C> (data + i, size - i), + parent, + f, + this->container_)); break; } @@ -252,16 +257,16 @@ namespace xsd 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 + list (const xercesc::DOMElement& e, flags, container* c) + : sequence<T> (c) { - init (text_content<C> (e), &e); + init (tree::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 + list (const xercesc::DOMAttr& a, flags, container* c) + : sequence<T> (c) { init (xml::transcode<C> (a.getValue ()), a.getOwnerElement ()); } @@ -270,9 +275,9 @@ namespace xsd inline list<T, C, ST, true>:: list (const std::basic_string<C>& s, const xercesc::DOMElement* parent, - flags f, + flags, container* c) - : sequence<T> (flags (f & ~flags::keep_dom), c) // ambiguous + : sequence<T> (c) { init (s, parent); } @@ -329,7 +334,7 @@ namespace xsd string<C, B>:: string (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c), - base_type (text_content<C> (e)) + base_type (tree::text_content<C> (e)) { } @@ -696,7 +701,7 @@ namespace xsd uri<C, B>:: uri (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c), - base_type (trim (text_content<C> (e))) + base_type (trim (tree::text_content<C> (e))) { } @@ -726,7 +731,7 @@ namespace xsd qname (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - std::basic_string<C> v (trim (text_content<C> (e))); + std::basic_string<C> v (trim (tree::text_content<C> (e))); ns_ = resolve (v, &e); name_ = xml::uq_name (v); } @@ -797,7 +802,7 @@ namespace xsd { // This implementation is not optimal. // - std::basic_string<C> str (trim (text_content<C> (e))); + std::basic_string<C> str (trim (tree::text_content<C> (e))); decode (xml::string (str).c_str ()); } @@ -832,7 +837,7 @@ namespace xsd { // This implementation is not optimal. // - std::basic_string<C> str (trim (text_content<C> (e))); + std::basic_string<C> str (trim (tree::text_content<C> (e))); decode (xml::string (str).c_str ()); } diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx index 3dafdaa..8bbd3a8 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/boolean.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/boolean.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_BOOLEAN_HXX @@ -42,7 +41,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx index 0a127c9..d6cf1d3 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/byte.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/byte.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_BYTE_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx b/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx index 913786c..29b12b6 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/date-time.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/date-time.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/ro-string.hxx> @@ -60,7 +59,7 @@ namespace xsd gday (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -110,7 +109,7 @@ namespace xsd gmonth (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -160,7 +159,7 @@ namespace xsd gyear (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -223,7 +222,7 @@ namespace xsd gmonth_day (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -274,7 +273,7 @@ namespace xsd gyear_month (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -338,7 +337,7 @@ namespace xsd date (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -403,7 +402,7 @@ namespace xsd time (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -470,7 +469,7 @@ namespace xsd date_time (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> @@ -557,7 +556,7 @@ namespace xsd duration (const xercesc::DOMElement& e, flags f, container* c) : B (e, f, c) { - parse (text_content<C> (e)); + parse (tree::text_content<C> (e)); } template <typename C, typename B> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx index 636c0f5..b615d3c 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/decimal.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/decimal.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_DECIMAL_HXX @@ -45,7 +44,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx index 1507ccf..4466f7d 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/double.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/double.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_DOUBLE_HXX @@ -45,7 +44,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx b/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx index bb9a4c6..6ac9674 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/element-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/element-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_ELEMENT_MAP_TXX @@ -17,7 +16,7 @@ namespace xsd namespace tree { template <typename C, typename T> - std::auto_ptr<element_type<C, T> > element_map<C, T>:: + XSD_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)); @@ -30,10 +29,10 @@ namespace xsd } template<typename T, typename C, typename B> - std::auto_ptr<element_type<C, B> > + XSD_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)); + return XSD_AUTO_PTR<element_type<C, B> > (new T (e, f)); } } } diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx index 3e34f93..ee582e5 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/float.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/float.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_FLOAT_HXX @@ -45,7 +44,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx index d996d3a..b4eec88 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/int.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/int.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_INT_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx index 742ade1..070e66d 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/long.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/long.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_LONG_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx index 3a7ead8..90d5144 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/short.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/short.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_SHORT_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx index ce336be..c172e93 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-byte.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/unsigned-byte.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_UNSIGNED_BYTE_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx index e908dd0..07fb7f2 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-int.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/unsigned-int.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_UNSIGNED_INT_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx index 647b8dd..0036e0d 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-long.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/unsigned-long.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_UNSIGNED_LONG_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx index f53c724..838a2a8 100644 --- a/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx +++ b/xsd/libxsd/xsd/cxx/tree/parsing/unsigned-short.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/parsing/unsigned-short.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_PARSING_UNSIGNED_SHORT_HXX @@ -41,7 +40,7 @@ namespace xsd 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); + return create (tree::text_content<C> (e), 0, f, c); } template <typename C> diff --git a/xsd/libxsd/xsd/cxx/tree/serialization.hxx b/xsd/libxsd/xsd/cxx/tree/serialization.hxx index 612185f..24b26e2 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_SERIALIZATION_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/serialization.txx b/xsd/libxsd/xsd/cxx/tree/serialization.txx index 29364f4..055f603 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization.txx +++ b/xsd/libxsd/xsd/cxx/tree/serialization.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <string> @@ -92,9 +91,29 @@ namespace xsd // Insertion operators for type. // inline void - operator<< (xercesc::DOMElement& e, const type&) + operator<< (xercesc::DOMElement& e, const type& x) { xml::dom::clear<char> (e); + + if (!x.null_content () && x.dom_content ().present ()) + { + // Clone the contents of the element. + // + using namespace xercesc; + + DOMDocument& doc (*e.getOwnerDocument ()); + const DOMElement& se (x.dom_content ().get ()); + DOMNamedNodeMap& sa (*se.getAttributes ()); + + for (XMLSize_t i (0), n (sa.getLength ()); i != n; ++i) + e.setAttributeNode ( + static_cast<DOMAttr*> (doc.importNode (sa.item (i), true))); + + for (DOMNode* sn (se.getFirstChild ()); + sn != 0; + sn = sn->getNextSibling ()) + e.appendChild (doc.importNode (sn, true)); + } } inline void @@ -110,23 +129,30 @@ namespace xsd // Insertion operators for simple_type. // - template <typename B> + template <typename C, typename B> inline void - operator<< (xercesc::DOMElement& e, const simple_type<B>&) + operator<< (xercesc::DOMElement& e, const simple_type<C, B>& x) { - xml::dom::clear<char> (e); + if (x.null_content ()) + xml::dom::clear<char> (e); + else + e << x.text_content (); } - template <typename B> + template <typename C, typename B> inline void - operator<< (xercesc::DOMAttr&, const simple_type<B>&) + operator<< (xercesc::DOMAttr& a, const simple_type<C, B>& x) { + if (!x.null_content ()) + a << x.text_content (); } template <typename C, typename B> inline void - operator<< (list_stream<C>&, const simple_type<B>&) + operator<< (list_stream<C>& ls, const simple_type<C, B>& x) { + if (!x.null_content ()) + ls << x.text_content (); } // Insertion operators for list. diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx index ce34560..90978c4 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/boolean.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/boolean.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 583eda9..bd7bceb 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/byte.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/byte.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/byte.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 1180e1c..c2a02d6 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/date-time.txx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/date-time.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/date-time.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <locale> diff --git a/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx b/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx index 971622f..6e48809 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/decimal.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/decimal.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 6d21536..bc4d5c4 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/double.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/double.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/double.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 9870ff2..63149f4 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/element-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/element-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/element-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 2d37ae6..9aa79b0 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/float.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/float.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/float.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index f88d6b8..f96124a 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/int.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/int.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/int.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index c37338b..98a4632 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/long.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/long.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/long.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 7d885c1..f8a9b94 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/short.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/short.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/short.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 114f1a1..f30c575 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-byte.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/unsigned-byte.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index f91fe21..7dbb3a8 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-int.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/unsigned-int.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index f5f12f3..8808e34 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-long.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/unsigned-long.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 52437e0..ac3a448 100644 --- a/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx +++ b/xsd/libxsd/xsd/cxx/tree/serialization/unsigned-short.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/serialization/unsigned-short.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 28619a5..836ee30 100644 --- a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/std-ostream-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_STD_OSTREAM_MAP_HXX @@ -28,7 +27,7 @@ namespace xsd std_ostream_map (); void - register_type (const type_id&, inserter, bool override = true); + register_type (const type_id&, inserter, bool replace = true); void unregister_type (const type_id&); diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx index 6a748ec..ef65ef2 100644 --- a/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/std-ostream-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/tree/types.hxx> @@ -25,7 +24,7 @@ namespace xsd &inserter_impl<C, type>, false); - typedef simple_type<type> simple_type; + typedef simple_type<C, type> simple_type; register_type ( typeid (simple_type), &inserter_impl<C, simple_type>, @@ -211,9 +210,9 @@ namespace xsd template <typename C> void std_ostream_map<C>:: - register_type (const type_id& tid, inserter i, bool override) + register_type (const type_id& tid, inserter i, bool replace) { - if (override || type_map_.find (&tid) == type_map_.end ()) + if (replace || type_map_.find (&tid) == type_map_.end ()) type_map_[&tid] = i; } diff --git a/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx b/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx index a7ab357..9a8f976 100644 --- a/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx +++ b/xsd/libxsd/xsd/cxx/tree/std-ostream-operators.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/std-ostream-operators.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_STD_OSTREAM_OPERATORS_HXX @@ -25,6 +24,7 @@ namespace xsd inline std::basic_ostream<C>& operator<< (std::basic_ostream<C>& os, const type&) { + // Not printing DOM content even if it's there. return os; } @@ -33,8 +33,11 @@ namespace xsd // template <typename C, typename B> inline std::basic_ostream<C>& - operator<< (std::basic_ostream<C>& os, const simple_type<B>&) + operator<< (std::basic_ostream<C>& os, const simple_type<C, B>& x) { + if (!x.null_content ()) + os << x.text_content (); + return os; } diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx index dd4c79a..f57c435 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.hxx @@ -1,15 +1,16 @@ // file : xsd/cxx/tree/stream-extraction-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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 <memory> // std::auto_ptr/unique_ptr #include <cstddef> // std::size_t +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + #include <xsd/cxx/tree/elements.hxx> #include <xsd/cxx/tree/istream.hxx> #include <xsd/cxx/xml/qualified-name.hxx> @@ -24,7 +25,7 @@ namespace xsd struct stream_extraction_map { typedef xml::qualified_name<C> qualified_name; - typedef std::auto_ptr<type> (*extractor) ( + typedef XSD_AUTO_PTR<type> (*extractor) ( istream<S>&, flags, container*); public: @@ -33,12 +34,12 @@ namespace xsd void register_type (const qualified_name& name, extractor, - bool override = true); + bool replace = true); void unregister_type (const qualified_name& name); - std::auto_ptr<type> + XSD_AUTO_PTR<type> extract (istream<S>&, flags, container*); public: @@ -82,7 +83,7 @@ namespace xsd // // template<typename S, typename T> - std::auto_ptr<type> + XSD_AUTO_PTR<type> extractor_impl (istream<S>&, flags, container*); diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx index a4e429e..61dd306 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-extraction-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/tree/types.hxx> @@ -31,7 +30,7 @@ namespace xsd &extractor_impl<S, type>, false); - typedef simple_type<type> simple_type; + typedef simple_type<C, type> simple_type; register_type ( qualified_name (bits::any_simple_type<C> (), xsd), &extractor_impl<S, simple_type>, @@ -219,9 +218,9 @@ namespace xsd void stream_extraction_map<S, C>:: register_type (const qualified_name& name, extractor e, - bool override) + bool replace) { - if (override || type_map_.find (name) == type_map_.end ()) + if (replace || type_map_.find (name) == type_map_.end ()) type_map_[name] = e; } @@ -233,11 +232,34 @@ namespace xsd } template <typename S, typename C> - std::auto_ptr<type> stream_extraction_map<S, C>:: + XSD_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; + std::basic_string<C> ns, name; + + // The namespace and name strings are pooled. + // + std::size_t id; + istream_common::as_size<std::size_t> as_size (id); + s >> as_size; + + if (id != 0) + s.pool_string (id, ns); + else + { + s >> ns; + s.pool_add (ns); + } + + s >> as_size; + + if (id != 0) + s.pool_string (id, name); + else + { + s >> name; + s.pool_add (name); + } if (extractor e = find (qualified_name (name, ns))) { @@ -280,10 +302,10 @@ namespace xsd // // template<typename S, typename T> - std::auto_ptr<type> + XSD_AUTO_PTR<type> extractor_impl (istream<S>& s, flags f, container* c) { - return std::auto_ptr<type> (new T (s, f, c)); + return XSD_AUTO_PTR<type> (new T (s, f, c)); } diff --git a/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx b/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx index f82042f..ee39bcc 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx +++ b/xsd/libxsd/xsd/cxx/tree/stream-extraction.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-extraction.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_STREAM_EXTRACTION_HXX @@ -29,12 +28,18 @@ namespace xsd // simple_type // - template <typename B> + template <typename C, typename B> template <typename S> - inline simple_type<B>:: + inline simple_type<C, B>:: simple_type (istream<S>& s, flags f, container* c) - : type (s, f, c) + : type (s, f & ~flags::extract_content, c) { + if (f & flags::extract_content) + { + std::basic_string<C> t; + s >> t; + this->content_.reset (new text_content_type (t)); + } } // fundamental_base @@ -55,7 +60,7 @@ namespace xsd template <typename S> list<T, C, ST, false>:: list (istream<S>& s, flags f, container* c) - : sequence<T> (f, c) + : sequence<T> (c) { std::size_t size; istream_common::as_size<std::size_t> as_size (size); @@ -66,18 +71,15 @@ namespace xsd this->reserve (size); while (size--) - { - std::auto_ptr<T> p (new T (s, f, c)); - this->push_back (p); - } + this->push_back (traits<T, C, ST>::create (s, f, c)); } } 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) + list (istream<S>& s, flags, container* c) + : sequence<T> (c) { std::size_t size; istream_common::as_size<std::size_t> as_size (size); diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx index e26a3da..c8a113b 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_STREAM_INSERTION_MAP_HXX @@ -34,7 +33,7 @@ namespace xsd register_type (const type_id&, const qualified_name& name, inserter, - bool override = true); + bool replace = true); void unregister_type (const type_id&); diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx index 07bfa8b..78fbacb 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xsd/cxx/tree/types.hxx> @@ -32,7 +31,7 @@ namespace xsd &inserter_impl<S, type>, false); - typedef simple_type<type> simple_type; + typedef simple_type<C, type> simple_type; register_type ( typeid (simple_type), qualified_name (bits::any_simple_type<C> (), xsd), @@ -248,9 +247,9 @@ namespace xsd register_type (const type_id& tid, const qualified_name& name, inserter i, - bool override) + bool replace) { - if (override || type_map_.find (&tid) == type_map_.end ()) + if (replace || type_map_.find (&tid) == type_map_.end ()) type_map_[&tid] = type_info (name, i); } @@ -269,7 +268,24 @@ namespace xsd { const qualified_name& qn (ti->name ()); - s << qn.namespace_ () << qn.name (); + // Pool the namespace and name strings. + // + const std::basic_string<C>& ns (qn.namespace_ ()); + const std::basic_string<C>& n (qn.name ()); + + std::size_t ns_id (s.pool_string (ns)); + std::size_t n_id (s.pool_string (n)); + + s << ostream_common::as_size<std::size_t> (ns_id); + + if (ns_id == 0) + s << ns; + + s << ostream_common::as_size<std::size_t> (n_id); + + if (n_id == 0) + s << n; + ti->inserter () (s, x); } else diff --git a/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx index c345e80..b04846f 100644 --- a/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx +++ b/xsd/libxsd/xsd/cxx/tree/stream-insertion.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/stream-insertion.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_STREAM_INSERTION_HXX @@ -24,15 +23,19 @@ namespace xsd inline ostream<S>& operator<< (ostream<S>& s, const type&) { + // Not saving DOM content even if it's there. return s; } // simple_type // - template <typename S, typename B> + template <typename S, typename C, typename B> inline ostream<S>& - operator<< (ostream<S>& s, const simple_type<B>&) + operator<< (ostream<S>& s, const simple_type<C, B>& x) { + if (!x.null_content ()) + s << x.text_content (); + return s; } diff --git a/xsd/libxsd/xsd/cxx/tree/text.hxx b/xsd/libxsd/xsd/cxx/tree/text.hxx index 15f12dc..8808787 100644 --- a/xsd/libxsd/xsd/cxx/tree/text.hxx +++ b/xsd/libxsd/xsd/cxx/tree/text.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/text.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_TEXT_HXX diff --git a/xsd/libxsd/xsd/cxx/tree/text.txx b/xsd/libxsd/xsd/cxx/tree/text.txx index 2d83c71..6764d5c 100644 --- a/xsd/libxsd/xsd/cxx/tree/text.txx +++ b/xsd/libxsd/xsd/cxx/tree/text.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/text.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xercesc/dom/DOMText.hpp> @@ -31,14 +30,7 @@ namespace xsd 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; @@ -51,14 +43,7 @@ namespace xsd 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: diff --git a/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx b/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx index 7e849db..b2558c7 100644 --- a/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/type-factory-map.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/type-factory-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX @@ -8,11 +7,13 @@ #include <map> #include <string> -#include <memory> // std::auto_ptr +#include <memory> // std::auto_ptr/unique_ptr #include <cstddef> // std::size_t #include <xercesc/dom/DOMElement.hpp> +#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR + #include <xsd/cxx/tree/elements.hxx> #include <xsd/cxx/xml/qualified-name.hxx> @@ -26,16 +27,16 @@ namespace xsd struct type_factory_map { typedef xml::qualified_name<C> qualified_name; - typedef std::auto_ptr<type> (*factory) (const xercesc::DOMElement&, - flags, - container*); + typedef XSD_AUTO_PTR<type> (*factory) (const xercesc::DOMElement&, + flags, + container*); public: type_factory_map (); void register_type (const qualified_name& name, factory, - bool override = true); + bool replace = true); void unregister_type (const qualified_name& name); @@ -49,7 +50,7 @@ namespace xsd unregister_element (const qualified_name& root, const qualified_name& subst); - std::auto_ptr<type> + XSD_AUTO_PTR<type> create (const C* name, // element name const C* ns, // element namespace factory static_type, @@ -66,7 +67,7 @@ namespace xsd private: template <typename T> - static std::auto_ptr<type> + static XSD_AUTO_PTR<type> traits_adapter (const xercesc::DOMElement&, flags, container*); private: @@ -132,7 +133,7 @@ namespace xsd // // template<typename T> - std::auto_ptr<type> + XSD_AUTO_PTR<type> factory_impl (const xercesc::DOMElement&, flags, container*); // diff --git a/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx b/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx index b9e0a06..e1fe0cc 100644 --- a/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/type-factory-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/type-factory-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xercesc/validators/schema/SchemaSymbols.hpp> @@ -38,7 +37,7 @@ namespace xsd &factory_impl<type>, false); - typedef simple_type<type> simple_type; + typedef simple_type<C, type> simple_type; register_type ( qualified_name (bits::any_simple_type<C> (), xsd), &factory_impl<simple_type>, @@ -226,9 +225,9 @@ namespace xsd void type_factory_map<C>:: register_type (const qualified_name& name, factory f, - bool override) + bool replace) { - if (override || type_map_.find (name) == type_map_.end ()) + if (replace || type_map_.find (name) == type_map_.end ()) type_map_[name] = f; } @@ -273,7 +272,7 @@ namespace xsd } template <typename C> - std::auto_ptr<type> type_factory_map<C>:: + XSD_AUTO_PTR<type> type_factory_map<C>:: create (const C* name, const C* ns, factory static_type, @@ -307,7 +306,7 @@ namespace xsd } if (f == 0) - return std::auto_ptr<type> (0); // No match. + return XSD_AUTO_PTR<type> (); // No match. // Check for xsi:type // @@ -326,11 +325,10 @@ namespace xsd template <typename C> template <typename T> - std::auto_ptr<type> type_factory_map<C>:: + XSD_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 ()); + return XSD_AUTO_PTR<type> (traits<T, C>::create (e, f, c)); } template <typename C> @@ -428,10 +426,10 @@ namespace xsd // // template<typename T> - std::auto_ptr<type> + XSD_AUTO_PTR<type> factory_impl (const xercesc::DOMElement& e, flags f, container* c) { - return std::auto_ptr<type> (new T (e, f, c)); + return XSD_AUTO_PTR<type> (new T (e, f, c)); } // diff --git a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx index 491ad3b..f461b7d 100644 --- a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx +++ b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/type-serializer-map.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_TYPE_SERIALIZER_MAP_HXX @@ -16,6 +15,7 @@ #include <xsd/cxx/tree/elements.hxx> #include <xsd/cxx/xml/qualified-name.hxx> +#include <xsd/cxx/xml/dom/auto-ptr.hxx> #include <xsd/cxx/xml/dom/serialization-header.hxx> // namespace_infomap namespace xsd @@ -35,7 +35,7 @@ namespace xsd register_type (const type_id&, const qualified_name& name, serializer, - bool override = true); + bool replace = true); void unregister_type (const type_id&); @@ -70,7 +70,7 @@ namespace xsd // Create DOMDocument with root element suitable for serializing // x into it. // - xml::dom::auto_ptr<xercesc::DOMDocument> + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> serialize (const C* name, // element name const C* ns, // element namespace const xml::dom::namespace_infomap<C>&, diff --git a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx index 859331f..44a2204 100644 --- a/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx +++ b/xsd/libxsd/xsd/cxx/tree/type-serializer-map.txx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/type-serializer-map.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #include <xercesc/util/XMLUni.hpp> @@ -12,8 +11,6 @@ #include <xsd/cxx/tree/types.hxx> #include <xsd/cxx/tree/bits/literals.hxx> -#include <iostream> - namespace xsd { namespace cxx @@ -39,7 +36,7 @@ namespace xsd &serializer_impl<type>, false); - typedef simple_type<type> simple_type; + typedef simple_type<C, type> simple_type; register_type ( typeid (simple_type), qualified_name (bits::any_simple_type<C> (), xsd), @@ -255,9 +252,9 @@ namespace xsd register_type (const type_id& tid, const qualified_name& name, serializer s, - bool override) + bool replace) { - if (override || type_map_.find (&tid) == type_map_.end ()) + if (replace || type_map_.find (&tid) == type_map_.end ()) type_map_[&tid] = type_info (name, s); } @@ -399,7 +396,7 @@ namespace xsd } template <typename C> - xml::dom::auto_ptr<xercesc::DOMDocument> type_serializer_map<C>:: + XSD_DOM_AUTO_PTR<xercesc::DOMDocument> type_serializer_map<C>:: serialize (const C* name, const C* ns, const xml::dom::namespace_infomap<C>& m, diff --git a/xsd/libxsd/xsd/cxx/tree/types.hxx b/xsd/libxsd/xsd/cxx/tree/types.hxx index 299824f..288a291 100644 --- a/xsd/libxsd/xsd/cxx/tree/types.hxx +++ b/xsd/libxsd/xsd/cxx/tree/types.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/types.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file /** @@ -272,6 +271,29 @@ namespace xsd } }; + /** + * @brief %string comparison operator. + * + * @return True if the strings are equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator== (const string<C, B>& a, const string<C, B>& b) + { + return static_cast<const std::basic_string<C>&> (a) == b; + } + + /** + * @brief %string comparison operator. + * + * @return True if the strings are not equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator!= (const string<C, B>& a, const string<C, B>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema normalizedString @@ -1014,7 +1036,7 @@ namespace xsd * @brief Default constructor creates no elements. */ nmtokens () - : base_type (0, this) + : base_type (this) { } @@ -1120,6 +1142,31 @@ namespace xsd //@} }; + /** + * @brief %nmtokens comparison operator. + * + * @return True if the lists of nmtokens are equal, false otherwise. + */ + template <typename C, typename B, typename nmtoken> + inline bool + operator== (const nmtokens<C, B, nmtoken>& a, + const nmtokens<C, B, nmtoken>& b) + { + return static_cast<const list<nmtoken, C>&> (a) == b; + } + + /** + * @brief %nmtokens comparison operator. + * + * @return True if the lists of nmtokens are not equal, false otherwise. + */ + template <typename C, typename B, typename nmtoken> + inline bool + operator!= (const nmtokens<C, B, nmtoken>& a, + const nmtokens<C, B, nmtoken>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema Name built-in @@ -2076,20 +2123,7 @@ namespace xsd 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 (); - } + using B::_container; //@endcond @@ -2483,7 +2517,7 @@ namespace xsd * @brief Default constructor creates no elements. */ idrefs () - : base_type (0, this) + : base_type (this) { } @@ -2589,6 +2623,29 @@ namespace xsd //@} }; + /** + * @brief %idrefs comparison operator. + * + * @return True if the lists of idrefs are equal, false otherwise. + */ + template <typename C, typename B, typename idref> + inline bool + operator== (const idrefs<C, B, idref>& a, const idrefs<C, B, idref>& b) + { + return static_cast<const list<idref, C>&> (a) == b; + } + + /** + * @brief %idrefs comparison operator. + * + * @return True if the lists of idrefs are not equal, false otherwise. + */ + template <typename C, typename B, typename idref> + inline bool + operator!= (const idrefs<C, B, idref>& a, const idrefs<C, B, idref>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema anyURI built-in @@ -2825,6 +2882,29 @@ namespace xsd friend class qname; }; + /** + * @brief %uri comparison operator. + * + * @return True if the uris are equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator== (const uri<C, B>& a, const uri<C, B>& b) + { + return static_cast<const std::basic_string<C>&> (a) == b; + } + + /** + * @brief %uri comparison operator. + * + * @return True if the uris are not equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator!= (const uri<C, B>& a, const uri<C, B>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema QName built-in @@ -3225,6 +3305,29 @@ namespace xsd decode (const XMLCh*); }; + /** + * @brief %base64_binary comparison operator. + * + * @return True if the binaries are equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator== (const base64_binary<C, B>& a, const base64_binary<C, B>& b) + { + return static_cast<const buffer<C>&> (a) == b; + } + + /** + * @brief %base64_binary comparison operator. + * + * @return True if the binaries are not equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator!= (const base64_binary<C, B>& a, const base64_binary<C, B>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema hexBinary @@ -3418,6 +3521,29 @@ namespace xsd decode (const XMLCh*); }; + /** + * @brief %hex_binary comparison operator. + * + * @return True if the binaries are equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator== (const hex_binary<C, B>& a, const hex_binary<C, B>& b) + { + return static_cast<const buffer<C>&> (a) == b; + } + + /** + * @brief %hex_binary comparison operator. + * + * @return True if the binaries are not equal, false otherwise. + */ + template <typename C, typename B> + inline bool + operator!= (const hex_binary<C, B>& a, const hex_binary<C, B>& b) + { + return !(a == b); + } /** * @brief Class corresponding to the XML Schema ENTITY built-in @@ -3677,7 +3803,7 @@ namespace xsd * @brief Default constructor creates no elements. */ entities () - : base_type (0, this) + : base_type (this) { } @@ -3782,6 +3908,32 @@ namespace xsd container* c = 0); //@} }; + + /** + * @brief %entities comparison operator. + * + * @return True if the lists of entities are equal, false otherwise. + */ + template <typename C, typename B, typename entity> + inline bool + operator== (const entities<C, B, entity>& a, + const entities<C, B, entity>& b) + { + return static_cast<const list<entity, C>&> (a) == b; + } + + /** + * @brief %entities comparison operator. + * + * @return True if the lists of entities are not equal, false otherwise. + */ + template <typename C, typename B, typename entity> + inline bool + operator!= (const entities<C, B, entity>& a, + const entities<C, B, entity>& b) + { + return !(a == b); + } } } } diff --git a/xsd/libxsd/xsd/cxx/tree/types.txx b/xsd/libxsd/xsd/cxx/tree/types.txx index 8d6d79f..8696171 100644 --- a/xsd/libxsd/xsd/cxx/tree/types.txx +++ b/xsd/libxsd/xsd/cxx/tree/types.txx @@ -1,13 +1,17 @@ // file : xsd/cxx/tree/types.txx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 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/config.hxx> // XSD_CXX11 + +#ifdef XSD_CXX11 +# include <memory> // std::unique_ptr +#else +# include <xsd/cxx/auto-array.hxx> +#endif #include <xsd/cxx/xml/std-memory-manager.hxx> @@ -168,11 +172,6 @@ namespace xsd 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) @@ -211,11 +210,6 @@ namespace xsd 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 @@ -321,52 +315,24 @@ namespace xsd 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; + using namespace xercesc; 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 - } +#ifdef XSD_CXX11 + std::unique_ptr<XMLByte[], xml::std_memory_manager&> r ( #else - unsigned int n; - - xml::std_memory_manager mm; auto_array<XMLByte, xml::std_memory_manager> r ( +#endif Base64::encode ( reinterpret_cast<const XMLByte*> (this->data ()), - static_cast<unsigned int> (this->size ()), + static_cast<XMLSize_t> (this->size ()), &n, &mm), mm); @@ -376,14 +342,13 @@ namespace xsd str.reserve (n + 1); str.resize (n); - for (unsigned int i (0); i < n; ++i) + for (XMLSize_t i (0); i < n; ++i) str[i] = C (r[i]); } else { //@@ throw } -#endif return str; } @@ -392,28 +357,18 @@ namespace xsd void base64_binary<C, B>:: decode (const XMLCh* src) { - // HP aCC3 cannot handle using namespace xercesc; - // - using xercesc::Base64; + using namespace xercesc; 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); + +#ifdef XSD_CXX11 + std::unique_ptr<XMLByte[], xml::std_memory_manager&> data ( #else - unsigned int size; auto_array<XMLByte, xml::std_memory_manager> data ( +#endif Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), - mm); -#endif // _XERCES_VERSION >= 30000 + mm); if (data) { @@ -425,30 +380,6 @@ namespace xsd { //@@ 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 } @@ -496,11 +427,6 @@ namespace xsd 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 diff --git a/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx b/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx index ebc3d22..d3b6ce1 100644 --- a/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-common.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/xdr-stream-common.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef 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 index 012c1e4..d64825b 100644 --- a/xsd/libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-extraction.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/xdr-stream-extraction.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_XDR_STREAM_EXTRACTION_HXX @@ -9,6 +8,19 @@ #include <rpc/types.h> #include <rpc/xdr.h> +// Of course BSD has to be different and name its functions u_intXX +// instead of uintXX. Plus it does not have XX == 8. +// +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) +# if !defined(XSD_CXX_TREE_ASSUME_SUN_XDR) && !defined(xdr_int8_t) +# define xdr_int8_t(x, y) xdr_char(x, reinterpret_cast<char*> (y)) +# define xdr_uint8_t(x, y) xdr_u_char(x, reinterpret_cast<unsigned char*> (y)) +# define xdr_uint16_t xdr_u_int16_t +# define xdr_uint32_t xdr_u_int32_t +# define xdr_uint64_t xdr_u_int64_t +# endif +#endif + #include <string> #include <xsd/cxx/tree/buffer.hxx> @@ -249,7 +261,7 @@ namespace xsd // Dangerous but fast. // x.clear (); - + if (n != 0) { x.resize (n); diff --git a/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx b/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx index 00031d2..113569f 100644 --- a/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx +++ b/xsd/libxsd/xsd/cxx/tree/xdr-stream-insertion.hxx @@ -1,6 +1,5 @@ // file : xsd/cxx/tree/xdr-stream-insertion.hxx -// author : Boris Kolpackov <boris@codesynthesis.com> -// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file #ifndef XSD_CXX_TREE_XDR_STREAM_INSERTION_HXX @@ -9,6 +8,19 @@ #include <rpc/types.h> #include <rpc/xdr.h> +// Of course BSD has to be different and name its functions u_intXX +// instead of uintXX. Plus it does not have XX == 8. +// +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) +# if !defined(XSD_CXX_TREE_ASSUME_SUN_XDR) && !defined(xdr_int8_t) +# define xdr_int8_t(x, y) xdr_char(x, reinterpret_cast<char*> (y)) +# define xdr_uint8_t(x, y) xdr_u_char(x, reinterpret_cast<unsigned char*> (y)) +# define xdr_uint16_t xdr_u_int16_t +# define xdr_uint32_t xdr_u_int32_t +# define xdr_uint64_t xdr_u_int64_t +# endif +#endif + #include <string> #include <xsd/cxx/tree/buffer.hxx> |