COPASI API  4.16.103
CArrayElementReference.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/report/CArrayElementReference.cpp,v $
3 // $Revision: 1.5 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2009/01/07 19:04:15 $
7 // End CVS Header
8 
9 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
11 // and The University of Manchester.
12 // All rights reserved.
13 
14 #include "CArrayElementReference.h"
15 #include "CCopasiContainer.h"
17 
18 CArrayElementReference::CArrayElementReference(const std::string & index, const CCopasiContainer * pParent)
19  : CCopasiObject(index, pParent, "ElementReference",
20  CCopasiObject::Reference |
21  CCopasiObject::NonUniqueName |
22  CCopasiObject::ValueDbl),
23  // mpReference(NULL),
24  mIndex(index)
25 {
26  assert(pParent != NULL);
27 }
28 
30 {
31  // if (mpReference)
32  // *mpReference = value;
33 }
34 
36  {
37  CArrayAnnotation * tmpAA = dynamic_cast<CArrayAnnotation*>(getObjectParent());
38  if (!tmpAA) return NULL;
39 
40  //now get the array indices. At the moment only numerical indices...
41  //this could be done in the constructor, actually
42  unsigned C_INT32 ii = 0;
44  std::string tmpIndexString;
45  while ((tmpIndexString = mIndex.getElementName(ii, false)) != "")
46  {
47  if (tmpIndexString == ".")
48  break; //"." indicates 0-dimensional array. This means index should stay empty
49  index.push_back(mIndex.getElementIndex(ii));
50  ++ii;
51  }
52 
53  if (index.size() != tmpAA->dimensionality()) //wrong number of indices for this array
54  return NULL;
55 
56  for (ii = 0; ii < tmpAA->dimensionality(); ++ii)
57  if (index[ii] >= tmpAA->size()[ii]) //out of range
58  return NULL;
59 
60  return &(*tmpAA->array())[index];
61 
62  //TODO
63  //TODO perhaps we should cache the pointer. This would mean we need to invalidate the pointer
64  //if somthing with the array changes
65 
66  //return mpReference;
67  }
68 
69 std::string CArrayElementReference::getObjectDisplayName(bool regular, bool richtext) const
70  {
71  if (getObjectParent())
72  {
73  //if the array has as task as ancestor, use the task (skip the problem/method)
74  CCopasiContainer* pT = getObjectAncestor("Task");
75 
76  std::string part;
77  if (pT)
78  part = pT->getObjectDisplayName(regular, richtext) + ".";
80  part = getObjectParent()->getObjectParent()->getObjectDisplayName(regular, richtext) + ".";
81 
82  //now part contains the display name of the task, or the parent of the parent
83  return part + getObjectParent()->getObjectName() + mIndex;
84  }
85  else
86  return "Array" + mIndex;
87  }
88 
90  {
91  if (getObjectParent())
92  return getObjectParent()->getCN() + mIndex;
93  else
94  return "Array" + mIndex;
95  }
96 
97 void CArrayElementReference::print(std::ostream * ostream) const
98  {
99  //if (mpReference)
100  // (*ostream) << *mpReference;
101 
102  //TODO perhaps we should cache the
104  if (tmp)
105  (*ostream) << *tmp;
106  };
size_t getElementIndex(const size_t &pos=0) const
CCopasiContainer * getObjectAncestor(const std::string &type) const
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
virtual CCopasiObjectName getCN() const
const std::string & getObjectName() const
CCopasiAbstractArray * array()
const std::string & getObjectType() const
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
#define C_INT32
Definition: copasi.h:90
virtual void print(std::ostream *ostream) const
virtual CCopasiObjectName getCN() const
std::string getElementName(const size_t &pos, const bool &unescape=true) const
void updateMethod(const CCopasiAbstractArray::data_type &value)
Header file of class CCopasiContainer.
virtual void * getValuePointer() const
Header file of class CArrayAnnotation.
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
CCopasiAbstractArray::index_type size() const
size_t dimensionality() const
CCopasiContainer * getObjectParent() const