COPASI API  4.16.103
CCallParameters.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2003 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "copasi.h"
16 #include "CCallParameters.h"
17 #include "CFunction.h"
18 
20 
21 // static
22 CCopasiObject * CFunctionParameterMap::pUnmappedObject = NULL;
23 
24 //TODO: modify the constructors so that CFunctionParameterMap behaves like a CCopasiObject
25 
27  mPointers(),
28  mObjects(),
29  mpFunctionParameters(NULL)
30 {
31  if (pUnmappedObject == NULL)
32  {
33  C_FLOAT64 InvalidValue = std::numeric_limits< C_FLOAT64 >::quiet_NaN();
34 
36  new CCopasiParameter("NaN", CCopasiParameter::DOUBLE, & InvalidValue);
37  }
38 };
39 
41  mPointers(src.mPointers),
42  mObjects(src.mObjects),
43  mpFunctionParameters(new CFunctionParameters(*src.mpFunctionParameters))
44 {
45  size_t i, imax = mpFunctionParameters->size();
46 
47  for (i = 0; i < imax; ++i)
48  if ((*mpFunctionParameters)[i]->getType() >= CFunctionParameter::VINT32)
49  {
50  mPointers[i].vector = new CCallParameters<C_FLOAT64>(*src.mPointers[i].vector);
51  mObjects[i].vector = new CCallParameters<CCopasiObject>(*src.mObjects[i].vector);
52  }
53 }
54 
56 {
59 };
60 
62 {
64 
67 
69 }
70 
72 {
74  {
75  size_t i, imax = mpFunctionParameters->size();
76 
77  for (i = 0; i < imax; i++)
78  {
79  if ((*mpFunctionParameters)[i]->getType() >= CFunctionParameter::VINT32)
80  {
81  if (mObjects[i].vector)
82  delete mObjects[i].vector;
83 
84  if (mPointers[i].vector)
85  delete mPointers[i].vector;
86  }
87  }
88  }
89 
90  mPointers.clear();
91  mObjects.clear();
92 }
93 
95 {
96  size_t i, imax = mpFunctionParameters->size();
97 
98  // Resizing call the CCallParameters clear() method and initializes
99  // all values to NULL.
100  mPointers.resize(imax);
101  mObjects.resize(imax);
102 
103  for (i = 0; i < imax; i++)
104  {
105  if ((*mpFunctionParameters)[i]->getType() >= CFunctionParameter::VINT32)
106  {
108  mPointers[i].vector = new CCallParameters<C_FLOAT64>;
109  }
110  }
111 }
112 
114 {
115  size_t i, imax = mpFunctionParameters->size();
116  size_t j, jmax;
117 
118  for (i = 0; i < imax; i++)
119  {
120  if (mPointers[i].vector == NULL)
121  fatalError();
122 
123  if (mObjects[i].vector == NULL)
124  fatalError();
125 
126  if ((*mpFunctionParameters)[i]->getType() < CFunctionParameter::VINT32)
127  continue;
128 
129  jmax = mPointers[i].vector->size();
130 
131  for (j = 0; j < jmax; j++)
132  if ((*mPointers[i].vector)[j].value == NULL)
133  fatalError();
134 
135  if (jmax != mObjects[i].vector->size()) fatalError();
136 
137  for (j = 0; j < jmax; j++)
138  if ((*mObjects[i].vector)[j].value == NULL)
139  fatalError();
140  }
141 }
142 
143 void CFunctionParameterMap::setCallParameter(const std::string paramName, const CCopasiObject* obj)
144 {
146  size_t index = findParameterByName(paramName, type);
147 
148  if (type >= CFunctionParameter::VINT32) fatalError(); // is a vector
149 
150  // TODO: check type of object
151  mObjects[index].value = obj;
152 
153  assert(obj->getValuePointer());
154  assert(obj->isValueDbl());
155  mPointers[index].value = (const C_FLOAT64*) obj->getValuePointer();
156 }
157 
158 void CFunctionParameterMap::addCallParameter(const std::string paramName, const CCopasiObject* obj)
159 {
161  size_t index = findParameterByName(paramName, type);
162 
163  if (type < CFunctionParameter::VINT32) fatalError(); // is not a vector
164 
165  assert(obj->getValuePointer());
166  assert(obj->isValueDbl());
167 
168  mObjects[index].vector->push_back(obj);
169  mPointers[index].vector->push_back((const C_FLOAT64*) obj->getValuePointer());
170 }
171 
172 void CFunctionParameterMap::clearCallParameter(const std::string paramName)
173 {
175  size_t index = findParameterByName(paramName, type);
176 
177  if (type < CFunctionParameter::VINT32) fatalError(); // is not a vector
178 
179  // TODO: check type of object
180  mObjects[index].vector->clear();
181 
182  mPointers[index].vector->clear();
183 }
184 
185 size_t CFunctionParameterMap::findParameterByName(const std::string & name,
186  CFunctionParameter::DataType & dataType) const
187 {
188  return mpFunctionParameters->findParameterByName(name, dataType);
189 }
190 
192 {
193  return mPointers;
194 }
195 
197 {
198  return mPointers;
199 }
200 
201 std::vector< const CCopasiObject * > CFunctionParameterMap::getObjects(const size_t & index) const
202 {
203  std::vector< const CCopasiObject * > Objects;
204 
205  if (index != C_INVALID_INDEX)
206  {
207  if ((*mpFunctionParameters)[index]->getType() < CFunctionParameter::VINT32)
208  Objects.push_back(mObjects[index].value);
209  else
210  {
211  size_t i, imax = mObjects[index].vector->size();
212 
213  for (i = 0; i < imax; i++)
214  Objects.push_back((*mObjects[index].vector)[i].value);
215  }
216  }
217 
218  return Objects;
219 }
220 
221 // CCallParameters<CCopasiObject> & CFunctionParameterMap::getObjects() {return mObjects;};
222 
224 {return mObjects;};
225 
227 {return * mpFunctionParameters;};
#define pdelete(p)
Definition: copasi.h:215
void clearCallParameter(const std::string paramName)
void push_back(const Type *value)
#define fatalError()
const CFunctionParameters & getFunctionParameters() const
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
CCallParameters< CCopasiObject > & getObjects()
void resize(const size_t &size)
#define C_INVALID_INDEX
Definition: copasi.h:222
CFunctionParameters * mpFunctionParameters
CCallParameters< C_FLOAT64 > & getPointers()
CCallParameters< C_FLOAT64 > mPointers
#define C_FLOAT64
Definition: copasi.h:92
void initializeFromFunctionParameters(const CFunctionParameters &src)
size_t size() const
void setCallParameter(const std::string paramName, const CCopasiObject *obj)
void checkCallParameters() const
static CCopasiObject * pUnmappedObject
bool isValueDbl() const
virtual void * getValuePointer() const
void addCallParameter(const std::string paramName, const CCopasiObject *obj)
CCallParameters< CCopasiObject > mObjects
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const