1 | /* |
2 | * compare_general.hpp |
3 | * |
4 | * Created on: Nov 1, 2015 |
5 | * Author: i-bird |
6 | */ |
7 | |
8 | #ifndef OPENFPM_DATA_SRC_UTIL_COMPARE_GENERAL_HPP_ |
9 | #define OPENFPM_DATA_SRC_UTIL_COMPARE_GENERAL_HPP_ |
10 | |
11 | |
12 | #include "util/common.hpp" |
13 | #include "util/util_debug.hpp" |
14 | #include "util/for_each_ref.hpp" |
15 | #include <boost/mpl/range_c.hpp> |
16 | |
17 | /*! \brief structure to copy aggregates |
18 | * |
19 | * \tparam T type to copy |
20 | * |
21 | */ |
22 | template<typename T, unsigned int agg=2 * is_aggregate<T>::value> |
23 | struct compare_general |
24 | { |
25 | /*! \brief Spacialization when there is unknown compare method |
26 | * |
27 | * \tparam src source object to copy |
28 | * \tparam dst destination object |
29 | * |
30 | */ |
31 | static inline bool compare_general_f(const T & src, const T & dst) |
32 | { |
33 | #ifndef DISABLE_ALL_RTTI |
34 | std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << demangle(typeid(T).name()) << " does not have an operator== and is not an aggregate or an openfpm native structure, comparation is not possible" << "\n" ; |
35 | #endif |
36 | return false; |
37 | } |
38 | }; |
39 | |
40 | |
41 | template<typename T> |
42 | struct compare_general<T,2> |
43 | { |
44 | /*! \brief compare objects that are aggregates |
45 | * |
46 | * \tparam src source object to copy |
47 | * \tparam dst destination object |
48 | * |
49 | */ |
50 | static inline bool compare_general_f(const T & src, const T & dst) |
51 | { |
52 | compare_aggregate<T> cp(src,dst); |
53 | |
54 | boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(cp); |
55 | |
56 | return cp.result(); |
57 | } |
58 | }; |
59 | |
60 | template<typename T> |
61 | struct compare_general<T,0> |
62 | { |
63 | /*! \brief compare objects that are aggregates but define an operator= |
64 | * |
65 | * \tparam src source object to copy |
66 | * \tparam dst destination object |
67 | * |
68 | */ |
69 | static inline bool compare_general_f(const T & src, const T & dst) |
70 | { |
71 | return dst == src; |
72 | } |
73 | }; |
74 | |
75 | |
76 | #endif /* OPENFPM_DATA_SRC_UTIL_COMPARE_GENERAL_HPP_ */ |
77 | |