]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Return a reference from the vector2d accessors in any case, since the objects stored...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 May 2002 06:36:11 +0000 (06:36 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 May 2002 06:36:11 +0000 (06:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@5949 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/vector2d.h
deal.II/doc/news/2002/c-3-3.html
tests/base/vector2d.cc

index 6f36ab5e2508a72af264feb760659ba4d683fcf9..ee903918ba695950c2c06e1017397a61bd316456 100644 (file)
@@ -61,6 +61,26 @@ class vector2d : public Subscriptor
     class ConstRowAccessor
     {
       public:
+                                        /**
+                                         * Typedef iterator and other
+                                         * types to the elements of
+                                         * this row. Since this class
+                                         * represents rows of
+                                         * constant objects,
+                                         * @p{iterator} and
+                                         * @p{const_iterator} have
+                                         * the same type.
+                                         */
+       typedef const T value_type;
+       typedef value_type* pointer;
+       typedef const value_type* const_pointer;
+       typedef value_type* iterator;
+       typedef const value_type* const_iterator;
+       typedef value_type& reference;
+       typedef const value_type& const_reference;
+       typedef size_t size_type;
+       typedef ptrdiff_t difference_type;
+       
                                         /**
                                          * Constructor.
                                          */
@@ -70,7 +90,20 @@ class vector2d : public Subscriptor
                                         /**
                                          * Access operator.
                                          */
-       T  operator [] (const unsigned int column) const;
+       const_reference operator [] (const unsigned int column) const;
+
+                                        /**
+                                         * Return an iterator to the
+                                         * first element of this row.
+                                         */
+       const_iterator begin () const;
+
+                                        /**
+                                         * Return an interator to the
+                                         * element past the end of
+                                         * this row.
+                                         */
+       const_iterator end () const;
        
       protected:
                                         /**
@@ -112,6 +145,26 @@ class vector2d : public Subscriptor
     class NonConstRowAccessor
     {
       public:
+                                        /**
+                                         * Typedef constant and
+                                         * non-constant iterator
+                                         * types to the elements of
+                                         * this row, as well as all
+                                         * the other types usually
+                                         * required for the standard
+                                         * library algorithms.
+                                         */
+       typedef T value_type;
+       typedef value_type* pointer;
+       typedef const value_type* const_pointer;
+       typedef value_type* iterator;
+       typedef const value_type* const_iterator;
+       typedef value_type& reference;
+       typedef const value_type& const_reference;
+       typedef size_t size_type;
+       typedef ptrdiff_t difference_type;
+
+       
                                         /**
                                          * Constructor.
                                          */
@@ -122,7 +175,36 @@ class vector2d : public Subscriptor
                                         /**
                                          * Access operator.
                                          */
-       T & operator [] (const unsigned int column) const;
+       reference operator [] (const unsigned int column) const;
+
+                                        /**
+                                         * Return an iterator to the
+                                         * first element of this
+                                         * row. Constant version.
+                                         */
+       const_iterator begin () const;
+
+                                        /**
+                                         * Return an iterator to the
+                                         * first element of this
+                                         * row. Non-constant version.
+                                         */
+       iterator begin ();
+       
+                                        /**
+                                         * Return an interator to the
+                                         * element past the end of
+                                         * this row. Constant version.
+                                         */
+       const_iterator end () const;
+       
+                                        /**
+                                         * Return an interator to the
+                                         * element past the end of
+                                         * this row. Non-constant
+                                         * version.
+                                         */
+       iterator end ();
        
       private:
                                         /**
@@ -240,10 +322,19 @@ class vector2d : public Subscriptor
     
                                     /**
                                      * Return the value of the
-                                     * element at position @p{(i,j)}.
+                                     * element at position @p{(i,j)}
+                                     * as a constant reference.
+                                     *
+                                     * We return the requested value
+                                     * as a constant reference rather
+                                     * than by value since this
+                                     * object may hold data types
+                                     * that may be large, and we
+                                     * don't know here whether
+                                     * copying is expensive or not.
                                      */
-    T operator() (const unsigned int i,
-                 const unsigned int j) const;
+    const T & operator() (const unsigned int i,
+                         const unsigned int j) const;
     
                                     /**
                                      * Return a read-write reference to
@@ -325,14 +416,23 @@ class vector2d : public Subscriptor
   
                                     /**
                                      * Return the value of the
-                                     * element @p{(i,j)}.
+                                     * element @p{(i,j)} as a
+                                     * read-only reference.
                                      *
                                      * This function does no bounds
                                      * checking and is only to be
                                      * used internally and in
                                      * functions already checked.
+                                     *
+                                     * We return the requested value
+                                     * as a constant reference rather
+                                     * than by value since this
+                                     * object may hold data types
+                                     * that may be large, and we
+                                     * don't know here whether
+                                     * copying is expensive or not.
                                      */
-    T el (const unsigned int i, const unsigned int j) const;    
+    const T & el (const unsigned int i, const unsigned int j) const;    
   
                                     /**
                                      * Direct read-only access to
@@ -411,6 +511,26 @@ operator [] (const unsigned int column) const
 
 
 
+template <typename T>
+inline
+typename vector2d<T>::ConstRowAccessor::const_iterator
+vector2d<T>::ConstRowAccessor::begin () const
+{
+  return row_start;
+};
+
+
+
+template <typename T>
+inline
+typename vector2d<T>::ConstRowAccessor::const_iterator
+vector2d<T>::ConstRowAccessor::end () const
+{
+  return row_start+parent.n_cols();
+};
+
+
+
 template <typename T>
 inline
 vector2d<T>::NonConstRowAccessor::
@@ -424,6 +544,7 @@ NonConstRowAccessor (vector2d<T>        &parent,
 };
 
 
+
 template <typename T>
 inline
 T &
@@ -436,6 +557,36 @@ operator [] (const unsigned int column) const
 
 
 
+template <typename T>
+inline
+typename vector2d<T>::NonConstRowAccessor::iterator
+vector2d<T>::NonConstRowAccessor::begin ()
+{
+  return row_start;
+};
+
+
+
+template <typename T>
+inline
+typename vector2d<T>::NonConstRowAccessor::const_iterator
+vector2d<T>::NonConstRowAccessor::end () const
+{
+  return row_start+parent.n_cols();
+};
+
+
+
+template <typename T>
+inline
+typename vector2d<T>::NonConstRowAccessor::iterator
+vector2d<T>::NonConstRowAccessor::end ()
+{
+  return row_start+parent.n_cols();
+};
+
+
+
 template <typename T>
 inline
 vector2d<T>::~vector2d ()
@@ -653,7 +804,7 @@ vector2d<T>::el (const unsigned int i, const unsigned int j)
 
 
 template <typename T>
-inline T
+inline const T &
 vector2d<T>::el (const unsigned int i, const unsigned int j) const
 {
   return val[i*n_cols()+j];
@@ -662,7 +813,7 @@ vector2d<T>::el (const unsigned int i, const unsigned int j) const
 
 
 template <typename T>
-inline T
+inline const T &
 vector2d<T>::operator() (const unsigned int i, const unsigned int j) const
 {  
   Assert (i<num_rows, ExcIndexRange (i, 0, num_rows));
index b6bb149a3f5853bba80b741480bb882ad23852a4..f8a560e693dfc54e774c7cd6dbff74942eb9096f 100644 (file)
@@ -150,6 +150,16 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>base</h3>
 
 <ol>
+  <li> <p> 
+       New: The <code class="class">vector2d</code> row accessor
+       classes now have member functions <code
+       class="member">begin<code> and <code class="member">end<code>
+       which allow iterating over the elements of a row of such an
+       object. 
+       <br>
+       (WB 2002/05/30)
+       </p>
+
   <li> <p> 
        New: The <code class="class">Legendre</code> and
        <code class="class">LagrangeEquidistant</code> classes now have
index 467399b07b7c796c9af31385f5b240e9795b2653..87174a9d5f6dee8d907d4e6b6419d846047396f1 100644 (file)
@@ -48,6 +48,10 @@ main ()
        Assert (Ti[i][j] == Ti(i,j), ExcInternalError());
        Assert (Ti[i][j] == Td(i,j), ExcInternalError());
 
+       Assert (Td[i].begin()+j == Td(i,j), ExcInternalError());
+       Assert (Ti[i].begin()+j == Ti(i,j), ExcInternalError());
+       Assert (Ti[i].begin()+j == Td(i,j), ExcInternalError());
+
        logfile << i << " " << j << " " << Td[i][j] << " ok" << std::endl;
       };
 };

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.