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
Encap.hpp
1 /*
2  * Encap.hpp
3  *
4  * Created on: Feb 2, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef ENCAP_HPP_
9 #define ENCAP_HPP_
10 
11 #include "util/for_each_ref.hpp"
12 #include "util/copy_compare/meta_copy.hpp"
13 #include "boost/mpl/range_c.hpp"
14 #include <boost/fusion/container/vector.hpp>
15 #ifdef SE_CLASS2
16 #include "Memleak_check.hpp"
17 #endif
18 #include "util/se_util.hpp"
19 #include "util/copy_compare/copy_fusion_vector.hpp"
20 #include "util/copy_compare/compare_fusion_vector.hpp"
21 
33 template<typename e_src, typename e_dst>
35 {
37  const e_src & src;
38  e_dst & dst;
39 
40 
50  inline copy_cpu_encap_encap(const e_src & src, e_dst & dst)
51  :src(src),dst(dst)
52  {
53 #ifdef SE_CLASS1
54  // e_src and e_dst must have the same number of properties
55 
56  if (e_src::max_prop != e_dst::max_prop)
57  std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the number of properties between src and dst must match";
58 #endif
59  };
60 
61 
62 #ifdef SE_CLASS1
63 
69  inline copy_cpu_encap_encap(const e_src && src, const e_dst && dst)
70  :src(src),dst(dst)
71  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object";};
72 #endif
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 e_src::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> cp(src.template get<T::value>(),dst.template get<T::value>());
85  }
86 };
87 
88 
100 template<typename e_src, typename e_dst>
102 {
104  const e_src & src;
105  const e_dst & dst;
106 
107 
117  inline compare_cpu_encap_encap(const e_src & src, const e_dst & dst)
118  :src(src),dst(dst)
119  {
120 #ifdef SE_CLASS1
121  // e_src and e_dst must have the same number of properties
122 
123  if (e_src::max_prop != e_dst::max_prop)
124  std::cerr << "Error " << __FILE__ << ":" << __LINE__ << " the number of properties between src and dst must match";
125 #endif
126  };
127 
128 
129 #ifdef SE_CLASS1
130 
136  inline compare_cpu_encap_encap(const e_src && src, const e_dst && dst)
137  :src(src),dst(dst)
138  {std::cerr << "Error: " <<__FILE__ << ":" << __LINE__ << " Passing a temporal object";};
139 #endif
140 
142  template<typename T>
143  inline void operator()(T& t) const
144  {
145  // This is the type of the object we have to copy
146  typedef typename boost::fusion::result_of::at_c<typename e_src::type,T::value>::type copy_type;
147 
148  // Remove the reference from the type to copy
149  typedef typename boost::remove_reference<copy_type>::type copy_rtype;
150 
151  meta_compare<copy_rtype> cp(src.template get<T::value>(),dst.template get<T::value>());
152  }
153 };
154 
164 template<unsigned int p,typename mem>
166 {
168  typedef typename mem::vtype vtype;
170  typedef typename boost::fusion::result_of::at< vtype,boost::mpl::int_<p> >::type type;
171 };
172 
182 template<unsigned int p,typename Mem>
184 {
186  typedef Mem vtype;
188  typedef typename boost::fusion::result_of::at< vtype,boost::mpl::int_<p> >::type rtype;
190  typedef typename boost::remove_reference<rtype>::type mtype;
192  typedef typename mtype::type type;
193 };
194 
195 
196 
208 template<unsigned int dim,typename T,typename Mem>
209 class encapc
210 {
211 public:
212  typedef typename T::type type;
213 
214 private:
215 
216  type & data_c;
217 
218 public:
219 
220  typedef int yes_i_am_encap;
221 
222  typedef T T_type;
223 
224  static const int max_prop = T::max_prop;
225 
226  // constructor require a key and a memory data
227  inline encapc(type & data_c)
228  :data_c(data_c)
229  {}
230 
236  inline type * operator&()
237  {
238  return &data_c;
239  }
240 
246  template <unsigned int p> inline typename type_cpu_prop<p,Mem>::type get()
247  {
248 #ifdef SE_CLASS2
249  check_valid(&boost::fusion::at_c<p>(data_c),sizeof(typename type_cpu_prop<p,Mem>::type));
250 #endif
251  return boost::fusion::at_c<p>(data_c);
252  }
253 
259  template <unsigned int p> inline const typename type_cpu_prop<p,Mem>::type get() const
260  {
261 #ifdef SE_CLASS2
262  check_valid(&boost::fusion::at_c<p>(data_c),sizeof(typename type_cpu_prop<p,Mem>::type));
263 #endif
264  return boost::fusion::at_c<p>(data_c);
265  }
266 
267  // access the data
268  template <unsigned int p> inline void set(typename type_cpu_prop<p,Mem>::type & ele)
269  {
270 #ifdef SE_CLASS2
271  check_valid(&boost::fusion::at_c<p>(data_c),sizeof(typename type_cpu_prop<p,T>::type));
272 #endif
273  return boost::fusion::at_c<p>(data_c) = ele;
274  }
275 
282  {
284 
285  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
286 
287  return *this;
288  }
289 
295  inline encapc<dim,T,Mem> & operator=(const T & obj)
296  {
297  copy_fusion_vector<typename T::type> cp(obj.data,data_c);
298 
299  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
300 
301  return *this;
302  }
303 
311  inline bool operator==(const encapc<dim,T,Mem> & ec) const
312  {
313  compare_fusion_vector<typename T::type> cp(ec.data_c,data_c);
314 
315  boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
316 
317  return cp.result();
318  }
319 
327  inline bool operator!=(const encapc<dim,T,Mem> & ec) const
328  {
329  return ! this->operator==(ec);
330  }
331 };
332 
340 template<unsigned int dim,typename Mem>
341 class encapc<dim,void,Mem>
342 {
343 public:
344 
345  // constructor require a key and a memory data
346  encapc()
347  {}
348 
349  // access the data
350  template <unsigned int p> void get()
351  {}
352 
353  // access the data
354  template <unsigned int p, typename S> void set(S & ele)
355  {}
356 };
357 
369 template<unsigned int dim,typename T,typename Mem>
370 class encapg
371 {
372  // constructor require a key
373  Mem & data;
374  size_t k;
375 
376 public:
377 
378  typedef int yes_i_am_encap;
379 
380  typedef T T_type;
381 
382  // constructor require a key and a memory data
383  encapg(Mem & data, size_t k)
384  :data(data),k(k)
385  {}
386 
387  // access the data
388  template <unsigned int p> typename type_gpu_prop<p,Mem>::type::reference get()
389  {
390  return boost::fusion::at_c<p>(data).mem_r->operator[](k);
391  }
392 
393  // access the data
394  template <unsigned int p> const typename type_gpu_prop<p,Mem>::type::reference get() const
395  {
396  return boost::fusion::at_c<p>(data).mem_r->operator[](k);
397  }
398 };
399 
400 #include "util/common.hpp"
401 
402 template<typename T, typename Sfinae = void>
403 struct is_encap: std::false_type {};
404 
405 
415 template<typename T>
416 struct is_encap<T, typename Void< typename T::yes_i_am_encap>::type> : std::true_type
417 {};
418 
419 #endif /* ENCAP_HPP_ */
void operator()(T &t) const
It call the copy function for each property.
Definition: Encap.hpp:76
bool operator!=(const encapc< dim, T, Mem > &ec) const
Compare.
Definition: Encap.hpp:327
this class is a functor for "for_each" algorithm
Definition: Encap.hpp:101
this class is a functor for "for_each" algorithm
This class is an helper to get the return type for get method for each property.
Definition: Encap.hpp:165
This class is an helper to get the return type of get for each property.
Definition: Encap.hpp:183
void operator()(T &t) const
It call the copy function for each property.
Definition: Encap.hpp:143
Mem vtype
return a boost::fusion::vector<memory_c<....>....>
Definition: Encap.hpp:186
boost::remove_reference< rtype >::type mtype
remove the reference
Definition: Encap.hpp:190
This class copy general objects.
const e_src & src
object we have to compare
Definition: Encap.hpp:104
encapc< dim, T, Mem > & operator=(const T &obj)
Assignment.
Definition: Encap.hpp:295
bool operator==(const encapc< dim, T, Mem > &ec) const
Compare.
Definition: Encap.hpp:311
this structure encapsulate an object of the grid
Definition: Encap.hpp:209
bool result()
Returh the result of the comparison.
Void structure.
Definition: common.hpp:40
This class compare general objects.
encapc< dim, T, Mem > & operator=(const encapc< dim, T, Mem > &ec)
Assignment.
Definition: Encap.hpp:281
mtype::type type
get the base type that the buffer is storing
Definition: Encap.hpp:192
compare_cpu_encap_encap(const e_src &src, const e_dst &dst)
constructor
Definition: Encap.hpp:117
this class is a functor for "for_each" algorithm
Definition: Encap.hpp:34
this structure encapsulate an object of the grid
Definition: Encap.hpp:370
boost::fusion::result_of::at< vtype, boost::mpl::int_< p > >::type rtype
return a memory_c<...>
Definition: Encap.hpp:188
boost::fusion::result_of::at< vtype, boost::mpl::int_< p > >::type type
return a memory_c<...>
Definition: Encap.hpp:170
type * operator&()
Return the address of the base.
Definition: Encap.hpp:236
copy_cpu_encap_encap(const e_src &src, e_dst &dst)
constructor
Definition: Encap.hpp:50
this class is a functor for "for_each" algorithm
const e_src & src
object we have to store
Definition: Encap.hpp:37
mem::vtype vtype
return a boost::fusion::vector<memory_c<....>....>
Definition: Encap.hpp:168