MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlErrorOutput.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_ERROR_OUTPUT_H
14#define ML_ERROR_OUTPUT_H
15
17
18#include "mlUtilsSystem.h"
19#include "mlUtilsAPI.h"
20#include "mlMutex.h"
21#include "mlTrace.h"
22
23
24//-----------------------------------------------------------------------------------
25// Forward declarations.
26//-----------------------------------------------------------------------------------
28
30class ErrorOutput;
31
33
34
38class State;
40
41
42//-----------------------------------------------------------------------------------
43// Stream output for std::ostream
44//-----------------------------------------------------------------------------------
45namespace std
46{
47
49 ML_UTILS_EXPORT ostream& operator<<(ostream& s, const ML_UTILS_NAMESPACE::ErrorOutput& errorOutput);
50} // namespace std
51
52
54
55//---------------------------------------------------------------------------------------------
57//---------------------------------------------------------------------------------------------
58class ErrorOutputInfos;
59
60//---------------------------------------------------------------------------------------------
62//---------------------------------------------------------------------------------------------
63class RuntimeType;
64
65//---------------------------------------------------------------------------------------------
67
90//---------------------------------------------------------------------------------------------
92{
93
94public:
95 //---------------------------------------------------------------------------------------------
99 //---------------------------------------------------------------------------------------------
100 typedef void ErrorOutputCB(void* usrData, const char* errStr, const ErrorOutputInfos& infos);
101
102 //---------------------------------------------------------------------------------------------
116 //---------------------------------------------------------------------------------------------
117 typedef char* DumpCB(const void* dumpObj, const RuntimeType* dumpObjRT);
118
119 //---------------------------------------------------------------------------------------------
121 //---------------------------------------------------------------------------------------------
123
124 //---------------------------------------------------------------------------------------------
126 //---------------------------------------------------------------------------------------------
128
129 //-----------------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------------
132 void reset();
133
134 //---------------------------------------------------------------------------------------------
137 //---------------------------------------------------------------------------------------------
143 void init();
144
147 void destroy();
149
150
151 //---------------------------------------------------------------------------------------------
157 //---------------------------------------------------------------------------------------------
158
162
166
167 //---------------------------------------------------------------------------------------------
170 //---------------------------------------------------------------------------------------------
176 void setMessageFilter(MLuint32 messageType);
177
182
183
184 //-----------------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------------
191 void setDumpCB(DumpCB* dumpCB);
192
194 DumpCB* getDumpCB() const;
196
197
198 //---------------------------------------------------------------------------------------------
206 //---------------------------------------------------------------------------------------------
208 void setFullDebuggingOn(bool on);
209
211 bool isFullDebuggingOn() const;
213
214
215 //---------------------------------------------------------------------------------------------
218 //---------------------------------------------------------------------------------------------
224 void addErrorOutputCB(void* userData, ErrorOutputCB* callback);
225
228 void removeErrorOutputCB(void* userData, ErrorOutputCB* callback);
229
233 bool hasErrorOutputCB(void* userData, ErrorOutputCB* callback) const;
234
239
241 size_t getNumOutputCBs() const
242 {
243 return _errorOutputCBList.size();
244 }
246
247
248 //---------------------------------------------------------------------------------------------
251 //---------------------------------------------------------------------------------------------
253 void addDebugEnvName(const std::string& envName);
254
256 void removeDebugEnvName(const std::string& envName);
257
259 bool hasDebugEnvName(const std::string& envName) const;
260
262 const std::vector<std::string>& getDebugEnvNames() const;
263
267
269 size_t getNumDebugEnvNames() const;
271
272 //---------------------------------------------------------------------------------------------
275 //---------------------------------------------------------------------------------------------
276
279 {
280 _outputMessagesInVisualStudio = flag;
281 }
282
285 {
286 return _outputMessagesInVisualStudio;
287 }
288
290
291
292 //---------------------------------------------------------------------------------------------
295 //---------------------------------------------------------------------------------------------
298 {
299 return _sendToCout;
300 }
301
304 void sendMessagesToCout(bool on);
305
308 {
309 return _sendToCerr;
310 }
311
314 void sendMessagesToCerr(bool on);
316
317 //---------------------------------------------------------------------------------------------
320 //---------------------------------------------------------------------------------------------
323 {
324 return _maxNumTraceListDumps;
325 }
326
329
332 {
333 return _maxNumTraceStackDumps;
334 }
335
338
342 {
343 return _traceDumpMessageBits;
344 }
345
350
351
352 // -------------------------------------------------------------------------------------------
358 // -------------------------------------------------------------------------------------------
359
383 // ErrorOutput::printAndNotify(ML_WARNING, // message type
384 // "ML_", // Library prefix
385 // "Function=", // function prefix
386 // "MyFunction", // functionName
387 // "MyFunction had an overflow", // reason
388 // "I will do nothing to handle it", // handling
389 // __FILE__, // file
390 // __LINE__); // line
391 // NULL, // no runtime object to be dumped
392 // NULL, // no runtime type of any object
393 // ML_CALCULATION_ERROR); // line
397 void printAndNotify(MLMessageType messageType, const std::string& libraryPrefix, const std::string& fPrefix,
398 const std::string& functionName, const std::string& reason, const std::string& handling = "",
399 const std::string& file = "", int line = -1, const void* dumpObj = nullptr,
400 const RuntimeType* dumpObjRT = nullptr, MLErrorCode errCode = ML_RESULT_OK) const;
401
405 void printAndNotify(MLMessageType messageType, const std::string& libraryPrefix, const std::string& fPrefix,
406 const std::string& functionName, MLErrorCode reason, const std::string& handling = "",
407 const std::string& file = "", int line = -1, const void* dumpObj = nullptr,
408 const RuntimeType* dumpObjRT = nullptr) const;
409
420 void handleDebugPrint(const std::string& envVar, const std::string& libraryPrefix, std::stringstream& reason,
421 const char* file, int line) const;
422
434 void handleDebugPrint(const std::string& envVar, const std::string& libraryPrefix, const char* reason,
435 const char* file, int line) const;
436
438
439
440protected:
442 friend class ML_NAMESPACE::State;
443
446
449
450private:
452 friend std::ostream& std::operator<<(std::ostream& s, const ErrorOutput& errorOutput);
453
455 void _init();
456
458 void _printConsole(const std::string& errStr, const ErrorOutputInfos& infos) const;
459
463 std::string getTraceDump() const;
464
468 std::streambuf* _defaultCoutBuffer;
469
473 std::streambuf* _defaultCerrBuffer;
474
476 bool _sendToCout;
477
479 bool _sendToCerr;
480
481 //---------------------------------------------------------------------------------------------
484 //---------------------------------------------------------------------------------------------
485
487 bool _isFullDebuggingOn;
488
490 MLuint32 _messageTypeBits;
491
494 DumpCB* _dumpCB;
495
496
498 MLTerminator _infoTerm;
499
501 MLTerminator _warnTerm;
502
504 MLTerminator _errorTerm;
505
508 MLTerminator _fatalTerm;
509
511 MLTerminator _debugTerm;
512
514 MLTerminator _coutTerm;
515
517 MLTerminator _cerrTerm;
518
520 MLTerminator _otherTerm;
521
524 MLGlobalTraceBufferType _maxNumTraceListDumps;
525
528 MLGlobalTraceBufferType _maxNumTraceStackDumps;
529
532 MLuint32 _traceDumpMessageBits;
533
535 std::vector<void*> _errorUserDataList;
536
538 std::vector<ErrorOutputCB*> _errorOutputCBList;
539
541 std::vector<std::string> _debugEnvStrings;
542
547 mutable RecursiveMutex _mutex;
548
550 bool _outputMessagesInVisualStudio;
551
553};
554
557
559
560#endif // End of __mlErrorOutput_H
Struct that contains all information about errors, fatal errors, warnings, information,...
Class to handle all ML debug prints, errors, warnings, and information.
void sendMessagesToCout(bool on)
If on is passed as true, the sending of a message to std::cout is enabled.
size_t getNumOutputCBs() const
Returns the number of registered callbacks.
void init()
Only to force access to instances of this class to make the objects automatically initialize during D...
ErrorOutput(const ErrorOutput &errorOutput)
Copy constructor, only to be used by state class of the ML.
void destroy()
Destroys global settings; to be called during ML or mlUtils destruction; not to be called by applicat...
void setFullDebuggingOn(bool on)
Enables/disables full debugging by passing true or false as on.
MLTerminator getTerminationType(MLMessageType level) const
Returns the way how the ML shall handle messages.
char * DumpCB(const void *dumpObj, const RuntimeType *dumpObjRT)
Definition of a callback type that can be registered at the ML C-API.
bool hasErrorOutputCB(void *userData, ErrorOutputCB *callback) const
Returns true if the output function is registered, i.e., if both parameters are identical with their ...
MLuint32 getTraceDumpMessageBits() const
Returns the bit mask describing all message types that shall lead to a trace list and trace stack dum...
void removeAllErrorOutputCBs()
Removes all registered error print functions from the list.
ErrorOutput()
Constructor.
void setOutputMessagesInVisualStudio(bool flag)
Sets whether messages should be printed in Visual Studio (turned on by default in debug mode).
~ErrorOutput()
Destructor.
void addDebugEnvName(const std::string &envName)
Adds a debug environment string whose information shall be printed.
void setMaxNumTraceListDumps(MLGlobalTraceBufferType num)
Sets the maximum number of trace list entries to be shown on fatal error outputs.
const std::vector< std::string > & getDebugEnvNames() const
Returns a list of debug environment names.
bool areMessagesSentToCout() const
Messages are only sent to std::cout if this flag is true.
bool areMessagesSentToCerr() const
Messages are only sent to std::cerr if this flag is true.
void sendMessagesToCerr(bool on)
If on is passed as true, the sending of a message to std::cerr is enabled.
void setDumpCB(DumpCB *dumpCB)
Registers a dump function dumpCB that will be called by the ML to dump object structures,...
void removeDebugEnvName(const std::string &envName)
Removes a registered debug environment string whose information shall not be printed anymore.
size_t getNumDebugEnvNames() const
Returns the number of registered debug environment names.
void setTerminationType(MLMessageType level, MLTerminator term)
Sets the way how the ML shall handle a specific message type, note that ML_ALL_MESSAGES is not a vali...
void addErrorOutputCB(void *userData, ErrorOutputCB *callback)
Registers a function called when any message is sent MLErrorOutput.
DumpCB * getDumpCB() const
Returns the currently registered dump callback. Default is NULL.
bool hasDebugEnvName(const std::string &envName) const
Returns true if the debug environment name exists.
void setMessageFilter(MLuint32 messageType)
Sets messages to be handled by MLErrorOutput as set bits in messageType.
bool shouldOutputMessagesInVisualStudio() const
Returns wheter messages should be printed in Visual Studio.
MLuint32 getMaxNumTraceStackDumps() const
Returns the maximum number of trace stack entries to be shown on fatal error outputs.
void removeErrorOutputCB(void *userData, ErrorOutputCB *callback)
Removes an error-print function from the function list if both parameters are identical with their co...
void ErrorOutputCB(void *usrData, const char *errStr, const ErrorOutputInfos &infos)
Function type that can be passed to the ErrorOutput class.
void removeAllDebugEnvNames()
Removes all registered debug environment strings from list.
MLuint32 getMessageFilter()
Returns the bit mask specifying the message filter that is composed from binary OR'd MLMessageTypes e...
void setMaxNumTraceStackDumps(MLGlobalTraceBufferType num)
Sets the maximum number of trace stack entries to be shown on fatal error outputs.
void setTraceDumpMessageBits(MLuint32 bitMask)
Sets the bit mask describing all message types that shall lead to a trace list and trace stack dump.
MLuint32 getMaxNumTraceListDumps() const
Returns the maximum number of trace list entries to be shown on fatal error outputs.
void reset()
Resets instance to construction state.
bool isFullDebuggingOn() const
Returns true if full debugging is enabled; otherwise, it returns false.
ErrorOutput & operator=(const ErrorOutput &errorOutput)
Assignment operator, only to be used by state class of the ML.
RuntimeType contains type and inheritance information of a class and a static dictionary with informa...
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
#define ML_RESULT_OK
No error. Everything seems to be okay.
Definition mlTypeDefs.h:780
void printAndNotify(MLMessageType messageType, const std::string &libraryPrefix, const std::string &fPrefix, const std::string &functionName, const std::string &reason, const std::string &handling="", const std::string &file="", int line=-1, const void *dumpObj=nullptr, const RuntimeType *dumpObjRT=nullptr, MLErrorCode errCode=ML_RESULT_OK) const
Core error printing function used by all other functions.
boost::recursive_mutex RecursiveMutex
Defines a recursive mutex.
Definition mlMutex.h:32
void handleDebugPrint(const std::string &envVar, const std::string &libraryPrefix, const char *reason, const char *file, int line) const
Function called from mlDebugPrint.
void handleDebugPrint(const std::string &envVar, const std::string &libraryPrefix, std::stringstream &reason, const char *file, int line) const
Function called from mlDebugPrint.
void printAndNotify(MLMessageType messageType, const std::string &libraryPrefix, const std::string &fPrefix, const std::string &functionName, MLErrorCode reason, const std::string &handling="", const std::string &file="", int line=-1, const void *dumpObj=nullptr, const RuntimeType *dumpObjRT=nullptr) const
Similar to the other printAndNotify() function with the difference that reason is an MLErrorCode that...
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLTerminator
Termination types for error handling.
unsigned int MLuint32
Definition mlTypeDefs.h:185
MLMessageType
Message types handled by the ErrorOutput class.
Definition mlTypeDefs.h:750
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18
ML_UTILS_EXPORT ErrorOutput MLErrorOutput
This is a singleton used for all ML Error input and output;.
MLuint16 MLGlobalTraceBufferType
The type used in the MLGlobalTraceBuffer.
Definition mlTrace.h:257
STL namespace.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator '<<' for stream output of Field objects.