DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testOutputIteratorAdapter.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include <map>
33
#include <vector>
34
35
#include "DGtal/base/Common.h"
36
#include "DGtal/base/BasicFunctors.h"
37
#include "DGtal/base/OutputIteratorAdapter.h"
38
#include "DGtal/base/IteratorAdapter.h"
39
40
42
43
using namespace
std
;
44
using namespace
DGtal
;
45
47
// Functions for testing class OutputIteratorAdapter.
49
53
bool
testPairs
()
54
{
55
int
nb = 0;
56
int
nbok = 0;
57
58
typedef
map<string,string>
Map
;
59
typedef
pair<string,string> Pair;
60
61
//input
62
Map
m;
63
m.insert( Pair(
"Proudhon"
,
"Pierre-Joseph"
) );
64
m.insert( Pair(
"Reclus"
,
"Élisée"
) );
65
m.insert( Pair(
"Zamenhof"
,
"Ludwik Lejzer"
) );
66
67
typedef
vector<string> Vec;
68
Vec v;
69
v.push_back(
"P-J."
);
70
v.push_back(
"E."
);
71
v.push_back(
"L. L."
);
72
73
//result
74
Map
m2;
75
m2.insert( Pair(
"Proudhon"
,
"P-J."
) );
76
m2.insert( Pair(
"Reclus"
,
"E."
) );
77
m2.insert( Pair(
"Zamenhof"
,
"L. L."
) );
78
79
{
//test output iterator
80
trace
.
beginBlock
(
"OutputIteratorAdapter..."
);
81
82
typedef
OutputIteratorAdapter<Map::iterator, DGtal::functors::Pair2ndMutator<string>
,
string
> Adapter;
83
BOOST_CONCEPT_ASSERT((
boost::OutputIterator<Adapter, string>
));
84
functors::Pair2ndMutator<string>
f;
85
86
Adapter a( m.begin(), f );
87
88
copy(v.begin(), v.end(), a);
89
90
bool
flag;
91
flag = std::equal( m.begin(), m.end(), m2.begin() );
92
nbok += (flag)?1:0;
93
nb++;
94
95
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
")"
<< std::endl;
96
trace
.
endBlock
();
97
}
98
99
{
//test iterator
100
trace
.
beginBlock
(
"IteratorAdapter..."
);
101
102
functors::Pair2ndMutator<string>
f;
103
104
typedef
IteratorAdapter<Map::iterator, functors::Pair2ndMutator<string>
,
string
> Adapter;
105
BOOST_CONCEPT_ASSERT((
boost::ForwardIterator<Adapter>
));
106
107
//writing
108
Adapter a( m.begin(), f );
109
copy(v.begin(), v.end(), a);
110
bool
flag1 = std::equal( m.begin(), m.end(), m2.begin() );
111
112
//reading
113
Adapter aBegin( m.begin(), f);
114
Adapter aEnd( m.end(), f);
115
bool
flag2 = std::equal( aBegin, aEnd, v.begin() );
116
117
nbok += (flag1 && flag2)?1:0;
118
nb++;
119
120
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
")"
<< std::endl;
121
trace
.
endBlock
();
122
}
123
124
return
(nb == nbok);
125
}
126
128
// Standard services - public :
129
130
int
main
(
int
argc,
char
** argv )
131
{
132
trace
.
beginBlock
(
"Testing class OutputIteratorAdapter"
);
133
trace
.
info
() <<
"Args:"
;
134
for
(
int
i = 0; i < argc; ++i )
135
trace
.
info
() <<
" "
<< argv[ i ];
136
trace
.
info
() << endl;
137
138
bool
res =
testPairs
()
139
;
// && ... other tests
140
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
141
trace
.
endBlock
();
142
return
res ? 0 : 1;
143
}
144
// //
DGtal::IteratorAdapter
This class adapts any lvalue iterator so that operator* returns a member on the element pointed to by...
Definition
IteratorAdapter.h:78
DGtal::OutputIteratorAdapter
Aim: Adapts an output iterator i with a unary functor f, both given at construction,...
Definition
OutputIteratorAdapter.h:76
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::functors::Pair2ndMutator
Aim: Define a simple unary functor that returns a reference on the first member of a pair in order to...
Definition
BasicFunctors.h:861
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
boost::ForwardIterator
Go to http://www.sgi.com/tech/stl/ForwardIterator.html.
Definition
Boost.dox:40
boost::OutputIterator
Go to http://www.sgi.com/tech/stl/OutputIterator.html.
Definition
Boost.dox:38
Map
std::unordered_map< Cell, CubicalCellData > Map
Definition
testCubicalComplex.cpp:57
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testPairs
bool testPairs()
Definition
testOutputIteratorAdapter.cpp:53
tests
base
testOutputIteratorAdapter.cpp
Generated on
for DGtal by
1.18.0