MeVisLab Toolbox Reference
ml::ProgressLogger Class Reference

Configurable logger and progress handler class which can be used as base class for logging, interruption checks and collection of messages in a user defined stream. More...

#include <mlProgressLogger.h>

Inheritance diagram for ml::ProgressLogger:
ml::DICOMFileListFilter ml::DirectDicomImportImporterBase ml::DirectDicomImportDPLImporter ml::DirectDicomImportOtherImporter

Public Types

enum  FormatFlags {
  NoFlags = 0 , Bold = 1 , Green = 2 , Yellow = 4 ,
  Red = 8 , Blue = 16
}
 Enumerator describing some formatting flags. More...
 
typedef bool(* InterruptCheckFunc) (void *userData)
 Function type to check to for an interruption. More...
 

Public Member Functions

 ProgressLogger (std::stringstream *outputStream=nullptr, NotifyField *intCheckField=nullptr, StringField *statusField=nullptr, bool useRichTextCoding=true)
 Default and convenience constructor. More...
 
virtual ~ProgressLogger ()
 Destructor. More...
 
void setAutoNewLineTermination (bool on)
 Enable/disable automatic newline termination of logged messages. More...
 
bool isAutoNewLineTerminationOn () const
 Returns enabled/disabled automatic newline termination of logged messages. More...
 
virtual bool messageHook (const ProgressLogger &, MLMessageType, const std::string *, const std::string *, MLErrorCode *, const std::string *, unsigned int *)
 All logging methods pass their function arguments through this hook which allows to collect all messages sent to the ProgressLogger. More...
 
void logAnyMessage (std::string msg, unsigned int formatFlags=NoFlags)
 Log any string into the console. More...
 
void logFatalError (const std::string &func, MLErrorCode err, const std::string &reason)
 Logs a fatal error, an error, warning or information to the defined output stream/console. More...
 
void logError (const std::string &func, MLErrorCode err, const std::string &reason)
 See logFatalError() for details. More...
 
void logWarning (const std::string &func, MLErrorCode err, const std::string &reason)
 See logFatalError() for details. More...
 
void logInfo (const std::string &func, const std::string &reason="")
 Same as logFatalError, logError, and logWarning, but logging only information without error. More...
 
void logFullFatalError (const std::string &func, MLErrorCode err, const std::string &reason)
 Logs a fatal error, an error, warning or information to the defined output stream/console and sends the information also to the MeVisLab error handler. More...
 
void logFullError (const std::string &func, MLErrorCode err, const std::string &reason)
 See logFullFatalError() for details. More...
 
void logFullWarning (const std::string &func, MLErrorCode err, const std::string &reason)
 See logFullFatalError() for details. More...
 
void logFullInfo (const std::string &func, const std::string &reason)
 Same as logFullFatalError, logFullError, and logFullWarning, but logging only information without error. More...
 
bool getRichTextCodingFlag () const
 If enabled (the default) then outputs newlines are always converted to hyper/rich text line separators (
) and different message types get different colors; if false then
contents they are always converted to normal newline characters and rich/hypertext color statements are not inserted. More...
 
void setRichTextCodingFlag (bool useRichTextCoding)
 See getRichTextCodingFlag() for details. More...
 
bool getUpdateProgressDuringInterruptChecksFlag () const
 If enabled then progress updates are performed on each interrupt check; this is useful to enable the busy cursor together with interrupt checks. More...
 
void setUpdateProgressDuringInterruptChecksFlag (bool callUpdateProgressDuringInterruptChecks)
 See getUpdateProgressDuringInterruptChecksFlag() for details. More...
 
void setStatusUpdateTimeIntervalInSeconds (double checkIntervalInSeconds)
 Sets a time interval which is used to avoid that too many Module::updateProgress() calls are performed to update the user interfaces (which usually are very expensive); default is 1 second. More...
 
double getStatusUpdateTimeIntervalInSeconds () const
 Returns the currently set Module::updateProgress() call time interval when status fields are updated. More...
 
void setCheckTimeIntervalInSeconds (double checkIntervalInSeconds)
 Sets a time interval which is used to avoid that too many interruption checks are performed which usually are very expensive, default is 1 second. More...
 
double getCheckTimeIntervalInSeconds () const
 Returns the currently set interrupt check time interval. More...
 
void setInterruptCheckFunction (InterruptCheckFunc checkFunc, void *userData)
 Set a function which actually does a check for interrupts and its user data. More...
 
InterruptCheckFunc getInterruptCheckFunction () const
 Returns the currently set function for interrupt checks. More...
 
void * getInterruptCheckFunctionUserData () const
 Returns the currently set user data pointer for interrupt checks. More...
 
void setInterruptCheckField (NotifyField *interruptField=nullptr)
 Set a NotifyField which shall be checked for button presses which mean interruptions; ignored if nullptr. More...
 
NotifyFieldgetInterruptCheckField () const
 Return the currently set NotifyField pointer which shall be checked for button presses; default is nullptr. More...
 
void setStatusField (StringField *statusField)
 Set a StringField which always shall be updated with all logged messages; ignored if nullptr. More...
 
StringFieldgetStatusField () const
 Return the currently set StringField pointer which is updated on logged messages; default is nullptr. More...
 
virtual bool wasInterrupted ()
 If the interruption flag is already set then immediately true is returned. More...
 
virtual bool getInterruptedFlag () const
 Returns current state of interruption flag (but does not check for interruption). More...
 
virtual void setInterruptedFlag (bool wasInterrupted)
 Sets current state of interruption flag (but does not check for interruption). More...
 
virtual bool orToInterruptedFlag (bool wasInterrupted)
 Update interruption flag by ORing the passed flag to the internal flag and then returning the flag (but does not check for interruption). More...
 
virtual void updateProgressIndicator (const std::string &, float)
 Update a progress indicator which shows the message info and the percentage percState. More...
 
void setHadFlags (bool hadFlag)
 Sets all had*Flags to hadFlag. More...
 
void setFatalErrorMessagePrefix (const std::string &msg)
 Set/get prefixes for messages. More...
 
void setErrorMessagePrefix (const std::string &msg)
 
void setWarningMessagePrefix (const std::string &msg)
 
void setInfoMessagePrefix (const std::string &msg)
 
std::string getFatalErrorMessagePrefix () const
 
std::string getErrorMessagePrefix () const
 
std::string getWarningMessagePrefix () const
 
std::string getInfoMessagePrefix () const
 
bool hadFatalError () const
 Returns true if any fatal error, error, warning or info was logged; can be reset with corresponding setHad*Flag(). More...
 
bool hadError () const
 
bool hadWarning () const
 
bool hadInfo () const
 
void setHadFatalErrorFlag (bool hadFatalErrorFlag)
 Sets the state of the corresponding _had* member; used to clear recent logging states. More...
 
void setHadErrorFlag (bool hadErrorFlag)
 
void setHadWarningFlag (bool hadWarningFlag)
 
void setHadInfoFlag (bool hadInfoFlag)
 

Static Public Member Functions

static bool isPressedField (NotifyField *fieldToCheck)
 Convenience implementation of an interrupt check function if user of this class does not want to implement his own check callback but only wants to check a NotifyField for presses. More...
 

Protected Member Functions

std::string _doAutoNewLineTerminate (const std::string &msg) const
 Helper to terminate msg with newline at end according. More...
 
virtual bool _isStopPressed () const
 Checks for interruption with currently set _checkFunc or _interruptCheckField or returns false if not available. More...
 
virtual void _updateConsole (bool=true)
 Updates the output console if there is any. More...
 

Static Protected Member Functions

static void _updateProgressIndicatorCB (void *userData, const std::string &info, float state)
 Static callback version to update a progress indicator about the current import state. More...
 

Detailed Description

Configurable logger and progress handler class which can be used as base class for logging, interruption checks and collection of messages in a user defined stream.

Definition at line 32 of file mlProgressLogger.h.

Member Typedef Documentation

◆ InterruptCheckFunc

typedef bool(* ml::ProgressLogger::InterruptCheckFunc) (void *userData)

Function type to check to for an interruption.

Definition at line 37 of file mlProgressLogger.h.

Member Enumeration Documentation

◆ FormatFlags

Enumerator describing some formatting flags.

Enumerator
NoFlags 
Bold 
Green 
Yellow 
Red 
Blue 

Definition at line 40 of file mlProgressLogger.h.

Constructor & Destructor Documentation

◆ ProgressLogger()

ml::ProgressLogger::ProgressLogger ( std::stringstream *  outputStream = nullptr,
NotifyField intCheckField = nullptr,
StringField statusField = nullptr,
bool  useRichTextCoding = true 
)

Default and convenience constructor.

Parameters
outputStreamIf non-nullptr (default is nullptr) this is the stream into which all messages are posted which are sent to the logger instance.
intCheckFieldIf non-nullptr (default is nullptr) then this NotifyField is checked for presses for interrupt handling when the logger is asked for this and the getCheckTimeIntervalInSeconds() is exceeded.
statusFieldIf non-nullptr (default is nullptr) then this is the StringField which is set to the current output message received by the logger. If getStatusUpdateTimeIntervalInSeconds() are exceeded Module::updateProgress() is called to refresh the GUI.
useRichTextCodingEnables coding out outputs as rich text if enabled (the default) otherwise it is disabled; see setRichTextCodingFlag() for more information.

◆ ~ProgressLogger()

virtual ml::ProgressLogger::~ProgressLogger ( )
virtual

Destructor.

Member Function Documentation

◆ _doAutoNewLineTerminate()

std::string ml::ProgressLogger::_doAutoNewLineTerminate ( const std::string &  msg) const
protected

Helper to terminate msg with newline at end according.

◆ _isStopPressed()

virtual bool ml::ProgressLogger::_isStopPressed ( ) const
protectedvirtual

Checks for interruption with currently set _checkFunc or _interruptCheckField or returns false if not available.

◆ _updateConsole()

virtual void ml::ProgressLogger::_updateConsole ( bool  = true)
inlineprotectedvirtual

Updates the output console if there is any.

If fullUpdate is true the the console is surely updated, if false then a time saving sloppy update is made. Does nothing, recommended to be reimplemented by subclasses.

Reimplemented in ml::DirectDicomImportImporterBase.

Definition at line 251 of file mlProgressLogger.h.

◆ _updateProgressIndicatorCB()

static void ml::ProgressLogger::_updateProgressIndicatorCB ( void *  userData,
const std::string &  info,
float  state 
)
staticprotected

Static callback version to update a progress indicator about the current import state.

This is usually used by derived classes to call the overridden updateProgressIndicator method conveniently.

◆ getCheckTimeIntervalInSeconds()

double ml::ProgressLogger::getCheckTimeIntervalInSeconds ( ) const

Returns the currently set interrupt check time interval.

◆ getErrorMessagePrefix()

std::string ml::ProgressLogger::getErrorMessagePrefix ( ) const
inline

Definition at line 212 of file mlProgressLogger.h.

◆ getFatalErrorMessagePrefix()

std::string ml::ProgressLogger::getFatalErrorMessagePrefix ( ) const
inline

Definition at line 211 of file mlProgressLogger.h.

◆ getInfoMessagePrefix()

std::string ml::ProgressLogger::getInfoMessagePrefix ( ) const
inline

Definition at line 214 of file mlProgressLogger.h.

◆ getInterruptCheckField()

NotifyField* ml::ProgressLogger::getInterruptCheckField ( ) const

Return the currently set NotifyField pointer which shall be checked for button presses; default is nullptr.

◆ getInterruptCheckFunction()

InterruptCheckFunc ml::ProgressLogger::getInterruptCheckFunction ( ) const

Returns the currently set function for interrupt checks.

◆ getInterruptCheckFunctionUserData()

void* ml::ProgressLogger::getInterruptCheckFunctionUserData ( ) const

Returns the currently set user data pointer for interrupt checks.

◆ getInterruptedFlag()

virtual bool ml::ProgressLogger::getInterruptedFlag ( ) const
virtual

Returns current state of interruption flag (but does not check for interruption).

◆ getRichTextCodingFlag()

bool ml::ProgressLogger::getRichTextCodingFlag ( ) const

If enabled (the default) then outputs newlines are always converted to hyper/rich text line separators (
) and different message types get different colors; if false then
contents they are always converted to normal newline characters and rich/hypertext color statements are not inserted.

◆ getStatusField()

StringField* ml::ProgressLogger::getStatusField ( ) const

Return the currently set StringField pointer which is updated on logged messages; default is nullptr.

◆ getStatusUpdateTimeIntervalInSeconds()

double ml::ProgressLogger::getStatusUpdateTimeIntervalInSeconds ( ) const

Returns the currently set Module::updateProgress() call time interval when status fields are updated.

◆ getUpdateProgressDuringInterruptChecksFlag()

bool ml::ProgressLogger::getUpdateProgressDuringInterruptChecksFlag ( ) const

If enabled then progress updates are performed on each interrupt check; this is useful to enable the busy cursor together with interrupt checks.

If disabled then the busy cursor must be controlled by the application itself.

◆ getWarningMessagePrefix()

std::string ml::ProgressLogger::getWarningMessagePrefix ( ) const
inline

Definition at line 213 of file mlProgressLogger.h.

◆ hadError()

bool ml::ProgressLogger::hadError ( ) const

◆ hadFatalError()

bool ml::ProgressLogger::hadFatalError ( ) const

Returns true if any fatal error, error, warning or info was logged; can be reset with corresponding setHad*Flag().

◆ hadInfo()

bool ml::ProgressLogger::hadInfo ( ) const

◆ hadWarning()

bool ml::ProgressLogger::hadWarning ( ) const

◆ isAutoNewLineTerminationOn()

bool ml::ProgressLogger::isAutoNewLineTerminationOn ( ) const

Returns enabled/disabled automatic newline termination of logged messages.

◆ isPressedField()

static bool ml::ProgressLogger::isPressedField ( NotifyField fieldToCheck)
static

Convenience implementation of an interrupt check function if user of this class does not want to implement his own check callback but only wants to check a NotifyField for presses.

◆ logAnyMessage()

void ml::ProgressLogger::logAnyMessage ( std::string  msg,
unsigned int  formatFlags = NoFlags 
)

Log any string into the console.

◆ logError()

void ml::ProgressLogger::logError ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

See logFatalError() for details.

◆ logFatalError()

void ml::ProgressLogger::logFatalError ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

Logs a fatal error, an error, warning or information to the defined output stream/console.

Parameters
funcString name of class and function.
errML Error code describing the nature of the problem or message.
reasonString description of the handling and the cause of the message/problem.

◆ logFullError()

void ml::ProgressLogger::logFullError ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

See logFullFatalError() for details.

◆ logFullFatalError()

void ml::ProgressLogger::logFullFatalError ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

Logs a fatal error, an error, warning or information to the defined output stream/console and sends the information also to the MeVisLab error handler.

Parameters
funcString name of class and function.
errML Error code describing the nature of the problem or message.
reasonString description of the handling and the cause of the message/problem.

◆ logFullInfo()

void ml::ProgressLogger::logFullInfo ( const std::string &  func,
const std::string &  reason 
)

Same as logFullFatalError, logFullError, and logFullWarning, but logging only information without error.

Parameters
funcString name of class and function.
reasonString description of the handling and the cause of the message/problem.

◆ logFullWarning()

void ml::ProgressLogger::logFullWarning ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

See logFullFatalError() for details.

◆ logInfo()

void ml::ProgressLogger::logInfo ( const std::string &  func,
const std::string &  reason = "" 
)

Same as logFatalError, logError, and logWarning, but logging only information without error.

Parameters
funcString name of class and function.
reasonString description of the handling and the cause of the message/problem.

◆ logWarning()

void ml::ProgressLogger::logWarning ( const std::string &  func,
MLErrorCode  err,
const std::string &  reason 
)

See logFatalError() for details.

◆ messageHook()

virtual bool ml::ProgressLogger::messageHook ( const ProgressLogger ,
MLMessageType  ,
const std::string *  ,
const std::string *  ,
MLErrorCode ,
const std::string *  ,
unsigned int *   
)
inlinevirtual

All logging methods pass their function arguments through this hook which allows to collect all messages sent to the ProgressLogger.

All pointer arguments will be only valid if they are available in the actually called method, otherwise they will be nullptr. If this message returns true the message will be formatted and logged according to the current instance state, if false then it will completely be skipped and not further handled nor logged. The default implementation is empty and just returning true.

Definition at line 84 of file mlProgressLogger.h.

◆ orToInterruptedFlag()

virtual bool ml::ProgressLogger::orToInterruptedFlag ( bool  wasInterrupted)
virtual

Update interruption flag by ORing the passed flag to the internal flag and then returning the flag (but does not check for interruption).

◆ setAutoNewLineTermination()

void ml::ProgressLogger::setAutoNewLineTermination ( bool  on)

Enable/disable automatic newline termination of logged messages.

◆ setCheckTimeIntervalInSeconds()

void ml::ProgressLogger::setCheckTimeIntervalInSeconds ( double  checkIntervalInSeconds)

Sets a time interval which is used to avoid that too many interruption checks are performed which usually are very expensive, default is 1 second.

◆ setErrorMessagePrefix()

void ml::ProgressLogger::setErrorMessagePrefix ( const std::string &  msg)
inline

Definition at line 207 of file mlProgressLogger.h.

◆ setFatalErrorMessagePrefix()

void ml::ProgressLogger::setFatalErrorMessagePrefix ( const std::string &  msg)
inline

Set/get prefixes for messages.

Definition at line 206 of file mlProgressLogger.h.

◆ setHadErrorFlag()

void ml::ProgressLogger::setHadErrorFlag ( bool  hadErrorFlag)

◆ setHadFatalErrorFlag()

void ml::ProgressLogger::setHadFatalErrorFlag ( bool  hadFatalErrorFlag)

Sets the state of the corresponding _had* member; used to clear recent logging states.

◆ setHadFlags()

void ml::ProgressLogger::setHadFlags ( bool  hadFlag)

Sets all had*Flags to hadFlag.

◆ setHadInfoFlag()

void ml::ProgressLogger::setHadInfoFlag ( bool  hadInfoFlag)

◆ setHadWarningFlag()

void ml::ProgressLogger::setHadWarningFlag ( bool  hadWarningFlag)

◆ setInfoMessagePrefix()

void ml::ProgressLogger::setInfoMessagePrefix ( const std::string &  msg)
inline

Definition at line 209 of file mlProgressLogger.h.

◆ setInterruptCheckField()

void ml::ProgressLogger::setInterruptCheckField ( NotifyField interruptField = nullptr)

Set a NotifyField which shall be checked for button presses which mean interruptions; ignored if nullptr.

◆ setInterruptCheckFunction()

void ml::ProgressLogger::setInterruptCheckFunction ( InterruptCheckFunc  checkFunc,
void *  userData 
)

Set a function which actually does a check for interrupts and its user data.

Can be reset with nullptr in both arguments to have no function.

◆ setInterruptedFlag()

virtual void ml::ProgressLogger::setInterruptedFlag ( bool  wasInterrupted)
virtual

Sets current state of interruption flag (but does not check for interruption).

◆ setRichTextCodingFlag()

void ml::ProgressLogger::setRichTextCodingFlag ( bool  useRichTextCoding)

See getRichTextCodingFlag() for details.

◆ setStatusField()

void ml::ProgressLogger::setStatusField ( StringField statusField)

Set a StringField which always shall be updated with all logged messages; ignored if nullptr.

◆ setStatusUpdateTimeIntervalInSeconds()

void ml::ProgressLogger::setStatusUpdateTimeIntervalInSeconds ( double  checkIntervalInSeconds)

Sets a time interval which is used to avoid that too many Module::updateProgress() calls are performed to update the user interfaces (which usually are very expensive); default is 1 second.

◆ setUpdateProgressDuringInterruptChecksFlag()

void ml::ProgressLogger::setUpdateProgressDuringInterruptChecksFlag ( bool  callUpdateProgressDuringInterruptChecks)

◆ setWarningMessagePrefix()

void ml::ProgressLogger::setWarningMessagePrefix ( const std::string &  msg)
inline

Definition at line 208 of file mlProgressLogger.h.

◆ updateProgressIndicator()

virtual void ml::ProgressLogger::updateProgressIndicator ( const std::string &  ,
float   
)
inlinevirtual

Update a progress indicator which shows the message info and the percentage percState.

Does nothing, recommended to be reimplemented by subclasses.

Reimplemented in ml::DICOMFileListFilter, and ml::DirectDicomImportImporterBase.

Definition at line 203 of file mlProgressLogger.h.

◆ wasInterrupted()

virtual bool ml::ProgressLogger::wasInterrupted ( )
virtual

If the interruption flag is already set then immediately true is returned.

If not then check for interruption if passed time interval is exceeded (see setCheckTimeIntervalInSeconds to avoid that too many expensive checks are performed), ORs the state to the internal interruption state and returns the state. For interruption checks the method _isStopPressed() is called which always returns false and which therefore should be reimplemented by subclasses.


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