From: Guido Kanschat <dr.guido.kanschat@gmail.com>
Date: Wed, 26 Sep 2012 16:29:09 +0000 (+0000)
Subject: add copy and access functions
X-Git-Tag: v8.0.0~2038
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f289da1e7c401d1aa889b0af25b2286b8bc8be5;p=dealii.git

add copy and access functions

git-svn-id: https://svn.dealii.org/trunk@26755 0785d39b-7218-0410-832d-ea1e28bc413d
---

diff --git a/deal.II/include/deal.II/grid/tria_iterator.h b/deal.II/include/deal.II/grid/tria_iterator.h
index 0c32918742..81144b1185 100644
--- a/deal.II/include/deal.II/grid/tria_iterator.h
+++ b/deal.II/include/deal.II/grid/tria_iterator.h
@@ -35,6 +35,7 @@
 DEAL_II_NAMESPACE_OPEN
 
 template <int dim, int spacedim> class Triangulation;
+template <int, int, int> class TriaAccessorBase;
 
 template <typename> class TriaRawIterator;
 template <typename> class TriaIterator;
@@ -42,7 +43,6 @@ template <typename> class TriaActiveIterator;
 
 
 
-
 // note: in non-debug mode, i.e. with optimizations, the file
 // tria_iterator.templates.h is included at the end of this file.
 // this includes a lot of templates and thus makes compilation
@@ -312,6 +312,18 @@ class TriaRawIterator : public std::iterator<std::bidirectional_iterator_tag,Acc
     template <typename OtherAccessor>
     TriaRawIterator (const TriaRawIterator<OtherAccessor> &i);
 
+				     /**
+				      * Another conversion operator,
+				      * where we use the pointers to
+				      * the Triangulation from a
+				      * TriaAccessorBase object, while
+				      * the additional data is used
+				      * according to the actual type
+				      * of Accessor.
+				      */
+    TriaRawIterator (const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+                  const typename Accessor::AccessorData *local_data);
+    
                                      /**
                                       * Conversion constructor. Same
                                       * as above with the difference
@@ -359,7 +371,7 @@ class TriaRawIterator : public std::iterator<std::bidirectional_iterator_tag,Acc
                                       *  version.
                                       */
     Accessor & operator * ();
-
+    
                                      /**
                                       *  Dereferencing operator, returns a
                                       *  reference of the cell pointed to.
@@ -375,6 +387,25 @@ class TriaRawIterator : public std::iterator<std::bidirectional_iterator_tag,Acc
                                       *  version.
                                       */
     Accessor * operator -> ();
+
+        
+    				     /**
+				      * In order be able to assign
+				      * end-iterators for different
+				      * accessors to each other, we
+				      * need an access function which
+				      * returns the accessor
+				      * regardless of its state.
+				      *
+				      * @warning This function should
+				      * not be used in application
+				      * programs. It is only intended
+				      * for limited purposes inside
+				      * the library and it makes
+				      * debugging much harder.
+				      */
+    const Accessor& access_any () const;
+    
                                      /*@}*/
 
                                      /**
@@ -661,6 +692,18 @@ class TriaIterator : public TriaRawIterator<Accessor>
     template <typename OtherAccessor>
     TriaIterator (const TriaIterator<OtherAccessor> &i);
 
+				     /**
+				      * Another conversion operator,
+				      * where we use the pointers to
+				      * the Triangulation from a
+				      * TriaAccessorBase object, while
+				      * the additional data is used
+				      * according to the actual type
+				      * of Accessor.
+				      */
+    TriaIterator (const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+                  const typename Accessor::AccessorData *local_data);
+    
                                      /**
                                       * Similar conversion operator to the above
                                       * one, but does a check whether the
@@ -850,6 +893,18 @@ class TriaActiveIterator : public TriaIterator<Accessor>
     template <typename OtherAccessor>
     TriaActiveIterator (const TriaActiveIterator<OtherAccessor> &i);
 
+    				     /**
+				      * Another conversion operator,
+				      * where we use the pointers to
+				      * the Triangulation from a
+				      * TriaAccessorBase object, while
+				      * the additional data is used
+				      * according to the actual type
+				      * of Accessor.
+				      */
+    TriaActiveIterator (const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+			const typename Accessor::AccessorData *local_data);
+    
                                      /**
                                       * Similar conversion operator to the above
                                       * one, but does a check whether the
@@ -1061,6 +1116,16 @@ TriaRawIterator<Accessor>::operator * ()
 
 
 
+template <typename Accessor>
+inline
+const Accessor &
+TriaRawIterator<Accessor>::access_any () const
+{
+  return accessor;
+}
+
+
+
 template <typename Accessor>
 inline
 const Accessor *
diff --git a/deal.II/include/deal.II/grid/tria_iterator.templates.h b/deal.II/include/deal.II/grid/tria_iterator.templates.h
index dfa1b5aaad..64211d1ba8 100644
--- a/deal.II/include/deal.II/grid/tria_iterator.templates.h
+++ b/deal.II/include/deal.II/grid/tria_iterator.templates.h
@@ -58,6 +58,18 @@ TriaRawIterator (const Triangulation<Accessor::dimension,Accessor::space_dimensi
 {}
 
 
+template <typename Accessor>
+inline
+TriaRawIterator<Accessor>::TriaRawIterator (
+  const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+  const typename Accessor::AccessorData *local_data)
+		:
+		accessor(0, -2, -2, local_data)
+{
+  accessor.copy_from(tria_accessor);
+}
+
+
 template <typename Accessor>
 inline
 TriaRawIterator<Accessor> &
@@ -209,6 +221,27 @@ TriaIterator<Accessor>::TriaIterator (const Triangulation<Accessor::dimension,Ac
 }
 
 
+template <typename Accessor>
+inline
+TriaIterator<Accessor>::TriaIterator (
+  const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+  const typename Accessor::AccessorData *local_data)
+		: TriaRawIterator<Accessor> (tria_accessor, local_data)
+{
+#ifdef DEBUG
+                                   // do this like this, because:
+                                   // if we write
+                                   // "Assert (IteratorState::past_the_end || used)"
+                                   // used() is called anyway, even if
+                                   // state==IteratorState::past_the_end, and will then
+                                   // throw the exception!
+  if (this->state() != IteratorState::past_the_end)
+    Assert (this->accessor.used(),
+            ExcAssignmentOfUnusedObject());
+#endif
+}
+
+
 template <typename Accessor>
 inline
 TriaIterator<Accessor> &
@@ -396,6 +429,27 @@ TriaActiveIterator<Accessor>::TriaActiveIterator (const Triangulation<Accessor::
 }
 
 
+template <typename Accessor>
+inline
+TriaActiveIterator<Accessor>::TriaActiveIterator (
+  const TriaAccessorBase<Accessor::structure_dimension,Accessor::dimension,Accessor::space_dimension>& tria_accessor,
+  const typename Accessor::AccessorData *local_data)
+		: TriaIterator<Accessor> (tria_accessor, local_data)
+{
+#ifdef DEBUG
+                                   // do this like this, because:
+                                   // if we write
+                                   // "Assert (IteratorState::past_the_end || !has_children())"
+                                   // has_children() is called anyway, even if
+                                   // state==IteratorState::past_the_end, and will then
+                                   // throw the exception!
+  if (this->state() != IteratorState::past_the_end)
+    Assert (this->accessor.has_children()==false,
+            ExcAssignmentOfInactiveObject());
+#endif
+}
+
+
 template <typename Accessor>
 inline
 TriaActiveIterator<Accessor> &