MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StrideIterPack_StrideIter.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef STRIDE_ITER_H
43 #define STRIDE_ITER_H
44 
45 #include "Moocho_ConfigDefs.hpp"
46 
47 namespace StrideIterPack {
48 
57 template<class T_iterator_type, class T_value_type, class T_reference_type
58  , class T_pointer_type, class T_difference_type>
59 class stride_iter {
60 public:
63 
65  typedef std::random_access_iterator_tag iterator_category;
67  typedef T_iterator_type iterator_type;
69  typedef T_value_type value_type;
71  typedef T_reference_type reference;
73  typedef T_pointer_type pointer;
75  typedef T_difference_type difference_type;
76 
78 
81 
84  {}
87  {}
90  {}
92  template<class Iter, class Val, class Ref, class Ptr, class Diff>
94  {}
96  template<class Iter, class Val, class Ref, class Ptr, class Diff>
98  current_ = rhs.current(); stride_ = rhs.stride(); return *this;
99  }
100 
102 
105 
108  return *current_;
109  }
111  pointer operator->() const {
112  return current_;
113  }
116  return current_[n * stride_];
117  }
118 
120 
123 
126  current_ += stride_;
127  return *this;
128  }
130  const stride_iter operator++(int) {
131  stride_iter tmp = *this;
132  ++*this; return tmp;
133  }
136  current_ -= stride_;
137  return *this;
138  }
140  const stride_iter operator--(int) {
141  stride_iter tmp = *this;
142  --*this; return tmp;
143  }
146  return stride_iter(current_ + n * stride_, stride_);
147  }
150  return stride_iter(current_ + n * stride_, stride_);
151  }
154  current_ += n * stride_;
155  return *this;
156  }
159  return stride_iter(current_ - n * stride_, stride_);
160  }
163  return stride_iter(current_ - n * stride_, stride_);
164  }
167  current_ -= n * stride_;
168  return *this;
169  }
170 
172 
175  return (current_ - itr.current_)/stride_;
176  }
177 
180 
183  return current_;
184  }
185 
188  return stride_;
189  }
190 
192 
193 private:
198 };
199 
200 // RAB: 2001/11/16: For some reason this \defgroup causing doxygen to crash
201 // when compiling RTOpPack?
202 
203 /* \defgroup stride_iter_funcs_grp Non-member functions for StrideIterPack::stride_itr
204  * \ingroup Misc_grp
205  */
206 // @{
207 
209 template<class Iter, class Val, class Ref, class Ptr, class Diff>
212 {
213  return itr + n;
214 }
215 
217 template<class Iter, class Val, class Ref, class Ptr, class Diff>
218 inline bool operator<(const stride_iter<Iter,Val,Ref,Ptr,Diff>& itr1,
220 {
221  return itr1.operator->() < itr2.operator->();
222 }
224 template<class Iter, class Val, class Ref, class Ptr, class Diff>
225 inline bool operator<=(const stride_iter<Iter,Val,Ref,Ptr,Diff>& itr1,
227 {
228  return itr1.operator->() <= itr2.operator->();
229 }
231 template<class Iter, class Val, class Ref, class Ptr, class Diff>
234 {
235  return itr1.operator->() > itr2.operator->();
236 }
238 template<class Iter, class Val, class Ref, class Ptr, class Diff>
241 {
242  return itr1.operator->() >= itr2.operator->();
243 }
245 template<class Iter, class Val, class Ref, class Ptr, class Diff>
248 {
249  return itr1.operator->() == itr2.operator->();
250 }
252 template<class Iter, class Val, class Ref, class Ptr, class Diff>
255 {
256  return itr1.operator->() != itr2.operator->();
257 }
258 
259 // @}
260 
261 } // end namespace StrideIterPack
262 
263 #endif // STRIDE_ITER_H
stride_iter & operator-=(difference_type n)
itr -= n
stride_iter(iterator_type current, difference_type stride)
constructs to the desired sliced iterator
std::random_access_iterator_tag iterator_category
stride_iter(const stride_iter< Iter, Val, Ref, Ptr, Diff > &rhs)
convert type of iterators (mainly for non-const to const)
bool operator!=(const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr1, const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr2)
itr1 != itr2
C++ Standard Library compatable iterator class for accesing nonunit stride arrays of data...
bool operator==(const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr1, const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr2)
itr1 == itr2
stride_iter operator-(difference_type n)
itr - n
const stride_iter operator--(int)
itr–
const stride_iter operator+(difference_type n) const
itr + n
const stride_iter operator-(difference_type n) const
itr - n
stride_iter()
constructs to a null iterator
const stride_iter< Iter, Val, Ref, Ptr, Diff > operator+(Diff n, const stride_iter< Iter, Val, Ref, Ptr, Diff > itr)
Allow difference_type as lhs argument in n + itr.
const stride_iter operator++(int)
itr++
const f_dbl_prec const f_int const f_int const f_int f_dbl_prec rhs[]
stride_iter & operator=(const stride_iter< Iter, Val, Ref, Ptr, Diff > &rhs)
assign different types of iterators (mainly for non-const to const)
difference_type operator-(const stride_iter &itr) const
distance = itr1 - itr2 (distance between elements)
bool operator>(const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr1, const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr2)
itr1 > itr 2
bool operator>=(const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr1, const stride_iter< Iter, Val, Ref, Ptr, Diff > &itr2)
itr1 >= itr2
stride_iter operator+(difference_type n)
itr + n
stride_iter(iterator_type current)
constructs to the standard iterator (behaves as) (increment 1). Allows conversion from iterator...
stride_iter & operator+=(difference_type n)
itr += n
reference operator[](difference_type n) const