casacore
Loading...
Searching...
No Matches
VectorSTLIterator.h
Go to the documentation of this file.
1//# VectorSTLIterator.h: Random access iterator for Casacore Vectors
2//# Copyright (C) 2004
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef CASA_VECTORSTLITERATOR_2_H
27#define CASA_VECTORSTLITERATOR_2_H
28
29//# Includes
30#include "Vector.h"
31
32#include <iterator>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37
38// <summary> Casacore Vector iterator </summary>
39// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
40// </reviewed>
41// <synopsis>
42// This class creates a random access STL iterator for an Casacore Vector. All
43// the STL functionality is present (or if something missing can be easily
44// added). <br>
45// The following comments hold:
46// <ul>
47// <li> A VectorSTLIterator can be created from a <src>Vector</src> (non-STL)
48// It is the same as using <src>Vector.begin()</src>
49// <li> No contiguous iterator is provided. Its construction is not necessary,
50// since <src>Vector.data()</src> is a fully functional STL iterator already.
51// <li> This iterator is non-intrusive. Since it needs state (the 'step')
52// nothing substantial is gained by having it included in the Vector class.
53// The major gain would be to be able to use the standard nomenclature:
54// <src>Vector::iterator()</src> rather than <src>VectorSTLiterator</src>
55// <li> It would be advisable, and easy to implement, to add a template argument
56// to the <src>Array</src> classes: <src><class T, bool isCont=true></src>. The
57// default is contiguous, since creation is contiguous. In that case correct
58// iterators for e.g. contiguous arrays are supplied automatically.
59// <li> needs probably some 'const' fine tuning; and the <src>-></src> operator
60// </ul>
61// </synopsis>
62
63template <typename T>
65 public:
66 // iterator traits
67 using iterator_category = std::random_access_iterator_tag;
68
69 typedef T value_type;
71 typedef const value_type* const_pointer;
76 typedef std::size_t size_type;
77 typedef ptrdiff_t difference_type;
78
79
80 // Constructors. The iterator constructor from a <src>Vector</src> is
81 // the same as if created from <src>Vector.begin()</src>. Copy
82 // constructor and assignment can be the default ones.
83 // <group>
84 explicit VectorSTLIterator(const Vector<T> &c)
85 : start_p(const_cast<T*>(c.data())),
86 step_p (std::max(ssize_t(1), c.steps()(0))),
87 iter_p (const_cast<T*>(c.data()))
88 {}
90 {}
92 : start_p(c.pos()),
93 step_p (std::max(ssize_t(1), c.steps()(0))),
95 {}
96 // </group>
97 // Access
98 // <group>
99 reference operator[](size_t i) { return *(start_p+i*step_p); };
100 const_reference operator[](size_t i) const {
101 return *(start_p+i*step_p); };
102 reference operator*() { return *iter_p; };
103 const_reference operator*() const { return *iter_p; };
104 pointer pos() const {return iter_p; }
105 // </group>
106 // Manipulation
107 // <group>
108 const iterator &operator++() { iter_p+=step_p; return *this; };
110 iterator t = *this; iter_p+=step_p; return t; };
111 iterator &operator--() { iter_p-=step_p; return *this; };
113 VectorSTLIterator<T> t = *this;iter_p-=step_p; return t; };
115 iter_p+=i*step_p; return *this; };
117 iter_p-=i*step_p; return *this; };
119 VectorSTLIterator<T> t = *this; return t+=i; };
121 VectorSTLIterator<T> t = *this; return t-=i; };
122 // </group>
123 // Size related
124 // <group>
126 return (iter_p-x.iter_p)/step_p; };
127 // </group>
128 // Comparisons
129 // <group>
130 bool operator== (const iterator &other) const {
131 return iter_p == other.iter_p; };
132 bool operator!= (const iterator other) const {
133 return iter_p != other.iter_p; };
134 bool operator< (const iterator &other) const {
135 return iter_p < other.iter_p; };
136 bool operator== (const_pointer const pos) const {
137 return iter_p == pos; };
138 bool operator!= (const_pointer const pos) const {
139 return iter_p != pos; };
140 bool operator< (const_pointer const pos) const {
141 return iter_p < pos; };
142 // </group>
143 protected:
144 // Start (for random indexing)
146 // Distance between elements
148 // Current element pointer
150};
151
152
153} //# NAMESPACE CASACORE - END
154
155#endif
reference operator[](size_t i)
Access.
const iterator & operator++()
Manipulation.
const value_type * const_pointer
bool operator==(const iterator &other) const
Comparisons.
iterator operator-(difference_type i) const
iterator & operator-=(difference_type i)
bool operator!=(const iterator other) const
difference_type operator-(const VectorSTLIterator< T > &x) const
Size related.
const value_type & const_reference
iterator & operator+=(difference_type i)
VectorSTLIterator(const Vector< T > &c)
Constructors.
std::random_access_iterator_tag iterator_category
iterator traits
const_reference operator[](size_t i) const
pointer iter_p
Current element pointer.
difference_type step_p
Distance between elements.
const VectorSTLIterator< T > const_iterator
iterator operator+(difference_type i) const
VectorSTLIterator< T > iterator
bool operator<(const iterator &other) const
pointer const start_p
Start (for random indexing).
const_reference operator*() const
VectorSTLIterator(const typename Array< T >::IteratorSTL &c)
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Definition Complex.h:350