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