1 | /* |
2 | * util_num.hpp |
3 | * |
4 | * Created on: Oct 23, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_HPP_ |
9 | #define OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_HPP_ |
10 | |
11 | #include "util/common.hpp" |
12 | #include "grid_dist_testing.hpp" |
13 | #include "Grid/grid_dist_id.hpp" |
14 | |
15 | template<typename T, typename Sfinae = void> |
16 | struct is_const_field: std::false_type {}; |
17 | |
18 | /*! \brief is_constant check if a type define a constant field |
19 | * |
20 | * ### Example |
21 | * \snippet util_num_unit_tests.hpp Constant fields struct definition |
22 | * \snippet util_num_unit_tests.hpp Usage of is_const_field |
23 | * |
24 | * return true if T::constant_field exist, it does not matter which type is |
25 | * |
26 | */ |
27 | template<typename T> |
28 | struct is_const_field<T, typename Void<typename T::const_field>::type> : std::true_type |
29 | {}; |
30 | |
31 | |
32 | template<typename T, typename Sfinae = void> |
33 | struct has_val_pos: std::false_type {}; |
34 | |
35 | |
36 | /*! \brief has_attributes check if a type has defined an |
37 | * internal structure with attributes |
38 | * |
39 | * ### Example |
40 | * \snippet util_test.hpp Declaration of struct with attributes and without |
41 | * \snippet util_test.hpp Check has_attributes |
42 | * |
43 | * return true if T::attributes::name[0] is a valid expression |
44 | * and produce a defined type |
45 | * |
46 | */ |
47 | template<typename T> |
48 | struct has_val_pos<T, typename Void<typename T::with_position >::type> : std::true_type |
49 | {}; |
50 | |
51 | |
52 | |
53 | template<typename T, typename Sfinae = void> |
54 | struct is_testing: std::false_type {}; |
55 | |
56 | |
57 | /*! \brief is_testing check if a struct T has testing member defined |
58 | * |
59 | * ### Example |
60 | * \snippet util_num_unit_tests.hpp Is on test struct definition |
61 | * \snippet util_num_unit_tests.hpp Usage of is_testing |
62 | * |
63 | * return true if T::attributes::name[0] is a valid expression |
64 | * and produce a defined type |
65 | * |
66 | */ |
67 | template<typename T> |
68 | struct is_testing<T, typename Void<typename T::testing >::type> : std::true_type |
69 | {}; |
70 | |
71 | |
72 | /*! \brief In case of testing return a stub grid |
73 | * |
74 | * ### Example |
75 | * \snippet util_num_unit_tests.hpp Is on test struct definition |
76 | * \snippet util_num_unit_tests.hpp Usage of is_testing |
77 | * |
78 | * return true if T::attributes::name[0] is a valid expression |
79 | * and produce a defined type |
80 | * |
81 | */ |
82 | template<typename T, unsigned int dims, typename stype, typename decomposition, bool stub=is_testing<T>::value> |
83 | struct stub_or_real |
84 | { |
85 | //! switch type if we are on testing or not |
86 | typedef grid_dist_testing<dims> type; |
87 | }; |
88 | |
89 | //! Case when we are not on testing |
90 | template<typename T, unsigned int dims, typename stype, typename decomposition> |
91 | struct stub_or_real<T,dims,stype,decomposition,false> |
92 | { |
93 | //! switch type if we are on testing or not |
94 | typedef grid_dist_id<dims,stype,aggregate<size_t>,decomposition> type; |
95 | }; |
96 | |
97 | #endif /* OPENFPM_NUMERICS_SRC_UTIL_UTIL_NUM_HPP_ */ |
98 | |