From: Wolfgang Bangerth Date: Tue, 29 Mar 2005 15:45:17 +0000 (+0000) Subject: Move table indices out into their own file, since they are now used elsewhere X-Git-Tag: v8.0.0~14260 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f47398b16354f0303b0b70d1835da49418e1e23;p=dealii.git Move table indices out into their own file, since they are now used elsewhere as well. git-svn-id: https://svn.dealii.org/trunk@10287 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index f69558eee8..41b68089f1 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -33,300 +34,6 @@ template class Table<6,T>; -/** - * Base class for an array of indices of fixed size used for the - * TableBase class. Actually, this class serves a dual purpose, - * as it not only stores indices into said class, but also the sizes - * of the table in its various coordinates. - * - * @author Wolfgang Bangerth, 2002 - */ - template - class TableIndicesBase - { - public: - /** - * Access the value of the - * ith index. - */ - unsigned int operator[] (const unsigned int i) const; - - /** - * Compare two index fields for - * equality. - */ - bool operator == (const TableIndicesBase &other) const; - - /** - * Compare two index fields for - * inequality. - */ - bool operator != (const TableIndicesBase &other) const; - - /** - * Sort the indices in ascending - * order. While this operation is not - * very useful for Table objects, it is - * used for the SymmetricTensor class. - */ - void sort (); - - protected: - /** - * Store the indices in an array. - */ - unsigned indices[N]; - }; - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the general template, and has no implementation. There are - * a number of specializations that are actually implemented (one for - * each used value of N), which only differ in the way they - * implement their constructors (they take N arguments, something - * that cannot be represented by a general template). Actual storage - * of and access to data is done by the TableIndicesBase base - * class of a specializations. - * - * @author Wolfgang Bangerth, 2002 - */ - template - class TableIndices - { - }; - - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a one-dimensional table, i.e. a - * vector. This class only differs in the non-default constructors - * from the other specializations. Actual storage of and access to - * data is done by the TableIndicesBase base class of a - * specializations. - * - * @author Wolfgang Bangerth, 2002 - */ - template <> - class TableIndices<1> : public TableIndicesBase<1> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1); - }; - - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a two-dimensional table. This class - * only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, 2002 - */ - template <> - class TableIndices<2> : public TableIndicesBase<2> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2); - }; - - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a three-dimensional table. This class - * only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, 2002 - */ - template <> - class TableIndices<3> : public TableIndicesBase<3> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3); - }; - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a four-dimensional table. This class - * only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, Ralf Hartmann 2002 - */ - template <> - class TableIndices<4> : public TableIndicesBase<4> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4); - }; - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a five-dimensional table. This class - * only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, Ralf Hartmann 2002 - */ - template <> - class TableIndices<5> : public TableIndicesBase<5> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5); - }; - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a six-dimensional table. This class - * only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, Ralf Hartmann 2002 - */ - template <> - class TableIndices<6> : public TableIndicesBase<6> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5, - const unsigned int index6); - }; - - -/** - * Array of indices of fixed size used for the TableBase - * class. - * - * This is the specialization for a seven-dimensional table. This - * class only differs in the non-default constructors from the other - * specializations. Actual storage of and access to data is done by - * the TableIndicesBase base class of a specializations. - * - * @author Wolfgang Bangerth, 2002, Ralf Hartmann 2004 - */ - template <> - class TableIndices<7> : public TableIndicesBase<7> - { - public: - /** - * Default constructor. Set all - * indices to zero. - */ - TableIndices (); - - /** - * Constructor. Set indices to - * the given values. - */ - TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5, - const unsigned int index6, - const unsigned int index7); - }; - - namespace internal { @@ -1860,236 +1567,6 @@ class Table<7,T> : public TableBase<7,T> /* --------------------- Template and inline functions ---------------- */ -template -inline -unsigned int -TableIndicesBase::operator [] (const unsigned int i) const -{ - Assert (i < N, ExcIndexRange (i, 0, N)); - return indices[i]; -} - - - -template -inline -bool -TableIndicesBase::operator == (const TableIndicesBase &other) const -{ - for (unsigned int i=0; i -inline -bool -TableIndicesBase::operator != (const TableIndicesBase &other) const -{ - return !(*this == other); -} - - - -template <> -inline -void -TableIndicesBase<1>::sort () -{} - - - -template <> -inline -void -TableIndicesBase<2>::sort () -{ - if (indices[1] < indices[0]) - std::swap (indices[0], indices[1]); -} - - - -template <> -inline -void -TableIndicesBase<3>::sort () -{ - // bubble sort for 3 elements - if (indices[1] < indices[0]) - std::swap (indices[0], indices[1]); - if (indices[2] < indices[1]) - std::swap (indices[1], indices[2]); - if (indices[1] < indices[0]) - std::swap (indices[0], indices[1]); -} - - - - -inline -TableIndices<1>::TableIndices () -{ - this->indices[0] = 0; -} - - - -inline -TableIndices<1>::TableIndices (const unsigned int index1) -{ - this->indices[0] = index1; -} - - - -inline -TableIndices<2>::TableIndices () -{ - this->indices[0] = this->indices[1] = 0; -} - - - -inline -TableIndices<2>::TableIndices (const unsigned int index1, - const unsigned int index2) -{ - this->indices[0] = index1; - this->indices[1] = index2; -} - - - -inline -TableIndices<3>::TableIndices () -{ - this->indices[0] = this->indices[1] = this->indices[2] = 0; -} - - - -inline -TableIndices<3>::TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3) -{ - this->indices[0] = index1; - this->indices[1] = index2; - this->indices[2] = index3; -} - - -inline -TableIndices<4>::TableIndices () -{ - this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = 0; -} - - - -inline -TableIndices<4>::TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4) -{ - this->indices[0] = index1; - this->indices[1] = index2; - this->indices[2] = index3; - this->indices[3] = index4; -} - - - -inline -TableIndices<5>::TableIndices () -{ - this->indices[0] = this->indices[1] - = this->indices[2] - = this->indices[3] - = this->indices[4] = 0; -} - - - -inline -TableIndices<5>::TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5) -{ - this->indices[0] = index1; - this->indices[1] = index2; - this->indices[2] = index3; - this->indices[3] = index4; - this->indices[4] = index5; -} - - - -inline -TableIndices<6>::TableIndices () -{ - this->indices[0] = this->indices[1] = this->indices[2] - = this->indices[3] = this->indices[4] - = this->indices[5] = 0; -} - - - -inline -TableIndices<6>::TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5, - const unsigned int index6) -{ - this->indices[0] = index1; - this->indices[1] = index2; - this->indices[2] = index3; - this->indices[3] = index4; - this->indices[4] = index5; - this->indices[5] = index6; -} - - - -inline -TableIndices<7>::TableIndices () -{ - this->indices[0] = this->indices[1] = this->indices[2] - = this->indices[3] = this->indices[4] - = this->indices[5] = this->indices[6] = 0; -} - - - -inline -TableIndices<7>::TableIndices (const unsigned int index1, - const unsigned int index2, - const unsigned int index3, - const unsigned int index4, - const unsigned int index5, - const unsigned int index6, - const unsigned int index7) -{ - this->indices[0] = index1; - this->indices[1] = index2; - this->indices[2] = index3; - this->indices[3] = index4; - this->indices[4] = index5; - this->indices[5] = index6; - this->indices[6] = index7; -} - - - template TableBase::TableBase () : diff --git a/deal.II/base/include/base/table_indices.h b/deal.II/base/include/base/table_indices.h new file mode 100644 index 0000000000..89ab488be4 --- /dev/null +++ b/deal.II/base/include/base/table_indices.h @@ -0,0 +1,550 @@ +//--------------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//--------------------------------------------------------------------------- +#ifndef __deal2__table_indices_h +#define __deal2__table_indices_h + + +#include +#include + + + +/** + * Base class for an array of indices of fixed size used for the TableBase and + * SymmetricTensor classes. Actually, this class serves a dual purpose, as it + * not only stores indices into the TableBase class, but also the sizes of the + * table in its various coordinates. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class TableIndicesBase +{ + public: + /** + * Access the value of the + * ith index. + */ + unsigned int operator[] (const unsigned int i) const; + + /** + * Compare two index fields for + * equality. + */ + bool operator == (const TableIndicesBase &other) const; + + /** + * Compare two index fields for + * inequality. + */ + bool operator != (const TableIndicesBase &other) const; + + /** + * Sort the indices in ascending + * order. While this operation is not + * very useful for Table objects, it is + * used for the SymmetricTensor class. + */ + void sort (); + + protected: + /** + * Store the indices in an array. + */ + unsigned indices[N]; +}; + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the general template, and has no implementation. There are + * a number of specializations that are actually implemented (one for + * each used value of N), which only differ in the way they + * implement their constructors (they take N arguments, something + * that cannot be represented by a general template). Actual storage + * of and access to data is done by the TableIndicesBase base + * class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template +class TableIndices +{ +}; + + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a one-dimensional table, i.e. a + * vector. This class only differs in the non-default constructors + * from the other specializations. Actual storage of and access to + * data is done by the TableIndicesBase base class of a + * specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<1> : public TableIndicesBase<1> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1); +}; + + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a two-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<2> : public TableIndicesBase<2> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2); +}; + + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a three-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, 2002 + */ +template <> +class TableIndices<3> : public TableIndicesBase<3> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3); +}; + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a four-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<4> : public TableIndicesBase<4> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4); +}; + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a five-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<5> : public TableIndicesBase<5> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5); +}; + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a six-dimensional table. This class + * only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, Ralf Hartmann 2002 + */ +template <> +class TableIndices<6> : public TableIndicesBase<6> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6); +}; + + +/** + * Array of indices of fixed size used for the TableBase + * class. + * + * This is the specialization for a seven-dimensional table. This + * class only differs in the non-default constructors from the other + * specializations. Actual storage of and access to data is done by + * the TableIndicesBase base class of a specializations. + * + * @author Wolfgang Bangerth, 2002, Ralf Hartmann 2004 + */ +template <> +class TableIndices<7> : public TableIndicesBase<7> +{ + public: + /** + * Default constructor. Set all + * indices to zero. + */ + TableIndices (); + + /** + * Constructor. Set indices to + * the given values. + */ + TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6, + const unsigned int index7); +}; + + +/* --------------------- Template and inline functions ---------------- */ + + +template +inline +unsigned int +TableIndicesBase::operator [] (const unsigned int i) const +{ + Assert (i < N, ExcIndexRange (i, 0, N)); + return indices[i]; +} + + + +template +inline +bool +TableIndicesBase::operator == (const TableIndicesBase &other) const +{ + for (unsigned int i=0; i +inline +bool +TableIndicesBase::operator != (const TableIndicesBase &other) const +{ + return !(*this == other); +} + + + +template <> +inline +void +TableIndicesBase<1>::sort () +{} + + + +template <> +inline +void +TableIndicesBase<2>::sort () +{ + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); +} + + + +template <> +inline +void +TableIndicesBase<3>::sort () +{ + // bubble sort for 3 elements + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); + if (indices[2] < indices[1]) + std::swap (indices[1], indices[2]); + if (indices[1] < indices[0]) + std::swap (indices[0], indices[1]); +} + + + + +inline +TableIndices<1>::TableIndices () +{ + this->indices[0] = 0; +} + + + +inline +TableIndices<1>::TableIndices (const unsigned int index1) +{ + this->indices[0] = index1; +} + + + +inline +TableIndices<2>::TableIndices () +{ + this->indices[0] = this->indices[1] = 0; +} + + + +inline +TableIndices<2>::TableIndices (const unsigned int index1, + const unsigned int index2) +{ + this->indices[0] = index1; + this->indices[1] = index2; +} + + + +inline +TableIndices<3>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = 0; +} + + + +inline +TableIndices<3>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; +} + + +inline +TableIndices<4>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] = this->indices[3] = 0; +} + + + +inline +TableIndices<4>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; +} + + + +inline +TableIndices<5>::TableIndices () +{ + this->indices[0] = this->indices[1] + = this->indices[2] + = this->indices[3] + = this->indices[4] = 0; +} + + + +inline +TableIndices<5>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; + this->indices[4] = index5; +} + + + +inline +TableIndices<6>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] + = this->indices[3] = this->indices[4] + = this->indices[5] = 0; +} + + + +inline +TableIndices<6>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; + this->indices[4] = index5; + this->indices[5] = index6; +} + + + +inline +TableIndices<7>::TableIndices () +{ + this->indices[0] = this->indices[1] = this->indices[2] + = this->indices[3] = this->indices[4] + = this->indices[5] = this->indices[6] = 0; +} + + + +inline +TableIndices<7>::TableIndices (const unsigned int index1, + const unsigned int index2, + const unsigned int index3, + const unsigned int index4, + const unsigned int index5, + const unsigned int index6, + const unsigned int index7) +{ + this->indices[0] = index1; + this->indices[1] = index2; + this->indices[2] = index3; + this->indices[3] = index4; + this->indices[4] = index5; + this->indices[5] = index6; + this->indices[6] = index7; +} + + + + +#endif