Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryParameterization.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 "berryParameterization.h"
14 #include "berryIParameter.h"
15 #include "berryIParameterValues.h"
16 
17 namespace berry
18 {
19 
20 const uint Parameterization::HASH_CODE_NOT_COMPUTED = 0;
21 const uint Parameterization::HASH_FACTOR = 89;
22 const uint Parameterization::HASH_INITIAL = qHash("berry::Parameterization");
23 
25 : hashCode(HASH_CODE_NOT_COMPUTED), parameter(parameter), value(value)
26 {
27  if (!parameter)
28  {
29  throw ctkInvalidArgumentException(
30  "You cannot parameterize a null parameter");
31  }
32 }
33 
35 : hashCode(p.hashCode), parameter(p.parameter), value(p.value)
36 {
37 
38 }
39 
41 {
42  this->hashCode = p.hashCode;
43  this->parameter = p.parameter;
44  this->value = p.value;
45 
46  return *this;
47 }
48 
49 bool Parameterization::operator==(const Parameterization& parameterization) const
50 {
51  if (this == &parameterization)
52  {
53  return true;
54  }
55 
56  // if (!(object instanceof Parameterization)) {
57  // return false;
58  // }
59 
60  if (this->parameter->GetId() != parameterization.parameter->GetId())
61  {
62  return false;
63  }
64 
65  return (this->value == parameterization.value);
66 }
67 
68 Parameterization::operator bool() const
69 {
70  return true;
71 }
72 
74 {
75  return parameter;
76 }
77 
79 {
80  return value;
81 }
82 
84 {
85  const QHash<QString,QString> parameterValues = parameter->GetValues()->GetParameterValues();
86 
87  QString returnValue;
88  for (IParameter::ParameterValues::const_iterator parameterValueItr = parameterValues.begin();
89  parameterValueItr != parameterValues.end(); ++ parameterValueItr)
90  {
91  const QString currentValue(parameterValueItr.value());
92  if (value == currentValue)
93  {
94  returnValue = parameterValueItr.key();
95  break;
96  }
97  }
98 
99  return returnValue;
100 }
101 
103 {
104  if (hashCode == HASH_CODE_NOT_COMPUTED)
105  {
106  hashCode = HASH_INITIAL * HASH_FACTOR + parameter->HashCode();
107  hashCode = hashCode * HASH_FACTOR + qHash(value);
108  if (hashCode == HASH_CODE_NOT_COMPUTED)
109  {
110  hashCode++;
111  }
112  }
113  return hashCode;
114 }
115 
116 }
Parameterization(const SmartPointer< const IParameter > parameter, const QString &value)
Implements transparent reference counting.
SmartPointer< const IParameter > GetParameter() const
unsigned int uint
bool operator==(const Parameterization &parameterization) const
Parameterization & operator=(const Parameterization &p)
uint qHash(const berry::Object &o)