Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLMessageCollection.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware Inc.
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Lee Newberg, Kitware Inc.
17
18==============================================================================*/
19
20#ifndef __vtkMRMLMessageCollection_h
21#define __vtkMRMLMessageCollection_h
22
23// MRML includes
24#include "vtkMRML.h"
25
26// VTK includes
27#include <vtkCallbackCommand.h>
28#include <vtkIdTypeArray.h>
29
30// STD includes
31#include <string>
32#include <vector>
33
35
38
39#ifndef vtkWarningToMessageCollectionMacro
40# define vtkWarningToMessageCollectionMacro(messageCollection, devMsgPrefix, userMsg) vtkWarningToMessageCollectionWithObjectMacro(this, messageCollection, devMsgPrefix, userMsg)
41#endif
42
43#ifndef vtkErrorToMessageCollectionMacro
44# define vtkErrorToMessageCollectionMacro(messageCollection, devMsgPrefix, userMsg) vtkErrorToMessageCollectionWithObjectMacro(this, messageCollection, devMsgPrefix, userMsg)
45#endif
46
47#ifndef vtkWarningToMessageCollectionWithObjectMacro
48# define vtkWarningToMessageCollectionWithObjectMacro(self, messageCollection, devMsgPrefix, userMsg) \
49 { \
50 vtkOStreamWrapper::EndlType endl; \
51 vtkOStreamWrapper::UseEndl(endl); \
52 if (messageCollection) \
53 { \
54 vtkOStrStreamWrapper userMsgStream; \
55 userMsgStream << userMsg; \
56 messageCollection->AddMessage(vtkCommand::WarningEvent, userMsgStream.str()); \
57 userMsgStream.rdbuf()->freeze(0); \
58 } \
59 vtkWarningWithObjectMacro(self, << devMsgPrefix << ": " << userMsg); \
60 }
61#endif
62
63#ifndef vtkErrorToMessageCollectionWithObjectMacro
64# define vtkErrorToMessageCollectionWithObjectMacro(self, messageCollection, devMsgPrefix, userMsg) \
65 { \
66 vtkOStreamWrapper::EndlType endl; \
67 vtkOStreamWrapper::UseEndl(endl); \
68 if (messageCollection) \
69 { \
70 vtkOStrStreamWrapper userMsgStream; \
71 userMsgStream << userMsg; \
72 messageCollection->AddMessage(vtkCommand::ErrorEvent, userMsgStream.str()); \
73 userMsgStream.rdbuf()->freeze(0); \
74 } \
75 vtkErrorWithObjectMacro(self, << devMsgPrefix << ": " << userMsg); \
76 }
77#endif
79
85class VTK_MRML_EXPORT vtkMRMLMessageCollection : public vtkObject
86{
87public:
88 vtkTypeMacro(vtkMRMLMessageCollection, vtkObject);
89 void PrintSelf(ostream& os, vtkIndent indent) override;
91
93 virtual int GetNumberOfMessages() const;
94
96 virtual int GetNumberOfMessagesOfType(unsigned long messageType) const;
97
99 virtual int GetNumberOfMessagesOfType(const char* eventName) const;
100
102 virtual unsigned long GetNthMessageType(int index) const;
103
105 virtual std::string GetNthMessageText(int index) const;
106
110 virtual void AddMessage(unsigned long messageType, const std::string& messageText);
111
114 virtual void AddSeparator();
115
118 virtual void AddMessages(vtkMRMLMessageCollection* source, const std::string& prefix = std::string());
119
121 virtual void ClearMessages();
122
124 virtual void DeepCopy(vtkMRMLMessageCollection* source);
125
129 virtual std::string GetAllMessagesAsString(bool* errorFound = nullptr, bool* warningFound = nullptr);
130
134 virtual void SetObservedObject(vtkObject* observedObject);
135
136protected:
141
144 struct VTK_MRML_EXPORT Message
145 {
146 Message(unsigned long messageType, const std::string& messageText);
147
148 unsigned long MessageType;
149 std::string MessageText;
150 };
151
152 static void CallbackFunction(vtkObject*, long unsigned int, void* clientData, void* callData);
153
154 vtkSmartPointer<vtkObject> ObservedObject;
155 vtkSmartPointer<vtkCallbackCommand> CallbackCommand;
156 std::vector<Message> Messages;
157};
158
159#endif
vtkSmartPointer< vtkCallbackCommand > CallbackCommand
virtual int GetNumberOfMessagesOfType(unsigned long messageType) const
Return the number of reported messages of the specified event type.
virtual int GetNumberOfMessages() const
Return the total number of reported messages.
virtual void SetObservedObject(vtkObject *observedObject)
virtual std::string GetNthMessageText(int index) const
Get event type of a message from the message vector.
static vtkMRMLMessageCollection * New()
~vtkMRMLMessageCollection() override
vtkSmartPointer< vtkObject > ObservedObject
virtual void DeepCopy(vtkMRMLMessageCollection *source)
Copy all messages from another collection.
static void CallbackFunction(vtkObject *, long unsigned int, void *clientData, void *callData)
void PrintSelf(ostream &os, vtkIndent indent) override
virtual int GetNumberOfMessagesOfType(const char *eventName) const
Get the number of reported messages of the specified event type.
virtual unsigned long GetNthMessageType(int index) const
Get text of a message from the message vector.
virtual void ClearMessages()
Clear the message vector.
virtual void AddMessages(vtkMRMLMessageCollection *source, const std::string &prefix=std::string())
virtual std::string GetAllMessagesAsString(bool *errorFound=nullptr, bool *warningFound=nullptr)
vtkMRMLMessageCollection(const vtkMRMLMessageCollection &)
virtual void AddSeparator()
void operator=(const vtkMRMLMessageCollection &)
virtual void AddMessage(unsigned long messageType, const std::string &messageText)
Message(unsigned long messageType, const std::string &messageText)