STK++ 0.9.13
STK_DenseRandomIterator.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Arrays
27 * created on: 10 mars 2017
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_DENSERANDOMITERATOR_H
37#define STK_DENSERANDOMITERATOR_H
38
40
41namespace STK
42{
43// forward declaration
44template<class Array_> struct DenseRandomIterator;
45template<class Array_> struct ConstDenseRandomIterator;
46
47namespace hidden
48{
52template<class Array_>
54{
55 typedef int Index;
56 typedef Array_ Array;
57
58 enum
59 {
66 };
67
68 typedef typename Traits< Array_ >::Type Type;
70
73
74 // std compatibility
75 typedef std::random_access_iterator_tag iterator_category;
76 typedef typename Array_::Type value_type;
77 typedef int difference_type;
80};
81
85template<class Array_>
115
116} // namespace hidden
117
121template<class Array_>
122struct DenseRandomIterator: public DenseIteratorBase< DenseRandomIterator<Array_> >
123 , public hidden::Traits< Array_ >::RowRange
124{
125 public:
128
129 enum
130 {
137 };
138
141
144
150
151 using Base::pos_;
152
157 : Base(pos)
158 , RowRange(array.range())
159 , p_array_(&array)
160 {}
170 {
171 Base::operator=(it);
172 RowRange::operator=(it);
173 p_array_ = it.p_array_;
174 return *this;
175 }
176
177 // comparing
179 bool operator==( DenseRandomIterator const& rhs) { return(pos_==rhs.pos_); }
181 bool operator!=( DenseRandomIterator const& rhs) { return(pos_!=rhs.pos_); }
182
183 // getting
184 inline reference operator*() { return p_array_->elt(pos_); }
185 inline pointer operator->() { return &(p_array_->elt(pos_)); }
186 inline reference operator[](Index pos) { return p_array_->elt(pos); }
187
188 // misc
190 {
191 Base::swap(lhs, rhs);
192 std::swap(lhs.p_array_, rhs.p_array_);
193 }
194
195 private:
197};
198
202template<class Array>
203struct ConstDenseRandomIterator: public DenseIteratorBase< ConstDenseRandomIterator<Array> >
204 , public hidden::Traits< Array >::RowRange
205{
207
209
210 enum
211 {
218 };
219
222
225
231
232 using Base::pos_;
233
237 ConstDenseRandomIterator( Array const& array, int pos)
238 : Base(pos)
239 , RowRange(array.range())
240 , p_array_(&array)
241 {}
249 {
250 Base::operator=(it);
251 RowRange::operator=(it);
252 p_array_ = it.p_array_;
253 return *this;
254 }
255 // getting
256 reference operator*() const { return p_array_->elt(pos_); }
257 pointer operator->() const { return &(p_array_->elt(pos_)); }
258 reference operator[](int pos) const { return p_array_->elt(pos); }
259
260 // comparing
262 bool operator==( ConstDenseRandomIterator const& rhs) { return(pos_==rhs.pos_); }
264 bool operator!=( ConstDenseRandomIterator const& rhs) { return(pos_!=rhs.pos_); }
265
266 // misc
268 {
269 std::swap(lhs.p_array_, rhs.p_array_);
270 Base::swap(lhs, rhs);
271 }
272
273 private:
274 Array const* p_array_;
275};
276
277} // namespace STK
278
279#endif /* STK_DENSERANDOMITERATOR_H */
In this file we define the base class for Iterators on dense arrays.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
The namespace STK is the main domain space of the Statistical ToolKit project.
ConstDenseRandomIterator allows to loop over the elements of containers Array.
hidden::IteratorTraits< ConstDenseRandomIterator >::RowRange RowRange
ConstDenseRandomIterator & operator=(ConstDenseRandomIterator const &it)
hidden::IteratorTraits< ConstDenseRandomIterator >::Index Index
hidden::IteratorTraits< ConstDenseRandomIterator >::ColRange ColRange
ConstDenseRandomIterator(Array const &array, int pos)
Constructor with array and position given.
hidden::IteratorTraits< ConstDenseRandomIterator >::pointer pointer
hidden::IteratorTraits< ConstDenseRandomIterator >::reference reference
DenseIteratorBase< ConstDenseRandomIterator< Array > > Base
hidden::IteratorTraits< ConstDenseRandomIterator >::value_type value_type
bool operator==(ConstDenseRandomIterator const &rhs)
comparing two iterators (only position is compared !)
friend void swap(ConstDenseRandomIterator &lhs, ConstDenseRandomIterator &rhs)
ConstDenseRandomIterator(ConstDenseRandomIterator const &it)
ConstDenseRandomIterator()
Default constructor.
hidden::IteratorTraits< ConstDenseRandomIterator >::iterator_category iterator_category
bool operator!=(ConstDenseRandomIterator const &rhs)
comparing two iterators (only position is compared !)
hidden::IteratorTraits< ConstDenseRandomIterator >::difference_type difference_type
hidden::IteratorTraits< ConstDenseRandomIterator >::TypeConst TypeConst
hidden::IteratorTraits< ConstDenseRandomIterator >::Type Type
IteratorBase is a base class for all iterators on dense arrays/matrix/vector/expressions.
Index pos_
Current position.
friend void swap(DenseIteratorBase &lhs, DenseIteratorBase &rhs)
swap two iterators (only position is swaped)
DenseRandomIterator allows to loop over the elements of containers Array.
bool operator==(DenseRandomIterator const &rhs)
comparing two iterators (only position is compared !)
DenseRandomIterator()
Default constructor.
hidden::IteratorTraits< DenseRandomIterator >::Type Type
hidden::IteratorTraits< DenseRandomIterator >::RowRange RowRange
Index pos_
Current position.
hidden::IteratorTraits< DenseRandomIterator >::difference_type difference_type
hidden::IteratorTraits< DenseRandomIterator >::TypeConst TypeConst
DenseIteratorBase< DenseRandomIterator > Base
hidden::IteratorTraits< DenseRandomIterator >::pointer pointer
hidden::IteratorTraits< DenseRandomIterator >::Index Index
DenseRandomIterator & operator=(DenseRandomIterator const &it)
assignment operator
hidden::IteratorTraits< DenseRandomIterator >::reference reference
hidden::IteratorTraits< DenseRandomIterator >::iterator_category iterator_category
hidden::IteratorTraits< DenseRandomIterator >::value_type value_type
friend void swap(DenseRandomIterator &lhs, DenseRandomIterator &rhs)
DenseRandomIterator(DenseRandomIterator const &it)
copy constructor
DenseRandomIterator(Array_ &array, int pos)
Constructor with array and position given.
bool operator!=(DenseRandomIterator const &rhs)
comparing two iterators (only position is compared !)
hidden::IteratorTraits< DenseRandomIterator >::ColRange ColRange