COPASI API  4.16.103
CCopasiArray.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/report/CCopasiArray.h,v $
3 // $Revision: 1.4 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/10/07 11:57:11 $
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 #ifndef COPASIARRAY_H
20 #define COPASIARRAY_H
21 
22 #include <vector>
23 
24 #include "copasi/copasi.h"
25 
27 
28 /**
29  * This abstract class defines the interface for an n-dimensional array of floats
30  */
32 {
33 public:
34  typedef std::vector<size_t> index_type;
36 
37  //CCopasiAbstractArray();
38  //CCopasiAbstractArray(const index_type & sizes);
39  virtual ~CCopasiAbstractArray() {};
40 
41  //virtual void resize(const index_type & sizes) = 0;
42 
43  virtual data_type & operator[](const index_type & index) = 0;
44  virtual const data_type & operator[](const index_type & index) const = 0;
45 
46  virtual const index_type & size() const = 0;
47 
48  virtual size_t dimensionality() const = 0;
49 };
50 
51 /**
52  * this class contains an n-dimensional array
53  */
55 {
56 public:
57  //typedef std::vector<size_t> index_type;
58  //typedef C_FLOAT64 data_type;
59 
60  CCopasiArray();
61  CCopasiArray(const index_type & sizes);
62  virtual ~CCopasiArray() {};
63 
64  void resize(const index_type & sizes);
65 
66  data_type & operator[](const index_type & index);
67  const data_type & operator[](const index_type & index) const;
68 
69 private:
70  std::vector<data_type> mData;
71  std::vector<size_t> mSizes;
72  size_t mDim;
73  std::vector<size_t> mFactors;
74 
75 public:
76  const index_type & size() const
77  {return mSizes;}
78 
79  size_t dimensionality() const
80  {return mDim;}
81 };
82 
83 /**
84  * this class provides an interface to a CMatrix<C_FLOAT64> or a CLinkMatrixView,
85  * that is to every 2-dimensional class that has numRows(), numCols(), and operator()(row, col)
86  */
87 
88 template<class MatrixType>
90 {
91 public:
92 
93  CCopasiMatrixInterface(MatrixType * matrix)
94  : mMatrix(matrix)
95  {
96  assert(mMatrix);
97  mSizes.resize(2);
98  mSizes[0] = mMatrix->numRows();
99  mSizes[1] = mMatrix->numCols();
100  }
102 
103  //void resize(const index_type & sizes);
104 
105  data_type & operator[](const index_type & index)
106  {
107 #ifdef COPASI_DEBUG
108  assert(index.size() == 2);
109 #endif
110  return (*mMatrix)(index[0], index[1]);
111  }
112 
113  const data_type & operator[](const index_type & index) const
114  {
115 #ifdef COPASI_DEBUG
116  assert(index.size() == 2);
117 #endif
118  return (*mMatrix)(index[0], index[1]);
119  }
120 
121 private:
122  MatrixType * mMatrix;
123  //std::vector<data_type> mData;
124  std::vector<size_t> mSizes;
125  //size_t mDim;
126  //std::vector<size_t> mFactors;
127 
128 public:
129  const index_type & size() const
130  {
131  CCopasiMatrixInterface * tmp = const_cast<CCopasiMatrixInterface*>(this);
132  tmp->mSizes[0] = mMatrix->numRows();
133  tmp->mSizes[1] = mMatrix->numCols();
134  return mSizes;
135  }
136 
137  size_t dimensionality() const
138  {return 2;}
139 };
140 
141 /**
142  * this class provides an interface to a CVector<C_FLOAT64>,
143  * or indeed to any container class that has a size() method and
144  * a [] operator that returns C_FLOAT64.
145  */
146 
147 template<class VectorType>
149 {
150 public:
151 
152  CCopasiVectorInterface(VectorType * vector)
153  : mVector(vector)
154  {
155  assert(mVector);
156  mSizes.resize(1);
157  mSizes[0] = mVector->size();
158  }
160 
161  data_type & operator[](const index_type & index)
162  {
163 #ifdef COPASI_DEBUG
164  assert(index.size() == 1);
165 #endif
166  return (*mVector)[index[0]];
167  }
168 
169  const data_type & operator[](const index_type & index) const
170  {
171 #ifdef COPASI_DEBUG
172  assert(index.size() == 1);
173 #endif
174  return (*mVector)[index[0]];
175  }
176 
177 private:
178  VectorType * mVector;
179  mutable std::vector<size_t> mSizes;
180 
181 public:
182  const index_type & size() const
183  {
184  //CCopasiMatrixInterface * tmp = const_cast<CCopasiMatrixInterface*>(this);
185  /*tmp->*/
186  mSizes[0] = mVector->size();
187  return mSizes;
188  }
189 
190  size_t dimensionality() const
191  {return 1;}
192 };
193 
194 #endif
void resize(const index_type &sizes)
std::vector< data_type > mData
Definition: CCopasiArray.h:70
size_t dimensionality() const
Definition: CCopasiArray.h:190
virtual ~CCopasiAbstractArray()
Definition: CCopasiArray.h:39
data_type & operator[](const index_type &index)
Definition: CCopasiArray.h:105
virtual const index_type & size() const =0
virtual ~CCopasiMatrixInterface()
Definition: CCopasiArray.h:101
data_type & operator[](const index_type &index)
const data_type & operator[](const index_type &index) const
Definition: CCopasiArray.h:169
virtual ~CCopasiVectorInterface()
Definition: CCopasiArray.h:159
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
std::vector< size_t > mFactors
Definition: CCopasiArray.h:73
CCopasiMatrixInterface(MatrixType *matrix)
Definition: CCopasiArray.h:93
CCopasiVectorInterface(VectorType *vector)
Definition: CCopasiArray.h:152
size_t dimensionality() const
Definition: CCopasiArray.h:137
data_type & operator[](const index_type &index)
Definition: CCopasiArray.h:161
const index_type & size() const
Definition: CCopasiArray.h:129
const data_type & operator[](const index_type &index) const
Definition: CCopasiArray.h:113
size_t dimensionality() const
Definition: CCopasiArray.h:79
std::vector< size_t > mSizes
Definition: CCopasiArray.h:71
std::vector< size_t > mSizes
Definition: CCopasiArray.h:124
#define C_FLOAT64
Definition: copasi.h:92
virtual data_type & operator[](const index_type &index)=0
std::vector< size_t > mSizes
Definition: CCopasiArray.h:179
const index_type & size() const
Definition: CCopasiArray.h:76
virtual ~CCopasiArray()
Definition: CCopasiArray.h:62
virtual size_t dimensionality() const =0
const index_type & size() const
Definition: CCopasiArray.h:182