Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
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 
39 #ifndef vtkWarningToMessageCollectionMacro
40 #define vtkWarningToMessageCollectionMacro(messageCollection, devMsgPrefix, userMsg) \
41  vtkWarningToMessageCollectionWithObjectMacro(this, messageCollection, devMsgPrefix, userMsg)
42 #endif
43 
44 #ifndef vtkErrorToMessageCollectionMacro
45 #define vtkErrorToMessageCollectionMacro(messageCollection, devMsgPrefix, userMsg) \
46  vtkErrorToMessageCollectionWithObjectMacro(this, messageCollection, devMsgPrefix, userMsg)
47 #endif
48 
49 #ifndef vtkWarningToMessageCollectionWithObjectMacro
50 #define vtkWarningToMessageCollectionWithObjectMacro(self, messageCollection, devMsgPrefix, userMsg) \
51  { \
52  vtkOStreamWrapper::EndlType endl; \
53  vtkOStreamWrapper::UseEndl(endl); \
54  if (messageCollection) \
55  { \
56  vtkOStrStreamWrapper userMsgStream; \
57  userMsgStream << userMsg; \
58  messageCollection->AddMessage(vtkCommand::WarningEvent, userMsgStream.str()); \
59  userMsgStream.rdbuf()->freeze(0); \
60  } \
61  vtkWarningWithObjectMacro(self, << devMsgPrefix << ": " << userMsg); \
62  }
63 #endif
64 
65 #ifndef vtkErrorToMessageCollectionWithObjectMacro
66 #define vtkErrorToMessageCollectionWithObjectMacro(self, messageCollection, devMsgPrefix, userMsg) \
67  { \
68  vtkOStreamWrapper::EndlType endl; \
69  vtkOStreamWrapper::UseEndl(endl); \
70  if (messageCollection) \
71  { \
72  vtkOStrStreamWrapper userMsgStream; \
73  userMsgStream << userMsg; \
74  messageCollection->AddMessage(vtkCommand::ErrorEvent, userMsgStream.str()); \
75  userMsgStream.rdbuf()->freeze(0); \
76  } \
77  vtkErrorWithObjectMacro(self, << devMsgPrefix << ": " << userMsg); \
78  }
79 #endif
80 
81 
87 class VTK_MRML_EXPORT vtkMRMLMessageCollection : public vtkObject
88 {
89 public:
90  vtkTypeMacro(vtkMRMLMessageCollection,vtkObject);
91  void PrintSelf(ostream& os, vtkIndent indent) override;
92  static vtkMRMLMessageCollection* New();
93 
95  virtual int GetNumberOfMessages() const;
96 
98  virtual int GetNumberOfMessagesOfType(unsigned long messageType) const;
99 
101  virtual int GetNumberOfMessagesOfType(const char *eventName) const;
102 
104  virtual unsigned long GetNthMessageType(int index) const;
105 
107  virtual std::string GetNthMessageText(int index) const;
108 
112  virtual void AddMessage(unsigned long messageType, const std::string &messageText);
113 
116  virtual void AddSeparator();
117 
120  virtual void AddMessages(vtkMRMLMessageCollection* source, const std::string& prefix=std::string());
121 
123  virtual void ClearMessages();
124 
126  virtual void DeepCopy(vtkMRMLMessageCollection* source);
127 
131  virtual std::string GetAllMessagesAsString(bool* errorFound=nullptr, bool* warningFound=nullptr);
132 
136  virtual void SetObservedObject(vtkObject* observedObject);
137 
138 protected:
140  ~vtkMRMLMessageCollection() override;
142  void operator=(const vtkMRMLMessageCollection&);
143 
146  struct VTK_MRML_EXPORT Message
147  {
148  Message(unsigned long messageType, const std::string &messageText);
149 
150  unsigned long MessageType;
151  std::string MessageText;
152  };
153 
154  static void CallbackFunction(vtkObject*, long unsigned int,
155  void* clientData, void* callData);
156 
157  vtkSmartPointer<vtkObject> ObservedObject;
158  vtkSmartPointer<vtkCallbackCommand> CallbackCommand;
159  std::vector<Message> Messages;
160 };
161 
162 #endif
std::vector< Message > Messages
vtkSmartPointer< vtkCallbackCommand > CallbackCommand
A helper class that describes a single message
vtkSmartPointer< vtkObject > ObservedObject