OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
copy_general.hpp
1 /*
2  * aggregate_copy.hpp
3  *
4  * Created on: Oct 31, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_
9 #define OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_
10 
11 #include "util/common.hpp"
12 #include "util/util_debug.hpp"
13 #include "copy_compare_aggregates.hpp"
14 #include "util/for_each_ref.hpp"
15 #include <boost/mpl/range_c.hpp>
16 #include <iostream>
17 
24 template<typename Tdst, typename Tsrc>
25 struct add_
26 {
33  static inline void operation(Tdst & dst, const Tsrc & src)
34  {
35  dst += src;
36  }
37 };
38 
45 template<typename Tdst, typename Tsrc>
46 struct replace_
47 {
54  static inline void operation(Tdst & dst, const Tsrc & src)
55  {
56  dst = src;
57  }
58 };
59 
66 template<typename Tdst, typename Tsrc>
67 struct merge_
68 {
75  static inline void operation(Tdst & dst, const Tsrc & src)
76  {
77  dst.add(src);
78  }
79 };
80 
86 template<typename T, unsigned int agg=2 * is_openfpm_native<T>::value + std::is_copy_assignable<T>::value>
88 {
95  inline copy_general(const T & src, T & dst)
96  {
97  std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << demangle(typeid(T).name()) << " does not have an operator= and is not an aggregate or an openfpm native structure, copy is not possible" << "\n";
98  }
99 };
100 
102 template<typename T>
103 struct copy_general<T,1>
104 {
111  inline copy_general(const T & src, T & dst)
112  {
113  dst = src;
114  }
115 };
116 
118 template<typename T>
119 struct copy_general<T,2>
120 {
127  inline copy_general(const T & src, T & dst)
128  {
129  copy_aggregate<T> cp(src,dst);
130 
131  boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(cp);
132  }
133 };
134 
136 template<typename T>
137 struct copy_general<T,3>
138 {
145  inline copy_general(const T & src, T & dst)
146  {
147  dst = src;
148  }
149 };
150 
152 
158 template<template<typename,typename> class op, typename T, unsigned int agg=2 * is_openfpm_native<T>::value + std::is_copy_assignable<T>::value>
160 {
167  inline copy_general_op(const T & src, T & dst)
168  {
169  std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " " << demangle(typeid(T).name()) << " does not have an operator= and is not an aggregate or an openfpm native structure, copy is not possible" << "\n";
170  }
171 };
172 
174 template<template<typename,typename> class op,typename T>
175 struct copy_general_op<op,T,1>
176 {
183  inline copy_general_op(const T & src, T & dst)
184  {
185  op<T,T>::operation(dst,src);
186  }
187 };
188 
190 template<template<typename,typename> class op, typename T>
191 struct copy_general_op<op,T,2>
192 {
199  inline copy_general_op(const T & src, T & dst)
200  {
201  copy_aggregate_op<op,T> cp(src,dst);
202 
203  boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(cp);
204  }
205 };
206 
208 template<template<typename,typename> class op,typename T>
209 struct copy_general_op<op,T,3>
210 {
217  inline copy_general_op(const T & src, T & dst)
218  {
219  op<T,T>::operation(dst,src);
220  }
221 };
222 
223 #endif /* OPENFPM_DATA_SRC_UTIL_COPY_GENERAL_HPP_ */
Structure to copy aggregates.
structure to copy aggregates applying an operation
This structure define the operation add to use with copy general.
copy_general(const T &src, T &dst)
copy objects that has an operator= (implicit or explicit)
structure to copy aggregates
copy_general_op(const T &src, T &dst)
copy objects that has an operator= (implicit or explicit)
This structure define the operation add to use with copy general.
static void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
Structure to copy aggregates applying an operation.
copy_general(const T &src, T &dst)
copy objects that are aggregates but define an operator=
static void operation(Tdst &dst, const Tsrc &src)
Defition of the replace operation.
is_openfpm_native check if a type is an openfpm native structure type
Definition: common.hpp:270
copy_general_op(const T &src, T &dst)
copy objects that are aggregates
copy_general_op(const T &src, T &dst)
copy objects that are aggregates but define an operator=
copy_general_op(const T &src, T &dst)
Specialization when there is unknown copy method.
static void operation(Tdst &dst, const Tsrc &src)
Defition of the add operation.
copy_general(const T &src, T &dst)
Specialization when there is unknown copy method.
This structure define the operation add to use with copy general.
copy_general(const T &src, T &dst)
copy objects that are aggregates