gsl_iterator.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef gslpp_iterator_hh
#define gslpp_iterator_hh
#include <cassert>
#include <iterator>
#include <iostream>
namespace gsl
{
class vector_iterator
{
public:
typedef double value_type;
typedef double *pointer;
typedef double& reference;
typedef size_t difference_type;
vector_iterator(double *base, int stride): m_current(base), m_stride(stride) {}
vector_iterator(const vector_iterator& other) = default;
vector_iterator(): m_current(nullptr), m_stride(0) {}
double& operator *()
{
return *m_current;
};
double *operator ->()
{
return m_current;
};
vector_iterator& operator ++()
{
m_current += m_stride;
return *this;
};
vector_iterator operator ++(int)
{
vector_iterator result(*this);
++(*this);
return result;
}
vector_iterator& operator --()
{
m_current -= m_stride;
return *this;
};
vector_iterator operator --(int)
{
vector_iterator result(*this);
--(*this);
return result;
}
vector_iterator& operator += (int dist)
{
m_current += dist * m_stride;
return *this;
}
vector_iterator& operator -= (int dist)
{
m_current -= dist * m_stride;
return *this;
}
double& operator[] (int idx)
{
return m_current[idx * m_stride];
}
difference_type operator - (const vector_iterator& other)
{
assert(m_stride == other.m_stride);
return (m_current - other.m_current) / m_stride;
}
bool operator == (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current == other.m_current;
}
bool operator != (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current != other.m_current;
}
bool operator < (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current < other.m_current;
}
bool operator <= (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current <= other.m_current;
}
bool operator > (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current > other.m_current;
}
bool operator >= (const vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current >= other.m_current;
}
private:
friend class const_vector_iterator;
double *m_current;
int m_stride;
};
inline vector_iterator operator + (const vector_iterator& it, int dist)
{
vector_iterator result(it);
result += dist;
return result;
}
inline vector_iterator operator - (const vector_iterator& it, int dist)
{
vector_iterator result(it);
result -= dist;
return result;
}
inline vector_iterator operator + (int dist, const vector_iterator& it)
{
vector_iterator result(it);
result += dist;
return result;
}
class const_vector_iterator
{
public:
typedef const double value_type;
typedef const double *pointer;
typedef const double& reference;
typedef size_t difference_type;
const_vector_iterator(const double *base, int stride):
m_current(base), m_stride(stride)
{
}
const_vector_iterator(const const_vector_iterator& other) = default;
const_vector_iterator(const vector_iterator& other):
m_current(other.m_current),
m_stride(other.m_stride)
{
}
const_vector_iterator():
m_current(nullptr),
m_stride(0)
{
}
const double& operator *() const
{
return *m_current;
};
const double *operator ->() const
{
return m_current;
};
const_vector_iterator& operator ++()
{
m_current += m_stride;
return *this;
};
const_vector_iterator operator ++(int)
{
const_vector_iterator result(*this);
++(*this);
return result;
}
const_vector_iterator& operator --()
{
m_current -= m_stride;
return *this;
};
const_vector_iterator operator --(int)
{
const_vector_iterator result(*this);
--(*this);
return result;
}
const_vector_iterator& operator += (int dist)
{
m_current += dist * m_stride;
return *this;
}
const_vector_iterator& operator -= (int dist)
{
m_current -= dist * m_stride;
return *this;
}
difference_type operator - (const const_vector_iterator& other)
{
assert(m_stride == other.m_stride);
return (m_current - other.m_current) / m_stride;
}
const double& operator[] (int idx) const
{
return m_current[idx * m_stride];
}
bool operator == (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current == other.m_current;
}
bool operator != (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current != other.m_current;
}
bool operator < (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current < other.m_current;
}
bool operator <= (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current <= other.m_current;
}
bool operator > (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current > other.m_current;
}
bool operator >= (const const_vector_iterator& other) const
{
assert(m_stride == other.m_stride);
return m_current >= other.m_current;
}
private:
const double *m_current;
int m_stride;
};
inline const_vector_iterator operator + (const const_vector_iterator& it, int dist)
{
const_vector_iterator result(it);
result += dist;
return result;
}
inline const_vector_iterator operator - (const const_vector_iterator& it, int dist)
{
const_vector_iterator result(it);
result -= dist;
return result;
}
inline const_vector_iterator operator + (int dist, const const_vector_iterator& it)
{
const_vector_iterator result(it);
result += dist;
return result;
}
}
namespace std
{
template <>
class iterator_traits< gsl::const_vector_iterator >
{
public:
typedef size_t difference_type;
typedef double value_type;
typedef const double *pointer;
typedef const double& reference;
typedef random_access_iterator_tag iterator_category;
};
template <>
class iterator_traits< gsl::vector_iterator >
{
public:
typedef size_t difference_type;
typedef double value_type;
typedef double *pointer;
typedef double& reference;
typedef random_access_iterator_tag iterator_category;
};
}
#endif
gsl::const_vector_iterator
Definition gsl_iterator.hh:171
gsl::const_vector_iterator::operator-
difference_type operator-(const const_vector_iterator &other)
Definition gsl_iterator.hh:246
gsl::const_vector_iterator::const_vector_iterator
const_vector_iterator(const const_vector_iterator &other)=default
gsl::const_vector_iterator::reference
const double & reference
Definition gsl_iterator.hh:175
gsl::const_vector_iterator::operator<=
bool operator<=(const const_vector_iterator &other) const
Definition gsl_iterator.hh:275
gsl::const_vector_iterator::operator>=
bool operator>=(const const_vector_iterator &other) const
Definition gsl_iterator.hh:287
gsl::const_vector_iterator::const_vector_iterator
const_vector_iterator(const double *base, int stride)
Definition gsl_iterator.hh:179
gsl::const_vector_iterator::operator--
const_vector_iterator & operator--()
Definition gsl_iterator.hh:221
gsl::const_vector_iterator::operator->
const double * operator->() const
Definition gsl_iterator.hh:203
gsl::const_vector_iterator::difference_type
size_t difference_type
Definition gsl_iterator.hh:176
gsl::const_vector_iterator::operator<
bool operator<(const const_vector_iterator &other) const
Definition gsl_iterator.hh:269
gsl::const_vector_iterator::const_vector_iterator
const_vector_iterator()
Definition gsl_iterator.hh:192
gsl::const_vector_iterator::operator[]
const double & operator[](int idx) const
Definition gsl_iterator.hh:252
gsl::const_vector_iterator::operator*
const double & operator*() const
Definition gsl_iterator.hh:198
gsl::const_vector_iterator::operator++
const_vector_iterator & operator++()
Definition gsl_iterator.hh:208
gsl::const_vector_iterator::operator-=
const_vector_iterator & operator-=(int dist)
Definition gsl_iterator.hh:240
gsl::const_vector_iterator::operator!=
bool operator!=(const const_vector_iterator &other) const
Definition gsl_iterator.hh:263
gsl::const_vector_iterator::pointer
const double * pointer
Definition gsl_iterator.hh:174
gsl::const_vector_iterator::const_vector_iterator
const_vector_iterator(const vector_iterator &other)
Definition gsl_iterator.hh:186
gsl::const_vector_iterator::operator==
bool operator==(const const_vector_iterator &other) const
Definition gsl_iterator.hh:257
gsl::const_vector_iterator::operator>
bool operator>(const const_vector_iterator &other) const
Definition gsl_iterator.hh:281
gsl::const_vector_iterator::operator+=
const_vector_iterator & operator+=(int dist)
Definition gsl_iterator.hh:234
gsl::const_vector_iterator::value_type
const double value_type
Definition gsl_iterator.hh:173
gsl::vector_iterator
Definition gsl_iterator.hh:32
gsl::vector_iterator::vector_iterator
vector_iterator()
Definition gsl_iterator.hh:43
gsl::vector_iterator::operator==
bool operator==(const vector_iterator &other) const
Definition gsl_iterator.hh:105
gsl::vector_iterator::operator>
bool operator>(const vector_iterator &other) const
Definition gsl_iterator.hh:129
gsl::vector_iterator::vector_iterator
vector_iterator(double *base, int stride)
Definition gsl_iterator.hh:39
gsl::vector_iterator::operator+=
vector_iterator & operator+=(int dist)
Definition gsl_iterator.hh:82
gsl::vector_iterator::vector_iterator
vector_iterator(const vector_iterator &other)=default
gsl::vector_iterator::operator-
difference_type operator-(const vector_iterator &other)
Definition gsl_iterator.hh:99
gsl::vector_iterator::operator-=
vector_iterator & operator-=(int dist)
Definition gsl_iterator.hh:88
gsl::vector_iterator::operator<=
bool operator<=(const vector_iterator &other) const
Definition gsl_iterator.hh:123
gsl::vector_iterator::reference
double & reference
Definition gsl_iterator.hh:36
gsl::vector_iterator::operator++
vector_iterator & operator++()
Definition gsl_iterator.hh:55
gsl::vector_iterator::operator!=
bool operator!=(const vector_iterator &other) const
Definition gsl_iterator.hh:111
gsl::vector_iterator::value_type
double value_type
Definition gsl_iterator.hh:34
gsl::vector_iterator::operator->
double * operator->()
Definition gsl_iterator.hh:50
gsl::vector_iterator::operator*
double & operator*()
Definition gsl_iterator.hh:45
gsl::vector_iterator::operator[]
double & operator[](int idx)
Definition gsl_iterator.hh:94
gsl::vector_iterator::pointer
double * pointer
Definition gsl_iterator.hh:35
gsl::vector_iterator::operator--
vector_iterator & operator--()
Definition gsl_iterator.hh:69
gsl::vector_iterator::const_vector_iterator
friend class const_vector_iterator
Definition gsl_iterator.hh:142
gsl::vector_iterator::operator>=
bool operator>=(const vector_iterator &other) const
Definition gsl_iterator.hh:135
gsl::vector_iterator::difference_type
size_t difference_type
Definition gsl_iterator.hh:37
gsl::vector_iterator::operator<
bool operator<(const vector_iterator &other) const
Definition gsl_iterator.hh:117
std::iterator_traits< gsl::const_vector_iterator >::pointer
const double * pointer
Definition gsl_iterator.hh:332
std::iterator_traits< gsl::const_vector_iterator >::value_type
double value_type
Definition gsl_iterator.hh:331
std::iterator_traits< gsl::const_vector_iterator >::iterator_category
random_access_iterator_tag iterator_category
Definition gsl_iterator.hh:334
std::iterator_traits< gsl::const_vector_iterator >::difference_type
size_t difference_type
Definition gsl_iterator.hh:330
std::iterator_traits< gsl::const_vector_iterator >::reference
const double & reference
Definition gsl_iterator.hh:333
std::iterator_traits< gsl::vector_iterator >::pointer
double * pointer
Definition gsl_iterator.hh:343
std::iterator_traits< gsl::vector_iterator >::value_type
double value_type
Definition gsl_iterator.hh:342
std::iterator_traits< gsl::vector_iterator >::iterator_category
random_access_iterator_tag iterator_category
Definition gsl_iterator.hh:345
std::iterator_traits< gsl::vector_iterator >::reference
double & reference
Definition gsl_iterator.hh:344
std::iterator_traits< gsl::vector_iterator >::difference_type
size_t difference_type
Definition gsl_iterator.hh:341
gsl
Definition gsl_iterator.hh:29
gsl::operator-
vector_iterator operator-(const vector_iterator &it, int dist)
Definition gsl_iterator.hh:155
gsl::operator+
vector_iterator operator+(const vector_iterator &it, int dist)
Definition gsl_iterator.hh:148
std
Definition gsl_iterator.hh:324