DGtal 1.4.0
Loading...
Searching...
No Matches
InputIteratorWithRankOnSequence.ih
1/**
2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 **/
16
17/**
18 * @file InputIteratorWithRankOnSequence.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21 *
22 * @date 2012/04/02
23 *
24 * Implementation of inline methods defined in InputIteratorWithRankOnSequence.h
25 *
26 * This file is part of the DGtal library.
27 */
28
29
30//////////////////////////////////////////////////////////////////////////////
31#include <cstdlib>
32//////////////////////////////////////////////////////////////////////////////
33
34///////////////////////////////////////////////////////////////////////////////
35// IMPLEMENTATION of inline methods.
36///////////////////////////////////////////////////////////////////////////////
37
38///////////////////////////////////////////////////////////////////////////////
39// ----------------------- Standard services ------------------------------
40
41//-----------------------------------------------------------------------------
42template <typename TSequence, typename TRank>
43inline
44DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
45~InputIteratorWithRankOnSequence()
46{
47}
48//-----------------------------------------------------------------------------
49template <typename TSequence, typename TRank>
50inline
51DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
52InputIteratorWithRankOnSequence( const Sequence & seq, ConstIterator it )
53 : mySequence( new Sequence( seq ) ), myIterator( it )
54{
55}
56//-----------------------------------------------------------------------------
57template <typename TSequence, typename TRank>
58inline
59DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
60InputIteratorWithRankOnSequence( Sequence* ptrSeq, ConstIterator it )
61 : mySequence( ptrSeq ), myIterator( it )
62{
63}
64//-----------------------------------------------------------------------------
65template <typename TSequence, typename TRank>
66inline
67DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
68InputIteratorWithRankOnSequence
69( const CountedPtr<Sequence> & ptrSeq, ConstIterator it )
70 : mySequence( ptrSeq ), myIterator( it )
71{
72}
73//-----------------------------------------------------------------------------
74template <typename TSequence, typename TRank>
75inline
76DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
77InputIteratorWithRankOnSequence( const Self & other )
78 : mySequence( other.mySequence ), myIterator( other.myIterator )
79{
80}
81//-----------------------------------------------------------------------------
82template <typename TSequence, typename TRank>
83inline
84typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self &
85DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
86operator= ( const Self & other )
87{
88 if ( this != &other )
89 {
90 mySequence = other.mySequence;
91 myIterator = other.myIterator;
92 }
93 return *this;
94}
95//-----------------------------------------------------------------------------
96template <typename TSequence, typename TRank>
97inline
98typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Value
99DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
100operator*() const
101{
102 return std::make_pair( *myIterator, (Rank) ( myIterator - mySequence->begin() ) );
103}
104//-----------------------------------------------------------------------------
105template <typename TSequence, typename TRank>
106inline
107typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Pointer
108DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
109operator->() const
110{
111 myTmpValue = this->operator*();
112 return &myTmpValue;
113}
114//-----------------------------------------------------------------------------
115template <typename TSequence, typename TRank>
116inline
117typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self &
118DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
119operator++()
120{
121 ++myIterator;
122 return *this;
123}
124//-----------------------------------------------------------------------------
125template <typename TSequence, typename TRank>
126inline
127typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self
128DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
129operator++( int )
130{
131 Self tmp = *this;
132 ++myIterator;
133 return tmp;
134}
135//-----------------------------------------------------------------------------
136template <typename TSequence, typename TRank>
137inline
138bool
139DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
140operator==( const Self & other ) const
141{
142 if ( mySequence.get() != 0 )
143 {
144 if ( other.mySequence.get() != 0 )
145 return ( myIterator == other.myIterator );
146 else
147 return ( myIterator == mySequence->end() );
148 }
149 else
150 {
151 if ( other.mySequence.get() != 0 )
152 return ( other.myIterator == other.mySequence->end() );
153 else
154 return true;
155 }
156}
157//-----------------------------------------------------------------------------
158template <typename TSequence, typename TRank>
159inline
160bool
161DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
162operator!=( const Self & other ) const
163{
164 return ! this->operator==( other );
165}
166
167///////////////////////////////////////////////////////////////////////////////
168// Interface - public :
169
170/**
171 * Writes/Displays the object on an output stream.
172 * @param out the output stream where the object is written.
173 */
174template <typename TSequence, typename TRank>
175inline
176void
177DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
178selfDisplay ( std::ostream & out ) const
179{
180 out << "[InputIteratorWithRankOnSequence]";
181}
182
183/**
184 * Checks the validity/consistency of the object.
185 * @return 'true' if the object is valid, 'false' otherwise.
186 */
187template <typename TSequence, typename TRank>
188inline
189bool
190DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
191isValid() const
192{
193 return true;
194}
195
196
197
198///////////////////////////////////////////////////////////////////////////////
199// Implementation of inline functions //
200
201template <typename TSequence, typename TRank>
202inline
203std::ostream&
204DGtal::operator<< ( std::ostream & out,
205 const InputIteratorWithRankOnSequence<TSequence,TRank> & object )
206{
207 object.selfDisplay( out );
208 return out;
209}
210
211// //
212///////////////////////////////////////////////////////////////////////////////
213
214