From 1d64d27b57169ab01f9c20758524855a654a6b8e Mon Sep 17 00:00:00 2001 From: Max Kahnt <max.kahnt@fu-berlin.de> Date: Sun, 1 Oct 2017 01:06:40 +0200 Subject: [PATCH] Move traits classes and utilities to separate directory. --- dune/matrix-vector/CMakeLists.txt | 3 +- dune/matrix-vector/matrixtraits.hh | 62 -------------- dune/matrix-vector/scalartraits.hh | 43 ---------- dune/matrix-vector/traits/CMakeLists.txt | 7 ++ dune/matrix-vector/traits/matrixtraits.hh | 61 +++++++++++++ dune/matrix-vector/traits/scalartraits.hh | 48 +++++++++++ dune/matrix-vector/traits/utilities.hh | 85 +++++++++++++++++++ .../{ => traits}/vectortraits.hh | 8 +- dune/matrix-vector/traitutilities.hh | 79 ----------------- 9 files changed, 207 insertions(+), 189 deletions(-) delete mode 100644 dune/matrix-vector/matrixtraits.hh delete mode 100644 dune/matrix-vector/scalartraits.hh create mode 100644 dune/matrix-vector/traits/CMakeLists.txt create mode 100644 dune/matrix-vector/traits/matrixtraits.hh create mode 100644 dune/matrix-vector/traits/scalartraits.hh create mode 100644 dune/matrix-vector/traits/utilities.hh rename dune/matrix-vector/{ => traits}/vectortraits.hh (77%) delete mode 100644 dune/matrix-vector/traitutilities.hh diff --git a/dune/matrix-vector/CMakeLists.txt b/dune/matrix-vector/CMakeLists.txt index ce19f4c..fb8e117 100644 --- a/dune/matrix-vector/CMakeLists.txt +++ b/dune/matrix-vector/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(test) +add_subdirectory(traits) #install headers install(FILES @@ -12,9 +13,7 @@ install(FILES crossproduct.hh genericvectortools.hh ldlt.hh - matrixtraits.hh promote.hh - scalartraits.hh singlenonzerocolumnmatrix.hh singlenonzerorowmatrix.hh tranpose.hh diff --git a/dune/matrix-vector/matrixtraits.hh b/dune/matrix-vector/matrixtraits.hh deleted file mode 100644 index 73c3c0d..0000000 --- a/dune/matrix-vector/matrixtraits.hh +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef DUNE_MATRIX_VECTOR_MATRIXTRAITS_HH -#define DUNE_MATRIX_VECTOR_MATRIXTRAITS_HH - -#include <dune/common/diagonalmatrix.hh> -#include <dune/common/fmatrix.hh> -#include <dune/istl/bcrsmatrix.hh> -#include <dune/istl/multitypeblockmatrix.hh> -#include <dune/istl/scaledidmatrix.hh> - -namespace Dune { - namespace MatrixVector { - - /** \brief Class to identify matrix types and extract information - * - * Specialize this class for all types that can be used like a matrix. - */ - template<class T> - struct MatrixTraits - { - constexpr static bool isMatrix = false; - constexpr static int rows = -1; - constexpr static int cols = -1; - }; - - template<class T, int n, int m> - struct MatrixTraits<Dune::FieldMatrix<T,n,m> > - { - constexpr static bool isMatrix = true; - constexpr static int rows = n; - constexpr static int cols = m; - }; - - template<class T, int n> - struct MatrixTraits<Dune::DiagonalMatrix<T,n> > - { - constexpr static bool isMatrix = true; - constexpr static int rows = n; - constexpr static int cols = n; - }; - - template<class T, int n> - struct MatrixTraits<Dune::ScaledIdentityMatrix<T,n> > - { - constexpr static bool isMatrix = true; - constexpr static int rows = n; - constexpr static int cols = n; - }; - - template<class T> - struct MatrixTraits<Dune::BCRSMatrix<T> > - { - constexpr static bool isMatrix = true; - }; - - template<class... T> - struct MatrixTraits<MultiTypeBlockMatrix<T...> > - { - constexpr static bool isMatrix = true; - }; - } -} -#endif diff --git a/dune/matrix-vector/scalartraits.hh b/dune/matrix-vector/scalartraits.hh deleted file mode 100644 index 66b47c3..0000000 --- a/dune/matrix-vector/scalartraits.hh +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef DUNE_MATRIX_VECTOR_SCALARTRAITS_HH -#define DUNE_MATRIX_VECTOR_SCALARTRAITS_HH - -#include <dune/common/diagonalmatrix.hh> -#include <dune/common/fmatrix.hh> -#include <dune/common/typetraits.hh> -#include <dune/istl/bcrsmatrix.hh> -#include <dune/istl/scaledidmatrix.hh> - -namespace Dune { -namespace MatrixVector { - /** \brief Class to identify scalar types - * - * Specialize this class for all types that can be used - * like scalar quantities. - */ - template <class T> - struct ScalarTraits { - constexpr static bool isScalar = Dune::IsNumber<T>::value; - }; - - template <class T> - struct ScalarTraits<Dune::FieldVector<T, 1>> { - constexpr static bool isScalar = true; - }; - - template <class T> - struct ScalarTraits<Dune::FieldMatrix<T, 1, 1>> { - constexpr static bool isScalar = true; - }; - - template <class T> - struct ScalarTraits<Dune::DiagonalMatrix<T, 1>> { - constexpr static bool isScalar = true; - }; - - template <class T> - struct ScalarTraits<Dune::ScaledIdentityMatrix<T, 1>> { - constexpr static bool isScalar = true; - }; -} -} -#endif diff --git a/dune/matrix-vector/traits/CMakeLists.txt b/dune/matrix-vector/traits/CMakeLists.txt new file mode 100644 index 0000000..1efde8c --- /dev/null +++ b/dune/matrix-vector/traits/CMakeLists.txt @@ -0,0 +1,7 @@ +#install headers +install(FILES + scalartraits.hh + matrixtraits.hh + vectortraits.hh + utilities.hh + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/matrix-vector/traits) diff --git a/dune/matrix-vector/traits/matrixtraits.hh b/dune/matrix-vector/traits/matrixtraits.hh new file mode 100644 index 0000000..9d53fae --- /dev/null +++ b/dune/matrix-vector/traits/matrixtraits.hh @@ -0,0 +1,61 @@ +#ifndef DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH +#define DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH + +#include <dune/common/diagonalmatrix.hh> +#include <dune/common/fmatrix.hh> + +#include <dune/istl/bcrsmatrix.hh> +#include <dune/istl/multitypeblockmatrix.hh> +#include <dune/istl/scaledidmatrix.hh> + +namespace Dune { +namespace MatrixVector { +namespace Traits { + +/** \brief Class to identify matrix types and extract information + * + * Specialize this class for all types that can be used like a matrix. + */ +template<class T> +struct MatrixTraits { + constexpr static bool isMatrix = false; + constexpr static int rows = -1; + constexpr static int cols = -1; +}; + +template<class T, int n, int m> +struct MatrixTraits<FieldMatrix<T, n, m>> { + constexpr static bool isMatrix = true; + constexpr static int rows = n; + constexpr static int cols = m; +}; + +template<class T, int n> +struct MatrixTraits<DiagonalMatrix<T, n>> { + constexpr static bool isMatrix = true; + constexpr static int rows = n; + constexpr static int cols = n; +}; + +template<class T, int n> +struct MatrixTraits<ScaledIdentityMatrix<T, n>> { + constexpr static bool isMatrix = true; + constexpr static int rows = n; + constexpr static int cols = n; +}; + +template<class T> +struct MatrixTraits<BCRSMatrix<T>> { + constexpr static bool isMatrix = true; +}; + +template<class... T> +struct MatrixTraits<MultiTypeBlockMatrix<T...> > { + constexpr static bool isMatrix = true; +}; + +} // end namespace Traits +} // end namespace MatrixVector +} // end namespace Dune + +#endif // DUNE_MATRIX_VECTOR_TRAITS_MATRIXTRAITS_HH diff --git a/dune/matrix-vector/traits/scalartraits.hh b/dune/matrix-vector/traits/scalartraits.hh new file mode 100644 index 0000000..2c284b4 --- /dev/null +++ b/dune/matrix-vector/traits/scalartraits.hh @@ -0,0 +1,48 @@ +#ifndef DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH +#define DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH + +#include <dune/common/diagonalmatrix.hh> +#include <dune/common/fmatrix.hh> +#include <dune/common/typetraits.hh> +#include <dune/istl/bcrsmatrix.hh> +#include <dune/istl/scaledidmatrix.hh> + +namespace Dune { +namespace MatrixVector { +namespace Traits { + +/** \brief Class to identify scalar types + * + * Specialize this class for all types that can be used + * like scalar quantities. + */ +template <class T> +struct ScalarTraits { + constexpr static bool isScalar = Dune::IsNumber<T>::value; +}; + +template <class T> +struct ScalarTraits<Dune::FieldVector<T, 1>> { + constexpr static bool isScalar = true; +}; + +template <class T> +struct ScalarTraits<Dune::FieldMatrix<T, 1, 1>> { + constexpr static bool isScalar = true; +}; + +template <class T> +struct ScalarTraits<Dune::DiagonalMatrix<T, 1>> { + constexpr static bool isScalar = true; +}; + +template <class T> +struct ScalarTraits<Dune::ScaledIdentityMatrix<T, 1>> { + constexpr static bool isScalar = true; +}; + +} // end namespace Traits +} // end namespace MatrixVector +} // end namespace Dune + +#endif // DUNE_MATRIX_VECTOR_TRAITS_SCALARTRAITS_HH diff --git a/dune/matrix-vector/traits/utilities.hh b/dune/matrix-vector/traits/utilities.hh new file mode 100644 index 0000000..ecc17b5 --- /dev/null +++ b/dune/matrix-vector/traits/utilities.hh @@ -0,0 +1,85 @@ +#ifndef DUNE_MATRIX_VECTOR_UTILITIES_HH +#define DUNE_MATRIX_VECTOR_UTILITIES_HH + +#include <type_traits> + +#include <dune/common/std/type_traits.hh> +#include <dune/common/typetraits.hh> + +#include <dune/matrix-vector/concepts.hh> +#include <dune/matrix-vector/traits/scalartraits.hh> +#include <dune/matrix-vector/traits/matrixtraits.hh> +#include <dune/matrix-vector/traits/vectortraits.hh> + +namespace Dune { +namespace MatrixVector { + +// convenience compile-time functions to classify types +template <class T> +constexpr auto isNumber() { + return Std::bool_constant<IsNumber<std::decay_t<T>>::value>(); +} + +template <class T> +constexpr auto isScalar() { + return Std::bool_constant<Traits::ScalarTraits<std::decay_t<T>>::isScalar>(); +} + +template <class T> +constexpr auto isVector() { + return Std::bool_constant<Traits::VectorTraits<std::decay_t<T>>::isVector>(); +} + +template <class T> +constexpr auto isMatrix() { + return Std::bool_constant<Traits::MatrixTraits<std::decay_t<T>>::isMatrix>(); +} + +template <class T> +constexpr auto isTupleOrDerived() { + return Std::bool_constant<IsTupleOrDerived<std::decay_t<T>>::value>(); +} + +// enable_if typedefs for traits ... +template <class T, class R = void> +using EnableNumber = std::enable_if_t<isNumber<T>(), R>; + +template <class T, class R = void> +using EnableScalar = std::enable_if_t<isScalar<T>(), R>; + +template <class T, class R = void> +using EnableVector = std::enable_if_t<isVector<T>(), R>; + +template <class T, class R = void> +using EnableMatrix = std::enable_if_t<isMatrix<T>(), R>; + +template <class T, class R = void> +using EnableTupleOrDerived = std::enable_if_t<isTupleOrDerived<T>(), R>; + +// ... and their negations +template <class T, class R = void> +using DisableNumber = std::enable_if_t<not isNumber<T>(), R>; + +template <class T, class R = void> +using DisableScalar = std::enable_if_t<not isScalar<T>(), R>; + +template <class T, class R = void> +using DisableVector = std::enable_if_t<not isVector<T>(), R>; + +template <class T, class R = void> +using DisableMatrix = std::enable_if_t<not isMatrix<T>(), R>; + +template <class T, class R = void> +using DisableTupleOrDerived = std::enable_if_t<not isTupleOrDerived<T>(), R>; + +// compile-time property checks +template <class T> +constexpr auto isSparseRangeIterable() { + return Std::bool_constant<isTupleOrDerived<T>() or + models<Concept::HasBegin, T>()>(); +} + +} // end namespace MatrixVector +} // end namespace Dune + +#endif // DUNE_MATRIX_VECTOR_TRAITS_UTILITIES_HH diff --git a/dune/matrix-vector/vectortraits.hh b/dune/matrix-vector/traits/vectortraits.hh similarity index 77% rename from dune/matrix-vector/vectortraits.hh rename to dune/matrix-vector/traits/vectortraits.hh index e505a7e..a58b7c1 100644 --- a/dune/matrix-vector/vectortraits.hh +++ b/dune/matrix-vector/traits/vectortraits.hh @@ -1,5 +1,5 @@ -#ifndef DUNE_MATRIX_VECTOR_VECTORTRAITS_HH -#define DUNE_MATRIX_VECTOR_VECTORTRAITS_HH +#ifndef DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH +#define DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH #include <dune/common/fvector.hh> #include <dune/istl/bvector.hh> @@ -7,6 +7,7 @@ namespace Dune { namespace MatrixVector { +namespace Traits { /** \brief Class to identify vector types and extract information * @@ -27,7 +28,8 @@ struct VectorTraits<BlockVector<Block>> { constexpr static bool isVector = true; }; +} // end namespace Traits } // end namespace MatrixVector } // end namespace Dune -#endif // DUNE_MATRIX_VECTOR_VECTORTRAITS_HH +#endif // DUNE_MATRIX_VECTOR_TRAITS_VECTORTRAITS_HH diff --git a/dune/matrix-vector/traitutilities.hh b/dune/matrix-vector/traitutilities.hh deleted file mode 100644 index 7be1950..0000000 --- a/dune/matrix-vector/traitutilities.hh +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH -#define DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH - -#include <type_traits> - -#include <dune/common/std/type_traits.hh> -#include <dune/common/typetraits.hh> - -#include <dune/matrix-vector/concepts.hh> -#include <dune/matrix-vector/scalartraits.hh> -#include <dune/matrix-vector/matrixtraits.hh> -#include <dune/matrix-vector/vectortraits.hh> - -namespace Dune { -namespace MatrixVector { - -// convenience compile-time functions to classify types -template <class T> -constexpr auto isNumber() { - return Std::bool_constant<IsNumber<T>::value>(); -} - -template <class T> -constexpr auto isScalar() { - return Std::bool_constant<ScalarTraits<T>::isScalar>(); -} - -template <class T> -constexpr auto isVector() { - return Std::bool_constant<VectorTraits<T>::isVector>(); -} - -template <class T> -constexpr auto isMatrix() { - return Std::bool_constant<MatrixTraits<T>::isMatrix>(); -} - -template <class T> -constexpr auto isTupleOrDerived() { - return Std::bool_constant<IsTupleOrDerived<std::decay_t<T>>::value>(); -} - -// enable_if typedefs for traits ... -template <class T> -using EnableNumber = std::enable_if_t<isNumber<T>()>; - -template <class T> -using EnableScalar = std::enable_if_t<isScalar<T>()>; - -template <class T> -using EnableVector = std::enable_if_t<isVector<T>()>; - -template <class T> -using EnableMatrix = std::enable_if_t<isMatrix<T>()>; - -// ... and their negations -template <class T> -using DisableNumber = std::enable_if_t<not isNumber<T>()>; - -template <class T> -using DisableScalar = std::enable_if_t<not isScalar<T>()>; - -template <class T> -using DisableVector = std::enable_if_t<not isVector<T>()>; - -template <class T> -using DisableMatrix = std::enable_if_t<not isMatrix<T>()>; - -// compile-time property checks -template <class T> -constexpr auto isSparseRangeIterable() { - return Std::bool_constant<isTupleOrDerived<T>() or - models<Concept::HasBegin, T>()>(); -} - -} // end namespace MatrixVector -} // end namespace Dune - -#endif // DUNE_MATRIX_VECTOR_TRAITUTILITIES_HH -- GitLab