COPASI API  4.16.103
CCopasiArray.cpp
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/report/CCopasiArray.cpp,v $
3 // $Revision: 1.2 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:32:38 $
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 #include "CCopasiArray.h"
20 
22  : mDim(0) {mData.resize(1);}
23 
25 {
26  resize(sizes);
27 }
28 
29 void CCopasiArray::resize(const index_type & sizes)
30 {
31  mDim = sizes.size();
32  mSizes = sizes;
33  mFactors.resize(mDim);
34 
35  size_t tmpDataSize = 1;
36  index_type::const_reverse_iterator it, itEnd = sizes.rend();
37  index_type::reverse_iterator itFaktor;
38 
39  for (it = sizes.rbegin(), itFaktor = mFactors.rbegin(); it != itEnd; ++it, ++itFaktor)
40  {
41  *itFaktor = tmpDataSize;
42  tmpDataSize *= *it;
43  }
44 
45  mData.resize(tmpDataSize);
46 }
47 
49 {
50 #ifdef COPASI_DEBUG
51  assert(index.size() == mDim);
52 #endif
53 
54  size_t tmpindex = 0;
55  index_type::const_iterator itIndex, it, itEnd = mFactors.end();
56 
57  for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
58  tmpindex += *itIndex * *it;
59 
60  return mData[tmpindex];
61 }
62 
64 {
65 #ifdef COPASI_DEBUG
66  assert(index.size() == mDim);
67 #endif
68 
69  size_t tmpindex = 0;
70  index_type::const_iterator itIndex, it, itEnd = mFactors.end();
71 
72  for (itIndex = index.begin(), it = mFactors.begin(); it != itEnd; ++it, ++itIndex)
73  tmpindex += *itIndex * *it;
74 
75  return mData[tmpindex];
76 }
void resize(const index_type &sizes)
std::vector< data_type > mData
Definition: CCopasiArray.h:70
data_type & operator[](const index_type &index)
std::vector< size_t > index_type
Definition: CCopasiArray.h:34
std::vector< size_t > mFactors
Definition: CCopasiArray.h:73
std::vector< size_t > mSizes
Definition: CCopasiArray.h:71