COPASI API  4.16.103
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
CNormalItemPower Class Reference

#include <CNormalItemPower.h>

Inheritance diagram for CNormalItemPower:
Inheritance graph
[legend]
Collaboration diagram for CNormalItemPower:
Collaboration graph
[legend]

Public Types

enum  ItemType {
  ITEM, FUNCTION, POWER, CHOICE,
  CALL, LOGICAL, INVALID
}
 

Public Member Functions

 CNormalItemPower ()
 
 CNormalItemPower (const CNormalItemPower &src)
 
 CNormalItemPower (const CNormalBase &item, const C_FLOAT64 &exp)
 
virtual CNormalBasecopy () const
 
const C_FLOAT64getExp () const
 
CNormalBasegetItem ()
 
const CNormalBasegetItem () const
 
ItemType getItemType () const
 
bool operator< (const CNormalItemPower &rhs) const
 
CNormalItemPoweroperator= (const CNormalItemPower &src)
 
bool operator== (const CNormalItemPower &rhs) const
 
bool setExp (const C_FLOAT64 &number)
 
bool setItem (const CNormalBase &item)
 
virtual bool simplify ()
 
virtual std::string toString () const
 
virtual ~CNormalItemPower ()
 
- Public Member Functions inherited from CNormalBase
virtual bool areEqual (const CNormalBase &rhs) const
 
virtual ~CNormalBase ()
 

Protected Attributes

C_FLOAT64 mExp
 
ItemType mItemType
 
CNormalBasempItem
 

Friends

std::ostream & operator<< (std::ostream &os, const CNormalItemPower &d)
 

Detailed Description

The class for powers of items with real positive exponent used in CNormal

Definition at line 34 of file CNormalItemPower.h.

Member Enumeration Documentation

Enumerator
ITEM 
FUNCTION 
POWER 
CHOICE 
CALL 
LOGICAL 
INVALID 

Definition at line 37 of file CNormalItemPower.h.

Constructor & Destructor Documentation

CNormalItemPower::CNormalItemPower ( )

Default constructor

Definition at line 45 of file CNormalItemPower.cpp.

Referenced by copy().

CNormalItemPower::CNormalItemPower ( const CNormalItemPower src)

Copy Constructor

Definition at line 51 of file CNormalItemPower.cpp.

References CNormalBase::copy(), INVALID, mItemType, and mpItem.

51  : CNormalBase(src), mpItem(NULL), mExp(src.mExp), mItemType(src.mItemType)
52 {
54  {
55  this->mpItem = src.mpItem->copy();
56  }
57 }
virtual CNormalBase * copy() const =0
CNormalBase * mpItem
CNormalItemPower::~CNormalItemPower ( )
virtual

Destructor

Definition at line 59 of file CNormalItemPower.cpp.

References mpItem.

60 {
61  if (this->mpItem != NULL) delete this->mpItem;
62 }
CNormalBase * mpItem
CNormalItemPower::CNormalItemPower ( const CNormalBase item,
const C_FLOAT64 exp 
)

Data constructor

Definition at line 89 of file CNormalItemPower.cpp.

References mExp, and setItem().

91 {
92  if (!this->setItem(item))
93  {
94  this->mExp = 1.0;
95  }
96 }
bool setItem(const CNormalBase &item)
CNormalBase * mpItem

Member Function Documentation

CNormalBase * CNormalItemPower::copy ( ) const
virtual

Implements CNormalBase.

Definition at line 372 of file CNormalItemPower.cpp.

References CNormalItemPower().

373 {
374  return new CNormalItemPower(*this);
375 }
const C_FLOAT64 & CNormalItemPower::getExp ( ) const
CNormalBase & CNormalItemPower::getItem ( )
const CNormalBase & CNormalItemPower::getItem ( ) const

Retrieve the base of this power

Returns
mItem

Definition at line 182 of file CNormalItemPower.cpp.

References mpItem.

183 {
184  return *mpItem;
185 }
CNormalBase * mpItem
CNormalItemPower::ItemType CNormalItemPower::getItemType ( ) const
bool CNormalItemPower::operator< ( const CNormalItemPower rhs) const

Examine inequality of two item powers.

Returns
bool.

Definition at line 240 of file CNormalItemPower.cpp.

References CALL, CHOICE, FUNCTION, INVALID, ITEM, LOGICAL, mExp, mItemType, mpItem, and POWER.

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 }
CNormalBase * mpItem
CNormalItemPower & CNormalItemPower::operator= ( const CNormalItemPower src)

Assignment operator Constructor

Definition at line 67 of file CNormalItemPower.cpp.

References CNormalBase::copy(), INVALID, mExp, mItemType, and mpItem.

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 }
virtual CNormalBase * copy() const =0
CNormalBase * mpItem
bool CNormalItemPower::operator== ( const CNormalItemPower rhs) const

Examine equality of two item powers.

Returns
bool.

Definition at line 200 of file CNormalItemPower.cpp.

References CALL, CHOICE, FUNCTION, INVALID, ITEM, LOGICAL, mExp, mItemType, mpItem, and POWER.

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 }
CNormalBase * mpItem
bool CNormalItemPower::setExp ( const C_FLOAT64 number)

Set the exponent of this power

Returns
true

Definition at line 160 of file CNormalItemPower.cpp.

References mExp.

Referenced by createItemPower(), CNormalSum::simplify(), CNormalProduct::simplify(), and test_simplify::test_simplify_1().

161 {
162  if (mExp < 0.0)
163  return false;
164 
165  mExp = number;
166  return true;
167 }
bool CNormalItemPower::setItem ( const CNormalBase item)

Set the base of this itempower.

Returns
true.

Definition at line 102 of file CNormalItemPower.cpp.

References CALL, CHOICE, CNormalBase::copy(), FUNCTION, ITEM, LOGICAL, mItemType, mpItem, and POWER.

Referenced by CNormalItemPower(), createItemPower(), CNormalSum::simplify(), CNormalProduct::simplify(), and test_simplify::test_simplify_1().

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 }
virtual CNormalBase * copy() const =0
CNormalBase * mpItem
bool CNormalItemPower::simplify ( )
virtual

Implements CNormalBase.

Definition at line 382 of file CNormalItemPower.cpp.

References mpItem, and CNormalBase::simplify().

Referenced by CNormalProduct::simplify(), and test_simplify::test_simplify_1().

383 {
384  return this->mpItem->simplify();
385 }
virtual bool simplify()=0
CNormalBase * mpItem
std::string CNormalItemPower::toString ( ) const
virtual

Implements CNormalBase.

Definition at line 351 of file CNormalItemPower.cpp.

References CALL, FUNCTION, ITEM, LOGICAL, mExp, mItemType, mpItem, POWER, and CNormalBase::toString().

Referenced by operator<<().

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 }
virtual std::string toString() const =0
CNormalBase * mpItem

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CNormalItemPower d 
)
friend

Definition at line 345 of file CNormalItemPower.cpp.

346 {
347  os << d.toString();
348  return os;
349 }
virtual std::string toString() const

Member Data Documentation

C_FLOAT64 CNormalItemPower::mExp
protected
ItemType CNormalItemPower::mItemType
protected
CNormalBase* CNormalItemPower::mpItem
protected

Enumeration of members.

Definition at line 53 of file CNormalItemPower.h.

Referenced by CNormalItemPower(), getItem(), operator<(), operator=(), operator==(), setItem(), simplify(), toString(), and ~CNormalItemPower().


The documentation for this class was generated from the following files: