DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Trace.ih
1 
29 
30 // IMPLEMENTATION of inline methods.
32 
34 #include <cstdlib>
35 #include <string>
36 #include <ostream>
37 #include <iostream>
38 #include <stack>
40 
41 
43 // Implementation of inline methods //
44 
45 
51 inline
53  myCurrentLevel(0), myCurrentPrefix (""), myWriter(writer)
54 {
55 }
56 
63 inline
65 {
66  myWriter.outputStream() << myWriter.postfixReset();
67 }
68 
69 
74 inline
75 void
76 DGtal::Trace::selfDisplay( std::ostream & out ) const
77 {
78  out << "[Trace]";
79 }
80 
85 inline
86 bool
88 {
89  return true;
90 }
91 
97 inline
98 void
100 {
101  myCurrentLevel = 0;
102  myCurrentPrefix = "";
103  while( !myKeywordStack.empty() )
104  myKeywordStack.pop();
105  while( !myClockStack.empty() )
106  myClockStack.pop();
107 
108 }
109 
115 inline
116 void
117 DGtal::Trace::beginBlock(const std::string &keyword)
118 {
119  myWriter.outputStream()<< myCurrentPrefix
120  << myWriter.prefixEmphase()
121  << "New Block ["<<keyword << "]"
122  << myWriter.postfixReset()
123  <<std::endl;
124  myCurrentLevel++;
125  myCurrentPrefix += TRACE_PATTERN;
126  myKeywordStack.push(keyword);
127 
128  //Block timer start
129  Clock *c = new(Clock);
130  c->startClock();
131  myClockStack.push(c);
132 }
133 
141 inline long
143 {
144  long tick;
145  Clock *localClock;
146 
147  ASSERT (myCurrentLevel >0);
148 
149  localClock = myClockStack.top();
150  tick = localClock->stopClock();
151 
152  myCurrentLevel--;
153  myCurrentPrefix = "";
154  for(unsigned int i = 0; i < myCurrentLevel; i++)
155  myCurrentPrefix += TRACE_PATTERN;
156 
157  myWriter.outputStream() << myCurrentPrefix
158  << myWriter.prefixEmphase()
159  << "EndBlock [" << myKeywordStack.top()
160  << "] (" << tick<<" ms)"
161  << myWriter.postfixReset()<< std::endl;
162  myKeywordStack.pop();
163  myClockStack.pop();
164  delete localClock;
165  return tick;
166 }
167 
173 inline std::ostream &
175 {
176  myWriter.outputStream() << myCurrentPrefix << myWriter.prefixWarning();
177  return myWriter.outputStream();
178 }
179 
180 
186 inline std::ostream &
188 {
189  myWriter.outputStream() << myCurrentPrefix << myWriter.prefixError();
190  return myWriter.outputStream();
191 }
192 
193 
199 inline std::ostream &
201 {
202  myWriter.outputStream() << myCurrentPrefix << myWriter.prefixEmphase();
203  return myWriter.outputStream();
204 }
205 
210 inline std::ostream &
212 {
213  myWriter.outputStream() << myCurrentPrefix << myWriter.prefixInfo();
214  return myWriter.outputStream();
215 }
216 
217 inline void
218 DGtal::Trace::progressBar(const double currentValue, const double maximumValue) const
219 {
220  // how wide you want the progress meter to be
221  int totaldotz=60;
222  double fraction = currentValue /maximumValue;
223 
224  // part of the progressmeter that's already "full"
225  int dotz = (int)floor(fraction * totaldotz);
226 
227  // create the "meter"
228  int ii=0;
229  myWriter.outputStream() << myCurrentPrefix<<"[";
230  // part that's full already
231  for ( ; ii < dotz;ii++)
232  {
233  myWriter.outputStream()<< "#";
234  }
235  // remaining part (spaces)
236  for ( ; ii < totaldotz;ii++)
237  {
238  myWriter.outputStream()<< " ";
239  }
240  // and back to line begin - do not forget the fflush to avoid output buffering problems!
241  myWriter.outputStream()<< "] "<< (int)(fraction*100)<<"/100\r";
242  myWriter.outputStream().flush();
243 }
244 
245 
246 
248 // Implementation of inline functions and external operators //
249 
256 inline
257 std::ostream&
258 DGtal::operator<<( std::ostream & out,
259  const Trace & object )
260 {
261  object.selfDisplay( out );
262  return out;
263 }
264 
265 // //
267 
268