From: cantor Date: Tue, 13 Nov 2007 21:14:25 +0000 (+0000) Subject: Rework iterator template again for Sun's broken STL. X-Git-Tag: 1.4.1~396 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fxmltooling.git;a=commitdiff_plain;h=fe94cc020bb1e493c48559dfa064fc1fc4705b61 Rework iterator template again for Sun's broken STL. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@430 de75baf8-a10c-0410-a50a-987c0e22f00f --- diff --git a/config_win32.h b/config_win32.h index 63a1a56..966b4d3 100644 --- a/config_win32.h +++ b/config_win32.h @@ -13,6 +13,10 @@ specialization. */ #define HAVE_GOOD_STL 1 +/* Defne to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#define HAVE_ITERATOR_TRAITS 1 + /* Define to 1 if you have the header file. */ /* #undef HAVE_INTTYPES_H */ diff --git a/configure.ac b/configure.ac index e70c47f..fe1063a 100644 --- a/configure.ac +++ b/configure.ac @@ -297,6 +297,12 @@ AC_TRY_LINK( [AC_DEFINE(HAVE_GOOD_STL,1, [Define if you have an STL implementation that supports useful string specialization.])], ) +AC_TRY_LINK( + [#include ], + [std::iterator_traits::iterator>::value_type foo=0], + [AC_DEFINE(HAVE_ITERATOR_TRAITS,1, + [Defne to 1 if you have an STL implementation that supports std::iterator_traits.])], + ) # Check for unit test support CXXTEST="/usr/bin/cxxtestgen.pl" diff --git a/xmltooling/config_pub.h.in b/xmltooling/config_pub.h.in index 144d787..a3df263 100644 --- a/xmltooling/config_pub.h.in +++ b/xmltooling/config_pub.h.in @@ -5,6 +5,10 @@ specialization. */ #undef HAVE_GOOD_STL +/* Defne to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#undef HAVE_ITERATOR_TRAITS + /* Define if log4shib library is used. */ #undef XMLTOOLING_LOG4SHIB diff --git a/xmltooling/config_pub_win32.h b/xmltooling/config_pub_win32.h index 0c13ee2..75111c2 100644 --- a/xmltooling/config_pub_win32.h +++ b/xmltooling/config_pub_win32.h @@ -5,6 +5,10 @@ specialization. */ #define HAVE_GOOD_STL 1 +/* Defne to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#define HAVE_ITERATOR_TRAITS 1 + /* Define if log4shib library is used. */ #define XMLTOOLING_LOG4SHIB 1 diff --git a/xmltooling/util/XMLObjectChildrenList.h b/xmltooling/util/XMLObjectChildrenList.h index f897df0..95f5c4c 100644 --- a/xmltooling/util/XMLObjectChildrenList.h +++ b/xmltooling/util/XMLObjectChildrenList.h @@ -81,28 +81,261 @@ namespace xmltooling { /** * STL iterator that mediates access to an iterator over typed XML children. - * @param _Ty a bidrectional sequence of the subtype to iterate over + * + * @param Container type of container + * @param _Ty a bidrectional iterator to guard */ - template + template class XMLObjectChildrenIterator { /// @cond OFF - typename _Ty::iterator m_iter; + typename _Ty m_iter; template friend class XMLObjectChildrenList; template friend class XMLObjectPairList; public: - typedef typename std::iterator_traits::iterator_category iterator_category; - typedef typename std::iterator_traits::value_type value_type; - typedef typename std::iterator_traits::difference_type difference_type; - typedef typename std::iterator_traits::pointer pointer; - typedef typename std::iterator_traits::reference reference; - typedef typename _Ty::const_reference const_reference; - typedef typename _Ty::const_pointer const_pointer; +#ifdef HAVE_ITERATOR_TRAITS + typedef typename std::iterator_traits<_Ty>::iterator_category iterator_category; + typedef typename std::iterator_traits<_Ty>::value_type value_type; + typedef typename std::iterator_traits<_Ty>::difference_type difference_type; + typedef typename std::iterator_traits<_Ty>::pointer pointer; + typedef typename std::iterator_traits<_Ty>::reference reference; +#else + typedef typename _Ty::iterator_category iterator_category; + typedef typename _Ty::value_type value_type; + typedef typename _Ty::difference_type difference_type; + typedef typename _Ty::pointer pointer; + typedef typename _Ty::reference reference; +#endif + typedef typename Container::const_reference const_reference; + typedef typename Container::const_pointer const_pointer; + + XMLObjectChildrenIterator() { + } + + XMLObjectChildrenIterator(_Ty iter) { + m_iter=iter; + } + + const_reference operator*() const { + return *m_iter; + } + + const_reference operator->() const { + return *m_iter; + } + + XMLObjectChildrenIterator& operator++() { + // preincrement + ++m_iter; + return (*this); + } + + XMLObjectChildrenIterator& operator--() { + // predecrement + --m_iter; + return (*this); + } + + XMLObjectChildrenIterator operator++(int) { + // postincrement + XMLObjectChildrenIterator _Tmp = *this; + ++*this; + return (_Tmp); + } + + XMLObjectChildrenIterator operator--(int) { + // postdecrement + XMLObjectChildrenIterator _Tmp = *this; + --*this; + return (_Tmp); + } + + XMLObjectChildrenIterator& operator+=(difference_type _Off) { + // increment by integer + m_iter += _Off; + return (*this); + } + + XMLObjectChildrenIterator operator+(difference_type _Off) const { + // return this + integer + return m_iter + _Off; + } + + XMLObjectChildrenIterator& operator-=(difference_type _Off) { + // decrement by integer + return (*this += -_Off); + } + + XMLObjectChildrenIterator operator-(difference_type _Off) const { + // return this - integer + XMLObjectChildrenIterator _Tmp = *this; + return (_Tmp -= _Off); + } + + difference_type operator-(const XMLObjectChildrenIterator& _Right) const { + // return difference of iterators + return m_iter - _Right.m_iter; + } + + const_reference operator[](difference_type _Off) const { + // subscript + return (*(*this + _Off)); + } + + bool operator==(const XMLObjectChildrenIterator &_Right) const { + // test for iterator equality + return (m_iter == _Right.m_iter); + } + + bool operator!=(const XMLObjectChildrenIterator &_Right) const { + // test for iterator inequality + return (!(m_iter == _Right.m_iter)); + } + + bool operator<(const XMLObjectChildrenIterator &_Right) const { + return (m_iter < _Right.m_iter); + } + /// @endcond + }; + +#ifndef HAVE_ITERATOR_TRAITS + /** + * STL iterator that mediates access to an iterator that's a pointer. + * + * @param Container type of container + * @param _Ty the type of object being referenced + */ + template + class XMLObjectChildrenIterator + { + /// @cond OFF + typename _Ty* m_iter; + template friend class XMLObjectChildrenList; + template friend class XMLObjectPairList; + public: + typedef std::random_access_iterator_tag iterator_category; + typedef _Ty value_type; + typedef ptrdiff_t difference_type; + typedef _Ty* pointer; + typedef _Ty& reference; + typedef const _Ty& const_reference; + typedef const _Ty* const_pointer; + + XMLObjectChildrenIterator() { + } + + XMLObjectChildrenIterator(_Ty* iter) { + m_iter=iter; + } + + const_reference operator*() const { + return *m_iter; + } + + const_reference operator->() const { + return *m_iter; + } + + XMLObjectChildrenIterator& operator++() { + // preincrement + ++m_iter; + return (*this); + } + + XMLObjectChildrenIterator& operator--() { + // predecrement + --m_iter; + return (*this); + } + + XMLObjectChildrenIterator operator++(int) { + // postincrement + XMLObjectChildrenIterator _Tmp = *this; + ++*this; + return (_Tmp); + } + + XMLObjectChildrenIterator operator--(int) { + // postdecrement + XMLObjectChildrenIterator _Tmp = *this; + --*this; + return (_Tmp); + } + + XMLObjectChildrenIterator& operator+=(difference_type _Off) { + // increment by integer + m_iter += _Off; + return (*this); + } + + XMLObjectChildrenIterator operator+(difference_type _Off) const { + // return this + integer + return m_iter + _Off; + } + + XMLObjectChildrenIterator& operator-=(difference_type _Off) { + // decrement by integer + return (*this += -_Off); + } + + XMLObjectChildrenIterator operator-(difference_type _Off) const { + // return this - integer + XMLObjectChildrenIterator _Tmp = *this; + return (_Tmp -= _Off); + } + + difference_type operator-(const XMLObjectChildrenIterator& _Right) const { + // return difference of iterators + return m_iter - _Right.m_iter; + } + + const_reference operator[](difference_type _Off) const { + // subscript + return (*(*this + _Off)); + } + + bool operator==(const XMLObjectChildrenIterator &_Right) const { + // test for iterator equality + return (m_iter == _Right.m_iter); + } + + bool operator!=(const XMLObjectChildrenIterator &_Right) const { + // test for iterator inequality + return (!(m_iter == _Right.m_iter)); + } + + bool operator<(const XMLObjectChildrenIterator &_Right) const { + return (m_iter < _Right.m_iter); + } + /// @endcond + }; + + /** + * STL iterator that mediates access to an iterator that's a const pointer. + * + * @param Container type of container + * @param _Ty the type of object being referenced + */ + template + class XMLObjectChildrenIterator + { + /// @cond OFF + typename const _Ty* m_iter; + template friend class XMLObjectChildrenList; + template friend class XMLObjectPairList; + public: + typedef std::random_access_iterator_tag iterator_category; + typedef _Ty value_type; + typedef ptrdiff_t difference_type; + typedef const _Ty* pointer; + typedef const _Ty& reference; + typedef const _Ty& const_reference; + typedef const _Ty* const_pointer; XMLObjectChildrenIterator() { } - XMLObjectChildrenIterator(typename _Ty::iterator iter) { + XMLObjectChildrenIterator(_Ty* iter) { m_iter=iter; } @@ -187,6 +420,7 @@ namespace xmltooling { } /// @endcond }; +#endif /** * STL-compatible container that mediates access to underlying lists of typed XML children. @@ -210,8 +444,8 @@ namespace xmltooling { typedef typename Container::size_type size_type; // We override the iterator types with our constrained wrapper. - typedef XMLObjectChildrenIterator iterator; - typedef XMLObjectChildrenIterator const_iterator; + typedef XMLObjectChildrenIterator iterator; + typedef XMLObjectChildrenIterator const_iterator; /// @endcond /** @@ -364,8 +598,8 @@ namespace xmltooling { typedef typename Container::size_type size_type; // We override the iterator types with our constrained wrapper. - typedef XMLObjectChildrenIterator iterator; - typedef XMLObjectChildrenIterator const_iterator; + typedef XMLObjectChildrenIterator iterator; + typedef XMLObjectChildrenIterator const_iterator; /// @endcond /**