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 std::iterator<std::random_access_iterator_tag, T> {
66 public:
67 typedef T value_type;
69 typedef const value_type* const_pointer;
74 typedef std::size_t size_type;
75 typedef ptrdiff_t difference_type;
76 // Constructors. The iterator constructor from a <src>Vector</src> is
77 // the same as if created from <src>Vector.begin()</src>. Copy
78 // constructor and assignment can be the default ones.
79 // <group>
80 explicit VectorSTLIterator(const Vector<T> &c)
81 : start_p(const_cast<T*>(c.data())),
82 step_p (std::max(ssize_t(1), c.steps()(0))),
83 iter_p (const_cast<T*>(c.data()))
84 {}
86 {}
88 : start_p(c.pos()),
89 step_p (std::max(ssize_t(1), c.steps()(0))),
91 {}
92 // </group>
93 // Access
94 // <group>
95 reference operator[](size_t i) { return *(start_p+i*step_p); };
96 const_reference operator[](size_t i) const {
97 return *(start_p+i*step_p); };
98 reference operator*() { return *iter_p; };
99 const_reference operator*() const { return *iter_p; };
100 pointer pos() const {return iter_p; }
101 // </group>
102 // Manipulation
103 // <group>
104 const iterator &operator++() { iter_p+=step_p; return *this; };
106 iterator t = *this; iter_p+=step_p; return t; };
107 iterator &operator--() { iter_p-=step_p; return *this; };
109 VectorSTLIterator<T> t = *this;iter_p-=step_p; return t; };
111 iter_p+=i*step_p; return *this; };
113 iter_p-=i*step_p; return *this; };
115 VectorSTLIterator<T> t = *this; return t+=i; };
117 VectorSTLIterator<T> t = *this; return t-=i; };
118 // </group>
119 // Size related
120 // <group>
122 return (iter_p-x.iter_p)/step_p; };
123 // </group>
124 // Comparisons
125 // <group>
126 bool operator== (const iterator &other) const {
127 return iter_p == other.iter_p; };
128 bool operator!= (const iterator other) const {
129 return iter_p != other.iter_p; };
130 bool operator< (const iterator &other) const {
131 return iter_p < other.iter_p; };
132 bool operator== (const_pointer const pos) const {
133 return iter_p == pos; };
134 bool operator!= (const_pointer const pos) const {
135 return iter_p != pos; };
136 bool operator< (const_pointer const pos) const {
137 return iter_p < pos; };
138 // </group>
139 protected:
140 // Start (for random indexing)
142 // Distance between elements
144 // Current element pointer
146};
147
148
149} //# NAMESPACE CASACORE - END
150
151#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.
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
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