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