From: Wolfgang Bangerth Date: Sun, 25 Jun 2017 02:17:26 +0000 (-0600) Subject: Reindent and reformat parts of index_set.h. X-Git-Tag: v9.0.0-rc1~1473^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4545%2Fhead;p=dealii.git Reindent and reformat parts of index_set.h. No functional changes, just beautify the contents of this file somewhat. --- diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 6a5e153197..08cb306ce0 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -896,39 +896,74 @@ IndexSet complete_index_set (const unsigned int N) /* IntervalAccessor */ inline -IndexSet::IntervalAccessor::IntervalAccessor(const IndexSet *idxset, const IndexSet::size_type range_idx) - : index_set(idxset), range_idx(range_idx) +IndexSet::IntervalAccessor:: +IntervalAccessor(const IndexSet *idxset, + const IndexSet::size_type range_idx) + : + index_set(idxset), + range_idx(range_idx) { Assert(range_idx < idxset->n_intervals(), ExcInternalError("Invalid range index")); } + + inline -IndexSet::IntervalAccessor::IntervalAccessor(const IndexSet *idxset) - : index_set(idxset), range_idx(numbers::invalid_dof_index) +IndexSet::IntervalAccessor:: +IntervalAccessor(const IndexSet *idxset) + : + index_set(idxset), + range_idx(numbers::invalid_dof_index) {} + + inline -IndexSet::size_type IndexSet::IntervalAccessor::n_elements() const +IndexSet::IntervalAccessor:: +IntervalAccessor(const IndexSet::IntervalAccessor &other) + : + index_set (other.index_set), + range_idx(other.range_idx) +{ + Assert( range_idx == numbers::invalid_dof_index || is_valid(), + ExcMessage("invalid iterator")); +} + + + +inline +IndexSet::size_type +IndexSet::IntervalAccessor::n_elements() const { Assert(is_valid(), ExcMessage("invalid iterator")); return index_set->ranges[range_idx].end - index_set->ranges[range_idx].begin; } + + inline -bool IndexSet::IntervalAccessor::is_valid() const +bool +IndexSet::IntervalAccessor::is_valid() const { return index_set != nullptr && range_idx < index_set->n_intervals(); } + + inline -IndexSet::ElementIterator IndexSet::IntervalAccessor::begin() const +IndexSet::ElementIterator +IndexSet::IntervalAccessor::begin() const { Assert(is_valid(), ExcMessage("invalid iterator")); - return IndexSet::ElementIterator(index_set, range_idx, index_set->ranges[range_idx].begin); + return IndexSet::ElementIterator(index_set, range_idx, + index_set->ranges[range_idx].begin); } + + inline -IndexSet::ElementIterator IndexSet::IntervalAccessor::end() const +IndexSet::ElementIterator +IndexSet::IntervalAccessor::end() const { Assert(is_valid(), ExcMessage("invalid iterator")); @@ -939,6 +974,8 @@ IndexSet::ElementIterator IndexSet::IntervalAccessor::end() const return index_set->end(); } + + inline IndexSet::size_type IndexSet::IntervalAccessor::last() const @@ -948,12 +985,7 @@ IndexSet::IntervalAccessor::last() const return index_set->ranges[range_idx].end-1; } -inline -IndexSet::IntervalAccessor::IntervalAccessor(const IndexSet::IntervalAccessor &other) - : index_set (other.index_set), range_idx(other.range_idx) -{ - Assert( range_idx == numbers::invalid_dof_index || is_valid(), ExcMessage("invalid iterator")); -} + inline IndexSet::IntervalAccessor & @@ -961,28 +993,40 @@ IndexSet::IntervalAccessor::operator = (const IndexSet::IntervalAccessor &other) { index_set = other.index_set; range_idx = other.range_idx; - Assert( range_idx == numbers::invalid_dof_index || is_valid(), ExcMessage("invalid iterator")); + Assert( range_idx == numbers::invalid_dof_index || is_valid(), + ExcMessage("invalid iterator")); return *this; } + + inline -bool IndexSet::IntervalAccessor::operator == (const IndexSet::IntervalAccessor &other) const +bool +IndexSet::IntervalAccessor::operator == (const IndexSet::IntervalAccessor &other) const { - Assert (index_set == other.index_set, ExcMessage("Can not compare accessors pointing to different IndexSets")); + Assert (index_set == other.index_set, + ExcMessage("Can not compare accessors pointing to different IndexSets")); return range_idx == other.range_idx; } + + inline -bool IndexSet::IntervalAccessor::operator < (const IndexSet::IntervalAccessor &other) const +bool +IndexSet::IntervalAccessor::operator < (const IndexSet::IntervalAccessor &other) const { - Assert (index_set == other.index_set, ExcMessage("Can not compare accessors pointing to different IndexSets")); + Assert (index_set == other.index_set, + ExcMessage("Can not compare accessors pointing to different IndexSets")); return range_idx < other.range_idx; } + + inline void IndexSet::IntervalAccessor::advance () { - Assert(is_valid(), ExcMessage("Impossible to advance an IndexSet::IntervalIterator that is invalid")); + Assert (is_valid(), + ExcMessage("Impossible to advance an IndexSet::IntervalIterator that is invalid")); ++range_idx; // set ourselves to invalid if we walk off the end @@ -990,28 +1034,42 @@ void IndexSet::IntervalAccessor::advance () range_idx = numbers::invalid_dof_index; } + /* IntervalIterator */ inline -IndexSet::IntervalIterator::IntervalIterator(const IndexSet *idxset, const IndexSet::size_type range_idx) - : accessor(idxset, range_idx) +IndexSet::IntervalIterator::IntervalIterator(const IndexSet *idxset, + const IndexSet::size_type range_idx) + : + accessor(idxset, range_idx) {} + + inline IndexSet::IntervalIterator::IntervalIterator() - : accessor(nullptr) + : + accessor(nullptr) {} + + inline IndexSet::IntervalIterator::IntervalIterator(const IndexSet *idxset) - : accessor(idxset) + : + accessor(idxset) {} + + inline IndexSet::IntervalIterator::IntervalIterator(const IndexSet::IntervalIterator &other) - : accessor(other.accessor) + : + accessor(other.accessor) {} + + inline IndexSet::IntervalIterator & IndexSet::IntervalIterator::operator = (const IntervalIterator &other) @@ -1021,6 +1079,7 @@ IndexSet::IntervalIterator::operator = (const IntervalIterator &other) } + inline IndexSet::IntervalIterator & IndexSet::IntervalIterator::operator++ () @@ -1029,6 +1088,8 @@ IndexSet::IntervalIterator::operator++ () return *this; } + + inline IndexSet::IntervalIterator IndexSet::IntervalIterator::operator++ (int) @@ -1038,6 +1099,8 @@ IndexSet::IntervalIterator::operator++ (int) return iter; } + + inline const IndexSet::IntervalAccessor & IndexSet::IntervalIterator::operator* () const @@ -1045,6 +1108,8 @@ IndexSet::IntervalIterator::operator* () const return accessor; } + + inline const IndexSet::IntervalAccessor * IndexSet::IntervalIterator::operator-> () const @@ -1052,31 +1117,52 @@ IndexSet::IntervalIterator::operator-> () const return &accessor; } + + inline -bool IndexSet::IntervalIterator::operator == (const IndexSet::IntervalIterator &other) const +bool +IndexSet::IntervalIterator::operator == (const IndexSet::IntervalIterator &other) const { return accessor == other.accessor; } + + inline -bool IndexSet::IntervalIterator::operator != (const IndexSet::IntervalIterator &other) const +bool +IndexSet::IntervalIterator::operator != (const IndexSet::IntervalIterator &other) const { return !(*this == other); } + + inline -bool IndexSet::IntervalIterator::operator < (const IndexSet::IntervalIterator &other) const +bool +IndexSet::IntervalIterator::operator < (const IndexSet::IntervalIterator &other) const { return accessor < other.accessor; } + + inline -int IndexSet::IntervalIterator::operator - (const IndexSet::IntervalIterator &other) const +int +IndexSet::IntervalIterator::operator - (const IndexSet::IntervalIterator &other) const { - Assert (accessor.index_set == other.accessor.index_set, ExcMessage("Can not compare iterators belonging to different IndexSets")); - - const size_type lhs = (accessor.range_idx == numbers::invalid_dof_index) ? accessor.index_set->ranges.size() : accessor.range_idx; - const size_type rhs = (other.accessor.range_idx == numbers::invalid_dof_index) ? accessor.index_set->ranges.size() : other.accessor.range_idx; + Assert (accessor.index_set == other.accessor.index_set, + ExcMessage("Can not compare iterators belonging to different IndexSets")); + + const size_type lhs = (accessor.range_idx == numbers::invalid_dof_index) + ? + accessor.index_set->ranges.size() + : + accessor.range_idx; + const size_type rhs = (other.accessor.range_idx == numbers::invalid_dof_index) + ? + accessor.index_set->ranges.size() + : + other.accessor.range_idx; if (lhs > rhs) return static_cast(lhs - rhs); @@ -1085,23 +1171,18 @@ int IndexSet::IntervalIterator::operator - (const IndexSet::IntervalIterator &ot } -/* ElementIterator */ -inline -bool IndexSet::ElementIterator::is_valid() const -{ - Assert( - (range_idx == numbers::invalid_dof_index && idx == numbers::invalid_dof_index) - || - (range_idx < index_set->ranges.size() && idxranges[range_idx].end) - , ExcInternalError("Invalid ElementIterator state.")); - - return range_idx < index_set->ranges.size() && idxranges[range_idx].end; -} +/* ElementIterator */ inline -IndexSet::ElementIterator::ElementIterator(const IndexSet *idxset, const IndexSet::size_type range_idx, const IndexSet::size_type index) - : index_set(idxset), range_idx(range_idx), idx(index) +IndexSet::ElementIterator:: +ElementIterator(const IndexSet *idxset, + const IndexSet::size_type range_idx, + const IndexSet::size_type index) + : + index_set(idxset), + range_idx(range_idx), + idx(index) { Assert(range_idx < index_set->ranges.size(), ExcMessage("Invalid range index for IndexSet::ElementIterator constructor.")); @@ -1111,30 +1192,62 @@ IndexSet::ElementIterator::ElementIterator(const IndexSet *idxset, const IndexSe ExcInternalError("Invalid index argument for IndexSet::ElementIterator constructor.")); } + + inline IndexSet::ElementIterator::ElementIterator(const IndexSet *idxset) - : index_set(idxset), range_idx(numbers::invalid_dof_index), idx(numbers::invalid_dof_index) + : + index_set(idxset), + range_idx(numbers::invalid_dof_index), + idx(numbers::invalid_dof_index) {} + + +inline +bool +IndexSet::ElementIterator::is_valid() const +{ + Assert((range_idx == numbers::invalid_dof_index && idx == numbers::invalid_dof_index) + || + (range_idx < index_set->ranges.size() && idxranges[range_idx].end), + ExcInternalError("Invalid ElementIterator state.")); + + return (range_idx < index_set->ranges.size() && + idxranges[range_idx].end); +} + + + + inline IndexSet::size_type IndexSet::ElementIterator::operator* () const { - Assert(is_valid(), ExcMessage("Impossible to dereference an IndexSet::ElementIterator that is invalid")); + Assert (is_valid(), + ExcMessage("Impossible to dereference an IndexSet::ElementIterator that is invalid")); return idx; } + + inline -bool IndexSet::ElementIterator::operator == (const IndexSet::ElementIterator &other) const +bool +IndexSet::ElementIterator::operator == (const IndexSet::ElementIterator &other) const { - Assert (index_set == other.index_set, ExcMessage("Can not compare iterators belonging to different IndexSets")); + Assert (index_set == other.index_set, + ExcMessage("Can not compare iterators belonging to different IndexSets")); return range_idx == other.range_idx && idx==other.idx; } + + inline -void IndexSet::ElementIterator::advance () +void +IndexSet::ElementIterator::advance () { - Assert(is_valid(), ExcMessage("Impossible to advance an IndexSet::ElementIterator that is invalid")); + Assert (is_valid(), + ExcMessage("Impossible to advance an IndexSet::ElementIterator that is invalid")); if (idx < index_set->ranges[range_idx].end) ++idx; // end of this range? @@ -1155,6 +1268,8 @@ void IndexSet::ElementIterator::advance () } } + + inline IndexSet::ElementIterator & IndexSet::ElementIterator::operator++ () @@ -1163,6 +1278,8 @@ IndexSet::ElementIterator::operator++ () return *this; } + + inline IndexSet::ElementIterator IndexSet::ElementIterator::operator++ (int) @@ -1172,23 +1289,32 @@ IndexSet::ElementIterator::operator++ (int) return it; } + + inline bool IndexSet::ElementIterator::operator != (const IndexSet::ElementIterator &other) const { return !(*this == other); } + + inline bool IndexSet::ElementIterator::operator < (const IndexSet::ElementIterator &other) const { - Assert (index_set == other.index_set, ExcMessage("Can not compare iterators belonging to different IndexSets")); + Assert (index_set == other.index_set, + ExcMessage("Can not compare iterators belonging to different IndexSets")); return range_idx < other.range_idx || (range_idx == other.range_idx && idx0) @@ -1317,69 +1509,14 @@ IndexSet::IntervalIterator IndexSet::begin_intervals() const return end_intervals(); } -inline -IndexSet::IntervalIterator IndexSet::end_intervals() const -{ - compress(); - return IndexSet::IntervalIterator(this); -} - - - -inline -IndexSet::IndexSet () - : - is_compressed (true), - index_space_size (0), - largest_range (numbers::invalid_unsigned_int) -{} - - - -inline -IndexSet::IndexSet (const size_type size) - : - is_compressed (true), - index_space_size (size), - largest_range (numbers::invalid_unsigned_int) -{} - - - -inline -IndexSet::IndexSet (IndexSet &&is) - : - ranges (std::move(is.ranges)), - is_compressed (is.is_compressed), - index_space_size (is.index_space_size), - largest_range (is.largest_range) -{ - is.ranges.clear (); - is.is_compressed = true; - is.index_space_size = 0; - is.largest_range = numbers::invalid_unsigned_int; - - compress (); -} - inline -IndexSet &IndexSet::operator= (IndexSet &&is) +IndexSet::IntervalIterator +IndexSet::end_intervals() const { - ranges = std::move (is.ranges); - is_compressed = is.is_compressed; - index_space_size = is.index_space_size; - largest_range = is.largest_range; - - is.ranges.clear (); - is.is_compressed = true; - is.index_space_size = 0; - is.largest_range = numbers::invalid_unsigned_int; - - compress (); - - return *this; + compress(); + return IndexSet::IntervalIterator(this); } @@ -1542,6 +1679,7 @@ IndexSet::is_contiguous () const } + inline bool IndexSet::is_empty () const @@ -1644,6 +1782,7 @@ IndexSet::nth_index_in_set (const unsigned int n) const } + inline IndexSet::size_type IndexSet::index_within_set (const size_type n) const