Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
berryNamedHandleObjectWithState.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 
19 
20 #include "berryState.h"
21 
22 namespace berry
23 {
24 
25 void NamedHandleObjectWithState::AddState(const QString& stateId,
26  const State::Pointer& state)
27 {
28  if (!state)
29  {
30  throw Poco::NullPointerException("Cannot add a null state");
31  }
32 
33  states[stateId] = state;
34 }
35 
37 {
38  const QString description(NamedHandleObject::GetDescription()); // Trigger a NDE.
39 
41  descriptionState(this->GetState(INamedHandleStateIds::DESCRIPTION));
42  if (descriptionState.IsNotNull())
43  {
44  const Object::ConstPointer value(descriptionState->GetValue());
45  if (value.IsNotNull())
46  {
47  return value->ToString();
48  }
49  }
50 
51  return description;
52 }
53 
55 {
56  const QString name(NamedHandleObject::GetName()); // Trigger a NDE, if necessary.
57 
59  nameState(this->GetState(INamedHandleStateIds::NAME));
60  if (nameState.IsNotNull())
61  {
62  const Object::ConstPointer value(nameState->GetValue());
63  if (value.IsNotNull())
64  {
65  return value->ToString();
66  }
67  }
68 
69  return name;
70 }
71 
73  const QString& stateId) const
74 {
75  if (states.empty())
76  {
77  return State::Pointer(nullptr);
78  }
79 
80  QHash<QString, State::Pointer>::const_iterator iter = states.find(stateId);
81  return iter.value();
82 }
83 
85 {
86  if (states.empty())
87  {
88  return QList<QString>();
89  }
90 
91  QList<QString> stateIds;
92  for (QHash<QString, State::Pointer>::const_iterator iter = states.begin();
93  iter != states.end(); ++iter)
94  {
95  stateIds.push_back(iter.key());
96  }
97  return stateIds;
98 }
99 
101 {
102  if (id.isEmpty())
103  {
104  throw ctkInvalidArgumentException("Cannot remove an empty id");
105  }
106 
107  states.remove(id);
108 }
109 
111  : NamedHandleObject(id)
112 {
113 }
114 
115 }
virtual QString GetName() const
virtual QString GetDescription() const
QList< QString > GetStateIds() const override
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:88
const SmartPointer< State > & state
SmartPointer< State > GetState(const QString &stateId) const override