]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add some more conversions between iterators.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 20 Feb 1999 14:32:31 +0000 (14:32 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 20 Feb 1999 14:32:31 +0000 (14:32 +0000)
git-svn-id: https://svn.dealii.org/trunk@860 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/tria_iterator.h

index 658fb80649536df480347dca58d57c0d2c824923..62943461952d8949994c410fe992c287c0e6e3f8 100644 (file)
@@ -238,6 +238,22 @@ class TriaRawIterator : public bidirectional_iterator<Accessor,int> {
                                      */
     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,int> {
     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<dim,Accessor>;
-    friend class TriaActiveIterator<dim,Accessor>;
+                                    /**
+                                     * Make all other iterator class templates
+                                     * friends of this class. This is
+                                     * necessary for the implementation of
+                                     * conversion constructors.
+                                     */
+    template <typename SomeAccessor>
+    friend class TriaRawIterator<dim,SomeAccessor>;
+
+    template <typename SomeAccessor>
+    friend class TriaIterator<dim,SomeAccessor>;
+
+    template <typename SomeAccessor>
+    friend class TriaActiveIterator<dim,SomeAccessor>;
 };
 
 
@@ -539,6 +563,15 @@ class TriaIterator : public TriaRawIterator<dim,Accessor> {
     template <typename OtherAccessor>
     TriaIterator (const TriaIterator<dim,OtherAccessor> &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 <typename OtherAccessor>
+    TriaIterator (const TriaRawIterator<dim,OtherAccessor> &i);
+
                                     /**
                                      *  Assignment operator.
                                      */
@@ -688,6 +721,19 @@ class TriaActiveIterator : public TriaIterator<dim,Accessor> {
     template <typename OtherAccessor>
     TriaActiveIterator (const TriaActiveIterator<dim,OtherAccessor> &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<dim,OtherAccessor>#.
+                                     */
+    template <typename OtherAccessor>
+    TriaActiveIterator (const TriaRawIterator<dim,OtherAccessor> &i);
+
                                     /**
                                      *  Assignment operator.
                                      */
@@ -770,6 +816,14 @@ class TriaActiveIterator : public TriaIterator<dim,Accessor> {
 
 
 
+template <int dim, typename Accessor>
+inline
+TriaRawIterator<dim,Accessor>::TriaRawIterator (const Accessor &a) :
+               accessor (a)
+{};
+
+
+
 template <int dim, typename Accessor>
 template <typename OtherAccessor>
 inline
@@ -884,6 +938,27 @@ TriaIterator<dim,Accessor>::TriaIterator (const TriaIterator<dim,OtherAccessor>
 
 
 
+template <int dim, typename Accessor>
+template <typename OtherAccessor>
+inline
+TriaIterator<dim,Accessor>::TriaIterator (const TriaRawIterator<dim,OtherAccessor> &i)
+               : TriaRawIterator<dim,Accessor> (static_cast<TriaRawIterator<dim,OtherAccessor> >(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 <int dim, typename Accessor>
 template <typename OtherAccessor>
 inline
@@ -893,6 +968,27 @@ TriaActiveIterator<dim,Accessor>::TriaActiveIterator (const TriaActiveIterator<d
 
 
 
+template <int dim, typename Accessor>
+template <typename OtherAccessor>
+inline
+TriaActiveIterator<dim,Accessor>::TriaActiveIterator (const TriaRawIterator<dim,OtherAccessor> &i)
+               : TriaIterator<dim,Accessor> (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 <int dim, typename Accessor>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.