Medical Imaging Interaction Toolkit  2018.4.99-93926fb8
Medical Imaging Interaction Toolkit
berryStatus.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "berryStatus.h"
14 
15 #include "internal/berryIRuntimeConstants.h"
16 
17 #include <QTextStream>
18 
19 namespace berry
20 {
21 
22 const QList<IStatus::Pointer> Status::theEmptyStatusArray = QList<IStatus::Pointer>();
23 
25 {
27  IRuntimeConstants::PI_RUNTIME(), 0, "OK", sl));
28  return status;
29 }
30 
32 {
34  IRuntimeConstants::PI_RUNTIME(), 1, "", sl));
35  return status;
36 }
37 
38 Status::Status(const Severity& severity, const QString& pluginId, int code,
39  const QString& message, const SourceLocation& sl)
40  : exception(nullptr), sourceLocation(sl)
41 {
42  SetSeverity(severity);
43  SetPlugin(pluginId);
44  SetCode(code);
45  SetMessage(message);
46 }
47 
48 Status::Status(const Severity& severity, const QString& pluginId, int code,
49  const QString& message, const ctkException& exception,
50  const SourceLocation& sl)
51  : exception(nullptr), sourceLocation(sl)
52 {
53  SetSeverity(severity);
54  SetPlugin(pluginId);
55  SetCode(code);
56  SetMessage(message);
57  SetException(exception);
58 }
59 
60 Status::Status(const Severity& severity, const QString& pluginId,
61  const QString& message, const SourceLocation& sl)
62  : exception(nullptr), sourceLocation(sl)
63 {
64  SetSeverity(severity);
65  SetPlugin(pluginId);
66  SetMessage(message);
67  SetCode(0);
68 }
69 
70 Status::Status(const Severity& severity, const QString& pluginId,
71  const QString& message, const ctkException& exception,
72  const SourceLocation& sl)
73  : exception(nullptr), sourceLocation(sl)
74 {
75  SetSeverity(severity);
76  SetPlugin(pluginId);
77  SetMessage(message);
78  SetException(exception);
79  SetCode(0);
80 }
81 
82 QList<IStatus::Pointer> Status::GetChildren() const
83 {
84  return theEmptyStatusArray;
85 }
86 
87 int Status::GetCode() const
88 {
89  return code;
90 }
91 
92 const ctkException* Status::GetException() const
93 {
94  return exception;
95 }
96 
97 /* (Intentionally not javadoc'd)
98  * Implements the corresponding method on <code>IStatus</code>.
99  */
100 QString Status::GetMessage() const
101 {
102  return message;
103 }
104 
105 QString Status::GetPlugin() const
106 {
107  return pluginId;
108 }
109 
111 {
112  return severity;
113 }
114 
116 {
117  return false;
118 }
119 
120 bool Status::IsOK() const
121 {
122  return severity == OK_TYPE;
123 }
124 
125 bool Status::Matches(const Severities& severityMask) const
126 {
127  return (severity & severityMask) != 0;
128 }
129 
130 QString Status::GetFileName() const
131 {
132  return sourceLocation.fileName;
133 }
134 
135 QString Status::GetMethodName() const
136 {
137  return sourceLocation.methodName;
138 }
139 
141 {
142  return sourceLocation.lineNumber;
143 }
144 
145 void Status::SetCode(int code)
146 {
147  this->code = code;
148 }
149 
150 void Status::SetException(const ctkException& exception)
151 {
152  delete this->exception;
153  this->exception = exception.clone();
154 }
155 
156 void Status::SetMessage(const QString& message)
157 {
158  this->message = message;
159 }
160 
161 void Status::SetPlugin(const QString& pluginId)
162 {
163  Q_ASSERT(!pluginId.isEmpty());
164  this->pluginId = pluginId;
165 }
166 
167 void Status::SetSeverity(const Severity& severity)
168 {
169  this->severity = severity;
170 }
171 
172 QString Status::ToString() const
173 {
174  QString str;
175  QTextStream ss(&str);
176  ss << "Status ";
177  switch (severity)
178  {
179  case OK_TYPE:
180  ss << "OK";
181  break;
182  case ERROR_TYPE:
183  ss << "ERROR";
184  break;
185  case WARNING_TYPE:
186  ss << "WARNING";
187  break;
188  case INFO_TYPE:
189  ss << "INFO";
190  break;
191  case CANCEL_TYPE:
192  ss << "CANCEL";
193  break;
194  default:
195  ss << "severity=" << severity;
196  }
197 
198  ss << ": " << pluginId << " code=" << code << " " << message;
199  if (exception)
200  {
201  ss << " " << exception->what();
202  }
203  return str;
204 }
205 
206 }
bool IsMultiStatus() const override
QString GetMessage() const override
virtual void SetPlugin(const QString &pluginId)
int GetCode() const override
Definition: berryStatus.cpp:87
QString GetPlugin() const override
static const IStatus::Pointer CANCEL_STATUS(const SourceLocation &sl)
Definition: berryStatus.cpp:31
Implements transparent reference counting.
QString GetMethodName() const override
QString ToString() const override
bool Matches(const Severities &severityMask) const override
bool IsOK() const override
virtual void SetSeverity(const Severity &severity)
QString GetFileName() const override
const ctkException * GetException() const override
Definition: berryStatus.cpp:92
virtual void SetMessage(const QString &message)
Severity GetSeverity() const override
static const IStatus::Pointer OK_STATUS(const SourceLocation &sl)
Definition: berryStatus.cpp:24
virtual void SetCode(int code)
QList< IStatus::Pointer > GetChildren() const override
Definition: berryStatus.cpp:82
int GetLineNumber() const override
Status(const Severity &severity, const QString &pluginId, int code, const QString &message, const SourceLocation &sl)
Definition: berryStatus.cpp:38
virtual void SetException(const ctkException &exception)