MeVisLab Toolbox Reference
mlProgressLogger.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code
3//----------------------------------------------------------------------------------
7
12//----------------------------------------------------------------------------------
13#pragma once
14
15// Local includes
17#include "mlModuleIncludes.h"
18#include "mlTimeCounter.h"
19#include <FMEThirdPartyWarningsDisable.h>
20#include <string>
21#include <sstream>
22#include <FMEThirdPartyWarningsRestore.h>
23
25
26
27//----------------------------------------------------------------------------------
31//----------------------------------------------------------------------------------
33
34 public:
35
37 typedef bool (*InterruptCheckFunc)(void *userData);
38
41 NoFlags = 0,
42 Bold = 1,
43 Green = 2,
44 Yellow = 4,
45 Red = 8,
46 Blue = 16
47 };
48
62 ProgressLogger(std::stringstream *outputStream = nullptr,
63 NotifyField *intCheckField = nullptr,
64 StringField *statusField = nullptr,
65 bool useRichTextCoding = true);
66
68 virtual ~ProgressLogger();
69
72
75
84 virtual bool messageHook(const ProgressLogger & /*this*/,
85 MLMessageType /*msgType*/,
86 const std::string * /*msg*/,
87 const std::string * /*func*/,
88 MLErrorCode * /*err*/,
89 const std::string * /*reason*/,
90 unsigned int * /*formatFlags*/){ return true; }
91
93 void logAnyMessage(std::string msg, unsigned int formatFlags=NoFlags);
94
99 void logFatalError (const std::string &func, MLErrorCode err, const std::string &reason);
101 void logError (const std::string &func, MLErrorCode err, const std::string &reason);
103 void logWarning (const std::string &func, MLErrorCode err, const std::string &reason);
104
108 void logInfo (const std::string &func, const std::string &reason="");
109
115 void logFullFatalError (const std::string &func, MLErrorCode err, const std::string &reason);
117 void logFullError (const std::string &func, MLErrorCode err, const std::string &reason);
119 void logFullWarning (const std::string &func, MLErrorCode err, const std::string &reason);
120
125 void logFullInfo (const std::string &func, const std::string &reason);
126
135
142
147
151
155
158
161 void setInterruptCheckFunction(InterruptCheckFunc checkFunc, void *userData);
162
164 InterruptCheckFunc getInterruptCheckFunction() const;
165
168
172
176
179
183
189 virtual bool wasInterrupted();
190
192 virtual bool getInterruptedFlag() const;
193
195 virtual void setInterruptedFlag(bool wasInterrupted);
196
199 virtual bool orToInterruptedFlag(bool wasInterrupted);
200
203 virtual void updateProgressIndicator(const std::string &/*info*/, float /*percState*/){};
204
206 inline void setFatalErrorMessagePrefix (const std::string &msg){ _fatalErrorPrefix = msg; }
207 inline void setErrorMessagePrefix (const std::string &msg){ _errorPrefix = msg; }
208 inline void setWarningMessagePrefix (const std::string &msg){ _warningPrefix = msg; }
209 inline void setInfoMessagePrefix (const std::string &msg){ _infoPrefix = msg; }
210
211 inline std::string getFatalErrorMessagePrefix () const { return _fatalErrorPrefix; }
212 inline std::string getErrorMessagePrefix () const { return _errorPrefix ; }
213 inline std::string getWarningMessagePrefix () const { return _warningPrefix ; }
214 inline std::string getInfoMessagePrefix () const { return _infoPrefix ; }
216
218 bool hadFatalError() const;
219 bool hadError() const;
220 bool hadWarning() const;
221 bool hadInfo() const;
223
226
233
238
239 protected:
240
242 std::string _doAutoNewLineTerminate(const std::string &msg) const;
243
246 virtual bool _isStopPressed() const;
247
251 virtual void _updateConsole(bool /*fullUpdate*/=true){}
252
256 static void _updateProgressIndicatorCB(void *userData,
257 const std::string &info,
258 float state);
259
260 private:
261
267 void _sendMessage(std::string stringToSend);
268
270 bool _autoNewLineTerminate;
271
273 std::stringstream *_outputStream;
274
276 NotifyField *_interruptCheckField;
277
279 StringField *_statusField;
280
283 bool _useRichTextCodingFlag;
284
288 bool _updateProgressDuringInterruptChecksFlag;
289
291 bool _wasInterrupted;
292
294 std::string _fatalErrorPrefix;
295
297 std::string _errorPrefix;
298
300 std::string _warningPrefix;
301
303 std::string _infoPrefix;
304
306 bool _hadFatalError;
307
309 bool _hadError;
310
312 bool _hadWarning;
313
315 bool _hadInfo;
316
318 TimeCounter _stopTestTimeCounter;
319
321 TimeCounter _statusUpdateTimeCounter;
322
324 double _stopTestTimeIntervalInSeconds;
325
327 double _checkStatusUpdateTimeIntervalInSeconds;
328
330 InterruptCheckFunc _checkFunc;
331
333 void *_checkFuncUserData;
334};
335
Project global and OS specific declarations.
#define MLRELEASE_TOOLS_EXPORT
DLL export macro definition.
Field without value for notifications.
Definition mlFields.h:659
Configurable logger and progress handler class which can be used as base class for logging,...
double getStatusUpdateTimeIntervalInSeconds() const
Returns the currently set Module::updateProgress() call time interval when status fields are updated.
void setInterruptCheckField(NotifyField *interruptField=nullptr)
Set a NotifyField which shall be checked for button presses which mean interruptions; ignored if null...
virtual bool getInterruptedFlag() const
Returns current state of interruption flag (but does not check for interruption).
void logFullInfo(const std::string &func, const std::string &reason)
Same as logFullFatalError, logFullError, and logFullWarning, but logging only information without err...
std::string getWarningMessagePrefix() const
FormatFlags
Enumerator describing some formatting flags.
void setInfoMessagePrefix(const std::string &msg)
void logInfo(const std::string &func, const std::string &reason="")
Same as logFatalError, logError, and logWarning, but logging only information without error.
bool getRichTextCodingFlag() const
If enabled (the default) then outputs newlines are always converted to hyper/rich text line separator...
void logFullError(const std::string &func, MLErrorCode err, const std::string &reason)
See logFullFatalError() for details.
StringField * getStatusField() const
Return the currently set StringField pointer which is updated on logged messages; default is nullptr.
virtual bool _isStopPressed() const
Checks for interruption with currently set _checkFunc or _interruptCheckField or returns false if not...
void logWarning(const std::string &func, MLErrorCode err, const std::string &reason)
See logFatalError() for details.
void logError(const std::string &func, MLErrorCode err, const std::string &reason)
See logFatalError() for details.
bool hadFatalError() const
Returns true if any fatal error, error, warning or info was logged; can be reset with corresponding s...
void logAnyMessage(std::string msg, unsigned int formatFlags=NoFlags)
Log any string into the console.
static void _updateProgressIndicatorCB(void *userData, const std::string &info, float state)
Static callback version to update a progress indicator about the current import state.
void logFullWarning(const std::string &func, MLErrorCode err, const std::string &reason)
See logFullFatalError() for details.
void setAutoNewLineTermination(bool on)
Enable/disable automatic newline termination of logged messages.
void setErrorMessagePrefix(const std::string &msg)
virtual void updateProgressIndicator(const std::string &, float)
Update a progress indicator which shows the message info and the percentage percState.
void setFatalErrorMessagePrefix(const std::string &msg)
Set/get prefixes for messages.
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 t...
double getCheckTimeIntervalInSeconds() const
Returns the currently set interrupt check time interval.
virtual ~ProgressLogger()
Destructor.
void setHadWarningFlag(bool hadWarningFlag)
void setHadFlags(bool hadFlag)
Sets all had*Flags to hadFlag.
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.
std::string getErrorMessagePrefix() const
void setCheckTimeIntervalInSeconds(double checkIntervalInSeconds)
Sets a time interval which is used to avoid that too many interruption checks are performed which usu...
void setStatusUpdateTimeIntervalInSeconds(double checkIntervalInSeconds)
Sets a time interval which is used to avoid that too many Module::updateProgress() calls are performe...
std::string getInfoMessagePrefix() const
bool hadInfo() const
InterruptCheckFunc getInterruptCheckFunction() const
Returns the currently set function for interrupt checks.
bool hadWarning() const
void setRichTextCodingFlag(bool useRichTextCoding)
See getRichTextCodingFlag() for details.
virtual void setInterruptedFlag(bool wasInterrupted)
Sets current state of interruption flag (but does not check for interruption).
bool getUpdateProgressDuringInterruptChecksFlag() const
If enabled then progress updates are performed on each interrupt check; this is useful to enable the ...
virtual void _updateConsole(bool=true)
Updates the output console if there is any.
std::string getFatalErrorMessagePrefix() const
NotifyField * getInterruptCheckField() const
Return the currently set NotifyField pointer which shall be checked for button presses; default is nu...
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 messa...
std::string _doAutoNewLineTerminate(const std::string &msg) const
Helper to terminate msg with newline at end according.
void setWarningMessagePrefix(const std::string &msg)
bool isAutoNewLineTerminationOn() const
Returns enabled/disabled automatic newline termination of logged messages.
virtual bool orToInterruptedFlag(bool wasInterrupted)
Update interruption flag by ORing the passed flag to the internal flag and then returning the flag (b...
virtual bool wasInterrupted()
If the interruption flag is already set then immediately true is returned.
void setHadErrorFlag(bool hadErrorFlag)
void setInterruptCheckFunction(InterruptCheckFunc checkFunc, void *userData)
Set a function which actually does a check for interrupts and its user data.
ProgressLogger(std::stringstream *outputStream=nullptr, NotifyField *intCheckField=nullptr, StringField *statusField=nullptr, bool useRichTextCoding=true)
Default and convenience constructor.
bool hadError() const
void setHadInfoFlag(bool hadInfoFlag)
void setUpdateProgressDuringInterruptChecksFlag(bool callUpdateProgressDuringInterruptChecks)
See getUpdateProgressDuringInterruptChecksFlag() for details.
static bool isPressedField(NotifyField *fieldToCheck)
Convenience implementation of an interrupt check function if user of this class does not want to impl...
void setStatusField(StringField *statusField)
Set a StringField which always shall be updated with all logged messages; ignored if nullptr.
void * getInterruptCheckFunctionUserData() const
Returns the currently set user data pointer for interrupt checks.
void setHadFatalErrorFlag(bool hadFatalErrorFlag)
Sets the state of the corresponding _had* member; used to clear recent logging states.
Field to encapsulate a string value.
Definition mlFields.h:610
Class to measure precise time intervals.
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLMessageType
Message types handled by the ErrorOutput class.
Definition mlTypeDefs.h:696