OpenFPM  5.2.0
Project that contain the implementation of distributed structures
copy_compare_aggregates.hpp
1 /*
2  * copy_aggregates.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_UTIL_COPY_COMPARE_AGGREGATES_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_COPY_COMPARE_AGGREGATES_HPP_
10 
11 #include <boost/type_traits.hpp>
12 #include <boost/mpl/vector_c.hpp>
13 #include <iostream>
14 
15 template<typename T> struct meta_copy;
16 template<template<typename,typename> class op, typename T> struct meta_copy_op;
17 template<typename T> struct meta_compare;
18 template<typename Tsrc,typename Tdst> struct meta_copy_d;
19 
25 template<typename S, typename S2>
27 {
29  const S src;
30 
32  S2 & dst;
33 
35  inline copy_aggregate_dual(S src, S2 & dst)
36  :src(src),dst(dst){};
37 
39  template<typename T>
40  inline void operator()(T& t) const
41  {
42  // This is the type of the object we have to copy
43  typedef typename boost::fusion::result_of::at_c<typename S2::type,T::value>::type copy_type;
44 
45  // Remove the reference from the type to copy
46  typedef typename boost::remove_reference<copy_type>::type copy_rtype;
47 
48  meta_copy_d<decltype(src.template get<T::value>()), copy_rtype>::meta_copy_d_(src.template get<T::value>(),dst.template get<T::value>());
49  }
50 };
51 
52 template<typename T> struct meta_copy;
53 template<template<typename,typename> class op, typename T> struct meta_copy_op;
54 template<typename T> struct meta_compare;
55 
61 template<typename S>
63 {
65  const S & src;
66 
68  S & dst;
69 
71  inline copy_aggregate(const S & src, S & dst)
72  :src(src),dst(dst){};
73 
75  template<typename T>
76  inline void operator()(T& t) const
77  {
78  // This is the type of the object we have to copy
79  typedef typename boost::fusion::result_of::at_c<typename S::type,T::value>::type copy_type;
80 
81  // Remove the reference from the type to copy
82  typedef typename boost::remove_reference<copy_type>::type copy_rtype;
83 
84  meta_copy<copy_rtype>::meta_copy_(src.template get<T::value>(),dst.template get<T::value>());
85  }
86 };
87 
94 template<template<typename,typename> class op, typename S>
96 {
98  const S & src;
99 
101  S & dst;
102 
104  inline copy_aggregate_op(const S & src, S & dst)
105  :src(src),dst(dst){};
106 
108  template<typename T>
109  inline void operator()(T& t) const
110  {
111  // This is the type of the object we have to copy
112  typedef typename boost::fusion::result_of::at_c<typename S::type,T::value>::type copy_type;
113 
114  // Remove the reference from the type to copy
115  typedef typename boost::remove_reference<copy_type>::type copy_rtype;
116 
117  meta_copy_op<op,copy_rtype>::meta_copy_op_(src.template get<T::value>(),dst.template get<T::value>());
118  }
119 };
120 
121 
127 template<typename S>
129 {
131  bool eq;
132 
134  const S & src;
135 
137  const S & dst;
138 
140  inline compare_aggregate(const S & src, const S & dst)
141  :eq(true),src(src),dst(dst){};
142 
144  template<typename T>
145  inline void operator()(T& t)
146  {
147  // This is the type of the object we have to copy
148  typedef typename boost::fusion::result_of::at_c<typename S::type,T::value>::type compare_type;
149 
150  // Remove the reference from the type to copy
151  typedef typename boost::remove_reference<compare_type>::type compare_rtype;
152 
153  if (eq == false)
154  return;
155 
156  eq = meta_compare<compare_rtype>::meta_compare_f(boost::fusion::at_c<T::value>(src.data),boost::fusion::at_c<T::value>(dst.data));
157  }
158 
164  inline bool result()
165  {
166  return eq;
167  }
168 };
169 
170 #endif /* OPENFPM_DATA_SRC_UTIL_COPY_COMPARE_AGGREGATES_HPP_ */
copy_aggregate_op::src
const S & src
src
Definition: copy_compare_aggregates.hpp:98
copy_aggregate_dual::operator()
void operator()(T &t) const
It call the copy function for each member.
Definition: copy_compare_aggregates.hpp:40
compare_aggregate::eq
bool eq
result of the comparation
Definition: copy_compare_aggregates.hpp:131
meta_copy::meta_copy_
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition: meta_copy.hpp:60
meta_copy_op
This class copy general objects applying an operation.
Definition: copy_compare_aggregates.hpp:16
compare_aggregate
Structure to compare aggregates.
Definition: copy_compare_aggregates.hpp:128
copy_aggregate::src
const S & src
src
Definition: copy_compare_aggregates.hpp:65
meta_copy_op::meta_copy_op_
static void meta_copy_op_(const T &src, T &dst)
Meta-copy applying an operation.
Definition: meta_copy.hpp:808
compare_aggregate::result
bool result()
Returh the result of the comparison.
Definition: copy_compare_aggregates.hpp:164
copy_aggregate_op
Structure to copy aggregates applying an operation.
Definition: copy_compare_aggregates.hpp:95
compare_aggregate::src
const S & src
src
Definition: copy_compare_aggregates.hpp:134
copy_aggregate_dual::dst
S2 & dst
Destination grid.
Definition: copy_compare_aggregates.hpp:32
compare_aggregate::operator()
void operator()(T &t)
It call the copy function for each member.
Definition: copy_compare_aggregates.hpp:145
copy_aggregate::dst
S & dst
Destination grid.
Definition: copy_compare_aggregates.hpp:68
copy_aggregate_op::copy_aggregate_op
copy_aggregate_op(const S &src, S &dst)
copy_aggregate
Definition: copy_compare_aggregates.hpp:104
copy_aggregate::copy_aggregate
copy_aggregate(const S &src, S &dst)
copy_aggregate
Definition: copy_compare_aggregates.hpp:71
copy_aggregate
Structure to copy aggregates.
Definition: copy_compare_aggregates.hpp:62
copy_aggregate_op::operator()
void operator()(T &t) const
It call the copy function for each member.
Definition: copy_compare_aggregates.hpp:109
meta_copy
This class copy general objects.
Definition: copy_compare_aggregates.hpp:15
copy_aggregate_dual
Structure to copy aggregates.
Definition: copy_compare_aggregates.hpp:26
compare_aggregate::compare_aggregate
compare_aggregate(const S &src, const S &dst)
copy_aggregate
Definition: copy_compare_aggregates.hpp:140
copy_aggregate_dual::src
const S src
src
Definition: copy_compare_aggregates.hpp:29
meta_copy_d
copy for a source object to a destination
Definition: copy_compare_aggregates.hpp:18
meta_compare
This class compare general objects.
Definition: copy_compare_aggregates.hpp:17
copy_aggregate_dual::copy_aggregate_dual
copy_aggregate_dual(S src, S2 &dst)
copy_aggregate
Definition: copy_compare_aggregates.hpp:35
copy_aggregate::operator()
void operator()(T &t) const
It call the copy function for each member.
Definition: copy_compare_aggregates.hpp:76
copy_aggregate_op::dst
S & dst
Destination grid.
Definition: copy_compare_aggregates.hpp:101
compare_aggregate::dst
const S & dst
Destination grid.
Definition: copy_compare_aggregates.hpp:137