STK++ 0.9.13
STK_ITContainer1D.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 * Purpose: Define the Interface 1D template Container class.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 *
30 **/
31
36#ifndef STK_ITCONTAINER1D_H
37#define STK_ITCONTAINER1D_H
38
39
40namespace STK
41{
74template <class Derived>
75class ITContainer1D: public IRecursiveTemplate<Derived>
76{
77 public:
78 enum
79 {
81 };
82
85
88
92
93
98
99 protected:
108
109 public:
111 inline RowRange const& range() const { return range_;}
113 inline int begin() const { return range_.begin();}
115 inline int end() const { return range_.end();}
117 inline int size() const { return range_.size();}
118
120 inline int lastIdx() const { return range_.lastIdx();}
121
125 Iterator endIterator() { return Iterator(this->asDerived(), end());}
128 ConstIterator beginConstIterator() const { return ConstIterator(this->asDerived(), begin());}
130 ConstIterator endConstIterator() const { return ConstIterator(this->asDerived(), end());}
133 ReverseIterator rbeginIterator() { return ReverseIterator(endIterator());}
136
141
145 bool empty() const { return range_.empty();}
150 inline Type& elt(int i)
151 {
152#ifdef STK_BOUNDS_CHECK
154 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, end() <= i);}
155#endif
156 return this->asDerived().elt1Impl(i);
157 }
161 inline TypeConst elt(int i) const
162 {
163#ifdef STK_BOUNDS_CHECK
165 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::elt, i, end() <= i);}
166#endif
167 return this->asDerived().elt1Impl(i);
168 }
172 inline Type& operator[](int i)
173 {
174#ifdef STK_BOUNDS_CHECK
175 if (begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::operator[], i, begin() > i);}
176 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::operator[], i, end() <= i);}
177#endif
178 return elt(i);
179 }
183 inline TypeConst operator[](int i) const
184 {
185#ifdef STK_BOUNDS_CHECK
186 if (begin() > i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::operator[], i, begin() > i);}
187 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::operator[], i, end() <= i);}
188#endif
189 return elt(i);
190 }
194 inline Type& at(int i)
195 {
197 if (end() <= i) { STKOUT_OF_RANGE_1ARG(ITContainer1D::at, i, end() <= i);}
198 return elt(i);
199 }
203 TypeConst at(int i) const
204 {
205 if (begin() > i)
207 if (end() <= i)
209 return elt(i);
210 }
215 inline SubVector sub(Range const& I) const
216 {
217#ifdef STK_BOUNDS_CHECK
218 if ((I.begin()<begin()))
220 if ((I.end()>end()))
222#endif
223 return SubVector(this->asDerived(), I, true);
224 }
225
227 inline Type& front() { return elt(begin());}
229 inline TypeConst front() const { return elt(begin());}
231 inline Type& back() { return elt(lastIdx());}
233 inline TypeConst back() const { return elt(lastIdx());}
234
236 void shift(int beg)
237 {
238 this->asDerived().shiftImpl(beg);
239 range_.shift(beg);
240 }
244 Derived& resize(Range const& I =RowRange())
245 { return this->asDerived().resizeImpl(I);}
246
247 protected:
251 void exchange(ITContainer1D& T) { std::swap(T.range_, range_ );}
255 void setRange(RowRange const& I = RowRange()) { range_ = I;}
259 void incRange(int n =1) { range_.inc(n);}
263 void incFirst(int n =1) { range_.incFirst(n);}
267 void decFirst(int n =1) { range_.decFirst(n);}
271 void incLast(int n =1) { range_.incLast(n);}
275 void decLast(int n =1) { range_.decLast(n);}
276
277 private:
280};
281
282} // namespace STK
283
284#endif // STK_ITCONTAINER1D_H
#define STKOUT_OF_RANGE_1ARG(Where, Arg, Error)
Definition STK_Macros.h:93
Interface base class for all classes implementing the curious recursive template paradigm.
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.
Interface base class for homogeneous 1D containers.
ReverseIterator rbeginIterator()
bool empty() const
Is there some data ?
RowRange range_
range of the array.
TypeConst front() const
hidden::Traits< Derived >::ColRange ColRange
void incRange(int n=1)
increment the range of the container (can be negative).
hidden::Traits< Derived >::ConstReverseIterator ConstReverseIterator
hidden::Traits< Derived >::SubVector SubVector
hidden::Traits< Derived >::RowRange RowRange
hidden::Traits< Derived >::ConstIterator ConstIterator
Derived & resize(Range const &I=RowRange())
ReverseIterator rendIterator()
void decFirst(int n=1)
decrement the beginning of the container.
hidden::Traits< Derived >::Col Col
ITContainer1D(RowRange const &I)
constructor with a specified range.
TypeConst operator[](int i) const
TypeConst elt(int i) const
ConstReverseIterator rbeginConstIterator() const
hidden::Traits< Derived >::Type Type
void setRange(RowRange const &I=RowRange())
Set range of the rows of the container.
hidden::Traits< Derived >::TypeConst TypeConst
ConstReverseIterator rendConstIterator() const
~ITContainer1D()
destructor.
void incFirst(int n=1)
increment the beginning of the container (can be negative).
hidden::Traits< Derived >::ReverseIterator ReverseIterator
TypeConst at(int i) const
void incLast(int n=1)
increment the end of the container (can be negative).
void exchange(ITContainer1D &T)
exchange this container with T
ConstIterator endConstIterator() const
hidden::Traits< Derived >::Iterator Iterator
ITContainer1D()
Default constructor.
TypeConst back() const
RowRange const & range() const
hidden::Traits< Derived >::Row Row
ConstIterator beginConstIterator() const
void decLast(int n=1)
decrement the end of the container.
SubVector sub(Range const &I) const
Access to many elements.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
The namespace STK is the main domain space of the Statistical ToolKit project.