COPASI API  4.16.103
CCopasiParameter.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2013 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 #ifndef COPASI_CCopasiParameter
16 #define COPASI_CCopasiParameter
17 
18 #include <string>
19 #include <vector>
20 
23 
25 
26 class CReadConfig;
27 
28 /**
29  * CCopasiParameter class.
30  * This class is used to describe parameters. This class is intended
31  * to be used with integration or optimization methods or reactions.
32  *
33  * Created for COPASI by Stefan Hoops 2002
34  */
36 {
37  // Attributes
38 public:
39  enum Type
40  {
41  DOUBLE = 0,
43  INT,
48  CN,
49  KEY,
53  };
54 
55  union Value
56  {
60  unsigned C_INT32 * pUINT;
61  bool * pBOOL;
62  std::vector< CCopasiParameter * > * pGROUP;
63  std::string * pSTRING;
65  std::string * pKEY;
66  std::string * pFILE;
67  std::string * pEXPRESSION;
68  void * pVOID;
69  };
70 
71  /**
72  * String literals for the GUI to display type names of parameters known
73  * to COPASI.
74  */
75  static const std::string TypeName[];
76 
77  /**
78  * XML type names of parameters known to COPASI.
79  */
80  static const char* XMLType[];
81 
82 protected:
83  /**
84  * The key of the parameter.
85  */
86  std::string mKey;
87 
88 private:
89  /**
90  * The type of the parameter
91  */
93 
94 protected:
95  /**
96  * The size allocated for the value of the parameter.
97  */
98  size_t mSize;
99 
100  /**
101  * A pointer to the value of the parameter.
102  */
104 
105  /**
106  * A pointer to the object reference for the value
107  */
109 
110  // Operations
111 
112 private:
113  /**
114  * Default constructor
115  */
117 
118 public:
119  /**
120  * Copy constructor
121  * @param const CCopasiParameter & src
122  * @param const CCopasiContainer * pParent (default: NULL)
123  */
125  const CCopasiContainer * pParent = NULL);
126 
127  /**
128  * Specific constructor
129  * @param const string & name
130  * @param const CCopasiParameter::Type & type
131  * @param const void * pValue (default: NULL)
132  * @param const CCopasiContainer * pParent (default: NULL)
133  * @param const std::string & objectType (default: "Parameter")
134  */
135  CCopasiParameter(const std::string & name,
136  const Type & type,
137  const void * pValue = NULL,
138  const CCopasiContainer * pParent = NULL,
139  const std::string & objectType = "Parameter");
140 
141  /**
142  * Destructor
143  */
144  virtual ~CCopasiParameter();
145 
146  /**
147  * Assignment operator
148  * @param const CCopasiParameter & rhs
149  * @return CCopasiParameter & lhs
150  */
152 
153  /**
154  * Return the key of this model
155  * @return string key
156  */
157  virtual const std::string & getKey() const;
158 
159  /**
160  * Set the value of the parameter
161  * @param const const CType & value
162  * @return bool isValidValue
163  */
164  template <class CType> bool setValue(const CType & value)
165  {
166  if (!isValidValue(value)) return false;
167 
168  *(CType *) mValue.pVOID = value;
169  return true;
170  }
171 
172  /**
173  * Set the value of the parameter when the origin is a parameter group.
174  * This function is currently not implemented and creates a fatalError
175  * when called.
176  * @param const CCopasiParameter::parameterGroup& value
177  * @return bool false
178  */
179  bool setValue(const std::vector< CCopasiParameter * > & value);
180 
181  /**
182  * Retrieve the private value of the parameter.
183  * @return const CCopasiParameter::Value & Value
184  */
185  const Value & getValue() const;
186 
187  /**
188  * Retrieve the private value of the parameter.
189  * @return CCopasiParameter::Value & Value
190  */
191  Value & getValue();
192 
193  /**
194  * Retrieve the object which represents the value of the parameter
195  * @return CCopasiObject * pValueReference
196  */
198 
199  /**
200  * Retrieve the type of the parameter.
201  * @return CCopasiParameter::Type & type
202  */
203  const CCopasiParameter::Type & getType() const;
204 
205  /**
206  * Check whether the value corresponds to the type
207  * @param const C_FLOAT64 & value
208  * @return bool isValidValue
209  */
210  bool isValidValue(const C_FLOAT64 & value) const;
211 
212  /**
213  * Check whether the value corresponds to the type
214  * @param const C_INT32 & value
215  * @return bool isValidValue
216  */
217  bool isValidValue(const C_INT32 & value) const;
218 
219  /**
220  * Check whether the value corresponds to the type
221  * @param const unsigned C_INT32 & value
222  * @return bool isValidValue
223  */
224  bool isValidValue(const unsigned C_INT32 & value) const;
225 
226  /**
227  * Check whether the value corresponds to the type
228  * @param const bool & value
229  * @return bool isValidValue
230  */
231  bool isValidValue(const bool & value) const;
232 
233  /**
234  * Check whether the value corresponds to the type
235  * @param const std::string & value
236  * @return bool isValidValue
237  */
238  bool isValidValue(const std::string & value) const;
239 
240  /**
241  * Check whether the value corresponds to the type
242  * @param const CRegisteredObjectName & value
243  * @return bool isValidValue
244  */
245  bool isValidValue(const CCopasiObjectName & value) const;
246 
247  /**
248  * Check whether the value corresponds to the type
249  * @param const CCopasiParameterGroup::parameterGroup & value
250  * @return bool isValidValue
251  */
252  bool isValidValue(const std::vector< CCopasiParameter * > & value) const;
253 
254  /**
255  * This is the output method for any object. The default implementation
256  * provided with CCopasiObject uses the ostream operator<< of the object
257  * to print the object.To override this default behavior one needs to
258  * reimplement the virtual print function.
259  * @param std::ostream * ostream
260  */
261  virtual void print(std::ostream * ostream) const;
262 
263  /**
264  * Output stream operator
265  * @param ostream & os
266  * @param const CCopasiParameter & A
267  * @return ostream & os
268  */
269  friend std::ostream &operator<<(std::ostream &os, const CCopasiParameter & o);
270 
271  /**
272  * Comparison operator
273  * @param const CCopasiParameter & lhs
274  * @param const CCopasiParameter & rhs
275  * @return bool equal
276  */
277  friend bool operator==(const CCopasiParameter & lhs, const CCopasiParameter & rhs);
278 
279  /**
280  * Retrieve the CN of the math container
281  * The math container provides values for the numerical values of model objects.
282  * For the CN mechanism to work properly it has to pretend to be the model.
283  * @return CCopasiObjectName
284  */
285  virtual CCopasiObjectName getCN() const;
286 
287  virtual void * getValuePointer() const;
288 
289  /**
290  * Overload display name. Special treatment for reaction parameters
291  * to provide a shorter display.
292  */
293  virtual std::string getObjectDisplayName(bool regular = true, bool richtext = false) const;
294 
295 private:
296  /**
297  * Create or copy the value
298  * @param const CCopasiParameter::Value & value
299  * @return CCopasiParameter::Value Value
300  */
301  Value createValue(const Value & value);
302 
303  /**
304  * Delete the value
305  */
306  void deleteValue();
307 };
308 
309 #endif // COPASI_CCopasiParameter
friend std::ostream & operator<<(std::ostream &os, const CCopasiParameter &o)
bool setValue(const CType &value)
objectType
static const std::string TypeName[]
bool isValidValue(const C_FLOAT64 &value) const
CCopasiParameter::Type mType
CCopasiParameter & operator=(const CCopasiParameter &rhs)
CCopasiObject * mpValueReference
std::vector< CCopasiParameter * > * pGROUP
CCopasiObject * getValueReference() const
virtual void * getValuePointer() const
#define C_INT32
Definition: copasi.h:90
CRegisteredObjectName * pCN
const CCopasiParameter::Type & getType() const
virtual const std::string & getKey() const
const Value & getValue() const
unsigned C_INT32 * pUINT
virtual void print(std::ostream *ostream) const
Value createValue(const Value &value)
Header file of class CCopasiContainer.
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
virtual CCopasiObjectName getCN() const
#define C_FLOAT64
Definition: copasi.h:92
friend bool operator==(const CCopasiParameter &lhs, const CCopasiParameter &rhs)
static const char * XMLType[]