Sierra Toolkit  Version of the Day
generic_iterator_eastl.h
1 /*
2 Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 
8 1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of
14  its contributors may be used to endorse or promote products derived
15  from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
30 // EASTL/internal/generic_iterator.h
31 //
32 // Written and maintained by Paul Pedriana - 2005.
34 
36 // Implements a generic iterator from a given iteratable type, such as a pointer.
37 // We cannot put this file into our own iterator.h file because we need to
38 // still be able to use this file when we have our iterator.h disabled.
39 //
41 
42 
43 #ifndef EASTL_INTERNAL_GENERIC_ITERATOR_H
44 #define EASTL_INTERNAL_GENERIC_ITERATOR_H
45 
46 
47 #include <stk_util/util/config_eastl.h>
48 #include <stk_util/util/iterator_eastl.h>
49 #include <stk_util/util/type_traits_eastl.h>
50 
51 
52 #ifdef _MSC_VER
53  #pragma warning(push) // VC++ generates a bogus warning that you cannot code away.
54  #pragma warning(disable: 4619) // There is no warning number 'number'.
55  #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction.
56 #endif
57 
58 
59 namespace eastl
60 {
61 
74  template <typename Iterator, typename Container = void>
76  {
77  protected:
78  Iterator mIterator;
79 
80  public:
81  typedef typename eastl::iterator_traits<Iterator>::iterator_category iterator_category;
82  typedef typename eastl::iterator_traits<Iterator>::value_type value_type;
83  typedef typename eastl::iterator_traits<Iterator>::difference_type difference_type;
84  typedef typename eastl::iterator_traits<Iterator>::reference reference;
85  typedef typename eastl::iterator_traits<Iterator>::pointer pointer;
86  typedef Iterator iterator_type;
87  typedef Container container_type;
89 
91  : mIterator(iterator_type()) { }
92 
93  explicit generic_iterator(const iterator_type& x)
94  : mIterator(x) { }
95 
96  this_type& operator=(const iterator_type& x)
97  { mIterator = x; return *this; }
98 
99  template <typename Iterator2>
101  : mIterator(x.base()) { }
102 
103  reference operator*() const
104  { return *mIterator; }
105 
106  pointer operator->() const
107  { return mIterator; }
108 
109  this_type& operator++()
110  { ++mIterator; return *this; }
111 
112  this_type operator++(int)
113  { return this_type(mIterator++); }
114 
115  this_type& operator--()
116  { --mIterator; return *this; }
117 
118  this_type operator--(int)
119  { return this_type(mIterator--); }
120 
121  reference operator[](const difference_type& n) const
122  { return mIterator[n]; }
123 
124  this_type& operator+=(const difference_type& n)
125  { mIterator += n; return *this; }
126 
127  this_type operator+(const difference_type& n) const
128  { return this_type(mIterator + n); }
129 
130  this_type& operator-=(const difference_type& n)
131  { mIterator -= n; return *this; }
132 
133  this_type operator-(const difference_type& n) const
134  { return this_type(mIterator - n); }
135 
136  const iterator_type& base() const
137  { return mIterator; }
138 
139  }; // class generic_iterator
140 
141 
142 
143 
144 
145  template <typename IteratorL, typename IteratorR, typename Container>
146  inline bool operator==(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
147  { return lhs.base() == rhs.base(); }
148 
149  template <typename Iterator, typename Container>
150  inline bool operator==(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
151  { return lhs.base() == rhs.base(); }
152 
153  template <typename IteratorL, typename IteratorR, typename Container>
154  inline bool operator!=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
155  { return lhs.base() != rhs.base(); }
156 
157  template <typename Iterator, typename Container>
158  inline bool operator!=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
159  { return lhs.base() != rhs.base(); }
160 
161  template <typename IteratorL, typename IteratorR, typename Container>
162  inline bool operator<(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
163  { return lhs.base() < rhs.base(); }
164 
165  template <typename Iterator, typename Container>
166  inline bool operator<(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
167  { return lhs.base() < rhs.base(); }
168 
169  template <typename IteratorL, typename IteratorR, typename Container>
170  inline bool operator>(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
171  { return lhs.base() > rhs.base(); }
172 
173  template <typename Iterator, typename Container>
174  inline bool operator>(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
175  { return lhs.base() > rhs.base(); }
176 
177  template <typename IteratorL, typename IteratorR, typename Container>
178  inline bool operator<=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
179  { return lhs.base() <= rhs.base(); }
180 
181  template <typename Iterator, typename Container>
182  inline bool operator<=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
183  { return lhs.base() <= rhs.base(); }
184 
185  template <typename IteratorL, typename IteratorR, typename Container>
186  inline bool operator>=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
187  { return lhs.base() >= rhs.base(); }
188 
189  template <typename Iterator, typename Container>
190  inline bool operator>=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs)
191  { return lhs.base() >= rhs.base(); }
192 
193  template <typename IteratorL, typename IteratorR, typename Container>
194  inline typename generic_iterator<IteratorL, Container>::difference_type
195  operator-(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs)
196  { return lhs.base() - rhs.base(); }
197 
198  template <typename Iterator, typename Container>
199  inline generic_iterator<Iterator, Container>
200  operator+(typename generic_iterator<Iterator, Container>::difference_type n, const generic_iterator<Iterator, Container>& x)
201  { return generic_iterator<Iterator, Container>(x.base() + n); }
202 
203 
204 
211  template <typename Iterator>
212  struct is_generic_iterator : public false_type { };
213 
214  template <typename Iterator, typename Container>
215  struct is_generic_iterator<generic_iterator<Iterator, Container> > : public true_type { };
216 
217 
218 } // namespace eastl
219 
220 
221 #ifdef _MSC_VER
222  #pragma warning(pop)
223 #endif
224 
225 
226 #endif // Header include guard
EA Standard Template Library.