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.
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.
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/>.
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
24 * Implementation of inline methods defined in InputIteratorWithRankOnSequence.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 //-----------------------------------------------------------------------------
42 template <typename TSequence, typename TRank>
44 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
45 ~InputIteratorWithRankOnSequence()
48 //-----------------------------------------------------------------------------
49 template <typename TSequence, typename TRank>
51 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
52 InputIteratorWithRankOnSequence( const Sequence & seq, ConstIterator it )
53 : mySequence( new Sequence( seq ) ), myIterator( it )
56 //-----------------------------------------------------------------------------
57 template <typename TSequence, typename TRank>
59 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
60 InputIteratorWithRankOnSequence( Sequence* ptrSeq, ConstIterator it )
61 : mySequence( ptrSeq ), myIterator( it )
64 //-----------------------------------------------------------------------------
65 template <typename TSequence, typename TRank>
67 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
68 InputIteratorWithRankOnSequence
69 ( const CountedPtr<Sequence> & ptrSeq, ConstIterator it )
70 : mySequence( ptrSeq ), myIterator( it )
73 //-----------------------------------------------------------------------------
74 template <typename TSequence, typename TRank>
76 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
77 InputIteratorWithRankOnSequence( const Self & other )
78 : mySequence( other.mySequence ), myIterator( other.myIterator )
81 //-----------------------------------------------------------------------------
82 template <typename TSequence, typename TRank>
84 typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self &
85 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
86 operator= ( const Self & other )
90 mySequence = other.mySequence;
91 myIterator = other.myIterator;
95 //-----------------------------------------------------------------------------
96 template <typename TSequence, typename TRank>
98 typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Value
99 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
102 return std::make_pair( *myIterator, (Rank) ( myIterator - mySequence->begin() ) );
104 //-----------------------------------------------------------------------------
105 template <typename TSequence, typename TRank>
107 typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Pointer
108 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
111 myTmpValue = this->operator*();
114 //-----------------------------------------------------------------------------
115 template <typename TSequence, typename TRank>
117 typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self &
118 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
124 //-----------------------------------------------------------------------------
125 template <typename TSequence, typename TRank>
127 typename DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::Self
128 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
135 //-----------------------------------------------------------------------------
136 template <typename TSequence, typename TRank>
139 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
140 operator==( const Self & other ) const
142 if ( mySequence.get() != 0 )
144 if ( other.mySequence.get() != 0 )
145 return ( myIterator == other.myIterator );
147 return ( myIterator == mySequence->end() );
151 if ( other.mySequence.get() != 0 )
152 return ( other.myIterator == other.mySequence->end() );
157 //-----------------------------------------------------------------------------
158 template <typename TSequence, typename TRank>
161 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
162 operator!=( const Self & other ) const
164 return ! this->operator==( other );
167 ///////////////////////////////////////////////////////////////////////////////
168 // Interface - public :
171 * Writes/Displays the object on an output stream.
172 * @param out the output stream where the object is written.
174 template <typename TSequence, typename TRank>
177 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
178 selfDisplay ( std::ostream & out ) const
180 out << "[InputIteratorWithRankOnSequence]";
184 * Checks the validity/consistency of the object.
185 * @return 'true' if the object is valid, 'false' otherwise.
187 template <typename TSequence, typename TRank>
190 DGtal::InputIteratorWithRankOnSequence<TSequence,TRank>::
198 ///////////////////////////////////////////////////////////////////////////////
199 // Implementation of inline functions //
201 template <typename TSequence, typename TRank>
204 DGtal::operator<< ( std::ostream & out,
205 const InputIteratorWithRankOnSequence<TSequence,TRank> & object )
207 object.selfDisplay( out );
212 ///////////////////////////////////////////////////////////////////////////////