msl 1.1.0
 
Loading...
Searching...
No Matches
Iterator.h
Go to the documentation of this file.
1// Copyright 2025 Julien Lamy, ICube, Université de Strasbourg-CNRS.
2// Part of msl, distributed under the terms of the MIT license.
3
4#ifndef _3608ae00_0c4a_4bb2_a439_7094206b302f
5#define _3608ae00_0c4a_4bb2_a439_7094206b302f
6
7#include "Counter.h"
8
9namespace msl
10{
11
13template<typename T>
15{
16public:
18 : _counter(0), _container()
19 {
21 }
22
23 ConstIterator(ConstIterator<T> const &) = default;
27 virtual ~ConstIterator() = default;
28
30 T const & container() const
31 {
32 return this->_container;
33 }
34
36 void setContainer(T const & container)
37 {
38 this->_counter.setEnd(container.size());
39 this->_counter.reset();
40
41 this->_container = container;
42 }
43
45 std::size_t index() const
46 {
47 return this->_counter.index();
48 }
49
51 typename T::value_type const & item() const
52 {
53 return this->_container[this->_counter.index()];
54 }
55
57 std::size_t end() const
58 {
59 return this->_counter.end();
60 }
61
64 {
65 this->_counter.reset();
66 return *this;
67 }
68
74 {
75 ++this->_counter;
76 return *this;
77 }
78
80 bool first() const
81 {
82 return this->_counter.first();
83 }
84
86 bool last() const
87 {
88 return this->_counter.last();
89 }
90
92 bool done() const
93 {
94 return this->_counter.done();
95 }
96
97protected:
100};
101
103template<typename T>
104class Iterator: public ConstIterator<T>
105{
106public:
107 Iterator(T const & container={})
109 {
110 // Nothing else
111 }
112
113 Iterator(Iterator<T> const &) = default;
114 Iterator(Iterator<T> &&) = default;
115 Iterator<T> & operator=(Iterator<T> const &) = default;
117
119 typename T::value_type & item()
120 {
121 return this->_container[this->_counter.index()];
122 }
123};
124
125}
126
127#endif // _3608ae00_0c4a_4bb2_a439_7094206b302f
Read-only iterator to a container.
Definition Iterator.h:15
std::size_t end() const
Return the end value.
Definition Iterator.h:57
msl::Mask::Points const & container() const
Definition Iterator.h:30
bool first() const
Test if the index is 0.
Definition Iterator.h:80
T _container
Definition Iterator.h:99
ConstIterator< T > & operator=(ConstIterator< T > &&)=default
bool last() const
Test if the index is equal to end-1.
Definition Iterator.h:86
ConstIterator & reset()
Reset the iterator to the start of the container.
Definition Iterator.h:63
T::value_type const & item() const
Return the current item.
Definition Iterator.h:51
void setContainer(T const &container)
Set the container, reset the counter.
Definition Iterator.h:36
ConstIterator & operator++()
Move to the next element.
Definition Iterator.h:73
ConstIterator(ConstIterator< T > &&)=default
ConstIterator(ConstIterator< T > const &)=default
virtual ~ConstIterator()=default
Counter _counter
Definition Iterator.h:98
ConstIterator< T > & operator=(ConstIterator< T > const &)=default
ConstIterator(T const &container={})
Definition Iterator.h:17
bool done() const
Test if the index is equal to end.
Definition Iterator.h:92
std::size_t index() const
Return the current index.
Definition Iterator.h:45
Counter from 0 (included) to end (excluded).
Definition Counter.h:14
Iterator< T > & operator=(Iterator< T > &&)=default
Iterator(Iterator< T > const &)=default
Iterator< T > & operator=(Iterator< T > const &)=default
Iterator(T const &container={})
Definition Iterator.h:107
T::value_type & item()
Return the current item.
Definition Iterator.h:119
Iterator(Iterator< T > &&)=default
Definition acceleration.h:17