From: wolf Date: Sat, 20 Feb 1999 14:32:31 +0000 (+0000) Subject: Add some more conversions between iterators. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cdeba0f668d4a18e9cd7df6f909007ddd190b08;p=dealii-svn.git Add some more conversions between iterators. git-svn-id: https://svn.dealii.org/trunk@860 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/tria_iterator.h b/deal.II/deal.II/include/grid/tria_iterator.h index 658fb80649..6294346195 100644 --- a/deal.II/deal.II/include/grid/tria_iterator.h +++ b/deal.II/deal.II/include/grid/tria_iterator.h @@ -238,6 +238,22 @@ class TriaRawIterator : public bidirectional_iterator { */ TriaRawIterator (const TriaRawIterator &); + /** + * Construct an iterator from the given + * accessor; the given accessor needs not + * be of the same type as the accessor of + * this class is, but it needs to be + * convertible. + * + * Through this constructor, it is also + * possible to construct object for + * derived iterators: + * #DoFCellAccessor dof_accessor; + * Triangulation::active_cell_iterator cell + * = accessor; #. + */ + TriaRawIterator (const Accessor &a); + /** * Proper constructor, initialized * with the triangulation, the @@ -454,12 +470,20 @@ class TriaRawIterator : public bidirectional_iterator { Accessor accessor; - // actually, I don't know why we need these - // classes to be friends, since they are - // derived classes anyway. but gcc and - // even egcs1.1.1 don't get it right - friend class TriaIterator; - friend class TriaActiveIterator; + /** + * Make all other iterator class templates + * friends of this class. This is + * necessary for the implementation of + * conversion constructors. + */ + template + friend class TriaRawIterator; + + template + friend class TriaIterator; + + template + friend class TriaActiveIterator; }; @@ -539,6 +563,15 @@ class TriaIterator : public TriaRawIterator { template TriaIterator (const TriaIterator &i); + /** + * Similar conversion operator to the above + * one, but does a check whether the + * iterator points to a used element, + * which is necessary for raw iterators. + */ + template + TriaIterator (const TriaRawIterator &i); + /** * Assignment operator. */ @@ -688,6 +721,19 @@ class TriaActiveIterator : public TriaIterator { template TriaActiveIterator (const TriaActiveIterator &i); + /** + * Similar conversion operator to the above + * one, but does a check whether the + * iterator points to a used element, + * and is active, which is necessary for + * raw iterators. Since usual iterators + * are also raw iterators, this constructor + * works also for parameters of type + * #TriaIterator#. + */ + template + TriaActiveIterator (const TriaRawIterator &i); + /** * Assignment operator. */ @@ -770,6 +816,14 @@ class TriaActiveIterator : public TriaIterator { +template +inline +TriaRawIterator::TriaRawIterator (const Accessor &a) : + accessor (a) +{}; + + + template template inline @@ -884,6 +938,27 @@ TriaIterator::TriaIterator (const TriaIterator +template +template +inline +TriaIterator::TriaIterator (const TriaRawIterator &i) + : TriaRawIterator (static_cast >(i)) +{ +#ifdef DEBUG + // do this like this, because: + // if we write + // "Assert (past_the_end || used)" + // used() is called anyway, even if + // state==past_the_end, and will then + // throw the exception! + if (state() != past_the_end) + Assert (accessor.used(), + ExcAssignmentOfUnusedObject()); +#endif +}; + + + template template inline @@ -893,6 +968,27 @@ TriaActiveIterator::TriaActiveIterator (const TriaActiveIterator +template +inline +TriaActiveIterator::TriaActiveIterator (const TriaRawIterator &i) + : TriaIterator (i) +{ +#ifdef DEBUG + // do this like this, because: + // if we write + // "Assert (past_the_end || used)" + // has_children() is called anyway, even if + // state==past_the_end, and will then + // throw the exception! + if (state() != past_the_end) + Assert (accessor.has_children()==false, + ExcAssignmentOfInactiveObject()); +#endif +}; + + + template