Cantera  2.1.2
vcs_IntStarStar.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_IntStarStar.cpp Implementation of class IntStarStar
3  */
5 
6 namespace VCSnonideal
7 {
9  m_nrows(0),
10  m_ncols(0)
11 {
12  m_data.clear();
13  m_colAddr.clear();
14 }
15 
16 IntStarStar::IntStarStar(size_t m, size_t n, int v) :
17  m_nrows(n),
18  m_ncols(m)
19 {
20  m_data.resize(n*m);
21  std::fill(m_data.begin(), m_data.end(), v);
22  m_colAddr.resize(m);
23  if (!m_data.empty()) {
24  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
25  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
26  }
27  }
28 }
29 
31 {
32  m_nrows = y.m_nrows;
33  m_ncols = y.m_ncols;
34  m_data.resize(m_nrows*m_ncols);
35  m_data = y.m_data;
36  m_colAddr.resize(m_ncols);
37  if (!m_data.empty()) {
38  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
39  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
40  }
41  }
42 }
43 
44 IntStarStar& IntStarStar::operator=(const IntStarStar& y)
45 {
46  if (&y == this) {
47  return *this;
48  }
49  m_nrows = y.m_nrows;
50  m_ncols = y.m_ncols;
51  m_data.resize(m_nrows*m_ncols);
52  m_data = y.m_data;
53  m_colAddr.resize(m_ncols);
54  if (!m_data.empty()) {
55  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
56  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
57  }
58  }
59  return *this;
60 }
61 
62 void IntStarStar::resize(size_t m, size_t n, int v)
63 {
64  std::vector<int> old_data;
65  bool doCopy = false;
66  if (m_nrows > 0 && m_ncols > 0) {
67  if (m_ncols != m) {
68  doCopy = true;
69  old_data = m_data;
70  }
71  }
72  m_data.resize(n*m, v);
73  if (doCopy) {
74  if (n >= m_nrows && m >= m_ncols) {
75  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
76  for (size_t irow = 0; irow < m_nrows; irow++) {
77  m_data[jcol*m + irow] = old_data[jcol*m_ncols + irow];
78  }
79  for (size_t irow = m_nrows; irow < n; irow++) {
80  m_data[jcol*m + irow] = v;
81  }
82  }
83  for (size_t jcol = m_ncols; jcol < m; jcol++) {
84  for (size_t irow = 0; irow < n; irow++) {
85  m_data[jcol*m + irow] = v;
86  }
87  }
88  } else {
89  std::fill(m_data.begin(), m_data.end(), v);
90  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
91  for (size_t irow = 0; irow < m_nrows; irow++) {
92  m_data[jcol*m + irow] = old_data[jcol*m_ncols + irow];
93  }
94  }
95  }
96  }
97  m_nrows = n;
98  m_ncols = m;
99  m_colAddr.resize(m_ncols);
100  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
101  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
102  }
103 }
104 
105 int* IntStarStar::operator[](size_t jcol)
106 {
107  return m_colAddr[jcol];
108 }
109 
110 const int* IntStarStar::operator[](size_t jcol) const
111 {
112  return (const int*) m_colAddr[jcol];
113 }
114 
116 {
117  return (int* const*) &(m_colAddr[0]);
118 }
119 
120 size_t IntStarStar::nRows() const
121 {
122  return m_nrows;
123 }
124 
125 size_t IntStarStar::nColumns() const
126 {
127  return m_ncols;
128 }
129 
130 }
size_t m_ncols
number of columns
Header file for class IntStarStar.
std::vector< int > m_data
Storage area for the matrix, layed out in Fortran style, row-inner, column outer format.
int * operator[](size_t jcol)
Pointer to the top of the column.
void resize(size_t mcol, size_t nrow, int v=0)
Resize the array, and fill the new entries with 'v'.
size_t nRows() const
Number of rows.
size_t m_nrows
number of rows
A class for 2D int arrays stored in column-major (Fortran-compatible) form.
size_t nColumns() const
Number of columns.
std::vector< int * > m_colAddr
Vector of column addresses.
int *const * baseDataAddr()
Returns a int** pointer to the base address.
IntStarStar()
Default constructor. Create an empty array.