From: bangerth Date: Sun, 29 Mar 2009 04:15:22 +0000 (+0000) Subject: Add a class that allows to find out whether a template argument is a block matrix. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b6ccdab2e716e613245e93e56380921e066682e;p=dealii-svn.git Add a class that allows to find out whether a template argument is a block matrix. git-svn-id: https://svn.dealii.org/trunk@18523 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/block_matrix_base.h b/deal.II/lac/include/lac/block_matrix_base.h index 6c81977467..baf6cd6c50 100644 --- a/deal.II/lac/include/lac/block_matrix_base.h +++ b/deal.II/lac/include/lac/block_matrix_base.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2004, 2005, 2006, 2007, 2008 by the deal.II authors +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -28,7 +28,77 @@ DEAL_II_NAMESPACE_OPEN template class MatrixIterator; +template class BlockMatrixBase; +template class BlockSparseMatrixEZ; +/** + * A class that can be used to determine whether a given type is a block + * matrix type or not. For example, + * @code + * IsBlockMatrix >::value + * @encode + * has the value false, whereas + * @code + * IsBlockMatrix >::value + * @encode + * is true. This is sometimes useful in template contexts where we may + * want to do things differently depending on whether a template type + * denotes a regular or a block matrix type. + * + * @author Wolfgang Bangerth, 2009 + */ +template +struct IsBlockMatrix +{ + private: + struct yes_type { char c[1]; }; + struct no_type { char c[2]; }; + + /** + * Overload returning true if the class + * is derived from BlockMatrixBase, which + * is what block matrices do (with the + * exception of BlockSparseMatrixEZ. + */ + template + static yes_type is_derived_from_BlockMatrixBase (const BlockMatrixBase *); + + /** + * Overload for BlockSparseMatrixEZ, + * which is the only block matrix not + * derived from BlockMatrixBase at the + * time of writing this class. + */ + template + static yes_type is_derived_from_BlockMatrixBase (const BlockSparseMatrixEZ *); + + /** + * Catch all for all other potential + * matrix types that are not block + * matrices. + */ + static no_type is_derived_from_BlockMatrixBase (...); + + public: + /** + * A statically computable value that + * indicates whether the template + * argument to this class is a block + * matrix (in fact whether the type is + * derived from BlockMatrix). + */ + static const bool value = (sizeof(is_derived_from_BlockMatrixBase + ((MatrixType*)0)) + == + sizeof(yes_type)); +}; + + +// instantiation of the static member +template +const bool IsBlockMatrix::value; + + /*! @addtogroup Matrix1 *@{