34#include "DGtal/base/Common.h"
35#include "DGtal/base/IteratorFunctions.h"
36#include "DGtal/base/Circulator.h"
37#include "DGtal/base/ReverseIterator.h"
46template<
typename Container,
typename T>
49 static void add(Container& c,
const T& obj)
55#include <forward_list>
58struct Tool<
std::forward_list<int>, T>
60 static void add(std::forward_list<int>& c,
const T& obj)
71template<
typename Container>
74 unsigned int nbok = 0;
80 typedef typename Container::iterator I;
82 trace.
info() <<
typeid(Category()).name() << std::endl;
85 Tool<Container,int>::add(c,1);
86 Tool<Container,int>::add(c,2);
87 Tool<Container,int>::add(c,3);
88 Tool<Container,int>::add(c,4);
89 Tool<Container,int>::add(c,5);
98 if ( (i != c.begin()) && ( i == res ) )
101 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
115 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
128template<
typename Container>
131 unsigned int nbok = 0;
137 typedef typename Container::iterator I;
139 trace.
info() <<
typeid(Category()).name() << std::endl;
141 trace.
info() <<
"empty underlying range" << std::endl;
142 if (
rangeSize(c.begin(), c.end()) == 0 )
145 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
150 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
154 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
159 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
162 Tool<Container,int>::add(c,5);
164 trace.
info() <<
"underlying range of one element" << std::endl;
165 if (
rangeSize(c.begin(), c.end()) == 1 )
168 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
175 Tool<Container,int>::add(c,1);
176 Tool<Container,int>::add(c,2);
177 Tool<Container,int>::add(c,3);
178 Tool<Container,int>::add(c,4);
179 Tool<Container,int>::add(c,5);
180 Tool<Container,int>::add(c,6);
182 trace.
info() <<
"two equal iterators" << std::endl;
183 if (
rangeSize(c.begin(), c.begin()) == 0 )
186 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
190 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
195 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
198 trace.
info() <<
"whole range (of 7 elements)" << std::endl;
199 if (
rangeSize(c.begin(), c.end()) == 7 )
202 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
207 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
210 I itb = c.begin(); ++itb;
212 ite++; ite++; ite++; ite++;
214 trace.
info() <<
"subrange (of 4 elements)" << std::endl;
218 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
223 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
227 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
232 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
246template<
typename Container>
249 unsigned int nbok = 0;
255 typedef typename Container::iterator I;
257 trace.
info() <<
typeid(Category()).name() << std::endl;
259 trace.
info() <<
"empty underlying range" << std::endl;
260 if (
rangeMiddle(c.begin(), c.end()) == c.begin() )
263 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
269 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
273 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
279 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
282 Tool<Container,int>::add(c,5);
284 trace.
info() <<
"underlying range of one element" << std::endl;
285 if (
rangeMiddle(c.begin(), c.end()) == c.begin() )
288 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
294 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
297 Tool<Container,int>::add(c,1);
298 Tool<Container,int>::add(c,2);
299 Tool<Container,int>::add(c,3);
300 Tool<Container,int>::add(c,4);
301 Tool<Container,int>::add(c,5);
302 Tool<Container,int>::add(c,6);
303 Tool<Container,int>::add(c,5);
305 trace.
info() <<
"two equal iterators" << std::endl;
306 if (
rangeMiddle(c.begin(), c.begin()) == c.begin() )
309 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
313 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
319 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
325 ite++; ite++; ite++; ite++;
327 res1++; res1++; res1++;
331 trace.
info() <<
"whole range with odd number of elements" << std::endl;
335 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
341 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
343 trace.
info() <<
"whole range with even number of elements" << std::endl;
347 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
353 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
361 trace.
info() <<
"subrange with odd number of elements" << std::endl;
365 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
371 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
375 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
381 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
386 trace.
info() <<
"subrange with even number of elements" << std::endl;
390 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
396 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
400 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
406 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
419 return (
isNotEmpty(itb,ite) == aFlagIsNotEmpty );
427template<
typename Container>
430 unsigned int nbok = 0;
436 typedef typename Container::iterator I;
438 trace.
info() <<
typeid(Category()).name() << std::endl;
440 trace.
info() <<
"empty underlying range" << std::endl;
444 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
449 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
454 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
457 Tool<Container,int>::add(c,5);
459 trace.
info() <<
"underlying range of one element" << std::endl;
463 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
468 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
473 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
476 Tool<Container,int>::add(c,1);
477 Tool<Container,int>::add(c,2);
478 Tool<Container,int>::add(c,3);
479 Tool<Container,int>::add(c,4);
480 Tool<Container,int>::add(c,5);
481 Tool<Container,int>::add(c,6);
482 Tool<Container,int>::add(c,5);
484 trace.
info() <<
"two equal iterators" << std::endl;
488 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
493 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
496 I itb = c.begin(); itb++;
501 trace.
info() <<
"whole range" << std::endl;
505 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
510 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
515 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
522 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
527 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
532 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << std::endl;
543int main(
int argc,
char** argv )
547 for (
int i = 0; i < argc; ++i )
551 std::forward_list<int> fl;
569 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
IteratorCirculatorTraits< IC >::Difference rangeSize(const IC &itb, const IC &ite)
IC subRangeMiddle(const IC &itb, const IC &ite)
bool isNotEmpty(const IC &itb, const IC &ite)
IC rangeMiddle(const IC &itb, const IC &ite)
void advanceIterator(IC &ic, typename IteratorCirculatorTraits< IC >::Difference n)
IteratorCirculatorTraits< IC >::Difference subRangeSize(const IC &itb, const IC &ite)
ToDGtalCategory< typenameboost::iterator_category< IC >::type >::Category Category
bool testRange(Container c)
bool testAdvance(Container c)
bool testIsNotEmpty(const IC &itb, const IC &ite, const bool &aFlagIsNotEmpty)
bool testMiddle(Container c)
bool testSize(Container c)