34 #ifndef __H__UG__COMMON__VARIABLE_ARRAY_IMPL_H__
35 #define __H__UG__COMMON__VARIABLE_ARRAY_IMPL_H__
65 if(
this == &other)
return;
76 if(values) {
delete[] values; values = NULL; }
94 if(newN == n)
return true;
98 if(values)
delete[] values;
104 UG_ASSERT(new_values != NULL,
"out of memory");
105 if(new_values == NULL)
return false;
106 memset(
reinterpret_cast<void *
> (new_values), 0,
sizeof(T)*newN);
119 size_t minN = std::min(n, newN);
120 for(
size_t i=0; i<minN; i++)
121 std::swap(new_values[i], values[i]);
124 if(values)
delete[] values;
171 for(
size_t i=0; i<arr.
size(); i++)
172 out << arr[i] <<
" ";
181 template<
typename T, eMatrixOrdering T_ordering>
190 template<
typename T, eMatrixOrdering T_ordering>
199 template<
typename T, eMatrixOrdering T_ordering>
202 if(
this == &other)
return;
208 values[i] = other.
values[i];
211 template<
typename T, eMatrixOrdering T_ordering>
214 if(values) {
delete[] values; values = NULL; }
220 template<
typename T, eMatrixOrdering T_ordering>
227 template<
typename T, eMatrixOrdering T_ordering>
235 template<
typename T, eMatrixOrdering T_ordering>
239 if(newRows == rows && newCols == cols)
return true;
241 if(newRows == 0 && newCols == 0)
244 if(values)
delete[] values;
249 value_type *new_values =
new T[newRows*newCols];
250 memset(
reinterpret_cast<void *
> (new_values), 0,
sizeof(T)*newRows*newCols);
251 UG_ASSERT(new_values != NULL,
"out of memory");
252 if(new_values==NULL)
return false;
263 size_t minRows = std::min(rows, newRows);
264 size_t minCols = std::min(cols, newCols);
268 for(
size_t r=0; r<minRows; r++)
269 for(
size_t c=0; c<minCols; c++)
270 std::swap(new_values[c+r*newCols], values[c+r*cols]);
272 for(
size_t r=0; r<minRows; r++)
273 for(
size_t c=0; c<minCols; c++)
274 std::swap(new_values[r+c*newRows], values[r+c*rows]);
277 if(values)
delete[] values;
285 template<
typename T, eMatrixOrdering T_ordering>
289 UG_ASSERT(r<rows,
"r = " << r <<
", rows = " << rows);
290 UG_ASSERT(c<cols,
"c = " << c <<
", cols = " << cols);
292 return values[c+r*cols];
294 return values[r+c*rows];
297 template<
typename T, eMatrixOrdering T_ordering>
301 UG_ASSERT(r<rows,
"r = " << r <<
", rows = " << rows);
302 UG_ASSERT(c<cols,
"c = " << c <<
", cols = " << cols);
304 return values[c+r*cols];
306 return values[r+c*rows];
309 template<
typename T, eMatrixOrdering T_ordering>
314 typedef size_t size_type;
315 for(size_type r=0; r<arr.
num_rows(); r++)
317 for(size_type c=0; c<arr.
num_cols(); c++)
318 out << arr(r, c) <<
" ";
319 if(r != arr.
num_rows()-1) out <<
"| ";
Definition: variable_array.h:59
~VariableArray1()
Definition: variable_array_impl.h:74
bool reserve(size_type n) const
Definition: variable_array_impl.h:141
size_t size_type
Definition: variable_array.h:62
size_type size() const
Definition: variable_array_impl.h:85
T value_type
Definition: variable_array.h:61
VariableArray1()
Definition: variable_array_impl.h:47
const T & operator[](size_type i) const
Definition: variable_array_impl.h:160
bool resize(size_type n, bool bCopyValues=true)
Definition: variable_array_impl.h:92
size_type capacity() const
Definition: variable_array_impl.h:132
Definition: variable_array.h:139
T value_type
Definition: variable_array.h:141
T * values
Definition: variable_array.h:206
VariableArray2()
Definition: variable_array_impl.h:182
bool resize(size_type newRows, size_type newCols, bool bCopyValues=true)
Definition: variable_array_impl.h:237
size_type num_rows() const
Definition: variable_array_impl.h:222
size_type num_cols() const
Definition: variable_array_impl.h:229
const T & operator()(size_type r, size_type c) const
Definition: variable_array_impl.h:299
size_t size_type
Definition: variable_array.h:142
~VariableArray2()
Definition: variable_array_impl.h:212
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)