Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
berryExpression.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 "berryExpression.h"
18 #include <Poco/Hash.h>
19 
20 
21 namespace berry {
22 
24 const uint Expression::HASH_FACTOR = 89;
25 const QString Expression::ATT_VALUE= "value";
26 
27 const Expression::Pointer Expression::TRUE_EVAL(new TRUE_EVALExpression());
28 const Expression::Pointer Expression::FALSE_EVAL(new FALSE_EVALExpression());
29 
31 {
32  fHashCode = HASH_CODE_NOT_COMPUTED;
33 }
34 
36 {
37 
38 }
39 
40 bool Expression::Equals(const QList<Expression::Pointer>& leftArray,
41  const QList<Expression::Pointer>& rightArray)
42 {
43  return (leftArray == rightArray);
44 }
45 
46 bool Expression::Equals(const QList<Object::Pointer>& leftArray,
47  const QList<Object::Pointer>& rightArray)
48 {
49  return (leftArray == rightArray);
50 }
51 
52 uint
54 {
55  return object != 0 ? object->HashCode() : 0;
56 }
57 
58 uint
59 Expression::HashCode(const QList<Expression::Pointer>& array)
60 {
61  if (array.size() == 0)
62  {
63  return 0;
64  }
65  uint hashCode = qHash("QList<Expression::Pointer>");
66  for (int i= 0; i < array.size(); i++)
67  {
68  hashCode = hashCode * HASH_FACTOR + HashCode(array[i]);
69  }
70  return hashCode;
71 }
72 
73 uint
74 Expression::HashCode(const QList<Object::Pointer>& array)
75 {
76  if (array.isEmpty())
77  {
78  return 0;
79  }
80  int hashCode = (int) Poco::hash("std::vector<Object::Pointer>");
81  for (int i= 0; i < array.size(); i++)
82  {
83  hashCode = hashCode + (int) array[i]->HashCode();
84  }
85  return hashCode;
86 }
87 
88 const ExpressionInfo*
90 {
91  auto result= new ExpressionInfo();
92  this->CollectExpressionInfo(result);
93  return result;
94 }
95 
96 void
98 {
99  info->AddMisBehavingExpressionType(typeid(this));
100 }
101 
102 uint
104 {
105  return qHash(this);
106 }
107 
109 {
110  if (fHashCode != HASH_CODE_NOT_COMPUTED)
111  return fHashCode;
112  fHashCode= this->ComputeHashCode();
113  if (fHashCode == HASH_CODE_NOT_COMPUTED)
114  fHashCode++;
115  return fHashCode;
116 }
117 
118 bool
119 Expression::operator==(const Object* object) const
120 {
121  if (const Expression* other = dynamic_cast<const Expression*>(object))
122  return this->HashCode() == other->HashCode();
123 
124  return false;
125 }
126 
127 QString Expression::ToString() const
128 {
129  return typeid(this).name();
130 }
131 
132 } // namespace berry
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:78
virtual bool operator==(const Object *object) const override
virtual uint ComputeHashCode() const
virtual QString ToString() const override
static const uint HASH_CODE_NOT_COMPUTED
static void info(const char *fmt,...)
Definition: svm.cpp:100
virtual const ExpressionInfo * ComputeExpressionInfo() const
berry::SmartPointer< Self > Pointer
Definition: berryObject.h:88
virtual void CollectExpressionInfo(ExpressionInfo *info) const
void AddMisBehavingExpressionType(const std::type_info &clazz)
static const QString ATT_VALUE
static const Expression::Pointer FALSE_EVAL
unsigned int uint
static const uint HASH_FACTOR
static bool Equals(const QList< Expression::Pointer > &leftArray, const QList< Expression::Pointer > &rightArray)
static const Expression::Pointer TRUE_EVAL
virtual uint HashCode() const override
uint qHash(const berry::Object &o)