DGtal  0.9.3
Functions
testIteratorCirculatorTraits.cpp File Reference
#include <iostream>
#include <list>
#include <vector>
#include <forward_list>
#include "DGtal/base/Common.h"
#include "DGtal/base/IteratorCirculatorTraits.h"
#include "DGtal/base/Circulator.h"
#include "DGtal/base/ReverseIterator.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/base/ConstIteratorAdapter.h"
#include "DGtal/base/IteratorAdapter.h"
Include dependency graph for testIteratorCirculatorTraits.cpp:

Go to the source code of this file.

Functions

template<typename IC , typename T >
bool compareType (IC, T)
 
template<typename IC , typename T >
bool compareCategory (IC, T)
 
bool testIteratorCirculatorTraits ()
 
bool testIteratorCirculatorTraitsAndAdapters ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/11/21

Functions for testing class IteratorCirculatorTraits.

This file is part of the DGtal library.

Definition in file testIteratorCirculatorTraits.cpp.

Function Documentation

◆ compareCategory()

template<typename IC , typename T >
bool compareCategory ( IC  ,
 
)
inline

Comparison between the category of (circular) iterator and T

Template Parameters
ICiterator or circulator
Ttype to compare with (Forward-, Bidirectional- and RandomAccessCategory).

Definition at line 72 of file testIteratorCirculatorTraits.cpp.

Referenced by testIteratorCirculatorTraits(), and testIteratorCirculatorTraitsAndAdapters().

72  {
73  return boost::is_same<
75  T >::value;
76 }
ToDGtalCategory< typename boost::iterator_category< IC >::type >::Category Category

◆ compareType()

template<typename IC , typename T >
bool compareType ( IC  ,
 
)
inline

Comparison between the type of (circular) iterator and T

Template Parameters
ICiterator or circulator
Ttype to compare with (IteratorType or CircularType).

Definition at line 59 of file testIteratorCirculatorTraits.cpp.

Referenced by testIteratorCirculatorTraits(), and testIteratorCirculatorTraitsAndAdapters().

59  {
60  return boost::is_same<
62  T >::value;
63 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 301 of file testIteratorCirculatorTraits.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testIteratorCirculatorTraits(), testIteratorCirculatorTraitsAndAdapters(), and DGtal::trace.

302 {
303  trace.beginBlock ( "Testing class IteratorCirculatorTraits" );
304  trace.info() << "Args:";
305  for ( int i = 0; i < argc; ++i )
306  trace.info() << " " << argv[ i ];
307  trace.info() << endl;
308 
310 
311  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
312  trace.endBlock();
313  return res ? 0 : 1;
314 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
bool testIteratorCirculatorTraits()
std::ostream & emphase()
std::ostream & info()
bool testIteratorCirculatorTraitsAndAdapters()

◆ testIteratorCirculatorTraits()

bool testIteratorCirculatorTraits ( )

Test of the IteratorCirculatorTraits class (Type and Category).

Definition at line 82 of file testIteratorCirculatorTraits.cpp.

References DGtal::Trace::beginBlock(), compareCategory(), compareType(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

83 {
84  unsigned int nbok = 0;
85  unsigned int nb = 0;
86 
87  trace.beginBlock ( "Testing tags for various (circular) iterators..." );
88 
89  //forward list
90  trace.info() << "forward list" << std::endl;
91  std::forward_list<int> fl;
92  if ( compareType( fl.begin(), IteratorType() ) )
93  nbok++;
94  nb++;
95  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
96  if ( compareCategory( fl.begin(), ForwardCategory() ) )
97  nbok++;
98  nb++;
99  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
100  Circulator< std::forward_list<int>::iterator > cfl(fl.begin(), fl.begin(), fl.end());
101  if ( compareType( cfl, CirculatorType() ) )
102  nbok++;
103  nb++;
104  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
105  if ( compareCategory( cfl, ForwardCategory() ) )
106  nbok++;
107  nb++;
108  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
109 
110  //list
111  trace.info() << "list" << std::endl;
112  std::list<int> bl;
113  if ( compareType( bl.begin(), IteratorType() ) )
114  nbok++;
115  nb++;
116  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
117  if ( compareCategory( bl.begin(), BidirectionalCategory() ) )
118  nbok++;
119  nb++;
120  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
121  Circulator< std::list<int>::iterator > cbl(bl.begin(), bl.begin(), bl.end());
122  if ( compareType( cbl, CirculatorType() ) )
123  nbok++;
124  nb++;
125  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
126  if ( compareCategory( cbl, BidirectionalCategory() ) )
127  nbok++;
128  nb++;
129  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
130 
131  //vector
132  trace.info() << "vector" << std::endl;
133  std::vector<int> v;
134  if ( compareType( v.begin(), IteratorType() ) )
135  nbok++;
136  nb++;
137  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
138  if ( compareCategory( v.begin(), RandomAccessCategory() ) )
139  nbok++;
140  nb++;
141  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
142  Circulator< std::vector<int>::iterator > cv(v.begin(), v.begin(), v.end());
143  if ( compareType( cv, CirculatorType() ) )
144  nbok++;
145  nb++;
146  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
147  if ( compareCategory( cv, RandomAccessCategory() ) )
148  nbok++;
149  nb++;
150  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
151 
152  //basic array
153  trace.info() << "basic array" << std::endl;
154  int t[5] = {1, 2, 3, 4, 5};
155  if ( compareType( t, IteratorType() ) )
156  nbok++;
157  nb++;
158  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
160  nbok++;
161  nb++;
162  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
163  Circulator< int* > ct(t+1, t, t+5);
164  if ( compareType( ct, CirculatorType() ) )
165  nbok++;
166  nb++;
167  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
168  if ( compareCategory( ct, RandomAccessCategory() ) )
169  nbok++;
170  nb++;
171  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
172 
173  trace.endBlock();
174 
175  return (nbok == nb);
176 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
bool compareType(IC, T)
bool compareCategory(IC, T)
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
std::ostream & info()

◆ testIteratorCirculatorTraitsAndAdapters()

bool testIteratorCirculatorTraitsAndAdapters ( )

Test of the IteratorCirculatorTraits class on adapters (Type and Category).

Definition at line 182 of file testIteratorCirculatorTraits.cpp.

References DGtal::Trace::beginBlock(), compareCategory(), compareType(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

183 {
184  unsigned int nbok = 0;
185  unsigned int nb = 0;
186 
187  trace.beginBlock ( "Testing tags for adapters (ReverseIterator, (Const)IteratorAdapter) " );
188 
189  int t[5] = {1, 2, 3, 4, 5};
190  //reverse
191  trace.info() << "ReverseIterator" << std::endl;
192  typedef ReverseIterator< int* > RI;
193  RI rt(t+5);
194  if ( compareType( rt, IteratorType() ) )
195  nbok++;
196  nb++;
197  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
198  if ( compareCategory( rt, RandomAccessCategory() ) )
199  nbok++;
200  nb++;
201  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
202  //const adapter
203  trace.info() << "ConstIteratorAdapter" << std::endl;
205  IA1 at1( t, functors::Identity() );
206  if ( compareType( at1, IteratorType() ) )
207  nbok++;
208  nb++;
209  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
210  if ( compareCategory( at1, RandomAccessCategory() ) )
211  nbok++;
212  nb++;
213  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
214  //adapter
215  trace.info() << "IteratorAdapter" << std::endl;
217  IA2 at2( t, functors::Identity() );
218  if ( compareType( at2, IteratorType() ) )
219  nbok++;
220  nb++;
221  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
222  if ( compareCategory( at2, RandomAccessCategory() ) )
223  nbok++;
224  nb++;
225  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
226 
227  //with circulators
228  typedef Circulator< int* > CI;
229 
230  //reverse circ, circ reverse,
231  trace.info() << "ReverseIterator<Circulator> and Circulator<ReverseIterator>" << std::endl;
232  Circulator< RI > crt( rt, RI(t+5), RI(t) );
233  if ( compareType( crt, CirculatorType() ) )
234  nbok++;
235  nb++;
236  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
237  if ( compareCategory( crt, RandomAccessCategory() ) )
238  nbok++;
239  nb++;
240  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
241  ReverseIterator< CI > rct( CI(t+5, t, t+5) );
242  if ( compareType( rct, CirculatorType() ) )
243  nbok++;
244  nb++;
245  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
246  if ( compareCategory( rct, RandomAccessCategory() ) )
247  nbok++;
248  nb++;
249  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
250 
251  //const iterator adapter circ, circ const iterator adapter
252  trace.info() << "ConstIteratorAdapter of Circulator and Circulator of ConstIteratorAdapter" << std::endl;
253  Circulator< IA1 > cat1( at1, at1, IA1(t+5, functors::Identity()) );
254  if ( compareType( cat1, CirculatorType() ) )
255  nbok++;
256  nb++;
257  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
258  if ( compareCategory( cat1, RandomAccessCategory() ) )
259  nbok++;
260  nb++;
261  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
263  if ( compareType( a1ct, CirculatorType() ) )
264  nbok++;
265  nb++;
266  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
267  if ( compareCategory( a1ct, RandomAccessCategory() ) )
268  nbok++;
269  nb++;
270  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
271 
272  //iterator adapter circ, circ iterator adapter
273  trace.info() << "IteratorAdapter of Circulator and Circulator of IteratorAdapter" << std::endl;
274  Circulator< IA2 > cat2( at2, at2, IA2(t+5, functors::Identity()) );
275  if ( compareType( cat2, CirculatorType() ) )
276  nbok++;
277  nb++;
278  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
279  if ( compareCategory( cat2, RandomAccessCategory() ) )
280  nbok++;
281  nb++;
282  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
284  if ( compareType( a2ct, CirculatorType() ) )
285  nbok++;
286  nb++;
287  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
288  if ( compareCategory( a2ct, RandomAccessCategory() ) )
289  nbok++;
290  nb++;
291  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
292 
293  trace.endBlock();
294 
295  return (nbok == nb);
296 }
void beginBlock(const std::string &keyword="")
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
Trace trace
Definition: Common.h:137
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa...
double endBlock()
bool compareType(IC, T)
Aim: Define a simple default functor that just returns its argument.
bool compareCategory(IC, T)
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
std::ostream & info()
This class adapts any lvalue iterator so that operator* returns a member on the element pointed to by...