MeVisLab Toolbox Reference
mlNotify.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_NOTIFY_H
14 #define ML_NOTIFY_H
15 
17 
31 #include "mlUtilsSystem.h"
32 
33 #include <iostream>
34 #include <vector>
35 
36 ML_UTILS_START_NAMESPACE
37 
38 
39  //---------------------------------------------------------------------------------------------
41  //---------------------------------------------------------------------------------------------
43 
44  public:
45  //---------------------------------------------------------------------------------------------
48  //---------------------------------------------------------------------------------------------
49 
51  Notify();
52 
54  Notify(const Notify &notifyObj);
55 
58 
60  Notify& operator=(const Notify& notifyObj);
61 
63  void reset();
64 
66  void setEnabled(bool flag);
67 
69  bool isEnabled() const;
70 
72  void addNotifyCB(void* userData, MLNotifyCB* callback);
73 
76  void removeNotifyCB(void* userData, MLNotifyCB* callback);
77 
81 
83  size_t getNumNotifyCBs() const;
84 
86  const std::vector<void*>& getUserDataList() const;
87 
89  const std::vector<MLNotifyCB*>& getCallbackList() const;
90 
93  void notify(MLuint32 objType,
94  void* objData1=nullptr,
95  void* objData2=nullptr);
96 
98 
99  protected:
100 
101  //---------------------------------------------------------------------------------------------
104  //---------------------------------------------------------------------------------------------
105 
107  std::vector<void*> _notifyCBUserDataList;
108 
110  std::vector<MLNotifyCB*> _notifyCBList;
111 
113  bool _enabled;
114 
116  };
117 
118 
119  //---------------------------------------------------------------------------------------------
121  //---------------------------------------------------------------------------------------------
123 
124 ML_UTILS_END_NAMESPACE
125 
126 //-----------------------------------------------------------------------------------
127 // Stream output for std::ostream
128 //-----------------------------------------------------------------------------------
129 namespace std {
130 
132  ML_UTILS_EXPORT ostream& operator<<(ostream& s, const ML_UTILS_NAMESPACE::Notify &notify);
133 
134 }
135 
136 #endif // End of __mlNotify_H
Class to handle all ML Notify prints, errors and warnings.
Definition: mlNotify.h:42
void notify(MLuint32 objType, void *objData1=nullptr, void *objData2=nullptr)
Calls all registered functions and pass object type code in objType.
void addNotifyCB(void *userData, MLNotifyCB *callback)
Registers a function callback callback that is called if any error, warning, Notify or cout/cerr prin...
const std::vector< MLNotifyCB * > & getCallbackList() const
Returns const access to callback function pointers.
void setEnabled(bool flag)
Enables/disables whether notifications are to be sent; default is true;.
size_t getNumNotifyCBs() const
Returns the number of registered callbacks.
const std::vector< void * > & getUserDataList() const
Returns const access to user data pointers.
void reset()
Resets instance to construction state.
std::vector< void * > _notifyCBUserDataList
User data for registered notify callbacks.
Definition: mlNotify.h:107
void removeNotifyCB(void *userData, MLNotifyCB *callback)
Unregisters a given callback function with its user data.
~Notify()
Destructor. Destroys the Notify object after removing all registered callbacks.
bool _enabled
Flag if notify sends notifications; enabled by default.
Definition: mlNotify.h:113
Notify()
Constructor. Creates a Notify object without registered callbacks.
Notify & operator=(const Notify &notifyObj)
Assignment operator.
std::vector< MLNotifyCB * > _notifyCBList
List of function pointers for error printing.
Definition: mlNotify.h:110
bool isEnabled() const
Returns true if notifications are enabled.
void removeAllNotifyCBs()
Removes all registered callback functions.
Notify(const Notify &notifyObj)
Copy constructor.
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
unsigned int MLuint32
Definition: mlTypeDefs.h:191
void MLNotifyCB(MLuint32 objType, void *usrData, void *objectData1, void *objData2)
Function type which is registered by the Notify object; it receives a code objType of type MLNotifyCh...
Definition: mlTypeDefs.h:1307
#define ML_UTILS_EXPORT
Defines platform dependent DLL export macro for mlUtils.
Definition: mlUtilities.h:20
ML_UTILS_EXPORT Notify MLNotify
Singleton which contains all registered callback functions of the ML.