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

#include <CNormalChoice.h>

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

Public Member Functions

 CNormalChoice ()
 
 CNormalChoice (const CNormalChoice &src)
 
virtual CNormalBasecopy () const
 
const CNormalLogicalgetCondition () const
 
CNormalLogicalgetCondition ()
 
const CNormalFractiongetFalseExpression () const
 
CNormalFractiongetFalseExpression ()
 
const CNormalFractiongetTrueExpression () const
 
CNormalFractiongetTrueExpression ()
 
bool operator< (const CNormalChoice &rhs) const
 
CNormalChoiceoperator= (const CNormalChoice &src)
 
bool operator== (const CNormalChoice &rhs) const
 
bool setCondition (const CNormalLogical &cond)
 
bool setFalseExpression (const CNormalFraction &branch)
 
bool setTrueExpression (const CNormalFraction &branch)
 
virtual bool simplify ()
 
virtual std::string toString () const
 
virtual ~CNormalChoice ()
 
- Public Member Functions inherited from CNormalBase
virtual bool areEqual (const CNormalBase &rhs) const
 
virtual ~CNormalBase ()
 

Static Public Member Functions

static bool checkConditionTree (const CNormalBase &branch)
 
static bool checkExpressionTree (const CNormalBase &branch)
 

Protected Attributes

CNormalLogicalmpCondition
 
CNormalFractionmpFalse
 
CNormalFractionmpTrue
 

Friends

std::ostream & operator<< (std::ostream &os, const CNormalChoice &choice)
 

Detailed Description

Definition at line 23 of file CNormalChoice.h.

Constructor & Destructor Documentation

CNormalChoice::CNormalChoice ( )

Definition at line 27 of file CNormalChoice.cpp.

Referenced by copy().

27  : CNormalBase(), mpCondition(NULL), mpTrue(NULL), mpFalse(NULL)
28 {}
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
CNormalChoice::CNormalChoice ( const CNormalChoice src)

Definition at line 30 of file CNormalChoice.cpp.

30  :
31  CNormalBase(src),
32  mpCondition(NULL),
33  mpTrue(NULL),
34  mpFalse(NULL)
35 {*this = src;}
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
CNormalChoice::~CNormalChoice ( )
virtual

Definition at line 37 of file CNormalChoice.cpp.

References mpCondition, mpFalse, mpTrue, and pdelete.

38 {
40  pdelete(mpTrue);
42 }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
#define pdelete(p)
Definition: copasi.h:215
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26

Member Function Documentation

bool CNormalChoice::checkConditionTree ( const CNormalBase branch)
static

Definition at line 133 of file CNormalChoice.cpp.

References CNormalItem::CONSTANT, getCondition(), getFalseExpression(), CNormalItem::getName(), getTrueExpression(), and CNormalItem::getType().

Referenced by checkExpressionTree(), and setCondition().

134 {
135  bool result = true;
136  const CNormalChoice* pChoice = dynamic_cast<const CNormalChoice*>(&branch);
137  if (pChoice != NULL)
138  {
139  // check the condition and the two branches
140  result = checkConditionTree(pChoice->getCondition());
141  if (result == true) result = checkConditionTree(pChoice->getTrueExpression());
142  if (result == true) result = checkConditionTree(pChoice->getFalseExpression());
143  }
144  else
145  {
146  const CNormalLogical* pLogical = dynamic_cast<const CNormalLogical*>(&branch);
147  if (pLogical == NULL)
148  {
149  const CNormalItem* pItem = dynamic_cast<const CNormalItem*>(&branch);
150  if (pItem == NULL)
151  {
152  result = false;
153  }
154  else
155  {
156  result = pItem->getType() == CNormalItem::CONSTANT;
157  if (result == true)
158  {
159  std::string name = pItem->getName();
160  if (name != "true" && name != "TRUE" && name != "false" && name != "FALSE")
161  {
162  result = false;
163  }
164  }
165  }
166  }
167  }
168  return result;
169 }
static bool checkConditionTree(const CNormalBase &branch)
const CNormalFraction & getTrueExpression() const
const CNormalLogical & getCondition() const
const CNormalFraction & getFalseExpression() const
const Type & getType() const
Definition: CNormalItem.cpp:91
const std::string getName() const
Definition: CNormalItem.cpp:82
bool CNormalChoice::checkExpressionTree ( const CNormalBase branch)
static

Definition at line 171 of file CNormalChoice.cpp.

References checkConditionTree(), getCondition(), getFalseExpression(), and getTrueExpression().

Referenced by setFalseExpression(), and setTrueExpression().

172 {
173  bool result = true;
174  const CNormalChoice* pChoice = dynamic_cast<const CNormalChoice*>(&branch);
175  if (pChoice != NULL)
176  {
177  result = checkConditionTree(pChoice->getCondition());
178  if (result == true) result = checkExpressionTree(pChoice->getTrueExpression());
179  if (result == true) result = checkExpressionTree(pChoice->getFalseExpression());
180  }
181  else
182  {
183  const CNormalFraction* pFraction = dynamic_cast<const CNormalFraction*>(&branch);
184  if (pFraction == NULL)
185  {
186  result = false;
187  }
188  }
189  return result;
190 }
static bool checkConditionTree(const CNormalBase &branch)
const CNormalFraction & getTrueExpression() const
const CNormalLogical & getCondition() const
const CNormalFraction & getFalseExpression() const
static bool checkExpressionTree(const CNormalBase &branch)
CNormalBase * CNormalChoice::copy ( ) const
virtual

Implements CNormalBase.

Definition at line 128 of file CNormalChoice.cpp.

References CNormalChoice().

129  {
130  return new CNormalChoice(*this);
131  }
const CNormalLogical & CNormalChoice::getCondition ( ) const

Definition at line 98 of file CNormalChoice.cpp.

References mpCondition.

Referenced by checkConditionTree(), checkExpressionTree(), convertToCEvaluationNode(), and normalize_variable_names().

99  {
100  return *mpCondition;
101  }
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
CNormalLogical & CNormalChoice::getCondition ( )

Definition at line 103 of file CNormalChoice.cpp.

References mpCondition.

104 {
105  return *mpCondition;
106 }
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
const CNormalFraction & CNormalChoice::getFalseExpression ( ) const

Definition at line 118 of file CNormalChoice.cpp.

References mpFalse.

Referenced by checkConditionTree(), checkExpressionTree(), convertToCEvaluationNode(), and normalize_variable_names().

119  {
120  return *mpFalse;
121  }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction & CNormalChoice::getFalseExpression ( )

Definition at line 123 of file CNormalChoice.cpp.

References mpFalse.

124 {
125  return *mpFalse;
126 }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
const CNormalFraction & CNormalChoice::getTrueExpression ( ) const

Definition at line 108 of file CNormalChoice.cpp.

References mpTrue.

Referenced by checkConditionTree(), checkExpressionTree(), convertToCEvaluationNode(), and normalize_variable_names().

109  {
110  return *mpTrue;
111  }
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalFraction & CNormalChoice::getTrueExpression ( )

Definition at line 113 of file CNormalChoice.cpp.

References mpTrue.

114 {
115  return *mpTrue;
116 }
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
bool CNormalChoice::operator< ( const CNormalChoice rhs) const

Definition at line 224 of file CNormalChoice.cpp.

References mpCondition, mpFalse, and mpTrue.

225  {
226  bool result = false;
227  if ((*this->mpCondition) < (*rhs.mpCondition))
228  {
229  result = true;
230  }
231  else if ((*this->mpCondition) == (*rhs.mpCondition))
232  {
233  if ((*this->mpTrue) < (*rhs.mpTrue))
234  {
235  result = true;
236  }
237  else if ((*this->mpTrue) == (*rhs.mpTrue))
238  {
239  if ((*this->mpFalse) < (*rhs.mpFalse))
240  {
241  result = true;
242  }
243  }
244  }
245  return result;
246  }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
CNormalChoice & CNormalChoice::operator= ( const CNormalChoice src)

Definition at line 44 of file CNormalChoice.cpp.

References mpCondition, mpFalse, mpTrue, and pdelete.

45 {
47  pdelete(mpTrue);
49 
50  if (src.mpCondition != NULL)
52  if (src.mpCondition != NULL)
53  mpTrue = new CNormalFraction(*src.mpTrue);
54  if (src.mpCondition != NULL)
55  mpFalse = new CNormalFraction(*src.mpFalse);
56 
57  return *this;
58 }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
#define pdelete(p)
Definition: copasi.h:215
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
bool CNormalChoice::operator== ( const CNormalChoice rhs) const

Definition at line 214 of file CNormalChoice.cpp.

References mpCondition, mpFalse, and mpTrue.

215  {
216  bool result = true;
217  if (!(((*this->mpCondition) == (*rhs.mpCondition)) && ((*this->mpTrue) == (*rhs.mpTrue)) && ((*this->mpFalse) == (*rhs.mpFalse))))
218  {
219  result = false;
220  }
221  return result;
222  }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
bool CNormalChoice::setCondition ( const CNormalLogical cond)

Definition at line 60 of file CNormalChoice.cpp.

References checkConditionTree(), mpCondition, and pdelete.

Referenced by createChoice().

61 {
62  bool result = true;
63 
65 
66  // check the cond if it is OK
67  result = checkConditionTree(cond);
68  if (result == true)
69  mpCondition = new CNormalLogical(cond);
70 
71  return result;
72 }
#define pdelete(p)
Definition: copasi.h:215
static bool checkConditionTree(const CNormalBase &branch)
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
bool CNormalChoice::setFalseExpression ( const CNormalFraction branch)

Definition at line 87 of file CNormalChoice.cpp.

References checkExpressionTree(), mpFalse, and pdelete.

Referenced by createChoice().

88 {
89  bool result = true;
91 
92  // check the branch if it is OK
93  result = checkExpressionTree(branch);
94  mpFalse = new CNormalFraction(branch);
95  return result;
96 }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
#define pdelete(p)
Definition: copasi.h:215
static bool checkExpressionTree(const CNormalBase &branch)
bool CNormalChoice::setTrueExpression ( const CNormalFraction branch)

Definition at line 74 of file CNormalChoice.cpp.

References checkExpressionTree(), mpTrue, and pdelete.

Referenced by createChoice().

75 {
76  bool result = true;
77 
78  pdelete(mpTrue);
79 
80  // check the branch if it is OK
81  result = checkExpressionTree(branch);
82 
83  mpTrue = new CNormalFraction(branch);
84  return result;
85 }
#define pdelete(p)
Definition: copasi.h:215
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
static bool checkExpressionTree(const CNormalBase &branch)
bool CNormalChoice::simplify ( )
virtual

Implements CNormalBase.

Definition at line 205 of file CNormalChoice.cpp.

References mpCondition, mpFalse, mpTrue, CNormalFraction::simplify(), and CNormalLogical::simplify().

206 {
207  bool result = true;
208  if (this->mpCondition != NULL) result &= this->mpCondition->simplify();
209  if (this->mpTrue != NULL) result &= this->mpTrue->simplify();
210  if (this->mpFalse != NULL) result &= this->mpFalse->simplify();
211  return result;
212 }
virtual bool simplify()
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
virtual bool simplify()
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
std::string CNormalChoice::toString ( ) const
virtual

Implements CNormalBase.

Definition at line 192 of file CNormalChoice.cpp.

References mpCondition, mpFalse, mpTrue, CNormalFraction::toString(), and CNormalLogical::toString().

Referenced by operator<<().

193  {
194  std::ostringstream os;
195  os << "if(" << this->mpCondition->toString() << ") then (" << this->mpTrue->toString() << ") else (" << this->mpFalse->toString() << ")";
196  return os.str();
197  }
CNormalFraction * mpFalse
Definition: CNormalChoice.h:28
CNormalFraction * mpTrue
Definition: CNormalChoice.h:27
virtual std::string toString() const
CNormalLogical * mpCondition
Definition: CNormalChoice.h:26
virtual std::string toString() const

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CNormalChoice choice 
)
friend

Definition at line 199 of file CNormalChoice.cpp.

200 {
201  os << choice.toString();
202  return os;
203 }
virtual std::string toString() const

Member Data Documentation

CNormalLogical* CNormalChoice::mpCondition
protected
CNormalFraction* CNormalChoice::mpFalse
protected
CNormalFraction* CNormalChoice::mpTrue
protected

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