1 #ifndef CLASSIC_Array2D_HH
2 #define CLASSIC_Array2D_HH
234 rows(0), cols(0), len(0), data(0)
240 rows(array.rows), cols(array.cols), len(array.len), data(new
T[len]) {
247 rows(r), cols(c), len(r *c), data(new
T[len])
253 rows(r), cols(c), len(r *c), data(new
T[len]) {
271 data =
new T[rhs.
len];
284 if(r < 0 || r >= rows || c < 0 || c >= ncols()) {
285 throw CLRangeError(
"Array2d::operator()",
"Index out of range.");
287 return data[cols*r+
c];
293 if(r < 0 || r >= rows || c < 0 || c >= ncols()) {
294 throw CLRangeError(
"Array2d::operator()",
"Index out of range.");
296 return data[cols*r+
c];
345 throw CLRangeError(
"Array2D::row_begin()",
"Row index out of range.");
347 return &data[cols*r];
354 throw CLRangeError(
"Array2D::row_end()",
"Row index out of range.");
356 return &data[cols*(r+1)];
363 throw CLRangeError(
"Array2D::row_begin()",
"Row index out of range.");
365 return &data[cols*r];
372 throw CLRangeError(
"Array2D::row_end()",
"Row index out of range.");
374 return &data[cols*(r+1)];
380 return &data[cols*r];
386 return &data[cols*r];
393 throw CLRangeError(
"Array2D::col_begin()",
"Column index out of range.");
402 throw CLRangeError(
"Array2D::col_end()",
"Column index out of range.");
411 throw CLRangeError(
"Array2D::col_begin()",
"Column index out of range.");
420 throw CLRangeError(
"Array2D::col_end()",
"Column index out of range.");
442 if(fromArray.
size() != rows) {
443 throw SizeError(
"Array2D::putColumn()",
"Dimensions inconsistent.");
451 if(fromArray.
size() != cols) {
452 throw SizeError(
"Array2D::putRow()",
"Dimensions inconsistent.");
460 std::swap_ranges(col_begin(col1), col_end(col1), col_begin(col2));
466 std::swap_ranges(row_begin(row1), row_end(row1), row_begin(row2));
471 std::ostream &operator<<(std::ostream &os, const Array2D<T> &v) {
472 for(
int i = 0; i < v.nrows(); ++i) {
473 for(
int j = 0; j < v.ncols(); ++j) {
474 os << v(i, j) <<
" ";
482 #endif // CLASSIC_Array2D_HH
void getColumn(Array1D< T > &toArray, int c) const
Fetch column.
constexpr double c
The velocity of light in m/s.
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
T * iterator
The iterator type for sequential access to all elements.
iterator begin()
Get pointer to beginning of data.
void getRow(Array1D< T > &toArray, int r) const
Fetch row.
iterator end()
Get pointer past end of data.
SliceIterator< T > col_iterator
The iterator type for access by columns.
int size() const
Get array size.
void putColumn(const Array1D< T > &fromArray, int c)
Store column.
int ncols() const
Get number of columns.
const T * const_iterator
The iterator type for sequential access to all elements.
Array2D()
Default constructor.
int nrows() const
Get number of rows.
const T * const_row_iterator
The iterator type for access by rows for a constant array.
clearpage the user may choose between constant or variable radius This model includes fringe fields begin
Inform & endl(Inform &inf)
void swapRows(int row1, int row2)
Exchange rows.
row_iterator operator[](int r)
Get row iterator.
col_iterator col_end(int c)
Get column iterator.
int size() const
Get total size (rows times columns).
iterator begin()
Get beginning of data.
T value_type
The value type of the array.
iterator end()
Get end of data.
col_iterator col_begin(int c)
Get column iterator.
ConstSliceIterator< T > const_col_iterator
The iterator type for access by columns for a constant array.
Iterator for array slice.
Iterator for array slice.
row_iterator row_begin(int r)
Get row iterator.
T * row_iterator
The iterator type for access by rows.
Array2D< T > & operator=(const Array2D< T > &)
void swapColumns(int c1, int c2)
Exchange columns.
void putRow(const Array1D< T > &fromArray, int r)
Store row.
row_iterator row_end(int r)
Get row iterator.
T & operator()(int r, int c)
Get element reference.