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