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
24ML_START_NAMESPACE
25
26
27//----------------------------------------------------------------------------------
31//----------------------------------------------------------------------------------
33
34 public:
35
37 typedef bool (*InterruptCheckFunc)(void *userData);
38
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
134 void setRichTextCodingFlag(bool useRichTextCoding);
135
141 void setUpdateProgressDuringInterruptChecksFlag(bool callUpdateProgressDuringInterruptChecks);
142
146 void setStatusUpdateTimeIntervalInSeconds(double checkIntervalInSeconds);
147
151
154 void setCheckTimeIntervalInSeconds(double checkIntervalInSeconds);
155
158
161 void setInterruptCheckFunction(InterruptCheckFunc checkFunc, void *userData);
162
165
168
171 void setInterruptCheckField(NotifyField *interruptField = nullptr);
172
176
178 void setStatusField(StringField *statusField);
179
183
189 virtual bool wasInterrupted();
190
192 virtual bool getInterruptedFlag() const;
193
196
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
225 void setHadFlags(bool hadFlag);
226
228 void setHadFatalErrorFlag(bool hadFatalErrorFlag);
229 void setHadErrorFlag(bool hadErrorFlag);
230 void setHadWarningFlag(bool hadWarningFlag);
231 void setHadInfoFlag(bool hadInfoFlag);
233
237 static bool isPressedField(NotifyField *fieldToCheck);
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
336ML_END_NAMESPACE
Project global and OS specific declarations.
#define MLRELEASE_TOOLS_EXPORT
DLL export macro definition.
double getStatusUpdateTimeIntervalInSeconds() const
void setInterruptCheckField(NotifyField *interruptField=nullptr)
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)
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="")
bool getRichTextCodingFlag() const
void logFullError(const std::string &func, MLErrorCode err, const std::string &reason)
See logFullFatalError() for details.
StringField * getStatusField() const
virtual bool _isStopPressed() const
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)
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)
void setFatalErrorMessagePrefix(const std::string &msg)
Set/get prefixes for messages.
void logFullFatalError(const std::string &func, MLErrorCode err, const std::string &reason)
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)
std::string getErrorMessagePrefix() const
void setCheckTimeIntervalInSeconds(double checkIntervalInSeconds)
void setStatusUpdateTimeIntervalInSeconds(double checkIntervalInSeconds)
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.
bool(* InterruptCheckFunc)(void *userData)
Function type to check to for an interruption.
virtual void setInterruptedFlag(bool wasInterrupted)
Sets current state of interruption flag (but does not check for interruption).
bool getUpdateProgressDuringInterruptChecksFlag() const
virtual void _updateConsole(bool=true)
std::string getFatalErrorMessagePrefix() const
NotifyField * getInterruptCheckField() const
virtual bool messageHook(const ProgressLogger &, MLMessageType, const std::string *, const std::string *, MLErrorCode *, const std::string *, unsigned int *)
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)
virtual bool wasInterrupted()
void setHadErrorFlag(bool hadErrorFlag)
void setInterruptCheckFunction(InterruptCheckFunc checkFunc, void *userData)
ProgressLogger(std::stringstream *outputStream=nullptr, NotifyField *intCheckField=nullptr, StringField *statusField=nullptr, bool useRichTextCoding=true)
bool hadError() const
void setHadInfoFlag(bool hadInfoFlag)
void setUpdateProgressDuringInterruptChecksFlag(bool callUpdateProgressDuringInterruptChecks)
See getUpdateProgressDuringInterruptChecksFlag() for details.
static bool isPressedField(NotifyField *fieldToCheck)
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.
Class to measure precise time intervals.
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:715
MLMessageType
Message types handled by the ErrorOutput class.
Definition mlTypeDefs.h:695