|
Sierra Toolkit
Version of the Day
|
00001 /* 00002 Copyright (C) 2005,2009-2010 Electronic Arts, Inc. All rights reserved. 00003 00004 Redistribution and use in source and binary forms, with or without 00005 modification, are permitted provided that the following conditions 00006 are met: 00007 00008 1. Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 2. Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in the 00012 documentation and/or other materials provided with the distribution. 00013 3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of 00014 its contributors may be used to endorse or promote products derived 00015 from this software without specific prior written permission. 00016 00017 THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY 00018 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY 00021 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00030 // EASTL/internal/generic_iterator.h 00031 // 00032 // Written and maintained by Paul Pedriana - 2005. 00034 00036 // Implements a generic iterator from a given iteratable type, such as a pointer. 00037 // We cannot put this file into our own iterator.h file because we need to 00038 // still be able to use this file when we have our iterator.h disabled. 00039 // 00041 00042 00043 #ifndef EASTL_INTERNAL_GENERIC_ITERATOR_H 00044 #define EASTL_INTERNAL_GENERIC_ITERATOR_H 00045 00046 00047 #include <stk_util/util/config_eastl.h> 00048 #include <stk_util/util/iterator_eastl.h> 00049 #include <stk_util/util/type_traits_eastl.h> 00050 00051 00052 #ifdef _MSC_VER 00053 #pragma warning(push) // VC++ generates a bogus warning that you cannot code away. 00054 #pragma warning(disable: 4619) // There is no warning number 'number'. 00055 #pragma warning(disable: 4217) // Member template functions cannot be used for copy-assignment or copy-construction. 00056 #endif 00057 00058 00059 namespace eastl 00060 { 00061 00074 template <typename Iterator, typename Container = void> 00075 class generic_iterator 00076 { 00077 protected: 00078 Iterator mIterator; 00079 00080 public: 00081 typedef typename eastl::iterator_traits<Iterator>::iterator_category iterator_category; 00082 typedef typename eastl::iterator_traits<Iterator>::value_type value_type; 00083 typedef typename eastl::iterator_traits<Iterator>::difference_type difference_type; 00084 typedef typename eastl::iterator_traits<Iterator>::reference reference; 00085 typedef typename eastl::iterator_traits<Iterator>::pointer pointer; 00086 typedef Iterator iterator_type; 00087 typedef Container container_type; 00088 typedef generic_iterator<Iterator, Container> this_type; 00089 00090 generic_iterator() 00091 : mIterator(iterator_type()) { } 00092 00093 explicit generic_iterator(const iterator_type& x) 00094 : mIterator(x) { } 00095 00096 this_type& operator=(const iterator_type& x) 00097 { mIterator = x; return *this; } 00098 00099 template <typename Iterator2> 00100 generic_iterator(const generic_iterator<Iterator2, Container>& x) 00101 : mIterator(x.base()) { } 00102 00103 reference operator*() const 00104 { return *mIterator; } 00105 00106 pointer operator->() const 00107 { return mIterator; } 00108 00109 this_type& operator++() 00110 { ++mIterator; return *this; } 00111 00112 this_type operator++(int) 00113 { return this_type(mIterator++); } 00114 00115 this_type& operator--() 00116 { --mIterator; return *this; } 00117 00118 this_type operator--(int) 00119 { return this_type(mIterator--); } 00120 00121 reference operator[](const difference_type& n) const 00122 { return mIterator[n]; } 00123 00124 this_type& operator+=(const difference_type& n) 00125 { mIterator += n; return *this; } 00126 00127 this_type operator+(const difference_type& n) const 00128 { return this_type(mIterator + n); } 00129 00130 this_type& operator-=(const difference_type& n) 00131 { mIterator -= n; return *this; } 00132 00133 this_type operator-(const difference_type& n) const 00134 { return this_type(mIterator - n); } 00135 00136 const iterator_type& base() const 00137 { return mIterator; } 00138 00139 }; // class generic_iterator 00140 00141 00142 00143 00144 00145 template <typename IteratorL, typename IteratorR, typename Container> 00146 inline bool operator==(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00147 { return lhs.base() == rhs.base(); } 00148 00149 template <typename Iterator, typename Container> 00150 inline bool operator==(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00151 { return lhs.base() == rhs.base(); } 00152 00153 template <typename IteratorL, typename IteratorR, typename Container> 00154 inline bool operator!=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00155 { return lhs.base() != rhs.base(); } 00156 00157 template <typename Iterator, typename Container> 00158 inline bool operator!=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00159 { return lhs.base() != rhs.base(); } 00160 00161 template <typename IteratorL, typename IteratorR, typename Container> 00162 inline bool operator<(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00163 { return lhs.base() < rhs.base(); } 00164 00165 template <typename Iterator, typename Container> 00166 inline bool operator<(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00167 { return lhs.base() < rhs.base(); } 00168 00169 template <typename IteratorL, typename IteratorR, typename Container> 00170 inline bool operator>(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00171 { return lhs.base() > rhs.base(); } 00172 00173 template <typename Iterator, typename Container> 00174 inline bool operator>(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00175 { return lhs.base() > rhs.base(); } 00176 00177 template <typename IteratorL, typename IteratorR, typename Container> 00178 inline bool operator<=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00179 { return lhs.base() <= rhs.base(); } 00180 00181 template <typename Iterator, typename Container> 00182 inline bool operator<=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00183 { return lhs.base() <= rhs.base(); } 00184 00185 template <typename IteratorL, typename IteratorR, typename Container> 00186 inline bool operator>=(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00187 { return lhs.base() >= rhs.base(); } 00188 00189 template <typename Iterator, typename Container> 00190 inline bool operator>=(const generic_iterator<Iterator, Container>& lhs, const generic_iterator<Iterator, Container>& rhs) 00191 { return lhs.base() >= rhs.base(); } 00192 00193 template <typename IteratorL, typename IteratorR, typename Container> 00194 inline typename generic_iterator<IteratorL, Container>::difference_type 00195 operator-(const generic_iterator<IteratorL, Container>& lhs, const generic_iterator<IteratorR, Container>& rhs) 00196 { return lhs.base() - rhs.base(); } 00197 00198 template <typename Iterator, typename Container> 00199 inline generic_iterator<Iterator, Container> 00200 operator+(typename generic_iterator<Iterator, Container>::difference_type n, const generic_iterator<Iterator, Container>& x) 00201 { return generic_iterator<Iterator, Container>(x.base() + n); } 00202 00203 00204 00211 template <typename Iterator> 00212 struct is_generic_iterator : public false_type { }; 00213 00214 template <typename Iterator, typename Container> 00215 struct is_generic_iterator<generic_iterator<Iterator, Container> > : public true_type { }; 00216 00217 00218 } // namespace eastl 00219 00220 00221 #ifdef _MSC_VER 00222 #pragma warning(pop) 00223 #endif 00224 00225 00226 #endif // Header include guard