COPASI API  4.16.103
CNormalItemPower.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/compareExpressions/CNormalItemPower.cpp,v $
3 // $Revision: 1.14 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:26:19 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #ifdef WIN32
24 # pragma warning (disable: 4786)
25 # pragma warning (disable: 4243)
26 // warning C4355: 'this' : used in base member initializer list
27 # pragma warning (disable: 4355)
28 #endif // WIN32
29 
30 #include <sstream>
31 
32 #include "copasi.h"
33 
34 #include "CNormalCall.h"
35 #include "CNormalChoice.h"
36 #include "CNormalFunction.h"
37 #include "CNormalGeneralPower.h"
38 #include "CNormalItem.h"
39 #include "CNormalItemPower.h"
40 #include "CNormalLogical.h"
41 
42 /**
43  * Default constructor
44  */
45 CNormalItemPower::CNormalItemPower(): CNormalBase(), mpItem(NULL), mExp(1.0), mItemType(CNormalItemPower::INVALID)
46 {}
47 
48 /**
49  * Copy Constructor
50  */
51 CNormalItemPower::CNormalItemPower(const CNormalItemPower& src): CNormalBase(src), mpItem(NULL), mExp(src.mExp), mItemType(src.mItemType)
52 {
54  {
55  this->mpItem = src.mpItem->copy();
56  }
57 }
58 
60 {
61  if (this->mpItem != NULL) delete this->mpItem;
62 }
63 
64 /**
65  * Assignment operator Constructor
66  */
68 {
69  if (this->mpItem != NULL) delete this->mpItem;
70 
71  this->mItemType = src.mItemType;
72 
74  {
75  this->mpItem = src.mpItem->copy();
76  }
77  else
78  {
79  this->mpItem = NULL;
80  }
81 
82  mExp = src.mExp;
83  return *this;
84 }
85 
86 /**
87  * Data constructor
88  */
90  : mpItem(NULL), mExp(exp), mItemType(CNormalItemPower::INVALID)
91 {
92  if (!this->setItem(item))
93  {
94  this->mExp = 1.0;
95  }
96 }
97 
98 /**
99  * Set the base of this itempower.
100  * @return true.
101  */
103 {
104  bool result = true;
105 
106  if (dynamic_cast<const CNormalItem*>(&item))
107  {
108  if (this->mpItem != NULL) delete this->mpItem;
109 
111  this->mpItem = item.copy();
112  }
113  else if (dynamic_cast<const CNormalFunction*>(&item))
114  {
115  if (this->mpItem != NULL) delete this->mpItem;
116 
118  this->mpItem = item.copy();
119  }
120  else if (dynamic_cast<const CNormalGeneralPower*>(&item))
121  {
122  if (this->mpItem != NULL) delete this->mpItem;
123 
125  this->mpItem = item.copy();
126  }
127  else if (dynamic_cast<const CNormalChoice*>(&item))
128  {
129  if (this->mpItem != NULL) delete this->mpItem;
130 
132  this->mpItem = item.copy();
133  }
134  else if (dynamic_cast<const CNormalCall*>(&item))
135  {
136  if (this->mpItem != NULL) delete this->mpItem;
137 
139  this->mpItem = item.copy();
140  }
141  else if (dynamic_cast<const CNormalLogical*>(&item))
142  {
143  if (this->mpItem != NULL) delete this->mpItem;
144 
146  this->mpItem = item.copy();
147  }
148  else
149  {
150  result = false;
151  }
152 
153  return result;
154 }
155 
156 /**
157  * Set the exponent of this power
158  * @return true
159  */
161 {
162  if (mExp < 0.0)
163  return false;
164 
165  mExp = number;
166  return true;
167 }
168 
169 /**
170  * Retrieve the base of this power
171  * @return mItem
172  */
174 {
175  return *mpItem;
176 }
177 
178 /**
179  * Retrieve the base of this power
180  * @return mItem
181  */
183 {
184  return *mpItem;
185 }
186 
187 /**
188  * Retrieve the exponent of this power
189  * @return mExp
190  */
192 {
193  return mExp;
194 }
195 
196 /**
197  * Examine equality of two item powers.
198  * @return bool.
199  */
201 {
202  bool result = (this->mItemType == rhs.mItemType);
203  result &= (this->mExp == rhs.mExp);
204 
205  if (result == true)
206  {
207  switch (this->mItemType)
208  {
210  result = (dynamic_cast<CNormalItem&>(*this->mpItem) == dynamic_cast<CNormalItem&>(*rhs.mpItem));
211  break;
213  result = (dynamic_cast<CNormalFunction&>(*this->mpItem) == dynamic_cast<CNormalFunction&>(*rhs.mpItem));
214  break;
216  result = (dynamic_cast<CNormalGeneralPower&>(*this->mpItem) == dynamic_cast<CNormalGeneralPower&>(*rhs.mpItem));
217  break;
219  result = (dynamic_cast<CNormalChoice&>(*this->mpItem) == dynamic_cast<CNormalChoice&>(*rhs.mpItem));
220  break;
222  result = (dynamic_cast<CNormalCall&>(*this->mpItem) == dynamic_cast<CNormalCall&>(*rhs.mpItem));
223  break;
225  result = (dynamic_cast<CNormalLogical&>(*this->mpItem) == dynamic_cast<CNormalLogical&>(*rhs.mpItem));
226  break;
228  result = true;
229  break;
230  }
231  }
232 
233  return result;
234 }
235 
236 /**
237  * Examine inequality of two item powers.
238  * @return bool.
239  */
241 {
242  bool result = false;
243 
244  if (this->mItemType < rhs.mItemType)
245  {
246  result = true;
247  }
248  else if (this->mItemType == rhs.mItemType)
249  {
250  switch (this->mItemType)
251  {
253  result = (dynamic_cast<CNormalItem&>(*this->mpItem) < dynamic_cast<CNormalItem&>(*rhs.mpItem));
254 
255  if (!result)
256  {
257  result = !(dynamic_cast<CNormalItem&>(*rhs.mpItem) < dynamic_cast<CNormalItem&>(*this->mpItem));
258 
259  if (result)
260  {
261  result = (rhs.mExp < this->mExp);
262  }
263  }
264 
265  break;
267  result = (dynamic_cast<CNormalFunction&>(*this->mpItem) < dynamic_cast<CNormalFunction&>(*rhs.mpItem));
268 
269  if (!result)
270  {
271  result = !(dynamic_cast<CNormalFunction&>(*rhs.mpItem) < dynamic_cast<CNormalFunction&>(*this->mpItem));
272 
273  if (result)
274  {
275  result = (rhs.mExp < this->mExp);
276  }
277  }
278 
279  break;
281  result = (dynamic_cast<CNormalGeneralPower&>(*this->mpItem) < dynamic_cast<CNormalGeneralPower&>(*rhs.mpItem));
282 
283  if (!result)
284  {
285  result = !(dynamic_cast<CNormalGeneralPower&>(*rhs.mpItem) < dynamic_cast<CNormalGeneralPower&>(*this->mpItem));
286 
287  if (result)
288  {
289  result = (rhs.mExp < this->mExp);
290  }
291  }
292 
293  break;
295  result = (dynamic_cast<CNormalChoice&>(*this->mpItem) < dynamic_cast<CNormalChoice&>(*rhs.mpItem));
296 
297  if (!result)
298  {
299  result = !(dynamic_cast<CNormalChoice&>(*rhs.mpItem) < dynamic_cast<CNormalChoice&>(*this->mpItem));
300 
301  if (result)
302  {
303  result = (rhs.mExp < this->mExp);
304  }
305  }
306 
307  break;
309  result = (dynamic_cast<CNormalCall&>(*this->mpItem) < dynamic_cast<CNormalCall&>(*rhs.mpItem));
310 
311  if (!result)
312  {
313  result = !(dynamic_cast<CNormalCall&>(*rhs.mpItem) < dynamic_cast<CNormalCall&>(*this->mpItem));
314 
315  if (result)
316  {
317  result = (rhs.mExp < this->mExp);
318  }
319  }
320 
321  break;
323  result = (dynamic_cast<CNormalLogical&>(*this->mpItem) < dynamic_cast<CNormalLogical&>(*rhs.mpItem));
324 
325  if (!result)
326  {
327  result = !(dynamic_cast<CNormalLogical&>(*rhs.mpItem) < dynamic_cast<CNormalLogical&>(*this->mpItem));
328 
329  if (result)
330  {
331  result = (rhs.mExp < this->mExp);
332  }
333  }
334 
335  break;
337  result = false;
338  break;
339  }
340  }
341 
342  return result;
343 }
344 
345 std::ostream & operator<< (std::ostream &os, const CNormalItemPower & d)
346 {
347  os << d.toString();
348  return os;
349 }
350 
351 std::string CNormalItemPower::toString() const
352 {
353  std::ostringstream os;
354 
356  {
357  os << this->mpItem->toString();
358  }
359  else
360  {
361  os << "(" << this->mpItem->toString() << ")";
362  }
363 
364  if (this->mExp != 1.0)
365  {
366  os << "^" << this->mExp;
367  }
368 
369  return os.str();
370 }
371 
373 {
374  return new CNormalItemPower(*this);
375 }
376 
378 {
379  return this->mItemType;
380 }
381 
383 {
384  return this->mpItem->simplify();
385 }
bool operator==(const CNormalItemPower &rhs) const
virtual ~CNormalItemPower()
virtual bool simplify()
bool operator<(const CNormalItemPower &rhs) const
virtual std::string toString() const =0
CNormalItemPower & operator=(const CNormalItemPower &src)
bool setItem(const CNormalBase &item)
ItemType getItemType() const
const C_FLOAT64 & getExp() const
virtual bool simplify()=0
std::ostream & operator<<(std::ostream &os, const CNormalItemPower &d)
#define C_FLOAT64
Definition: copasi.h:92
virtual std::string toString() const
virtual CNormalBase * copy() const
CNormalBase & getItem()
virtual CNormalBase * copy() const =0
CNormalBase * mpItem
bool setExp(const C_FLOAT64 &number)