COPASI API  4.16.103
CCopasiObjectReference.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) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * Class CCopasiObjectReference
17  *
18  * This class is the is used to make an existing object globally accessible.
19  *
20  * Copyright Stefan Hoops 2002
21  */
22 
23 #ifndef COPASI_CCopasiObjectReference
24 #define COPASI_CCopasiObjectReference
25 
26 #include "report/CCopasiObject.h"
28 
29 template <class CType> class CCopasiObjectReference: public CCopasiObject
30 {
31 public:
32  typedef CType referenceType;
33 
34  //Attributes
35 private:
36  CType * mpReference;
37 
38  //Operations
39 private:
41  mpReference(NULL)
42  {};
43 
44  void updateMethod(const CType & value)
45  {*mpReference = value;}
46 
47 public:
48  CCopasiObjectReference(const std::string & name,
49  const CCopasiContainer * pParent,
50  referenceType & reference,
51  const unsigned C_INT32 & flag = 0):
52  CCopasiObject(name, pParent, "Reference",
55  flag),
56  mpReference(&reference)
57  {assert(pParent != NULL);}
58 
60  const CCopasiContainer * pParent):
61  CCopasiObject(src, pParent),
63  {}
64 
66 
67  virtual void * getValuePointer() const {return mpReference;}
68 
69  virtual const CCopasiObject * getValueObject() const {return this;}
70 
71  virtual void setReference(referenceType & reference)
72  {mpReference = &reference;}
73 
74  virtual void print(std::ostream * ostream) const
75  {(*ostream) << *mpReference;};
76 
77  virtual std::string getObjectDisplayName(bool regular = true, bool richtext = false) const
78  {
79  //Suppress "Value"
80  if (getObjectParent() && getObjectName() == "Value")
81  return getObjectParent()->getObjectDisplayName(regular, richtext);
82 
83  //special treatment of metab children
84  if (getObjectParent()->getObjectType() == "Metabolite")
85  {
86  if (getObjectName() == "Concentration")
87  {
88  if (richtext)
89  {
90  return "<font color=\"#2222cc\">[</font>"
91  + getObjectParent()->getObjectDisplayName(regular, richtext)
92  + "<font color=\"#2222cc\">]</font>";
93  }
94  else
95  {return "[" + getObjectParent()->getObjectDisplayName(regular, richtext) + "]";}
96  }
97 
98  if (getObjectName() == "InitialConcentration")
99  {
100  if (richtext)
101  {
102  return "<font color=\"#2222cc\">[</font>"
103  + getObjectParent()->getObjectDisplayName(regular, richtext)
104  + "<font color=\"#2222cc\">]<sub>0</sub></font>";
105  }
106  else
107  {return "[" + getObjectParent()->getObjectDisplayName(regular, richtext) + "]_0";}
108  }
109  }
110 
111  return CCopasiObject::getObjectDisplayName(regular, richtext);
112  }
113 };
114 
115 template<> inline
117  const CCopasiContainer * pParent,
118  referenceType & reference,
119  const unsigned C_INT32 & flag):
120  CCopasiObject(name, pParent, "Reference",
121  CCopasiObject::Reference |
122  CCopasiObject::NonUniqueName |
123  CCopasiObject::ValueDbl |
124  flag),
125  mpReference(&reference)
126 {
127  assert(pParent != NULL);
129 }
130 
131 template<> inline
133  const CCopasiContainer * pParent,
134  referenceType & reference,
135  const unsigned C_INT32 & flag):
136  CCopasiObject(name, pParent, "Reference",
137  CCopasiObject::Reference |
138  CCopasiObject::NonUniqueName |
139  CCopasiObject::ValueInt |
140  flag),
141  mpReference(&reference)
142 {
143  assert(pParent != NULL);
145 }
146 
147 template<> inline
149  const CCopasiContainer * pParent,
150  referenceType & reference,
151  const unsigned C_INT32 & flag):
152  CCopasiObject(name, pParent, "Reference",
153  CCopasiObject::Reference |
154  CCopasiObject::NonUniqueName |
155  CCopasiObject::ValueBool |
156  flag),
157  mpReference(&reference)
158 {
159  assert(pParent != NULL);
161 }
162 
163 template <class CType> class CCopasiVectorReference: public CCopasiObject
164 {
165 public:
166  typedef CType referenceType;
167 
168  //Attributes
169 private:
170  CType & mReference;
171 
172  //Operations
173 private:
175  mReference(CType())
176  {};
177 
178 public:
179  CCopasiVectorReference(const std::string & name,
180  const CCopasiContainer * pParent,
181  referenceType & reference,
182  const unsigned C_INT32 & flag = 0):
183  CCopasiObject(name, pParent, "Reference",
186  flag),
187  mReference(reference)
188  {assert(pParent != NULL);}
189 
191  const CCopasiContainer * pParent):
192  CCopasiObject(src, pParent),
194  {}
195 
197 
199  {
200 #ifdef WIN32
202 #else
204 #endif
205  (getObjectName() + cn,
206  getObjectParent(),
207  mReference[cn.getElementIndex()],
211  );
212  }
213 
214  virtual void * getValuePointer() const {return &mReference;}
215  virtual const CCopasiObject * getValueObject() const {return this;}
216 
217  /**
218  * This is the output method for any object. The default implementation
219  * provided with CCopasiObject uses the ostream operator<< of the object
220  * to print the object.To override this default behavior one needs to
221  * reimplement the virtual print function.
222  * @param std::ostream * ostream
223  */
224  virtual void print(std::ostream * ostream) const
225  {*ostream << mReference;}
226 };
227 
228 template <class CType> class CCopasiMatrixReference: public CCopasiObject
229 {
230 public:
231  typedef CType referenceType;
232 
233  //Attributes
234 private:
235  CType & mReference;
236 
237  //Operations
238 private:
240  mReference(CType())
241  {};
242 
243 public:
244  CCopasiMatrixReference(const std::string & name,
245  const CCopasiContainer * pParent,
246  referenceType & reference,
247  const unsigned C_INT32 & flag = 0):
248  CCopasiObject(name, pParent, "Reference",
251  flag),
252  mReference(reference)
253  {assert(pParent != NULL);}
254 
256  const CCopasiContainer * pParent):
257  CCopasiObject(src, pParent),
259  {}
260 
262 
264  {
265 #ifdef WIN32
267 #else
269 #endif
270  (getObjectName() + cn,
271  getObjectParent(),
272  mReference(cn.getElementIndex(),
273  cn.getElementIndex(1)),
277  }
278 
279  virtual void * getValuePointer() const {return &mReference;}
280  virtual const CCopasiObject * getValueObject() const {return this;}
281 };
282 #endif // COPASI_CCopasiObjectReference
bool isValueInt() const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
const std::string & getObjectName() const
virtual void print(std::ostream *ostream) const
CCopasiObjectReference(const CCopasiObjectReference< referenceType > &src, const CCopasiContainer *pParent)
virtual const CCopasiObject * getValueObject() const
const std::string & getObjectType() const
#define C_INT32
Definition: copasi.h:90
virtual void * getValuePointer() const
void setUpdateMethod(CType *pType, void(CType::*method)(const C_FLOAT64 &))
CCopasiMatrixReference(const CCopasiMatrixReference< referenceType > &src, const CCopasiContainer *pParent)
void updateMethod(const CType &value)
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
virtual const CCopasiObject * getValueObject() const
virtual CCopasiObject * getObject(const CCopasiObjectName &cn)
virtual void setReference(referenceType &reference)
virtual void * getValuePointer() const
long int flag
Definition: f2c.h:52
bool isValueBool() const
bool isValueDbl() const
CCopasiVectorReference(const CCopasiVectorReference< referenceType > &src, const CCopasiContainer *pParent)
CCopasiObjectReference(const std::string &name, const CCopasiContainer *pParent, referenceType &reference, const unsigned C_INT32 &flag=0)
CCopasiMatrixReference(const std::string &name, const CCopasiContainer *pParent, referenceType &reference, const unsigned C_INT32 &flag=0)
CCopasiVectorReference(const std::string &name, const CCopasiContainer *pParent, referenceType &reference, const unsigned C_INT32 &flag=0)
virtual void * getValuePointer() const
virtual CCopasiObject * getObject(const CCopasiObjectName &cn)
virtual const CCopasiObject * getValueObject() const
CCopasiContainer * getObjectParent() const
virtual void print(std::ostream *ostream) const