COPASI API  4.16.103
CNodeK.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CNodeK.h,v $
3  $Revision: 1.21 $
4  $Name: $
5  $Author: gauges $
6  $Date: 2006/10/15 07:16:08 $
7  End CVS Header */
8 
9 // Copyright 2005 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc. and EML Research, gGmbH.
11 // All rights reserved.
12 
13 /* CNodeK
14  *
15  * CNodeK.cpp based on UDKType.cpp from
16  * (C) Pedro Mendes 1995-2000
17  *
18  * Created for Copasi by Stefan Hoops
19  * (C) Stefan Hoops 2001
20  */
21 
22 #ifndef COPASI_CNodeK
23 #define COPASI_CNodeK
24 
25 #include <string>
26 #include <vector>
27 
28 #include "utilities/CReadConfig.h"
29 //#include "utilities/CWriteConfig.h"
31 
32 // symbols for CNodeK types and values
33 #define N_NOP '@'
34 
35 #define N_ROOT '%' // the root note
36 #define N_OPERATOR 'O' // operator: + - * / ^ ()
37 #define N_IDENTIFIER 'I' // see specific subtypes
38 #define N_FUNCTION 'F' // see specific subtypes
39 #define N_OBJECT 'o' // an object
40 #define N_NUMBER 'N' // a C_FLOAT64 constant
41 
42 // subtypes for N_FUNCTION
43 #define N_LOG10 'L'
44 #define N_LOG 'l'
45 #define N_EXP 'e'
46 #define N_SIN 'S'
47 #define N_COS 'C'
48 #define N_RND 'R'
49 #define N_GAUSS 'G'
50 #define N_BOLTZ 'B'
51 
52 #define N_TAN 't'
53 #define N_SEC 'a'
54 #define N_CSC 'b'
55 #define N_COT 'c'
56 #define N_SINH 'd'
57 #define N_COSH 'f'
58 #define N_TANH 'g'
59 #define N_SECH 'h'
60 #define N_CSCH 'i'
61 #define N_COTH 'j'
62 #define N_ARCSIN 'n'
63 #define N_ARCCOS 'q'
64 #define N_ARCTAN 'r'
65 #define N_ARCSEC 'u'
66 #define N_ARCCSC 'v'
67 #define N_ARCCOT 'w'
68 #define N_ARCSINH 'x'
69 #define N_ARCCOSH 'y'
70 #define N_ARCTANH 'z'
71 #define N_ARCSECH 'A'
72 #define N_ARCCSCH 'D'
73 #define N_ARCCOTH 'E'
74 #define N_ABS 'H'
75 #define N_SQRT 'J'
76 
77 // subtypes for N_IDENTIFIER
78 #define N_SUBSTRATE 's'
79 #define N_PRODUCT 'p'
80 #define N_MODIFIER 'm'
81 #define N_KCONSTANT 'k'
82 #define N_VOLUME 'V'
83 
84 /** @dia:pos 12.7478,42.4925 */
85 class CNodeK
86  {
87  // Attributes
88  private:
89  /**
90  * The type of the node. One of N_ROOT, N_OPERATOR, N_IDENTIFIER,
91  * N_FUNCTION, N_NUMBER
92  */
93  char mType;
94 
95  /**
96  * The subtype of a node.
97  * for type N_FUNCTION one of: N_LOG10, N_LOG, N_EXP, N_SIN, N_COS,
98  * N_RND, N_GAUSS, N_BOLTZ
99  * for type N_IDENTIFIER one of:N_SUBSTRATE, N_PRODUCT, N_MODIFIER,
100  * N_KCONSTANT
101  * for type N_OPERATOR one of: + - * / ^ () ...
102  */
103  char mSubtype;
104 
105  /**
106  * The left branch of the tree originating from tyhis node
107  */
108  CNodeK * mLeft;
109 
110  /**
111  * The right branch of the tree originating from tyhis node
112  */
113  CNodeK * mRight;
114 
115  /**
116  * The value of a node of type N_NUMBER
117  */
119 
120  /**
121  * The name of the node for type N_IDENTIFIER
122  */
123  std::string mName;
124 
125  /**
126  * The index of the node for type N_IDENTIFIER
127  */
128  C_INT32 mIndex;
129 
130  /**
131  * The index in old Gepasi format
132  */
134 
135  /**
136  * WHAT IS THIS FOR??? PLEASE ADD COMMENT!
137  */
138  int attribute1;
139 
140  /**
141  * The explicit function string
142  */
143  std::string mExplicitFunction;
144 
145  // Operations
146  public:
147  /**
148  * Default constructor
149  */
150  CNodeK();
151 
152  /**
153  * Copy constructor
154  * @param "const CNodeK &" src
155  */
156  CNodeK(const CNodeK & src);
157 
158  /**
159  * Constructor for operator
160  * @param "const char" type
161  * @param "const char" subtype
162  */
163  CNodeK(char type, char subtype);
164 
165  /**
166  * Constructor for identifier
167  * @param "const string" &name
168  */
169  CNodeK(const std::string & name);
170 
171  /**
172  * Constructor for a constant
173  * @param "const C_FLOAT64" constant
174  */
175  CNodeK(C_FLOAT64 constant);
176 
177  /**
178  * Destructor
179  */
180  ~CNodeK();
181 
182  /**
183  * Delete
184  */
185  void cleanup();
186 
187  /**
188  * Loads an object with data coming from a CReadConfig object.
189  * (CReadConfig object reads an input stream)
190  * @param pconfigbuffer reference to a CReadConfig object.
191  * @return Fail
192  */
193  C_INT32 load(CReadConfig & configbuffer);
194 
195  /**
196  * Returns a string that contains the equation defined from
197  * this node downwards. The function contains explicit names
198  * of node identifiers, rather than the abstract symbol.
199  * @param "const CCallParameters &" callParameterNames a vector of string pointers with identifier names
200  * @param "const string &" r a suffix for parameter names (usually reaction number)
201  * @return string
202  */
203  std::string getExplicitFunctionString(const std::vector< std::vector< std::string > > & callParameterNames,
204  const std::string &r);
205 
206  void writeMathML(std::ostream & out, C_INT32 level) const;
207 
208  /**
209  * Retrieving mType the type of a node
210  * @return char
211  */
212  char getType() const;
213 
214  /**
215  * Retrieving mSubtype the subtype of a node
216  * @return char
217  */
218  char getSubtype() const;
219 
220  /**
221  * Retrieving mLeft the left branch of a node
222  * @return CNodeK
223  */
224  CNodeK & getLeft() const;
225 
226  /**
227  * Retrieving mName the name of a node
228  * @return string
229  */
230  CNodeK & getRight() const;
231 
232  /**
233  * Retrieving mName the name of a node
234  * @return string
235  */
236  std::string getName() const;
237 
238  /**
239  * Retrieving value of a node
240  * @return C_FLOAT64
241  */
242  C_FLOAT64 getConstant() const;
243 
244  /**
245  * Retrieving index the name of a node
246  * @return C_INT32
247  */
248  C_INT32 getIndex() const;
249 
250  /**
251  * Setting mType the subtype of a node
252  * @param "const char" type
253  */
254  void setType(const char ype);
255 
256  /**
257  * Setting mSubtype the subtype of a node
258  * @param "const char" subtype
259  */
260  void setSubtype(const char subtype);
261 
262  /**
263  * Setting mLeft the pointer to the left branch
264  * @param CNodeK &left
265  */
266  void setLeft(CNodeK & left);
267 
268  /**
269  * Setting mLeft the pointer to the left branch
270  * @param CNodeK *pleft
271  */
272  void setLeft(CNodeK * pleft);
273 
274  /**
275  * Setting mRight the pointer to the right branch
276  * @param CNodeK &right
277  */
278  void setRight(CNodeK & right);
279 
280  /**
281  * Setting mRight the pointer to the right branch
282  * @param CNodeK *pright
283  */
284  void setRight(CNodeK * pright);
285 
286  /**
287  * Setting mName the name of an identifier
288  * @param "const string" &name
289  */
290  void setName(const std::string & name);
291 
292  /**
293  * Setting the value of a number
294  * @param C_FLOAT64 &constant
295  */
296  void setConstant(C_FLOAT64 & constant);
297 
298  /**
299  * Setting the index of an identifier
300  * @param C_INT32 &index
301  */
302  void setIndex(C_INT32 index);
303 
304  /**
305  * Setting the old index
306  * (Gepasi format, each type is indexed separately)
307  * @param C_INT32 &index
308  */
309  void setOldIndex(C_INT32 oldindex);
310 
311  /**
312  * This checks whether mLeft points to a valid CNodeK
313  * @return int 1 or 0
314  */
315  C_INT16 isLeftValid() const;
316 
317  /**
318  * This checks whether mRight points to a valid CNodeK
319  * @return int 1 or 0
320  */
321  C_INT16 isRightValid() const;
322 
323  /**
324  * This checks whether the node is a number (mType = N_NUMBER)
325  * @return int 1 or 0
326  */
327  C_INT16 isNumber() const;
328 
329  /**
330  * This checks whether the node is an identifier (mType = N_IDENTIFIER)
331  * @return int 1 or 0
332  */
333  C_INT16 isIdentifier() const;
334 
335  /**
336  * This checks whether the node is a operator (mType = N_OPERATOR)
337  * @return int 1 or 0
338  */
339  C_INT16 isOperator() const;
340 
341  /**
342  * This returns the left precedence value of a node
343  * @return int
344  */
345  C_INT16 leftPrecedence() const;
346 
347  /**
348  * This returns the right precedence value of a node
349  * @return int
350  */
351  C_INT16 rightPrecedence() const;
352 
353  /**
354  * This calculates the value of this sub-tree (ie with this node as root)
355  * @param const CCallParameters<C_FLOAT64> & callParameters
356  * @return C_FLOAT64
357  */
358  C_FLOAT64 value(const CCallParameters<C_FLOAT64> & callParameters) const;
359  };
360 
361 #endif // COPASI_CNodeK
C_INT16 rightPrecedence() const
Definition: CNodeK.cpp:504
char mType
Definition: CNodeK.h:92
void setLeft(CNodeK &left)
Definition: CNodeK.cpp:395
CNodeK & getLeft() const
Definition: CNodeK.cpp:340
C_INT16 isRightValid() const
Definition: CNodeK.cpp:440
void writeMathML(std::ostream &out, C_INT32 level) const
CNodeK & getRight() const
Definition: CNodeK.cpp:348
void setConstant(C_FLOAT64 &constant)
Definition: CNodeK.cpp:420
void setIndex(C_INT32 index)
Definition: CNodeK.cpp:425
~CNodeK()
Definition: CNodeK.cpp:96
std::string mName
Definition: CNodeK.h:122
char getSubtype() const
Definition: CNodeK.cpp:335
C_INT32 mOldIndex
Definition: CNodeK.h:132
#define C_INT32
Definition: copasi.h:90
std::string mExplicitFunction
Definition: CNodeK.h:142
void cleanup()
Definition: CNodeK.cpp:93
C_INT16 isLeftValid() const
Definition: CNodeK.cpp:435
char getType() const
Definition: CNodeK.cpp:330
std::string getName() const
Definition: CNodeK.cpp:356
C_FLOAT64 getConstant() const
Definition: CNodeK.cpp:375
C_INT16 isNumber() const
Definition: CNodeK.cpp:445
void setOldIndex(C_INT32 oldindex)
Definition: CNodeK.cpp:430
C_INT16 isIdentifier() const
Definition: CNodeK.cpp:450
void setName(const std::string &name)
Definition: CNodeK.cpp:415
#define C_INT16
Definition: copasi.h:91
std::string getExplicitFunctionString(const std::vector< std::vector< std::string > > &callParameterNames, const std::string &r)
C_FLOAT64 value(const CCallParameters< C_FLOAT64 > &callParameters) const
C_INT32 getIndex() const
Definition: CNodeK.cpp:380
C_FLOAT64 mConstant
Definition: CNodeK.h:117
C_INT32 mIndex
Definition: CNodeK.h:127
Definition: CNodeK.h:84
void setType(const char ype)
Definition: CNodeK.cpp:385
#define C_FLOAT64
Definition: copasi.h:92
void setSubtype(const char subtype)
Definition: CNodeK.cpp:390
CNodeK * mLeft
Definition: CNodeK.h:107
int attribute1
Definition: CNodeK.h:137
void setRight(CNodeK &right)
Definition: CNodeK.cpp:405
C_INT16 isOperator() const
Definition: CNodeK.cpp:467
CNodeK * mRight
Definition: CNodeK.h:112
char mSubtype
Definition: CNodeK.h:102
C_INT16 leftPrecedence() const
Definition: CNodeK.cpp:472
CNodeK()
Definition: CNodeK.cpp:31
C_INT32 load(CReadConfig &configbuffer)
Definition: CNodeK.cpp:101