COPASI API  4.16.103
CKinFunction.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CKinFunction.cpp,v $
3 // $Revision: 1.68 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/05/17 16:39:23 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 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) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
16 // All rights reserved.
17 
18 /**
19  * CKinFunction
20  *
21  * Created for Copasi by Stefan Hoops
22  * (C) Stefan Hoops 2002
23  */
24 
25 #undef yyFlexLexer
26 #define yyFlexLexer CKinFunctionFlexLexer
27 
28 #include <sstream>
29 
30 #include "copasi.h"
31 
32 #include "CKinFunction.h"
35 #include "report/CCopasiObject.h"
36 #include "utilities/utility.h"
37 
38 CKinFunction::CKinFunction(const std::string & name,
39  const CCopasiContainer * pParent):
40  CFunction(name, pParent, CFunction::UserDefined)
41 {
43 }
44 
46  CReadConfig * configBuffer,
47  const CCopasiContainer * pParent):
48  CFunction(src, pParent)
49 {
51 
52  if (configBuffer)
53  {
54  C_INT32 i, Size;
55  configBuffer->getVariable("Nodes", "C_INT32", &Size);
56  mNodes.resize(Size);
57 
58  for (i = 0; i < Size; i++)
59  {
60  mNodes[i] = new CNodeK;
61  mNodes[i]->load(*configBuffer);
62  }
63 
65 
66  cleanupNodes();
67  }
68 
69  // compile();
70 }
71 
73  const CCopasiContainer * pParent):
74  CFunction(src, pParent)
75 {
77  //compile();
78 }
79 
81 {
82  /* int i;
83  for (i=0; i<ObjList.size(); i++)
84  ObjList[i] = NULL;
85  */
86  ObjList.clear();
87  cleanup();
89 }
90 
92 {
93  cleanupNodes();
94 }
95 
96 // This is only used when reading Gepasi Files
98 {
104 
105  size_t i, imax = mNodes.size();
106 
107  CFunctionParameter *pParameter;
108 
109  for (i = 0; i < imax; i++)
110  {
111  if (mNodes[i]->getType() == N_IDENTIFIER)
112  {
113  // We need to check that we have no reserved name.
114  const char *Reserved[] =
115  {"pi", "exponentiale", "true", "false", "infinity", "nan",
116  "PI", "EXPONENTIALE", "TRUE", "FALSE", "INFINITY", "NAN"
117  };
118 
119  std::string Name = mNodes[i]->getName();
120  size_t j, jmax = 12;
121 
122  for (j = 0; j < jmax; j++)
123  if (Name == Reserved[j]) break;
124 
125  if (j != jmax)
126  {
127  // It is save to prepend the identifyer with '_' since this is not allowed in
128  // Gepasi but within COPASI.
129  std::string OldName = Name;
130  Name = "_" + Name;
131 
132  // We have to replace the corresponding CEvaluationNodes to reflect the change.
133  std::vector< CEvaluationNode * >::iterator it = mpNodeList->begin();
134  std::vector< CEvaluationNode * >::iterator end = mpNodeList->end();
135 
136  for (; it != end; ++it)
137  if (((*it)->getType() & 0xFF000000) == CEvaluationNode::CONSTANT &&
138  (*it)->getData() == OldName)
139  (*it)->setData(Name);
140 
141  // The Infix has changed we need to update it.
143  }
144 
145  pParameter = new CFunctionParameter(Name);
147 
148  switch (mNodes[i]->getSubtype())
149  {
150  case N_SUBSTRATE:
152 
153  if (Substrates.getIndex(pParameter->getObjectName()) == C_INVALID_INDEX)
154  Substrates.add(pParameter, false);
155  else
156  pdelete(pParameter);
157 
158  break;
159 
160  case N_PRODUCT:
162 
163  if (Products.getIndex(pParameter->getObjectName()) == C_INVALID_INDEX)
164  Products.add(pParameter, false);
165  else
166  pdelete(pParameter);
167 
168  break;
169 
170  case N_MODIFIER:
172 
173  if (Modifiers.getIndex(pParameter->getObjectName()) == C_INVALID_INDEX)
174  Modifiers.add(pParameter, false);
175  else
176  pdelete(pParameter);
177 
178  break;
179 
180  case N_KCONSTANT:
181  case N_NOP:
183 
184  if (Parameters.getIndex(pParameter->getObjectName()) == C_INVALID_INDEX)
185  Parameters.add(pParameter, false);
186  else
187  pdelete(pParameter);
188 
189  break;
190 
191  case N_VOLUME:
193 
194  if (Volumes.getIndex(pParameter->getObjectName()) == C_INVALID_INDEX)
195  Volumes.add(pParameter, false);
196  else
197  pdelete(pParameter);
198 
199  break;
200 
201  default:
202  pdelete(pParameter);
203  fatalError();
204  }
205  }
206  }
207 
208  getVariables().cleanup();
209 
210  imax = Substrates.size();
211 
212  for (i = 0; i < imax; i++)
213  getVariables().add(Substrates[i], true);
214 
215  Substrates.cleanup();
216 
217  imax = Products.size();
218 
219  for (i = 0; i < imax; i++)
220  getVariables().add(Products[i], true);
221 
222  Products.cleanup();
223 
224  imax = Modifiers.size();
225 
226  for (i = 0; i < imax; i++)
227  getVariables().add(Modifiers[i], true);
228 
229  Modifiers.cleanup();
230 
231  imax = Parameters.size();
232 
233  for (i = 0; i < imax; i++)
234  getVariables().add(Parameters[i], true);
235 
236  Parameters.cleanup();
237 
238  imax = Volumes.size();
239 
240  for (i = 0; i < imax; i++)
241  getVariables().add(Volumes[i], true);
242 
243  Volumes.cleanup();
244 }
245 
246 std::vector< CNodeK * > & CKinFunction::getNodes() {return mNodes;}
247 
249 {
250  size_t i, imax = mNodes.size();
251 
252  for (i = 0; i < imax; i++)
253  if (mNodes[i]) delete mNodes[i];
254 
255  mNodes.clear();
256  return;
257 }
#define pdelete(p)
Definition: copasi.h:215
void setUsage(Role usage)
std::vector< CEvaluationNode * > * mpNodeList
const std::string & getObjectName() const
virtual size_t size() const
#define N_IDENTIFIER
Definition: CNodeK.h:37
#define fatalError()
std::string buildInfix() const
std::vector< CCopasiObject * > ObjList
Definition: CKinFunction.h:48
const CEvaluationTree::Type & getType() const
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
void setType(const CFunctionParameter::DataType &type)
#define C_INT32
Definition: copasi.h:90
virtual bool setInfix(const std::string &infix)
Definition: CFunction.cpp:73
#define N_SUBSTRATE
Definition: CNodeK.h:78
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
void add(const CFunctionParameter &parameter)
virtual bool add(const CType &src)
virtual void cleanup()
Header file of class CCopasiContainer.
Definition: CNodeK.h:84
void createParameters()
std::vector< CNodeK * > & getNodes()
#define N_NOP
Definition: CNodeK.h:33
void cleanupNodes()
CKinFunction(const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
The class for handling a chemical kinetic function.
Definition: CFunction.h:29
#define N_KCONSTANT
Definition: CNodeK.h:81
#define N_VOLUME
Definition: CNodeK.h:82
#define N_PRODUCT
Definition: CNodeK.h:79
C_INT32 getVariable(const std::string &name, const std::string &type, void *pout, CReadConfig::Mode mode=CReadConfig::NEXT)
Definition: CReadConfig.cpp:81
std::vector< CNodeK * > mNodes
Definition: CKinFunction.h:46
CFunctionParameters & getVariables()
Definition: CFunction.cpp:148
CEvaluationNode * mpRoot
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202
#define N_MODIFIER
Definition: CNodeK.h:80