From: Denis Davydov Date: Fri, 8 Feb 2019 15:37:18 +0000 (+0100) Subject: Add default constructor to SparsityPatternIterators::Accessor X-Git-Tag: v9.1.0-rc1~355^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7710%2Fhead;p=dealii.git Add default constructor to SparsityPatternIterators::Accessor --- diff --git a/doc/news/changes/minor/20190208DenisDavydov b/doc/news/changes/minor/20190208DenisDavydov new file mode 100644 index 0000000000..3d8c7ce6cd --- /dev/null +++ b/doc/news/changes/minor/20190208DenisDavydov @@ -0,0 +1,3 @@ +New: Add default constructor to SparsityPatternIterators::Accessor(). +
+(Denis Davydov, 2019/02/08) diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index 4182a1fd73..89c507a31e 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -146,6 +146,13 @@ namespace SparsityPatternIterators */ Accessor(const SparsityPattern *matrix); + /** + * Default constructor creating a dummy accessor. This constructor is here + * only to be able to store accessors in STL containers such as + * `std::vector`. + */ + Accessor(); + /** * Row number of the element represented by this object. This function can * only be called for entries for which is_valid_entry() is true. @@ -209,6 +216,12 @@ namespace SparsityPatternIterators operator<(const Accessor &) const; protected: + DeclExceptionMsg(DummyAccessor, + "The instance of this class was initialized" + " without SparsityPattern object, which" + " means that it is a dummy accessor that can" + " not do any operations."); + /** * The sparsity pattern we operate on accessed. */ @@ -1162,9 +1175,17 @@ namespace SparsityPatternIterators + inline Accessor::Accessor() + : container(nullptr) + , linear_index(numbers::invalid_size_type) + {} + + + inline bool Accessor::is_valid_entry() const { + Assert(container != nullptr, DummyAccessor()); return (linear_index < container->rowstart[container->rows] && container->colnums[linear_index] != SparsityPattern::invalid_entry); } @@ -1218,6 +1239,8 @@ namespace SparsityPatternIterators inline bool Accessor::operator==(const Accessor &other) const { + Assert(container != nullptr, DummyAccessor()); + Assert(other.container != nullptr, DummyAccessor()); return (container == other.container && linear_index == other.linear_index); } @@ -1226,6 +1249,8 @@ namespace SparsityPatternIterators inline bool Accessor::operator<(const Accessor &other) const { + Assert(container != nullptr, DummyAccessor()); + Assert(other.container != nullptr, DummyAccessor()); Assert(container == other.container, ExcInternalError()); return linear_index < other.linear_index; @@ -1236,6 +1261,7 @@ namespace SparsityPatternIterators inline void Accessor::advance() { + Assert(container != nullptr, DummyAccessor()); Assert(linear_index < container->rowstart[container->rows], ExcIteratorPastEnd()); ++linear_index;