1/*
2 * common.hpp
3 *
4 * Created on: Oct 11, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_NUMERICS_SRC_UTIL_COMMON_HPP_
9#define OPENFPM_NUMERICS_SRC_UTIL_COMMON_HPP_
10
11#define STAGGERED_GRID 1
12#define NORMAL_GRID 0
13
14template<typename T, typename Sfinae = void>
15struct has_grid_type: std::false_type {};
16
17
18/*! \brief has_grid_type check if T has defined the member grid_type
19 *
20 * # Define structures with information inside
21 * \snippet common_test.hpp Define structures
22 * # Usage on the defined structures
23 * \snippet common_test.hpp Check has grid_type
24 *
25 */
26template<typename T>
27struct has_grid_type<T, typename Void<decltype( T::grid_type )>::type> : std::true_type
28{};
29
30/*! \brief is_grid_staggered analyse T if it has a property grid_type defined and indicate that
31 * the grid is staggered
32 *
33 * This struct define a method value that return true if the grid is staggered, false otherwise
34 *
35 * # Define structures with information inside
36 * \snippet common_test.hpp Define structures
37 * # Usage on the defined structures
38 * \snippet common_test.hpp Check grid_type staggered
39 *
40 */
41template<typename T, bool has_gt = has_grid_type<T>::type::value >
42struct is_grid_staggered
43{
44 /*! \brief Return true if the grid is staggered
45 *
46 * If T define a staggered grid return true, if define a NORMAL grid or does not
47 * define any grid type return false
48 *
49 * \return true in case the grid type is staggered
50 *
51 */
52 static bool value()
53 {
54 return T::grid_type == STAGGERED_GRID;
55 };
56};
57
58/*! \brief is_grid_staggered analyse T if it has a property that define the type of grid
59 *
60 * This struct define a method value that return id T define a staggered or normal grid
61 *
62 * ### Structures that define a grid type
63 * \snippet util_num_unit_tests.hpp grid_type_struct
64 * ### Usage on the defined structures
65 * \snippet util_num_unit_tests.hpp Usage of is_grid_staggered
66 *
67 */
68template<typename T>
69struct is_grid_staggered<T,false>
70{
71
72 /*! \brief Return true if the grid is staggered
73 *
74 * If T define a staggered grid return true, if define a NORMAL grid or does not
75 * define any grid type return false
76 *
77 * \return true in case the grid type is staggered
78 *
79 */
80 static bool value()
81 {
82 return false;
83 };
84};
85
86#endif /* OPENFPM_NUMERICS_SRC_UTIL_COMMON_HPP_ */
87