| 1 | /* |
| 2 | * compare_fusion_vector.hpp |
| 3 | * |
| 4 | * Created on: Nov 1, 2015 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef OPENFPM_DATA_SRC_UTIL_COMPARE_FUSION_VECTOR_HPP_ |
| 9 | #define OPENFPM_DATA_SRC_UTIL_COMPARE_FUSION_VECTOR_HPP_ |
| 10 | |
| 11 | #include "meta_compare.hpp" |
| 12 | |
| 13 | /*! \brief this class is a functor for "for_each" algorithm |
| 14 | * |
| 15 | * It compare a boost::fusion::vector with another boost::fusion::vector |
| 16 | * |
| 17 | */ |
| 18 | template<typename bfv> |
| 19 | struct compare_fusion_vector |
| 20 | { |
| 21 | //! Result of the comparation |
| 22 | bool eq; |
| 23 | |
| 24 | //! operator1 |
| 25 | const bfv & src; |
| 26 | |
| 27 | //! operator2 |
| 28 | const bfv & dst; |
| 29 | |
| 30 | /*! \brief constructor |
| 31 | * |
| 32 | * It define the elements to compare. |
| 33 | * |
| 34 | * \param src operator1 |
| 35 | * \param dst operator2 |
| 36 | * |
| 37 | */ |
| 38 | inline compare_fusion_vector(const bfv & src, const bfv & dst) |
| 39 | :eq(true),src(src),dst(dst){}; |
| 40 | |
| 41 | #ifdef SE_CLASS1 |
| 42 | /*! \brief Constructor |
| 43 | * |
| 44 | * Calling this constructor produce an error. This class store the reference of the object, |
| 45 | * this mean that the object passed must not be a temporal object |
| 46 | * |
| 47 | */ |
| 48 | inline compare_fusion_vector(const bfv && src, const bfv && dst) |
| 49 | :eq(true),src(src),dst(dst) |
| 50 | {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n" ;}; |
| 51 | #endif |
| 52 | |
| 53 | /*! \brief It call the copy function for each property |
| 54 | * |
| 55 | * \tparam compile-time value |
| 56 | * |
| 57 | * \param t unused |
| 58 | * |
| 59 | */ |
| 60 | template<typename T> |
| 61 | inline void operator()(T& t) |
| 62 | { |
| 63 | // This is the type of the object we have to copy |
| 64 | typedef typename boost::fusion::result_of::at_c<bfv,T::value>::type copy_type; |
| 65 | |
| 66 | // Remove the reference from the type to copy |
| 67 | typedef typename boost::remove_reference<copy_type>::type copy_rtype; |
| 68 | |
| 69 | if (eq == false) |
| 70 | return; |
| 71 | |
| 72 | eq = meta_compare<copy_rtype>::meta_compare_f(boost::fusion::at_c<T::value>(src),boost::fusion::at_c<T::value>(dst)); |
| 73 | } |
| 74 | |
| 75 | /*! \brief Returh the result of the comparison |
| 76 | * |
| 77 | * \return true if aggregates match |
| 78 | * |
| 79 | */ |
| 80 | inline bool result() |
| 81 | { |
| 82 | return eq; |
| 83 | } |
| 84 | }; |
| 85 | |
| 86 | |
| 87 | |
| 88 | #endif /* OPENFPM_DATA_SRC_UTIL_COMPARE_FUSION_VECTOR_HPP_ */ |
| 89 | |