COPASI API  4.16.103
CFunctionParameters.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/function/CFunctionParameters.cpp,v $
3 // $Revision: 1.43 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:28:18 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 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  * CFunctionParameters
20  *
21  * Created for Copasi by Stefan Hoops
22  * (C) Stefan Hoops 2001
23  */
24 
25 #include "copasi.h"
26 #include "CFunctionParameters.h"
28 
30  const CCopasiContainer * pParent):
31  CCopasiContainer(name, pParent, "Variable Description"),
32  mParameters("Variables", this)
34 
36  const CCopasiContainer * pParent):
37  CCopasiContainer(src, pParent),
38  mParameters(src.mParameters, this)
40 
42 
44 {
46 }
47 
49 {
51  return *this;
52 }
53 
55 {
56  mParameters.add(parameter);
57 }
58 
60  const bool & adopt)
61 {
62  mParameters.add(parameter, adopt);
63 
64  return true;
65 }
66 
67 bool CFunctionParameters::add(const std::string & name,
68  const CFunctionParameter::DataType & type,
70 {
71  size_t Index = mParameters.getIndex(name);
72 
73  if (Index != C_INVALID_INDEX)
74  return false;
75 
76  CFunctionParameter *parameter =
77  new CFunctionParameter(name, type, usage);
78  mParameters.add(parameter, true);
79 
80  return true;
81 }
82 
83 void CFunctionParameters::remove(const std::string & name)
84 {
85  mParameters.remove(name);
86 }
87 
89 {return mParameters[index];}
90 
92 {return mParameters[index];}
93 
95 {return mParameters[name];}
96 
97 const CFunctionParameter * CFunctionParameters::operator[](const std::string &name) const
98 {return mParameters[name];}
99 
100 size_t CFunctionParameters::size() const {return mParameters.size();}
101 
102 void CFunctionParameters::swap(const size_t & from, const size_t & to)
103 {mParameters.swap(from, to);}
104 
105 const CFunctionParameter *
107  size_t & pos) const
108 {
109  size_t i, imax = mParameters.size();
110 
111  for (i = pos; i < imax; i++)
112  if (mParameters[i]->getUsage() == usage)
113  {
114  pos = i + 1;
115  return mParameters[i];
116  }
117 
120  CFunctionParameter::RoleNameDisplay[usage].c_str(), pos);
121 
122  return NULL;
123 }
124 
126 {
127  size_t i, imax = mParameters.size();
128  size_t count = 0;
129 
130  for (i = 0; i < imax; i++)
131  if (mParameters[i]->getUsage() == usage) ++count;
132 
133  return count;
134 }
135 
136 size_t CFunctionParameters::findParameterByName(const std::string & name,
137  CFunctionParameter::DataType & dataType) const
138 {
139  //std::string VectorName = name.substr(0, name.find_last_of('_'));
140  std::string Name;
141  size_t i, imax = mParameters.size();
142 
143  for (i = 0; i < imax; i++)
144  {
145  Name = mParameters[i]->getObjectName();
146 
147  if (Name == name)
148  {
149  dataType = mParameters[i]->getType();
150  return i;
151  }
152  }
153 
154  return C_INVALID_INDEX;
155 }
156 
158 {
159  size_t i, imax = mParameters.size();
160 
161  for (i = 0; i < imax; i++)
162  if (mParameters[i]->getUsage() == role)
163  return mParameters[i]->getType() >= CFunctionParameter::VINT32;
164 
165  //this assumes that if a parameter is not a vector then there
166  //will not be a vector parameter with the same role.
167  return false;
168 }
169 
171 {
172  if (size() != rhs.size()) return false;
173 
174  CFunctionParameter::Role lhsRole, rhsRole;
175 
176  size_t i, imax = size();
177 
178  for (i = 0; i < imax; ++i)
179  {
180  if (mParameters[i]->getObjectName() != rhs.mParameters[i]->getObjectName()) return false;
181 
182  if (mParameters[i]->getType() != rhs.mParameters[i]->getType()) return false;
183 
184  lhsRole = mParameters[i]->getUsage();
185  rhsRole = rhs.mParameters[i]->getUsage();
186 
187  // We do not destinguish between PARAMETER and VARIABLE
188  if ((lhsRole == CFunctionParameter::PARAMETER || lhsRole == CFunctionParameter::VARIABLE) &&
190  continue;
191 
192  if (lhsRole != rhsRole) return false;
193  }
194 
195  return true;
196 }
197 
198 std::ostream & operator<<(std::ostream &os, const CFunctionParameters & d)
199 {
200  //os << "++++CFunctionParameters: " << std::endl;
201  //os << " CFunctionParameters.mParameters " << std::endl << d.mParameters;
202  //os << "----CFunctionParameters " << std::endl;
203 
204  size_t i, imax = d.mParameters.size();
205 
206  for (i = 0; i < imax; ++i)
207  {
208  if (0 == i)
209  os << " (";
210  else
211  os << " ";
212 
213  os << *d.mParameters[i];
214 
215  if (imax - 1 == i)
216  os << ")\n";
217  else
218  os << ",\n";
219  }
220 
221  return os;
222 }
void swap(const size_t &from, const size_t &to)
#define MCFunctionParameters
virtual void swap(const size_t &indexFrom, const size_t &indexTo)
CFunctionParameter * operator[](size_t index)
const std::string & getObjectName() const
virtual size_t size() const
CFunctionParameters(const std::string &name="NoName", const CCopasiContainer *pParent=NULL)
bool operator==(const CFunctionParameters &rhs) const
size_t findParameterByName(const std::string &name, CFunctionParameter::DataType &dataType) const
size_t getNumberOfParametersByUsage(CFunctionParameter::Role usage) const
#define C_INVALID_INDEX
Definition: copasi.h:222
virtual size_t getIndex(const std::string &name) const
CCopasiVectorNS< CFunctionParameter > mParameters
#define DESTRUCTOR_TRACE
Definition: copasi.h:206
void add(const CFunctionParameter &parameter)
virtual bool add(const CType &src)
void deepCopy(const CCopasiVector< CType > &source)
virtual void cleanup()
void remove(const std::string &name)
const CFunctionParameter * getParameterByUsage(CFunctionParameter::Role usage, size_t &pos) const
virtual void remove(const std::string &name)
CFunctionParameters & operator=(const CFunctionParameters &src)
static const std::string RoleNameDisplay[]
bool isVector() const
std::ostream & operator<<(std::ostream &os, const CFunctionParameters &d)
#define CONSTRUCTOR_TRACE
Definition: copasi.h:202