OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
object_s_di.hpp
1 /*
2  * object_write.hpp
3  *
4  * Created on: Jun 11, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OBJECT_WRITE_HPP_
9 #define OBJECT_WRITE_HPP_
10 
11 
12 #include "for_each_ref.hpp"
13 #include "util/variadic_to_vmpl.hpp"
14 #include "util/copy_compare/meta_copy.hpp"
15 #include <boost/mpl/range_c.hpp>
16 #include <boost/fusion/include/size.hpp>
17 
18 template <typename> struct Debug;
19 
32 template<typename v_src,typename v_dst, int... prp>
34 {
36  typedef typename to_boost_vmpl<prp...>::type v_prp;
37 
39  const v_src & src;
40 
42  v_dst & dst;
43 
50  object_s_di_e(const v_src & src, v_dst & dst)
51  :src(src),dst(dst)
52  {
53  };
54 
55 #ifdef DEBUG
56 
62  object_s_di_e(const v_src && src, v_dst & dst)
63  :src(src),dst(dst)
64  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
65 #endif
66 
68  template<typename T>
69  void operator()(T& t)
70  {
71  // Remove the reference from the type to copy
72  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>())>::type copy_dtype;
73  typedef typename std::remove_reference<decltype(src.template get<T::value>())>::type copy_stype;
74 
75 // Debug<decltype(src.template get<T::value>())> a;
76 
77  meta_copy_d<copy_stype,copy_dtype>::meta_copy_d_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>());
78  }
79 };
80 
81 
95 template<template<typename,typename> class op, typename v_src,typename v_dst, int... prp>
97 {
99  typedef typename to_boost_vmpl<prp...>::type v_prp;
100 
102  const v_src & src;
103 
105  v_dst & dst;
106 
113  object_s_di_e_op(const v_src & src, v_dst & dst)
114  :src(src),dst(dst)
115  {
116  };
117 
118 #ifdef DEBUG
119 
125  object_s_di_e_op(v_src && src, v_dst & dst)
126  :src(src),dst(dst)
127  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
128 #endif
129 
131  template<typename T>
132  void operator()(T& t)
133  {
134  // Remove the reference from the type to copy
135  typedef typename boost::remove_reference<decltype(dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>())>::type copy_dtype;
136  typedef typename std::remove_reference<decltype(src.template get<T::value>())>::type copy_stype;
137 
138  meta_copy_op_d<op,copy_stype,copy_dtype>::meta_copy_op_d_(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>());
139  }
140 };
141 
153 template<typename v_src,typename v_dst, int... prp>
155 {
157  typedef typename to_boost_vmpl<prp...>::type v_prp;
158 
160  const v_src & src;
161 
163  v_dst & dst;
164 
171  object_s_di_f(const v_src & src, v_dst & dst)
172  :src(src),dst(dst)
173  {
174  };
175 
176 #ifdef DEBUG
177 
183  object_s_di_f(const v_src && src, v_dst & dst)
184  :src(src),dst(dst)
185  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
186 #endif
187 
189  template<typename T>
190  void operator()(T& t)
191  {
192  typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>>::type ctype;
193 
194  meta_copy<ctype>::meta_copy_(boost::fusion::at_c<T::value>(src.data),boost::fusion::at_c<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(dst.data));
195  }
196 };
197 
198 
211 template<template<typename,typename> class op, typename v_src,typename v_dst, int... prp>
213 {
215  typedef typename to_boost_vmpl<prp...>::type v_prp;
216 
218  const v_src & src;
219 
221  v_dst & dst;
222 
229  object_s_di_f_op(const v_src & src, v_dst & dst)
230  :src(src),dst(dst)
231  {
232  };
233 
234 #ifdef DEBUG
235 
241  object_s_di_f_op(v_src && src, v_dst & dst)
242  :src(src),dst(dst)
243  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
244 #endif
245 
247  template<typename T>
248  void operator()(T& t)
249  {
250  typedef typename boost::mpl::at<typename v_dst::type,typename boost::mpl::int_<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>>::type ctype;
251 
252  meta_copy_op<op,ctype>::meta_copy_op_(boost::fusion::at_c<T::value>(src.data),boost::fusion::at_c<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>(dst.data));
253  }
254 };
255 
256 #define OBJ_ENCAP 1
257 #define OBJ_NORMAL 2
258 
267 template<typename v_src, typename v_dst,int type_copy, int... prp>
269 {
276  inline object_s_di(const v_src & vs, v_dst & vd)
277  {
278  std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
279  };
280 };
281 
289 template<typename v_src, typename v_dst, int... prp>
290 struct object_s_di<v_src,v_dst,OBJ_NORMAL,prp...>
291 {
298  inline object_s_di(const v_src && vs, v_dst && vd)
299  {
300  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
301  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
302  }
303 
310  inline object_s_di(const v_src & vs, v_dst & vd)
311  {
312  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
313  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
314  }
315 };
316 
331 template<typename v_src, typename v_dst, int... prp>
332 struct object_s_di<v_src,v_dst,OBJ_ENCAP,prp...>
333 {
340  inline object_s_di(const v_src & vs, v_dst && vd)
341  {
342  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
343  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
344  }
345 
352  inline object_s_di(const v_src & vs, v_dst & vd)
353  {
354  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
355  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
356  }
357 };
358 
360 
369 template<template<typename,typename> class op, typename v_src, typename v_dst,int type_copy, int... prp>
371 {
378  inline object_s_di_op(const v_src & vs, v_dst & vd)
379  {
380  std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
381  };
382 };
383 
392 template<template<typename,typename> class op, typename v_src, typename v_dst, int... prp>
393 struct object_s_di_op<op,v_src,v_dst,OBJ_NORMAL,prp...>
394 {
401  inline object_s_di_op(const v_src && vs, v_dst && vd)
402  {
403  object_s_di_f_op<op,v_src,v_dst,prp...> obj(vs,vd);
404  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
405  }
406 
413  inline object_s_di_op(const v_src & vs, v_dst & vd)
414  {
415  object_s_di_f_op<op,v_src,v_dst,prp...> obj(vs,vd);
416  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
417  }
418 };
419 
420 
435 template<template<typename,typename> class op, typename v_src, typename v_dst, int... prp>
436 struct object_s_di_op<op, v_src,v_dst,OBJ_ENCAP,prp...>
437 {
444  inline object_s_di_op(const v_src & vs, v_dst && vd)
445  {
446  object_s_di_e_op<op,v_src,v_dst,prp...> obj(vs,vd);
447  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
448  }
449 
456  inline object_s_di_op(const v_src & vs, v_dst & vd)
457  {
458  object_s_di_e_op<op,v_src,v_dst,prp...> obj(vs,vd);
459  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
460  }
461 };
462 
463 #endif /* OBJECT_WRITE_HPP_ */
to_boost_vmpl< prp...>::type v_prp
Convert the packed properties into an MPL vector.
It copy the properties from one object to another.
object_s_di(const v_src &&vs, v_dst &&vd)
Implementation of the copy.
void operator()(T &t)
It call the functor for each member.
object_s_di(const v_src &vs, v_dst &vd)
Implementation of the copy.
to_boost_vmpl< prp...>::type v_prp
Convert the packed properties into an MPL vector.
to_boost_vmpl< prp...>::type v_prp
Convert the packed properties into an MPL vector.
Definition: object_s_di.hpp:99
const v_src & src
Source object.
object_s_di_e_op(const v_src &src, v_dst &dst)
Constructor.
object_s_di_op(const v_src &vs, v_dst &vd)
Implementation of the copy with operation.
static void meta_copy_(const T &src, T &dst)
copy and object from src to dst
Definition: meta_copy.hpp:37
this class is a functor for "for_each" algorithm
static void meta_copy_op_(const T &src, T &dst)
Meta-copy applying an operation.
Definition: meta_copy.hpp:569
object_s_di_f_op(const v_src &src, v_dst &dst)
Constructor.
object_s_di_f(const v_src &src, v_dst &dst)
Constructor.
v_dst & dst
Destination object.
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the functor for each member.
object_s_di_op(const v_src &&vs, v_dst &&vd)
Implementation of the copy with operation.
object_s_di_e(const v_src &src, v_dst &dst)
Constructor.
Definition: object_s_di.hpp:50
object_s_di(const v_src &vs, v_dst &&vd)
Implementation of the copy.
v_dst & dst
Destination object.
object_s_di(const v_src &vs, v_dst &vd)
Stub method.
object_s_di(const v_src &vs, v_dst &vd)
Implementation of the copy.
to_boost_vmpl< prp...>::type v_prp
Convert the packed properties into an MPL vector.
Definition: object_s_di.hpp:36
It copy the properties from one object to another applying an operation.
this class is a functor for "for_each" algorithm
Definition: object_s_di.hpp:96
object_s_di_op(const v_src &vs, v_dst &vd)
Stub method.
object_s_di_op(const v_src &vs, v_dst &&vd)
Implementation of the copy with operation.
void operator()(T &t)
It call the functor for each member.
static void meta_copy_op_d_(const Tsrc &src, Tdst &dst)
Meta-copy applying an operation.
Definition: meta_copy.hpp:664
void operator()(T &t)
It call the functor for each member.
Definition: object_s_di.hpp:69
const v_src & src
Source object.
v_dst & dst
Destination object.
const v_src & src
Source object.
Definition: object_s_di.hpp:39
v_dst & dst
Destination object.
Definition: object_s_di.hpp:42
const v_src & src
Source object.
object_s_di_op(const v_src &vs, v_dst &vd)
Implementation of the copy with operation.
static void meta_copy_d_(const Tsrc &src, Tdst &dst)
copy and object from src to dst
Definition: meta_copy.hpp:69
this class is a functor for "for_each" algorithm
Definition: object_s_di.hpp:33