COPASI API  4.16.103
CNormalLogicalItem.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/compareExpressions/CNormalLogicalItem.cpp,v $
3 // $Revision: 1.10 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2007/12/11 20:55:55 $
7 // End CVS Header
8 
9 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 #ifdef WIN32
14 # pragma warning (disable: 4786)
15 # pragma warning (disable: 4243)
16 // warning C4355: 'this' : used in base member initializer list
17 # pragma warning (disable: 4355)
18 #endif // WIN32
19 
20 #include <sstream>
21 
22 #include "CNormalLogicalItem.h"
23 
25 {}
26 
27 CNormalLogicalItem::CNormalLogicalItem(const CNormalLogicalItem& src): CNormalBase(src), mType(src.mType), mLeft(src.mLeft), mRight(src.mRight)
28 {}
29 
31 {}
32 
34 {
35  this->mType = src.mType;
36  this->mLeft = src.mLeft;
37  this->mRight = src.mRight;
38  return *this;
39 }
40 
42  {
43  bool result = false;
44  if (this->mType < rhs.mType)
45  {
46  result = true;
47  }
48  else if (this->mType == rhs.mType)
49  {
50  if (this->mLeft == rhs.mLeft)
51  {
52  result = (this->mRight < rhs.mRight);
53  }
54  else
55  {
56  result = (this->mLeft < rhs.mLeft);
57  }
58  }
59  return result;
60  }
61 
63  {
64  return new CNormalLogicalItem(*this);
65  }
66 
67 std::string CNormalLogicalItem::toString() const
68  {
69  std::ostringstream str;
70  switch (this->mType)
71  {
73  str << "TRUE";
74  break;
76  str << "FALSE";
77  break;
79  str << "(" << this->mLeft << " == " << this->mRight << ")";
80  break;
82  str << "(" << this->mLeft << " != " << this->mRight << ")";
83  break;
85  str << "(" << this->mLeft << " < " << this->mRight << ")";
86  break;
88  str << "(" << this->mLeft << " > " << this->mRight << ")";
89  break;
91  str << "(" << this->mLeft << " >= " << this->mRight << ")";
92  break;
94  str << "(" << this->mLeft << " <= " << this->mRight << ")";
95  break;
96  case INVALID:
97  break;
98  }
99  return str.str();
100  }
101 
103 {
104  bool result = true;
105  if (this->mType == GT)
106  {
107  // replace by LT and switch mpLeft and mpRight
108  this->mType = LT;
109  CNormalFraction TMP = this->mLeft;
110  this->mLeft = this->mRight;
111  this->mRight = TMP;
112  }
113  else if (this->mType == GE)
114  {
115  // replace by LE and switch mpLeft and mpRight
116  this->mType = LE;
117  CNormalFraction TMP = this->mLeft;
118  this->mLeft = this->mRight;
119  this->mRight = TMP;
120  }
121  result &= this->mLeft.simplify();
122  if (result) result &= this->mRight.simplify();
123  return result;
124 }
125 
127 {
128  return this->mLeft;
129 }
130 
132  {
133  return this->mLeft;
134  }
135 
137 {
138  return this->mRight;
139 }
140 
142  {
143  return this->mRight;
144  }
145 
147 {
148  bool result = false;
150  {
151  this->mLeft = left;
152  }
153  return result;
154 }
155 
157 {
158  bool result = false;
160  {
161  this->mRight = right;
162  }
163  return result;
164 }
165 
167  {
168  return this->mType;
169  }
170 
172 {
173  switch (type)
174  {
177  this->mLeft = CNormalFraction();
178  this->mRight = CNormalFraction();
179  break;
180  default:
181  break;
182  }
183  this->mType = type;
184 }
185 
186 std::ostream& operator<<(std::ostream& os, const CNormalLogicalItem& item)
187 {
188  os << item.toString();
189  return os;
190 }
191 
193 {
194  switch (this->mType)
195  {
196  case TRUE:
197  this->mType = FALSE;
198  break;
199  case FALSE:
200  this->mType = TRUE;
201  break;
202  case EQ:
203  this->mType = NE;
204  break;
205  case NE:
206  this->mType = EQ;
207  break;
208  case GT:
209  this->mType = LE;
210  break;
211  case LT:
212  this->mType = GE;
213  break;
214  case LE:
215  this->mType = GT;
216  break;
217  case GE:
218  this->mType = LT;
219  break;
220  case INVALID:
221  break;
222  }
223 }
224 
226  {
227  bool result = true;
228  if (this->mType == rhs.mType)
229  {
230  result = (this->mLeft == rhs.mLeft);
231  if (result)
232  {
233  result = (this->mRight == rhs.mRight);
234  }
235  }
236  else
237  {
238  result = false;
239  }
240  return result;
241  }
virtual bool simplify()
virtual std::string toString() const
virtual CNormalBase * copy() const
bool setRight(const CNormalFraction &right)
CNormalFraction & getLeft()
CNormalFraction mLeft
bool setLeft(const CNormalFraction &left)
CNormalLogicalItem & operator=(const CNormalLogicalItem &src)
std::ostream & operator<<(std::ostream &os, const CNormalLogicalItem &item)
bool operator==(const CNormalLogicalItem &rhs) const
bool operator<(const CNormalLogicalItem &rhs) const
CNormalFraction mRight
CNormalFraction & getRight()