Michele De Stefano's C++ Utilities
traits.hpp
Go to the documentation of this file.
1 // traits.hpp
2 //
3 // Copyright (c) 2009 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file COPYING)
6 
7 #ifndef MDS_UTILS_UBLAS_TRAITS_HPP_INCLUDED
8 #define MDS_UTILS_UBLAS_TRAITS_HPP_INCLUDED
9 
26 #include <boost/numeric/ublas/matrix.hpp>
27 #include <boost/numeric/ublas/matrix_sparse.hpp>
28 #include <boost/mpl/if.hpp>
29 #include <boost/mpl/and.hpp>
30 #include <boost/mpl/not.hpp>
31 #include <boost/mpl/has_xxx.hpp>
32 
33 namespace mds_utils {
34 
42  namespace ublas {
43 
44 /*
45  * \brief Defines the has_storage_category<T> boolean unary metafunction.
46  *
47  * If \p T contains a nested typedef named \p storage_category then
48  * inherits from std::true_type; otherwise it inherits from std::false_type.
49  *
50  * \headerfile traits.hpp mds_utils/ublas/traits.hpp
51  *
52  * \author Michele De Stefano
53  * \date 25/05/2014
54  */
55 BOOST_MPL_HAS_XXX_TRAIT_DEF(storage_category)
56 
57 /*
58  * \brief Defines the has_index_array_type<T> boolean unary metafunction.
59  *
60  * If \p T contains a nested typedef named \p has_index_array_type then
61  * inherits from std::true_type; otherwise it inherits from std::false_type.
62  *
63  * \headerfile traits.hpp mds_utils/ublas/traits.hpp
64  *
65  * \author Michele De Stefano
66  * \date 25/05/2014
67  */
68 BOOST_MPL_HAS_XXX_TRAIT_DEF(index_array_type)
69 
70 /*
71  * \brief Defines the has_value_array_type<T> boolean unary metafunction.
72  *
73  * If \p T contains a nested typedef named \p index_array_type then
74  * inherits from std::true_type; otherwise it inherits from std::false_type.
75  *
76  * \headerfile traits.hpp mds_utils/ublas/traits.hpp
77  *
78  * \author Michele De Stefano
79  * \date 25/05/2014
80  */
81 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_array_type)
82 
83 
84 template<class T,class Enable = void>
86 struct is_vector : std::false_type {};
87 
88 template<class T,class Enable = void>
89 struct is_matrix : std::false_type {};
90 
91 template<class T,class Enable = void>
92 struct is_compressed_matrix : std::false_type {};
94 
95 
112 template<class T>
113 struct is_vector<T,
114  typename std::enable_if<
115  boost::mpl::and_<
116  std::is_base_of<
117  boost::numeric::ublas::vector_container<T>,
118  T
119  >,
120  has_storage_category<T>,
121  std::is_same<
122  typename T::storage_category,
123  boost::numeric::ublas::dense_tag
124  >
125  >::value
126  >::type
127  > : std::true_type {};
128 
129 
146 template<class T>
147 struct is_matrix<T,
148  typename std::enable_if<
149  boost::mpl::and_<
150  std::is_base_of<
151  boost::numeric::ublas::matrix_container<T>,
152  T
153  >,
154  has_storage_category<T>,
155  std::is_same<
156  typename T::storage_category,
157  boost::numeric::ublas::dense_tag
158  >
159  >::value
160  >::type
161  > : std::true_type {};
162 
163 
164 
181 template<class T>
182 struct is_compressed_matrix<T,
183  typename std::enable_if<
184  boost::mpl::and_<
185  std::is_base_of<
186  boost::numeric::ublas::matrix_container<T>,
187  T
188  >,
189  has_storage_category<T>,
190  has_index_array_type<T>,
191  has_value_array_type<T>,
192  std::is_same<
193  typename T::storage_category,
194  boost::numeric::ublas::sparse_tag
195  >
196  >::value
197  >::type
198  > : std::true_type {};
199 
200 
216 template<class orientation_category>
218 
220 template<>
221 struct opposite_orientation<boost::numeric::ublas::row_major_tag> {
222  typedef boost::numeric::ublas::column_major type;
223 };
224 
225 template<>
226 struct opposite_orientation<boost::numeric::ublas::column_major_tag> {
227  typedef boost::numeric::ublas::row_major type;
228 };
230 
231 
232  }
233 }
234 
235 #endif
Main namespace of all Michele De Stefano&#39;s C++ utilities.
Definition: endian.hpp:30
Allows the computation of the opposite orientation tag with respect to the one passed as template par...
Definition: traits.hpp:217