COPASI API  4.16.103
CAnnotatedMatrix.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CAnnotatedMatrix.h,v $
3 // $Revision: 1.29 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/09/16 18:10: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) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 /*!
24  \file CAnnotatedMatrix.h
25  \brief Header file of class CArrayAnnotation
26  */
27 
28 #ifndef CANNOTATEDMATRIX_H
29 #define CANNOTATEDMATRIX_H
30 
33 
34 #include "report/CCopasiArray.h"
35 #include <string>
36 
37 #include "copasi.h"
38 
39 /**
40  * This class contains the annotations to a n-dimensional array. Annotations can be provided
41  * for the array as such, for each of the dimensions, and for each of the indices (rows,
42  * columns, ...)
43  */
45 {
46 public:
47 
48  /**
49  * The annotation to an array can work in different modes. The mode
50  * for each dimension can be changed independently.
51  *
52  * OBJECTS: The CNs for the rows, cols, ... of the array are given explicitly
53  *
54  * VECTOR: A CCopasiVector is provided from which the CNs are generated at
55  * the time the vector is set
56  *
57  * VECTOR_ON_THE_FLY: A CCopasiVector is provided, but the CNs are generated
58  * every time the annotations are retrieved (so that they are always up to date).
59  *
60  * STRINGS: The annotations for the rows, cols, ... are given explicitly
61  * as strings.
62  *
63  * NUMBERS: The rows, cols, ... of the array are only annotation with
64  * running numbers (starting with 0)-
65  */
66  enum Mode
67  {
73  };
74 
75 private:
78 
79  mutable std::vector< std::vector<CRegisteredObjectName> > mAnnotationsCN;
80  mutable std::vector< std::vector<std::string> > mAnnotationsString;
81 
82  std::vector< std::string > mDimensionDescriptions;
83  std::vector< const CCopasiContainer * > mCopasiVectors;
84 
85  /**
86  * This contains the mode for the different dimensions
87  */
88  std::vector<Mode> mModes;
89 
90  /**
91  * This contains the default mode that is used if during a resize()
92  * the dimensionality is increased.
93  */
95 
96  std::string mDescription;
97 
98 public:
99  CArrayAnnotation(const std::string & name,
100  const CCopasiContainer * pParent,
102  const bool & adopt);
103 
104  virtual ~CArrayAnnotation();
105 
106 private:
110 
111 public:
112 
113  /**
114  * let the ArrayAnnotation point to a different array.
115  * If you use this method without updating the annotations afterwards
116  * it is your responsibility to make sure the new array fits the
117  * existing annotation (in dimensionality and, if not in VECTOR_ON_THE_FLY mode,
118  * in size).
119  */
120  void setArray(CCopasiAbstractArray * a);
121 
123  {return mpArray;}
124 
125  const CCopasiAbstractArray * array() const
126  {return mpArray;}
127 
128  /**
129  * set the mode for the dimension d
130  */
131  void setMode(size_t d, Mode m);
132 
133  /**
134  * set the mode for all dimensions, this also sets the
135  * default mode that is used when resizing the ArrayAnnotion
136  * to a larger dimensionality
137  */
138  void setMode(Mode m);
139 
140  Mode getMode(size_t d) const
141  {return mModes[d];};
142 
144  {return mDefaultMode;};
145 
146  size_t dimensionality() const;
147 
149  {return mpArray->size();}
150 
151  /**
152  * Associates a dimension d of the array with a CCopasiVector of
153  * CCopasiObjects. If the mode of the dimension d is VECTOR than
154  * the CNs of the objects in the vector are generated and stored immediately.
155  * If the mode is VECTOR_ON_THE_FLY the CNs are generated when getAnnotationsCN()
156  * or getAnnotationsString() is called.
157  */
158  void setCopasiVector(size_t d, const CCopasiContainer* v);
159 
160  void setAnnotationCN(size_t d, size_t i, const std::string cn);
161  void setAnnotationString(size_t d, size_t i, const std::string s);
162 
163  /**
164  * returns the vector of CNs that correspond to the rows, columns, ... of the array.
165  * This method must not be called if the mode for the dimension d is STRINGS or NUMBERS
166  */
167  const std::vector<CRegisteredObjectName> & getAnnotationsCN(size_t d) const;
168 
169  /**
170  * This returns strings that annotate the rows, columns, ... of the array.
171  * If the mode is OBJECTS, VECTOR, or VECTOR_ON_THE_FLY the display argument determines
172  * if the object name or the object display name is used.
173  * Note that this method returns a reference. The content that the reference points to
174  * may be changes by later calls to the getAnnotationsCN() method with the same value for d.
175  * Specifically if you use this method to obtain a reference to the list of display names
176  * and then call the method again to get the plain object names, the first reference will
177  * after that also point to the plain object names.
178  */
179  const std::vector<std::string> & getAnnotationsString(size_t d, bool display = true) const;
180 
181  const std::string & getDimensionDescription(size_t d) const;
182  void setDimensionDescription(size_t d, const std::string & s);
183 
184  const std::string & getDescription() const;
185  void setDescription(const std::string & s);
186 
187  /**
188  * adjust the dimensionality and size to that of the array
189  */
190  void resize();
191 
192  /**
193  * an object that will act as a reference to one element of an array
194  * will be created and inserted as a child of the array annotation. Basically
195  * most of the work will be done by getObject(). If the element already
196  * exists, the existing element will be returned.
197  */
199 
200  /**
201  * a convenience function for 2-dimensional arrays.
202  */
204 
205  /**
206  * a convenience function for 1-dimensional arrays.
207  */
209 
210  /**
211  * Appends all element references to the set of objects
212  * @param std::set< const CCopasiObject * > & objects
213  */
214  void appendElementReferences(std::set< const CCopasiObject * > & objects) const;
215 
216  /**
217  * Resolve a cn. Since this is an array, the CN can start with an index like "[2][3]".
218  * Since this is also a container, this is not necessarily the case.
219  */
220  virtual const CObjectInterface * getObject(const CCopasiObjectName & cn) const;
221 
222  /**
223  * Check whether the size of array is greater than 0 for each dimension.
224  * Return true, if so. Otherwise, false.
225  */
226  bool isEmpty();
227 
228 //private:
229  /**
230  * resize the internal vectors according to the dimensionality of the array
231  */
232  void reDimensionalize(size_t d);
233 
234  void resizeOneDimension(size_t d);
235 
236  //void printDebugLoop(std::ostream & out, CCopasiAbstractArray::index_type & index, size_t level) const;
237 
238  /**
239  * generate the list of CNs from the COPASI vector v.
240  * v needs to be a CCopasiVector (or derived from it)!
241  */
242  bool createAnnotationsCNFromCopasiVector(size_t d, const CCopasiContainer* v) const;
243 
244  void createNumbers(size_t d) const;
245 
246  //void printDebug(std::ostream & out) const;
247 
248  void printRecursively(std::ostream & ostream, size_t level,
250  const std::vector<std::vector<std::string> > & display) const;
251 
252 public:
253 
254  /**
255  * generate a display name for the array annotation.
256  */
257  virtual std::string getObjectDisplayName(bool regular = true, bool richtext = false) const;
258 
259  virtual void print(std::ostream * ostream) const;
260 
261  friend std::ostream &operator<<(std::ostream &os, const CArrayAnnotation & o);
262 };
263 
264 #endif
std::vector< std::string > mDimensionDescriptions
virtual void print(std::ostream *ostream) const
void createNumbers(size_t d) const
const std::string & getDimensionDescription(size_t d) const
const std::vector< std::string > & getAnnotationsString(size_t d, bool display=true) const
virtual const CObjectInterface * getObject(const CCopasiObjectName &cn) const
virtual const index_type & size() const =0
Mode getDefaultMode() const
void resizeOneDimension(size_t d)
void setAnnotationCN(size_t d, size_t i, const std::string cn)
friend std::ostream & operator<<(std::ostream &os, const CArrayAnnotation &o)
CCopasiAbstractArray * array()
CCopasiAbstractArray * mpArray
void setDescription(const std::string &s)
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
void reDimensionalize(size_t d)
#define C_INT32
Definition: copasi.h:90
const std::string & getDescription() const
void setAnnotationString(size_t d, size_t i, const std::string s)
std::string mDescription
std::vector< Mode > mModes
virtual ~CArrayAnnotation()
CArrayAnnotation & operator=(const CArrayAnnotation &)
std::vector< std::vector< CRegisteredObjectName > > mAnnotationsCN
void appendElementReferences(std::set< const CCopasiObject * > &objects) const
void setCopasiVector(size_t d, const CCopasiContainer *v)
Header file of class CCopasiContainer.
std::vector< std::vector< std::string > > mAnnotationsString
void setMode(size_t d, Mode m)
void setDimensionDescription(size_t d, const std::string &s)
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
bool createAnnotationsCNFromCopasiVector(size_t d, const CCopasiContainer *v) const
const CObjectInterface * addElementReference(CCopasiAbstractArray::index_type index) const
Mode getMode(size_t d) const
std::vector< const CCopasiContainer * > mCopasiVectors
const std::vector< CRegisteredObjectName > & getAnnotationsCN(size_t d) const
void setArray(CCopasiAbstractArray *a)
CCopasiAbstractArray::index_type size() const
const CCopasiAbstractArray * array() const
size_t dimensionality() const
void printRecursively(std::ostream &ostream, size_t level, CCopasiAbstractArray::index_type &index, const std::vector< std::vector< std::string > > &display) const