From 4a7c11e2cd2e543ad1b5300614cb1e484776f05d Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 22 Dec 2015 16:26:37 -0600 Subject: [PATCH] Add more functions to create ArrayView objects. --- include/deal.II/base/array_view.h | 146 +++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 4 deletions(-) diff --git a/include/deal.II/base/array_view.h b/include/deal.II/base/array_view.h index 444640dcfd..6194ad2981 100644 --- a/include/deal.II/base/array_view.h +++ b/include/deal.II/base/array_view.h @@ -18,9 +18,9 @@ #include #include +#include + #include -#include -#include #include @@ -195,7 +195,7 @@ ArrayView::operator[](const std::size_t i) const * element and the size of the given argument. * * This function is used for non-@p const references to objects of vector type. - * Such objects contain elements that can be written. Consequently, the return + * Such objects contain elements that can be written to. Consequently, the return * type of this function is a view to a set of writable objects. * * @param[in] vector The vector for which we want to have an array @@ -245,7 +245,7 @@ make_array_view (const std::vector &vector) * @p starting_index-th element and the @p size_of_view as the length of the view. * * This function is used for non-@p const references to objects of vector type. - * Such objects contain elements that can be written. Consequently, the return + * Such objects contain elements that can be written to. Consequently, the return * type of this function is a view to a set of writable objects. * * @param[in] vector The vector for which we want to have an array @@ -309,6 +309,144 @@ make_array_view (const std::vector &vector, +/** + * Create a view to an entire row of a Table<2> object. This is equivalent + * to initializing an ArrayView object with a pointer to the first + * element of the given row, and the length of the row as the length + * of the view. + * + * This function is used for non-@p const references to objects of Table type. + * Such objects contain elements that can be written to. Consequently, the + * return type of this function is a view to a set of writable objects. + * + * @param[in] table The Table for which we want to have an array + * view object. The array view corresponds to an entire + * row. + * @param[in] row The index of the row into the table to which this view + * should correspond. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (Table<2,ElementType> &table, + const typename Table<2,ElementType>::size_type row) +{ + AssertIndexRange (row, table.size()[0]); + return ArrayView (&table[row][0], table.size()[1]); +} + + + +/** + * Create a view to an entire row of a Table<2> object. This is equivalent + * to initializing an ArrayView object with a pointer to the first + * element of the given row, and the length of the row as the length + * of the view. + * + * This function is used for @p const references to objects of Table type + * because they contain immutable elements. Consequently, the return type + * of this function is a view to a set of @p const objects. + * + * @param[in] table The Table for which we want to have an array + * view object. The array view corresponds to an entire + * row. + * @param[in] row The index of the row into the table to which this view + * should correspond. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (const Table<2,ElementType> &table, + const typename Table<2,ElementType>::size_type row) +{ + AssertIndexRange (row, table.size()[0]); + return ArrayView (&table[row][0], table.size()[1]); +} + + + +/** + * Create a view to (a part of) a row of a Table<2> object. + * + * This function is used for non-@p const references to objects of Table type. + * Such objects contain elements that can be written to. Consequently, the + * return type of this function is a view to a set of writable objects. + * + * @param[in] table The Table for which we want to have an array + * view object. The array view corresponds to an entire + * row. + * @param[in] row The index of the row into the table to which this view + * should correspond. + * @param[in] starting_column The index of the column into the given row + * of the table that corresponds to the first element of this view. + * @param[in] size_of_view The number of elements this view should have. + * This corresponds to the number of columns in the current row to + * which the view should correspond. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (Table<2,ElementType> &table, + const typename Table<2,ElementType>::size_type row, + const typename Table<2,ElementType>::size_type starting_column, + const std::size_t size_of_view) +{ + AssertIndexRange (row, table.size()[0]); + AssertIndexRange (starting_column, table.size()[1]); + Assert (starting_column + size_of_view <= table.size()[1], + ExcMessage ("The starting index and size of the view you want to " + "create would lead to a view that extends beyond the end " + "of a column of the given table.")); + return ArrayView (&table[row][starting_column], size_of_view); +} + + + +/** + * Create a view to (a part of) a row of a Table<2> object. + * + * This function is used for @p const references to objects of Table type + * because they contain immutable elements. Consequently, the return type + * of this function is a view to a set of @p const objects. + * + * @param[in] table The Table for which we want to have an array + * view object. The array view corresponds to an entire + * row. + * @param[in] row The index of the row into the table to which this view + * should correspond. + * @param[in] starting_column The index of the column into the given row + * of the table that corresponds to the first element of this view. + * @param[in] size_of_view The number of elements this view should have. + * This corresponds to the number of columns in the current row to + * which the view should correspond. + * + * @relates ArrayView + */ +template +inline +ArrayView +make_array_view (const Table<2,ElementType> &table, + const typename Table<2,ElementType>::size_type row, + const typename Table<2,ElementType>::size_type starting_column, + const std::size_t size_of_view) +{ + AssertIndexRange (row, table.size()[0]); + AssertIndexRange (starting_column, table.size()[1]); + Assert (starting_column + size_of_view <= table.size()[1], + ExcMessage ("The starting index and size of the view you want to " + "create would lead to a view that extends beyond the end " + "of a column of the given table.")); + return ArrayView (&table[row][starting_column], size_of_view); +} + + + DEAL_II_NAMESPACE_CLOSE #endif -- 2.39.5