]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use AlignedVector::size_type in all of table.h
authorMichael F. Herbst <info@michael-herbst.com>
Tue, 24 Feb 2015 15:07:59 +0000 (16:07 +0100)
committerMichael F. Herbst <info@michael-herbst.com>
Tue, 24 Feb 2015 15:07:59 +0000 (16:07 +0100)
In all classes of table.h the type Use AlignedVector::size_type is now
used for the calculation of indices for the values vector and the
indexing of elements in the values vector.

Note: This commit changes the interface of the n_elements function
in TableBase<N,T>

include/deal.II/base/table.h

index 965d08f44a76340c825f97cdec2f7bb971f98870..71f58c1e2ae95588b08d3025aac4247f3ecb420c 100644 (file)
@@ -153,6 +153,9 @@ namespace internal
 
       typedef typename Types<N,T,C>::iterator iterator;
       typedef typename Types<N,T,C>::const_iterator const_iterator;
+
+      typedef size_t size_type;
+      typedef ptrdiff_t difference_type;
     private:
       /**
        * Constructor. Take a pointer to the table object to know about the
@@ -400,6 +403,12 @@ template <int N, typename T>
 class TableBase : public Subscriptor
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename AlignedVector<T>::size_type size_type;
+
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -492,7 +501,7 @@ public:
    * Return the number of elements stored in this object, which is the product
    * of the extensions in each dimension.
    */
-  unsigned int n_elements () const;
+  size_type n_elements () const;
 
   /**
    * Return whether the object is empty, i.e. one of the directions is zero.
@@ -592,7 +601,7 @@ protected:
    * Return the position of the indicated element within the array of elements
    * stored one after the other. This function does no index checking.
    */
-  typename AlignedVector<T>::size_type position (const TableIndices<N> &indices) const;
+  size_type position (const TableIndices<N> &indices) const;
 
   /**
    * Return a read-write reference to the indicated element.
@@ -667,6 +676,11 @@ template <typename T>
 class Table<1,T> : public TableBase<1,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<1,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -781,6 +795,11 @@ template <typename T>
 class Table<2,T> : public TableBase<2,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<2,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -959,6 +978,11 @@ template <typename T>
 class Table<3,T> : public TableBase<3,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<3,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1088,6 +1112,11 @@ template <typename T>
 class Table<4,T> : public TableBase<4,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<4,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1175,6 +1204,12 @@ template <typename T>
 class Table<5,T> : public TableBase<5,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<5,T>::size_type size_type;
+
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1264,6 +1299,11 @@ template <typename T>
 class Table<6,T> : public TableBase<6,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<6,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1355,6 +1395,11 @@ template <typename T>
 class Table<7,T> : public TableBase<7,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<7,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1453,6 +1498,11 @@ template <typename T>
 class TransposeTable : public TableBase<2,T>
 {
 public:
+  /**
+   * Integer type used to count the number of elements in this container.
+   */
+  typedef typename TableBase<2,T>::size_type size_type;
+
   /**
    * Default constructor. Set all dimensions to zero.
    */
@@ -1663,7 +1713,7 @@ namespace internal
           // note: P>1, otherwise the
           // specialization would have
           // been taken!
-          unsigned int subobject_size = table.size()[N-1];
+          size_type subobject_size = table.size()[N-1];
           for (int p=P-1; p>1; --p)
             subobject_size *= table.size()[N-p];
           const iterator new_data = data + i*subobject_size;
@@ -1831,7 +1881,7 @@ TableBase<N,T>::reinit (const TableIndices<N> &new_sizes,
 {
   table_size = new_sizes;
 
-  const unsigned int new_size = n_elements();
+  const size_type new_size = n_elements();
 
   // if zero size was given: free all memory
   if (new_size == 0)
@@ -1878,10 +1928,10 @@ TableBase<N,T>::size (const unsigned int i) const
 
 template <int N, typename T>
 inline
-unsigned int
+typename TableBase<N,T>::size_type
 TableBase<N,T>::n_elements () const
 {
-  unsigned int s = 1;
+  size_type s = 1;
   for (unsigned int n=0; n<N; ++n)
     s *= table_size[n];
   return s;
@@ -1986,11 +2036,9 @@ TableBase<N,T>::memory_consumption () const
 
 template <int N, typename T>
 inline
-typename AlignedVector<T>::size_type
+typename TableBase<N,T>::size_type
 TableBase<N,T>::position (const TableIndices<N> &indices) const
 {
-  typedef typename AlignedVector<T>::size_type size_type;
-
   // specialize this for the
   // different numbers of dimensions,
   // to make the job somewhat easier
@@ -2216,7 +2264,7 @@ Table<2,T>::operator [] (const unsigned int i) const
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
   return dealii::internal::TableBaseAccessors::Accessor<2,T,true,1>(*this,
-         this->values.begin()+i*n_cols());
+         this->values.begin()+size_type(i)*n_cols());
 }
 
 
@@ -2229,7 +2277,7 @@ Table<2,T>::operator [] (const unsigned int i)
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
   return dealii::internal::TableBaseAccessors::Accessor<2,T,false,1>(*this,
-         this->values.begin()+i*n_cols());
+         this->values.begin()+size_type(i)*n_cols());
 }
 
 
@@ -2244,8 +2292,6 @@ Table<2,T>::operator () (const unsigned int i,
           ExcIndexRange (i, 0, this->table_size[0]));
   Assert (j < this->table_size[1],
           ExcIndexRange (j, 0, this->table_size[1]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(i)*this->table_size[1]+j];
 }
 
@@ -2261,8 +2307,6 @@ Table<2,T>::operator () (const unsigned int i,
           ExcIndexRange (i, 0, this->table_size[0]));
   Assert (j < this->table_size[1],
           ExcIndexRange (j, 0, this->table_size[1]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(i)*this->table_size[1]+j];
 }
 
@@ -2294,7 +2338,6 @@ typename AlignedVector<T>::const_reference
 Table<2,T>::el (const unsigned int i,
                 const unsigned int j) const
 {
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(i)*this->table_size[1]+j];
 }
 
@@ -2306,7 +2349,6 @@ typename AlignedVector<T>::reference
 Table<2,T>::el (const unsigned int i,
                 const unsigned int j)
 {
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(i)*this->table_size[1]+j];
 }
 
@@ -2373,8 +2415,6 @@ TransposeTable<T>::operator () (const unsigned int i,
           ExcIndexRange (i, 0, this->table_size[1]));
   Assert (j < this->table_size[0],
           ExcIndexRange (j, 0, this->table_size[0]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(j)*this->table_size[1]+i];
 }
 
@@ -2390,8 +2430,6 @@ TransposeTable<T>::operator () (const unsigned int i,
           ExcIndexRange (i, 0, this->table_size[1]));
   Assert (j < this->table_size[0],
           ExcIndexRange (j, 0, this->table_size[0]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(j)*this->table_size[1]+i];
 }
 
@@ -2403,7 +2441,6 @@ typename AlignedVector<T>::const_reference
 TransposeTable<T>::el (const unsigned int i,
                        const unsigned int j) const
 {
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(j)*this->table_size[1]+i];
 }
 
@@ -2415,7 +2452,6 @@ typename AlignedVector<T>::reference
 TransposeTable<T>::el (const unsigned int i,
                        const unsigned int j)
 {
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[size_type(j)*this->table_size[1]+i];
 }
 
@@ -2485,8 +2521,8 @@ Table<3,T>::operator [] (const unsigned int i) const
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2];
   return (dealii::internal::TableBaseAccessors::Accessor<3,T,true,2>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2501,8 +2537,8 @@ Table<3,T>::operator [] (const unsigned int i)
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2];
   return (dealii::internal::TableBaseAccessors::Accessor<3,T,false,2>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2523,8 +2559,6 @@ Table<3,T>::operator () (const unsigned int i,
           ExcIndexRange (j, 0, this->table_size[1]));
   Assert (k < this->table_size[2],
           ExcIndexRange (k, 0, this->table_size[2]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(size_type(i)*this->table_size[1]+j)
                       *this->table_size[2] + k];
 }
@@ -2544,8 +2578,6 @@ Table<3,T>::operator () (const unsigned int i,
           ExcIndexRange (j, 0, this->table_size[1]));
   Assert (k < this->table_size[2],
           ExcIndexRange (k, 0, this->table_size[2]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(size_type(i)*this->table_size[1]+j)
                       *this->table_size[2] + k];
 }
@@ -2598,9 +2630,9 @@ Table<4,T>::operator [] (const unsigned int i) const
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3];
   return (dealii::internal::TableBaseAccessors::Accessor<4,T,true,3>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2615,9 +2647,9 @@ Table<4,T>::operator [] (const unsigned int i)
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3];
   return (dealii::internal::TableBaseAccessors::Accessor<4,T,false,3>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2641,8 +2673,6 @@ Table<4,T>::operator () (const unsigned int i,
           ExcIndexRange (k, 0, this->table_size[2]));
   Assert (l < this->table_size[3],
           ExcIndexRange (l, 0, this->table_size[3]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[((size_type(i)*this->table_size[1]+j)
                        *this->table_size[2] + k)
                       *this->table_size[3] + l];
@@ -2666,8 +2696,6 @@ Table<4,T>::operator () (const unsigned int i,
           ExcIndexRange (k, 0, this->table_size[2]));
   Assert (l < this->table_size[3],
           ExcIndexRange (l, 0, this->table_size[3]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[((size_type(i)*this->table_size[1]+j)
                        *this->table_size[2] + k)
                       *this->table_size[3] + l];
@@ -2722,10 +2750,10 @@ Table<5,T>::operator [] (const unsigned int i) const
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4];
   return (dealii::internal::TableBaseAccessors::Accessor<5,T,true,4>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2740,10 +2768,10 @@ Table<5,T>::operator [] (const unsigned int i)
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4];
   return (dealii::internal::TableBaseAccessors::Accessor<5,T,false,4>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2770,8 +2798,6 @@ Table<5,T>::operator () (const unsigned int i,
           ExcIndexRange (l, 0, this->table_size[3]));
   Assert (m < this->table_size[4],
           ExcIndexRange (m, 0, this->table_size[4]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(((size_type(i)*this->table_size[1]+j)
                         *this->table_size[2] + k)
                        *this->table_size[3] + l)
@@ -2799,8 +2825,6 @@ Table<5,T>::operator () (const unsigned int i,
           ExcIndexRange (l, 0, this->table_size[3]));
   Assert (m < this->table_size[4],
           ExcIndexRange (m, 0, this->table_size[4]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(((size_type(i)*this->table_size[1]+j)
                         *this->table_size[2] + k)
                        *this->table_size[3] + l)
@@ -2857,11 +2881,11 @@ Table<6,T>::operator [] (const unsigned int i) const
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4] *
-                                      this->table_size[5];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4] *
+                                   this->table_size[5];
   return (dealii::internal::TableBaseAccessors::Accessor<6,T,true,5>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2876,11 +2900,11 @@ Table<6,T>::operator [] (const unsigned int i)
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4] *
-                                      this->table_size[5];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4] *
+                                   this->table_size[5];
   return (dealii::internal::TableBaseAccessors::Accessor<6,T,false,5>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -2910,8 +2934,6 @@ Table<6,T>::operator () (const unsigned int i,
           ExcIndexRange (m, 0, this->table_size[4]));
   Assert (n < this->table_size[5],
           ExcIndexRange (n, 0, this->table_size[5]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[((((size_type(i)*this->table_size[1]+j)
                          *this->table_size[2] + k)
                         *this->table_size[3] + l)
@@ -2943,8 +2965,6 @@ Table<6,T>::operator () (const unsigned int i,
           ExcIndexRange (m, 0, this->table_size[4]));
   Assert (n < this->table_size[5],
           ExcIndexRange (n, 0, this->table_size[5]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[((((size_type(i)*this->table_size[1]+j)
                          *this->table_size[2] + k)
                         *this->table_size[3] + l)
@@ -3003,12 +3023,12 @@ Table<7,T>::operator [] (const unsigned int i) const
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4] *
-                                      this->table_size[5] *
-                                      this->table_size[6];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4] *
+                                   this->table_size[5] *
+                                   this->table_size[6];
   return (dealii::internal::TableBaseAccessors::Accessor<7,T,true,6>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -3023,12 +3043,12 @@ Table<7,T>::operator [] (const unsigned int i)
 {
   Assert (i < this->table_size[0],
           ExcIndexRange (i, 0, this->table_size[0]));
-  const unsigned int subobject_size = this->table_size[1] *
-                                      this->table_size[2] *
-                                      this->table_size[3] *
-                                      this->table_size[4] *
-                                      this->table_size[5] *
-                                      this->table_size[6];
+  const size_type subobject_size = size_type(this->table_size[1]) *
+                                   this->table_size[2] *
+                                   this->table_size[3] *
+                                   this->table_size[4] *
+                                   this->table_size[5] *
+                                   this->table_size[6];
   return (dealii::internal::TableBaseAccessors::Accessor<7,T,false,6>
           (*this,
            this->values.begin() + i*subobject_size));
@@ -3061,8 +3081,6 @@ Table<7,T>::operator () (const unsigned int i,
           ExcIndexRange (n, 0, this->table_size[5]));
   Assert (o < this->table_size[6],
           ExcIndexRange (o, 0, this->table_size[6]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(((((size_type(i)*this->table_size[1]+j)
                           *this->table_size[2] + k)
                          *this->table_size[3] + l)
@@ -3098,8 +3116,6 @@ Table<7,T>::operator () (const unsigned int i,
           ExcIndexRange (n, 0, this->table_size[5]));
   Assert (o < this->table_size[5],
           ExcIndexRange (o, 0, this->table_size[6]));
-
-  typedef typename AlignedVector<T>::size_type size_type;
   return this->values[(((((size_type(i)*this->table_size[1]+j)
                           *this->table_size[2] + k)
                          *this->table_size[3] + l)

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.