DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Private Member Functions | Private Attributes
DGtal::Trace Class Reference

#include <Trace.h>

Collaboration diagram for DGtal::Trace:
Collaboration graph
[legend]

Public Member Functions

 Trace (TraceWriter &writer)
 ~Trace ()
void reset ()
void beginBlock (const std::string &keyword="")
long endBlock ()
std::ostream & info () const
std::ostream & warning () const
std::ostream & error () const
std::ostream & emphase () const
void progressBar (const double currentValue, const double maximalValue) const
void selfDisplay (std::ostream &out) const
bool isValid () const

Private Member Functions

 Trace (const Trace &other)
Traceoperator= (const Trace &other)

Private Attributes

unsigned int myCurrentLevel
std::string myCurrentPrefix
std::stack< std::string > myKeywordStack
TraceWritermyWriter
std::stack< Clock * > myClockStack

Detailed Description

implementation of basic methods to trace out messages with indentation levels.

Description of class 'Trace'

Aim: Trace objects use a TraceWriter to switch between terminal and file outputs. Methods postfixed with "Debug" contain no code if the compilation flag DEBUG is not set.

For usage examples, see the testtrace.cpp file.

See also:
testTrace.cpp
Todo:
Create a default constructor on TraceWriterTerm(std::cerr)

Definition at line 74 of file Trace.h.


Constructor & Destructor Documentation

DGtal::Trace::Trace ( DGtal::TraceWriter writer)
inline

Constructor.

Parameters:
writerthe output writer that will receive the traces.

Constructor.

Parameters:
outputStreamthe output stream that will receive the traces.

Definition at line 52 of file Trace.ih.

:
{
}
DGtal::Trace::~Trace ( )
inline

Destructor.

Destructor.

We send a last postfixReset to prevent bugs in some TraceWriterTerm terminals.

Definition at line 64 of file Trace.ih.

DGtal::Trace::Trace ( const Trace other)
private

Copy constructor.

Parameters:
otherthe object to clone. Forbidden by default.

Member Function Documentation

void DGtal::Trace::beginBlock ( const std::string &  keyword = "")
inline
std::ostream & DGtal::Trace::emphase ( ) const
inline

Create a string with an indentation prefix for an emphased trace.

Returns:
the cerr output stream with the prefix

Create a string with an indentation prefix for an emphased trace.

Returns:
the output stream with the prefix

Definition at line 200 of file Trace.ih.

long DGtal::Trace::endBlock ( )
inline

Leave a current block, decrease the indentation level and display the associate keyword

Returns:
the ellapsed time in the block in milliseconds (Class Clock).

Leave a current block, decrease the indentation level and display the associate keyword with ellapsed time in ms.

Returns:
the ellapsed time in the block in milliseconds (Class Clock).
Examples:
geometry/surfaces/greedy-plane-segmentation-ex2.cpp, geometry/surfaces/greedy-plane-segmentation.cpp, io/boards/dgtalBoard2D-1-points.cpp, io/boards/dgtalBoard2D-2-sets.cpp, io/boards/dgtalBoard2D-3-custom-classes.cpp, io/boards/dgtalBoard2D-3-custom-points.cpp, io/boards/dgtalBoard2D-4-colormaps.cpp, logoDGtal.cpp, topology/frontierAndBoundary.cpp, topology/homotopicThinning3D.cpp, topology/volScanBoundary.cpp, topology/volToOFF.cpp, and topology/volTrackBoundary.cpp.

Definition at line 142 of file Trace.ih.

References DGtal::Clock::stopClock().

Referenced by DGtal::DistanceTransformation< TSpace, TPointPredicate, p, IntegerLong >::computeFirstStep(), DGtal::VoronoiMap< TSpace, TPointPredicate, p >::computeOtherSteps(), DGtal::DistanceTransformation< TSpace, TPointPredicate, p, IntegerLong >::computeOtherSteps(), DGtal::ReverseDistanceTransformation< Image, p, IntegerShort >::computeSteps(), DGtal::testImplicitDigitalSurface(), and DGtal::testLightImplicitDigitalSurface().

{
long tick;
Clock *localClock;
ASSERT (myCurrentLevel >0);
localClock = myClockStack.top();
tick = localClock->stopClock();
for(unsigned int i = 0; i < myCurrentLevel; i++)
myCurrentPrefix += TRACE_PATTERN;
<< "EndBlock [" << myKeywordStack.top()
<< "] (" << tick<<" ms)"
<< myWriter.postfixReset()<< std::endl;
myClockStack.pop();
delete localClock;
return tick;
}
std::ostream & DGtal::Trace::error ( ) const
inline
std::ostream & DGtal::Trace::info ( ) const
inline
bool DGtal::Trace::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 87 of file Trace.ih.

{
return true;
}
Trace& DGtal::Trace::operator= ( const Trace other)
private

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'. Forbidden by default.
void DGtal::Trace::progressBar ( const double  currentValue,
const double  maximalValue 
) const
inline

Display a progress bar in the terminal.

Parameters:
currentValuecurrent step of the progress bar
maximalValueexpected maximal value
Examples:
geometry/surfaces/greedy-plane-segmentation-ex2.cpp, and geometry/surfaces/greedy-plane-segmentation.cpp.

Definition at line 218 of file Trace.ih.

{
// how wide you want the progress meter to be
int totaldotz=60;
double fraction = currentValue /maximumValue;
// part of the progressmeter that's already "full"
int dotz = (int)floor(fraction * totaldotz);
// create the "meter"
int ii=0;
// part that's full already
for ( ; ii < dotz;ii++)
{
}
// remaining part (spaces)
for ( ; ii < totaldotz;ii++)
{
}
// and back to line begin - do not forget the fflush to avoid output buffering problems!
myWriter.outputStream()<< "] "<< (int)(fraction*100)<<"/100\r";
}
void DGtal::Trace::reset ( )
inline

Reset all the variables of the Trace object (indentation level and keyword stack)

Reset all the variables of the Trace object (indentation level and keyword stack).

Definition at line 99 of file Trace.ih.

{
while( !myKeywordStack.empty() )
while( !myClockStack.empty() )
myClockStack.pop();
}
void DGtal::Trace::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 76 of file Trace.ih.

{
out << "[Trace]";
}
std::ostream & DGtal::Trace::warning ( ) const
inline

Field Documentation

std::stack<Clock*> DGtal::Trace::myClockStack
private

A stack to store the block clocks.

Definition at line 189 of file Trace.h.

unsigned int DGtal::Trace::myCurrentLevel
private

The indentation level.

Definition at line 178 of file Trace.h.

std::string DGtal::Trace::myCurrentPrefix
private

The indentation prefix string.

Definition at line 180 of file Trace.h.

std::stack<std::string> DGtal::Trace::myKeywordStack
private

A stack to store the block keywords.

Definition at line 183 of file Trace.h.

TraceWriter& DGtal::Trace::myWriter
private

A reference to the output writer.

Definition at line 186 of file Trace.h.


The documentation for this class was generated from the following files: