OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
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 
29 template<typename v_src,typename v_dst, int... prp>
31 {
32  // Convert the packed properties into an MPL vector
33  typedef typename to_boost_vmpl<prp...>::type v_prp;
34 
35  // Source object
36  const v_src & src;
37 
38  // Destination object
39  v_dst & dst;
40 
47  object_s_di_e(const v_src & src, v_dst & dst)
48  :src(src),dst(dst)
49  {
50  };
51 
52 #ifdef DEBUG
53 
59  object_s_di_e(const v_src && src, v_dst & dst)
60  :src(src),dst(dst)
61  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
62 #endif
63 
65  template<typename T>
66  void operator()(T& t)
67  {
68  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;
69 
70  meta_copy<ctype>(src.template get<T::value>(),dst.template get<boost::mpl::at<v_prp,boost::mpl::int_<T::value>>::type::value>());
71  }
72 };
73 
74 
86 template<typename v_src,typename v_dst, int... prp>
88 {
89  // Convert the packed properties into an MPL vector
90  typedef typename to_boost_vmpl<prp...>::type v_prp;
91 
92  // Source object
93  const v_src & src;
94 
95  // Destination object
96  v_dst & dst;
97 
104  object_s_di_f(const v_src & src, v_dst & dst)
105  :src(src),dst(dst)
106  {
107  };
108 
109 #ifdef DEBUG
110 
116  object_s_di_f(const v_src && src, v_dst & dst)
117  :src(src),dst(dst)
118  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object\n";};
119 #endif
120 
122  template<typename T>
123  void operator()(T& t)
124  {
125  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;
126 
127  meta_copy<ctype>(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));
128  }
129 };
130 
131 #define OBJ_ENCAP 1
132 #define OBJ_NORMAL 2
133 
142 template<typename v_src, typename v_dst,int type_copy, int... prp>
144 {
145  inline object_s_di(const v_src & vs, v_dst & vd)
146  {
147  std::cerr << "Error object_copy: " << __FILE__ << " " << __LINE__ << "\n";
148  };
149 };
150 
158 template<typename v_src, typename v_dst, int... prp>
159 struct object_s_di<v_src,v_dst,OBJ_NORMAL,prp...>
160 {
161  inline object_s_di(const v_src && vs, v_dst && vd)
162  {
163  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
164  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
165  }
166 
167  inline object_s_di(const v_src & vs, v_dst & vd)
168  {
169  object_s_di_f<v_src,v_dst,prp...> obj(vs,vd);
170  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
171  }
172 };
173 
188 template<typename v_src, typename v_dst, int... prp>
189 struct object_s_di<v_src,v_dst,OBJ_ENCAP,prp...>
190 {
191  inline object_s_di(const v_src && vs, v_dst && vd)
192  {
193  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
194  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
195  }
196 
197  inline object_s_di(const v_src & vs, v_dst & vd)
198  {
199  object_s_di_e<v_src,v_dst,prp...> obj(vs,vd);
200  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,sizeof...(prp)> >(obj);
201  }
202 };
203 
204 
205 
206 
207 #endif /* OBJECT_WRITE_HPP_ */
It copy the properties from one object to another.
void operator()(T &t)
It call the functor for each member.
this class is a functor for "for_each" algorithm
Definition: object_s_di.hpp:87
object_s_di_f(const v_src &src, v_dst &dst)
Constructor.
This class copy general objects.
object_s_di_e(const v_src &src, v_dst &dst)
Constructor.
Definition: object_s_di.hpp:47
void operator()(T &t)
It call the functor for each member.
Definition: object_s_di.hpp:66
this class is a functor for "for_each" algorithm
Definition: object_s_di.hpp:30