34 #ifndef __H__UG__COMMON__VARIABLE_ARRAY_IMPL_H__
35 #define __H__UG__COMMON__VARIABLE_ARRAY_IMPL_H__
48 template<
typename T, eMatrixOrdering T_ordering>
58 template<
typename T, eMatrixOrdering T_ordering>
68 template<
typename T, eMatrixOrdering T_ordering>
71 if(
this == &other)
return;
72 if(values) {
delete[] values; values = NULL; }
77 for(size_type i=0; i<rows*cols; i++)
78 values[i] = other.
values[i];
81 template<
typename T, eMatrixOrdering T_ordering>
84 if(values) {
delete[] values; values = NULL; }
90 template<
typename T, eMatrixOrdering T_ordering>
97 template<
typename T, eMatrixOrdering T_ordering>
105 template<
typename T, eMatrixOrdering T_ordering>
109 assert(newRows >= 0 && newCols >= 0);
110 if(newRows == rows && newCols == cols)
return true;
112 if(newRows == 0 && newCols == 0)
115 if(values)
delete[] values;
122 size_t minRows = std::min(rows, newRows);
123 size_t minCols = std::min(cols, newCols);
124 if(newRows*newCols > arraySize)
126 value_type *new_values =
new T[newRows*newCols];
127 arraySize = newRows*newCols;
128 memset(new_values, 0,
sizeof(T)*newRows*newCols);
129 UG_ASSERT(new_values != NULL,
"out of memory");
130 if(new_values==NULL)
return false;
142 for(
size_t r=0; r<minRows; r++)
143 for(
size_t c=0; c<minCols; c++)
144 std::swap(new_values[c+r*newCols], values[c+r*cols]);
146 for(
size_t r=0; r<minRows; r++)
147 for(
size_t c=0; c<minCols; c++)
148 std::swap(new_values[r+c*newRows], values[r+c*rows]);
150 if(values)
delete[] values;
158 for(
size_t r=1; r<minRows; r++)
159 for(
size_t c=0; c<minCols; c++)
160 std::swap(values[c+r*newCols], values[c+r*cols]);
163 else if(newCols > cols)
165 for(
size_t r=minRows-1; r>0; r--)
169 std::swap(values[c+r*newCols], values[c+r*cols]);
182 for(
size_t c=1; c<minCols; c++)
183 for(
size_t r=0; r<minRows; r++)
184 std::swap(values[r+c*newRows], values[r+c*rows]);
187 else if(newRows > rows)
189 for(
size_t c=minCols-1; c>0; c--)
193 std::swap(values[r+c*newRows], values[r+c*rows]);
212 template<
typename T, eMatrixOrdering T_ordering>
216 assert(r>=0 && r<rows);
217 assert(c>=0 && c<cols);
219 return values[c+r*cols];
221 return values[r+c*rows];
224 template<
typename T, eMatrixOrdering T_ordering>
228 assert(r>=0 && r<rows);
229 assert(c>=0 && c<cols);
231 return values[c+r*cols];
233 return values[r+c*rows];
236 template<
typename T, eMatrixOrdering T_ordering>
241 typedef size_t size_type;
242 for(size_type r=0; r<arr.
num_rows(); r++)
244 for(size_type c=0; c<arr.
num_cols(); c++)
245 out << arr(r, c) <<
" ";
246 if(r != arr.
num_rows()-1) out <<
"| ";
Definition: reservable_array.h:54
T * values
Definition: reservable_array.h:121
~ReservableArray2()
Definition: reservable_array_impl.h:82
ReservableArray2()
Definition: reservable_array_impl.h:49
T value_type
Definition: reservable_array.h:56
const T & operator()(size_type r, size_type c) const
Definition: reservable_array_impl.h:226
size_type num_rows() const
Definition: reservable_array_impl.h:92
size_type num_cols() const
Definition: reservable_array_impl.h:99
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: reservable_array_impl.h:107
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
@ RowMajor
Definition: storage.h:48
bool resize(size_t newRows, size_t newCols)