DGtal
1.5.beta
testTrace.cpp
Go to the documentation of this file.
1
34
#include <cstdio>
35
#include <cmath>
36
#include <iostream>
37
#include <fstream>
38
39
#include "DGtal/base/Config.h"
40
#include "DGtal/base/Common.h"
41
42
43
using namespace
DGtal
;
44
using namespace
std;
45
46
47
void
testSimple
()
48
{
49
trace
.
info
()<<
"This is an Info trace"
<<endl;
50
trace
.
warning
()<<
"This is an warning trace"
<<endl;
51
trace
.
error
()<<
"This is an Error trace"
<<endl;
52
trace
.
emphase
()<<
"This is an Emphased trace"
<<endl;
53
cerr<<endl;
54
}
55
56
void
testIndent
()
57
{
58
long
tmp=0;
59
60
trace
.
info
()<<
"This is an Info trace, level 0"
<<endl;
61
trace
.
beginBlock
(
"FirstMethod"
);
62
trace
.
info
()<<
"This is an Info trace, level 1"
<<endl;
63
trace
.
info
()<<
"This is an Info trace, level 1"
<<endl;
64
trace
.
beginBlock
(
"SecondMethod"
);
65
trace
.
warning
()<<
"This is an Warning trace, level 2"
<<endl;
66
trace
.
warning
()<<
"This is an Warning trace, level 2"
<<endl;
67
trace
.
info
()<<
"This is an Info trace, level 2"
<<endl;
68
trace
.
error
()<<
"This is an Error trace, level 2 (followed by a loop)"
<<endl;
69
70
for
(
unsigned
int
i=0 ; i< 450; i++)
71
tmp = (
long
)cos((
double
)tmp+i);
72
73
trace
.
endBlock
();
74
trace
.
info
()<<
"This is an Info trace, level 1 (followed by another loop)"
<<endl;
75
76
for
(
unsigned
int
i=0 ; i< 430; i++)
77
tmp = (
long
)cos((
double
)tmp+i);
78
79
trace
.
endBlock
();
80
trace
.
info
()<<
"This is an Info trace, level 0"
<<endl<<endl;
81
}
82
88
void
testFileStream
()
89
{
90
trace
.
beginBlock
(
"testFileStream"
);
91
trace
.
info
() <<
"Checking the filestream output.. Please check the 'example.txt' file"
<<endl;
92
93
ofstream myfile;
94
myfile.open (
"example.txt"
);
95
96
TraceWriterFile
traceWriterFile(myfile);
97
Trace
t2(traceWriterFile);
98
99
t2.
info
()<<
"This is an Info trace"
<<endl;
100
t2.
warning
()<<
"This is an warning trace"
<<endl;
101
102
t2.
error
()<<
"This is an Error trace"
<<endl;
103
t2.
emphase
()<<
"This is an Emphased trace"
<<endl;
104
105
t2.
beginBlock
(
"FirstMethod"
);
106
t2.
info
()<<
"This is an Info trace, level 1"
<<endl;
107
t2.
info
()<<
"This is an Info trace, level 1"
<<endl;
108
t2.
endBlock
();
109
110
myfile.close();
111
112
trace
.
endBlock
();
113
}
114
115
void
testTimings
()
116
{
117
size_t
duration;
118
119
trace
.
beginBlock
(
"Level0"
);
120
double
tmp=1.0;
121
122
trace
.
beginBlock
(
"Level1"
);
123
trace
.
info
()<<
"..."
<<std::endl;
124
for
(
unsigned
int
i=0 ; i< 4350; i++)
125
tmp = (
long
)cos((
double
)tmp+i);
126
duration =
trace
.
endBlock
();
127
128
trace
.
beginBlock
(
"Level1B"
);
129
trace
.
info
()<<
"..."
<<std::endl;
130
for
(
unsigned
int
i=0 ; i< 4350; i++)
131
tmp = (
long
)cos((
double
)tmp+i);
132
133
trace
.
beginBlock
(
"Level2"
);
134
trace
.
info
()<<
"..."
<<std::endl;
135
for
(
unsigned
int
i=0 ; i< 4350; i++)
136
tmp = (
long
)cos((
double
)tmp+i);
137
duration +=
trace
.
endBlock
();
138
139
trace
.
beginBlock
(
"Level2B"
);
140
trace
.
info
()<<
"..."
<<std::endl;
141
for
(
unsigned
int
i=0 ; i< 4350; i++)
142
tmp = (
long
)cos((
double
)tmp+i);
143
duration +=
trace
.
endBlock
();
144
145
trace
.
beginBlock
(
"Level2C"
);
146
trace
.
info
()<<
"..."
<<std::endl;
147
for
(
unsigned
int
i=0 ; i< 4450; i++)
148
tmp = (
long
)cos((
double
)tmp+i);
149
duration +=
trace
.
endBlock
();
150
151
duration +=
trace
.
endBlock
();
152
153
trace
.
beginBlock
(
"Level1C"
);
154
trace
.
info
()<<
"..."
<<std::endl;
155
for
(
unsigned
int
i=0 ; i< 430; i++)
156
tmp = (
long
)cos((
double
)tmp+i);
157
duration +=
trace
.
endBlock
();
158
159
duration +=
trace
.
endBlock
();
160
trace
.
info
()<<
"Duration="
<<duration<<std::endl;
161
162
}
163
164
165
166
int
main
()
167
{
168
testSimple
();
169
testIndent
();
170
testFileStream
();
171
testTimings
();
172
return
0;
173
}
174
DGtal::TraceWriterFile
Definition:
TraceWriterFile.h:57
DGtal::Trace
implementation of basic methods to trace out messages with indentation levels.
Definition:
Trace.h:74
DGtal::Trace::error
std::ostream & error()
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::warning
std::ostream & warning()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::trace
Trace trace
Definition:
Common.h:153
testIndent
void testIndent()
Definition:
testTrace.cpp:56
testSimple
void testSimple()
Definition:
testTrace.cpp:47
testFileStream
void testFileStream()
Definition:
testTrace.cpp:88
main
int main()
Definition:
testTrace.cpp:166
testTimings
void testTimings()
Definition:
testTrace.cpp:115
tests
base
testTrace.cpp
Generated on Wed Nov 27 2024 16:05:29 for DGtal by
1.9.1