OpenFPM  5.2.0
Project that contain the implementation of distributed structures
aggregate.hpp
1 /*
2  * aggregate.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_UTIL_AGGREGATE_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_AGGREGATE_HPP_
10 
11 #include <boost/fusion/container/vector.hpp>
12 #include <Packer_Unpacker/has_pack_agg.hpp>
13 #include "util/copy_compare/copy_compare_aggregates.hpp"
14 
20 template<typename bfv>
22 {
24  const bfv & src;
25 
27  bfv & dst;
28 
37  __device__ __host__ inline copy_fusion_vector(const bfv & src, bfv & dst)
38  :src(src),dst(dst){};
39 
40 #ifdef SE_CLASS1
47  inline copy_fusion_vector(const bfv && src, bfv && dst)
48  :src(src),dst(dst)
49  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
50 #endif
51 
53  template<typename T>
54  __device__ __host__ inline void operator()(T& t)
55  {
56  // This is the type of the object we have to copy
57  typedef typename boost::fusion::result_of::at_c<bfv,T::value>::type copy_type;
58 
59  // Remove the reference from the type to copy
60  typedef typename boost::remove_reference<copy_type>::type copy_rtype;
61 
62  meta_copy<copy_rtype>::meta_copy_(boost::fusion::at_c<T::value>(src),boost::fusion::at_c<T::value>(dst));
63  }
64 };
65 
66 #ifdef SE_CLASS3
67 
68 #define SE3_MAX_PROP(i) i+2
69 #define SE3_ADD_PROP(i) size_t[i+1],size_t
70 #define SE3_SUB_MAX_PROP -2
71 
77 template<typename T>
78 struct aggregate_bfv
79 {
81  typedef T type;
82 
84  typedef T type_real;
85 
87  type data;
88 
89  aggregate_bfv() {};
90 
91  static const unsigned int max_prop = boost::mpl::size<type>::type::value;
92  static const unsigned int max_prop_real = boost::mpl::size<type>::type::value + SE3_SUB_MAX_PROP;
93 };
94 
102 template<typename ... list>
103 struct aggregate
104 {
106  typedef boost::fusion::vector<list... , SE3_ADD_PROP(sizeof...(list))> type;
107 
109  typedef boost::fusion::vector<list... > type_real;
110 
112  static const int size = sizeof...(list);
113 
114  typedef int yes_is_aggregate;
115 
116  type data;
117 
118  __device__ __host__ inline aggregate()
119  {}
120 
121  __device__ __host__ inline aggregate(const aggregate<list ...> & aggr)
122  {
123  this->operator=(aggr);
124  }
125 
131  template<unsigned int i> typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get()
132  {
133  return boost::fusion::at_c<i>(data);
134  }
135 
141  template<unsigned int i> const typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get() const
142  {
143  return boost::fusion::at_c<i>(data);
144  }
145 
150  static bool noPointers()
151  {
152  return !has_pack_gen<aggregate<list ...>>::value;
153  }
154 
155  aggregate<list...> & operator=(const aggregate<list...> & ag)
156  {
157  copy_fusion_vector<aggregate<list...>::type> ca(ag.data,this->data);
158 
159  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(list)> >(ca);
160 
161  return *this;
162  }
163 
164  static const unsigned int max_prop = boost::mpl::size<type>::type::value;
165  static const unsigned int max_prop_real = boost::mpl::size<type>::type::value + SE3_SUB_MAX_PROP;
166 };
167 
168 
169 
170 #else
171 
177 template<typename T>
179 {
181  typedef T type;
182 
184  typedef T type_real;
185 
188 
194  template<unsigned int i> typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get()
195  {
196  return boost::fusion::at_c<i>(data);
197  }
198 
204  template<unsigned int i> const typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get() const
205  {
206  return boost::fusion::at_c<i>(data);
207  }
208 
209  static const unsigned int max_prop = boost::mpl::size<type>::type::value;
210 };
211 
219 template<typename ... list>
220 struct aggregate
221 {
223  typedef boost::fusion::vector<list...> type;
224 
226  typedef boost::fusion::vector<list...> type_real;
227 
229  static const int size = sizeof...(list);
230 
231  typedef int yes_is_aggregate;
232 
235 
236  __device__ __host__ inline aggregate()
237  {}
238 
239  __device__ __host__ inline aggregate(const aggregate<list ...> & aggr)
240  {
241  this->operator=(aggr);
242  }
243 
249  template<unsigned int i> __device__ __host__ typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get()
250  {
251  return boost::fusion::at_c<i>(data);
252  }
253 
258  static bool noPointers()
259  {
260  return !has_pack_gen<aggregate<list ...>>::value;
261  }
262 
268  template<unsigned int i> __device__ __host__ const typename boost::mpl::at<type,boost::mpl::int_<i>>::type & get() const
269  {
270  return boost::fusion::at_c<i>(data);
271  }
272 
273  inline aggregate<list...> & operator=(const aggregate<list...> & ag)
274  {
275  copy_fusion_vector<aggregate<list...>::type> ca(ag.data,this->data);
276 
277  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(list)> >(ca);
278 
279  return *this;
280  }
281 
282  static const unsigned int max_prop = boost::mpl::size<type>::type::value;
283  static const unsigned int max_prop_real = boost::mpl::size<type>::type::value;
284 };
285 
286 #endif
287 
288 template<typename T, typename Sfinae = void>
289 struct is_aggregate: std::false_type {};
290 
291 
297 template<typename T>
298 struct is_aggregate<T, typename Void< typename T::yes_is_aggregate>::type> : std::true_type
299 {};
300 
301 namespace openfpm
302 {
303  template<unsigned int p, typename aggr>
304  auto at_c(aggr & agg) -> decltype(boost::fusion::at_c<p>(agg.data))
305  {
306  return boost::fusion::at_c<p>(agg.data);
307  }
308 
309  template<unsigned int p, typename aggr>
310  auto get(aggr & agg) -> decltype(boost::fusion::at_c<p>(agg.data))
311  {
312  return boost::fusion::at_c<p>(agg.data);
313  }
314 }
315 
316 template<typename BlockT, typename T>
318 {
319 };
320 
321 template<typename BlockT, typename ... list>
322 struct AggregateAppend<BlockT, aggregate<list ...>>
323 {
324  typedef aggregate<list..., BlockT> type;
325 };
326 
327 #endif /* OPENFPM_DATA_SRC_UTIL_AGGREGATE_HPP_ */
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
convert a type into constant type
Definition: aggregate.hpp:302
Void structure.
Definition: common.hpp:74
An aggregate that accept a boost fusion vector as type.
Definition: aggregate.hpp:179
const boost::mpl::at< type, boost::mpl::int_< i > >::type & get() const
get the properties i
Definition: aggregate.hpp:204
type data
data to store
Definition: aggregate.hpp:187
T type
type the object store
Definition: aggregate.hpp:181
boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
Definition: aggregate.hpp:194
T type_real
real type the object store
Definition: aggregate.hpp:184
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:221
static bool noPointers()
it return false if this aggregate has no pointers
Definition: aggregate.hpp:258
static const int size
size of the variadic template argument list
Definition: aggregate.hpp:229
__device__ __host__ const boost::mpl::at< type, boost::mpl::int_< i > >::type & get() const
get the properties i
Definition: aggregate.hpp:268
boost::fusion::vector< list... > type_real
real internal type containing the data
Definition: aggregate.hpp:226
__device__ __host__ boost::mpl::at< type, boost::mpl::int_< i > >::type & get()
get the properties i
Definition: aggregate.hpp:249
type data
the data
Definition: aggregate.hpp:234
boost::fusion::vector< list... > type
internal type containing the data
Definition: aggregate.hpp:223
this class is a functor for "for_each" algorithm
Definition: aggregate.hpp:22
bfv & dst
destination fusion vector
Definition: aggregate.hpp:27
__device__ __host__ copy_fusion_vector(const bfv &src, bfv &dst)
constructor
Definition: aggregate.hpp:37
__device__ __host__ void operator()(T &t)
It call the copy function for each property.
Definition: aggregate.hpp:54
const bfv & src
source fusion vector
Definition: aggregate.hpp:24
It return true if the object T require complex serialization.
__device__ static __host__ void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition: meta_copy.hpp:60