epoc32/include/tools/stlport/stl/_iterator.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996-1998
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_ITERATOR_H
    31 #define _STLP_INTERNAL_ITERATOR_H
    32 
    33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
    34 #  include <stl/_iterator_base.h>
    35 #endif
    36 
    37 _STLP_BEGIN_NAMESPACE
    38 
    39 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
    40 // This is the new version of reverse_iterator, as defined in the
    41 //  draft C++ standard.  It relies on the iterator_traits template,
    42 //  which in turn relies on partial specialization.  The class
    43 //  reverse_bidirectional_iterator is no longer part of the draft
    44 //  standard, but it is retained for backward compatibility.
    45 
    46 template <class _Iterator>
    47 class reverse_iterator :
    48   public iterator<typename iterator_traits<_Iterator>::iterator_category,
    49                   typename iterator_traits<_Iterator>::value_type,
    50                   typename iterator_traits<_Iterator>::difference_type,
    51                   typename iterator_traits<_Iterator>::pointer,
    52                   typename iterator_traits<_Iterator>::reference> {
    53 protected:
    54   _Iterator current;
    55   typedef reverse_iterator<_Iterator> _Self;
    56 public:
    57   typedef typename iterator_traits<_Iterator>::iterator_category  iterator_category;
    58   typedef typename iterator_traits<_Iterator>::value_type value_type;
    59   typedef typename iterator_traits<_Iterator>::difference_type difference_type;
    60   typedef typename iterator_traits<_Iterator>::pointer pointer;
    61   typedef typename iterator_traits<_Iterator>::reference reference;
    62   typedef _Iterator iterator_type;
    63 public:
    64   reverse_iterator() {}
    65   explicit reverse_iterator(iterator_type __x) : current(__x) {}
    66   reverse_iterator(const _Self& __x) : current(__x.current) {}
    67   _Self& operator = (const _Self& __x) { current = __x.base(); return *this; }
    68 #  if defined (_STLP_MEMBER_TEMPLATES)
    69   template <class _Iter>
    70   reverse_iterator(const reverse_iterator<_Iter>& __x) : current(__x.base()) {}
    71   template <class _Iter>
    72   _Self& operator = (const reverse_iterator<_Iter>& __x) { current = __x.base(); return *this; }
    73 #  endif /* _STLP_MEMBER_TEMPLATES */
    74 
    75   iterator_type base() const { return current; }
    76   reference operator*() const {
    77     _Iterator __tmp = current;
    78     return *--__tmp;
    79   }
    80   _STLP_DEFINE_ARROW_OPERATOR
    81   _Self& operator++() {
    82     --current;
    83     return *this;
    84   }
    85   _Self operator++(int) {
    86     _Self __tmp = *this;
    87     --current;
    88     return __tmp;
    89   }
    90   _Self& operator--() {
    91     ++current;
    92     return *this;
    93   }
    94   _Self operator--(int) {
    95     _Self __tmp = *this;
    96     ++current;
    97     return __tmp;
    98   }
    99 
   100   _Self operator+(difference_type __n) const { return _Self(current - __n); }
   101   _Self& operator+=(difference_type __n) {
   102     current -= __n;
   103     return *this;
   104   }
   105   _Self operator-(difference_type __n) const { return _Self(current + __n); }
   106   _Self& operator-=(difference_type __n) {
   107     current += __n;
   108     return *this;
   109   }
   110   reference operator[](difference_type __n) const { return *(*this + __n); }
   111 };
   112 
   113 template <class _Iterator>
   114 inline bool  _STLP_CALL operator==(const reverse_iterator<_Iterator>& __x,
   115                                    const reverse_iterator<_Iterator>& __y)
   116 { return __x.base() == __y.base(); }
   117 
   118 template <class _Iterator>
   119 inline bool _STLP_CALL operator<(const reverse_iterator<_Iterator>& __x,
   120                                  const reverse_iterator<_Iterator>& __y)
   121 { return __y.base() < __x.base(); }
   122 
   123 #  if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
   124 template <class _Iterator>
   125 inline bool _STLP_CALL operator!=(const reverse_iterator<_Iterator>& __x,
   126                                   const reverse_iterator<_Iterator>& __y)
   127 { return !(__x == __y); }
   128 
   129 template <class _Iterator>
   130 inline bool _STLP_CALL operator>(const reverse_iterator<_Iterator>& __x,
   131                                  const reverse_iterator<_Iterator>& __y)
   132 { return __y < __x; }
   133 
   134 template <class _Iterator>
   135 inline bool _STLP_CALL operator<=(const reverse_iterator<_Iterator>& __x,
   136                                   const reverse_iterator<_Iterator>& __y)
   137 { return !(__y < __x); }
   138 
   139 template <class _Iterator>
   140 inline bool _STLP_CALL operator>=(const reverse_iterator<_Iterator>& __x,
   141                                   const reverse_iterator<_Iterator>& __y)
   142 { return !(__x < __y); }
   143 #  endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
   144 
   145 template <class _Iterator>
   146 #  if defined (__SUNPRO_CC)
   147 inline ptrdiff_t _STLP_CALL
   148 #  else
   149 inline typename reverse_iterator<_Iterator>::difference_type _STLP_CALL
   150 #  endif
   151 operator-(const reverse_iterator<_Iterator>& __x,
   152           const reverse_iterator<_Iterator>& __y)
   153 { return __y.base() - __x.base(); }
   154 
   155 template <class _Iterator, class _DifferenceType>
   156 inline reverse_iterator<_Iterator>  _STLP_CALL
   157 operator+(_DifferenceType n,const reverse_iterator<_Iterator>& x)
   158 { return x.operator+(n); }
   159 #endif
   160 
   161 template <class _Container>
   162 class back_insert_iterator
   163   : public iterator<output_iterator_tag, void, void, void, void> {
   164   typedef back_insert_iterator<_Container> _Self;
   165 protected:
   166   //c is a Standard name (24.4.2.1), do no make it STLport naming convention compliant.
   167   _Container *container;
   168 public:
   169   typedef _Container          container_type;
   170   typedef output_iterator_tag iterator_category;
   171 
   172   explicit back_insert_iterator(_Container& __x) : container(&__x) {}
   173 
   174   _Self& operator=(const _Self& __other) {
   175     container = __other.container;
   176     return *this;
   177   }
   178   _Self& operator=(const typename _Container::value_type& __val) {
   179     container->push_back(__val);
   180     return *this;
   181   }
   182   _Self& operator*() { return *this; }
   183   _Self& operator++() { return *this; }
   184   _Self  operator++(int) { return *this; }
   185 };
   186 
   187 template <class _Container>
   188 inline back_insert_iterator<_Container>  _STLP_CALL back_inserter(_Container& __x)
   189 { return back_insert_iterator<_Container>(__x); }
   190 
   191 template <class _Container>
   192 class front_insert_iterator
   193   : public iterator<output_iterator_tag, void, void, void, void> {
   194   typedef front_insert_iterator<_Container> _Self;
   195 protected:
   196   //c is a Standard name (24.4.2.3), do no make it STLport naming convention compliant.
   197   _Container *container;
   198 public:
   199   typedef _Container          container_type;
   200   typedef output_iterator_tag iterator_category;
   201   explicit front_insert_iterator(_Container& __x) : container(&__x) {}
   202 
   203   _Self& operator=(const _Self& __other) {
   204     container = __other.container;
   205     return *this;
   206   }
   207   _Self& operator=(const typename _Container::value_type& __val) {
   208     container->push_front(__val);
   209     return *this;
   210   }
   211   _Self& operator*() { return *this; }
   212   _Self& operator++() { return *this; }
   213   _Self  operator++(int) { return *this; }
   214 };
   215 
   216 template <class _Container>
   217 inline front_insert_iterator<_Container>  _STLP_CALL front_inserter(_Container& __x)
   218 { return front_insert_iterator<_Container>(__x); }
   219 
   220 template <class _Container>
   221 class insert_iterator
   222   : public iterator<output_iterator_tag, void, void, void, void> {
   223   typedef insert_iterator<_Container> _Self;
   224 protected:
   225   //container is a Standard name (24.4.2.5), do no make it STLport naming convention compliant.
   226   _Container *container;
   227   typename _Container::iterator _M_iter;
   228 public:
   229   typedef _Container          container_type;
   230   typedef output_iterator_tag iterator_category;
   231   insert_iterator(_Container& __x, typename _Container::iterator __i)
   232     : container(&__x), _M_iter(__i) {}
   233 
   234   _Self& operator=(_Self const& __other) {
   235     container = __other.container;
   236     _M_iter = __other._M_iter;
   237     return *this;
   238   }
   239   _Self& operator=(const typename _Container::value_type& __val) {
   240     _M_iter = container->insert(_M_iter, __val);
   241     ++_M_iter;
   242     return *this;
   243   }
   244   _Self& operator*() { return *this; }
   245   _Self& operator++() { return *this; }
   246   _Self& operator++(int) { return *this; }
   247 };
   248 
   249 template <class _Container, class _Iterator>
   250 inline insert_iterator<_Container>  _STLP_CALL
   251 inserter(_Container& __x, _Iterator __i) {
   252   typedef typename _Container::iterator __iter;
   253   return insert_iterator<_Container>(__x, __iter(__i));
   254 }
   255 
   256 _STLP_END_NAMESPACE
   257 
   258 #if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
   259 #  include <stl/_iterator_old.h>
   260 #endif
   261 
   262 #endif /* _STLP_INTERNAL_ITERATOR_H */
   263 
   264 // Local Variables:
   265 // mode:C++
   266 // End: