OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
object_creator.hpp
1#ifndef VECTOR_CREATOR
2#define VECTOR_CREATOR
3
4#include <boost/fusion/container/vector.hpp>
5#include <boost/mpl/vector.hpp>
6#include <boost/mpl/push_back.hpp>
7#include <boost/type_traits/remove_reference.hpp>
8#include <boost/mpl/range_c.hpp>
9#include <type_traits>
10#include "util_debug.hpp"
11#include "check_no_pointers.hpp"
12#include "util/for_each_ref.hpp"
13#include <iostream>
14
22template<typename v>
24{
25 size_t & ret;
26
27 check_types(size_t & ret)
28 :ret(ret)
29 {
30 ret = PNP::NO_POINTERS;
31 }
32
33 template<typename T>
34 void operator()(T& t)
35 {
36 typedef typename std::remove_all_extents< typename boost::mpl::at<v,boost::mpl::int_<T::value> >::type>::type tpy;
37
38 // if it is a pointer make no sense
39 if (std::is_pointer<tpy>::value == true)
40 {ret = PNP::POINTERS;return;}
41
42 // if it is an l-value reference make no send
43 if (std::is_lvalue_reference<tpy>::value == true)
44 {ret = PNP::POINTERS;return;}
45
46 // if it is an r-value reference make no send
47 if (std::is_rvalue_reference<tpy>::value == true)
48 {ret = PNP::POINTERS;return;}
49
50 if (std::is_fundamental<tpy>::value == true)
51 {return;}
52
53 // check that T has a method called noPointers
55 {
56 case PNP::UNKNOWN:
57 {
58#ifndef DISABLE_ALL_RTTI
59 std::cerr << "Warning: " << __FILE__ << ":" << __LINE__ << " impossible to check the type " << demangle(typeid(tpy).name()) << " please consider to add a static method \"static bool noPointers()\" \n" ;
60#endif
61 ret = PNP::UNKNOWN;
62 break;
63 }
64 case PNP::POINTERS:
65 {
66 ret = PNP::POINTERS;
67 break;
68 }
69 default:
70 {
71
72 }
73 }
74 }
75};
76
84template<typename v,typename p_ele,bool to_push>
86{
87 typedef typename boost::mpl::push_front<v,p_ele>::type type;
88};
89
97template<typename v,typename p_ele>
98struct conditional_push<v,p_ele,false>
99{
100 typedef v type;
101};
102
112template<typename v, int p1, int... prp>
114{
115 // Object we are analyzing
116 typedef typename std::remove_reference<typename std::remove_pointer<typename boost::mpl::at< v,boost::mpl::int_<p1> >::type>::type>::type obj_type;
117
118 // analyze the other properties, returning the output vector
119 typedef typename noPointers_sequence_impl<v ,prp...>::type v_step;
120
121 // push on the vector the element p1
122 typedef typename conditional_push<v_step, boost::mpl::int_<p1>, !has_noPointers<obj_type>::value && !std::is_fundamental<obj_type>::value >::type type;
123};
124
133template<typename v, int p1>
135{
136 // Object we are analyzing
137 typedef typename std::remove_reference< typename std::remove_pointer<typename boost::mpl::at< v,boost::mpl::int_<p1> >::type>::type>::type obj_type;
138
139 // push on the vector the element p1
140 typedef typename conditional_push<boost::mpl::vector<>, boost::mpl::int_<p1>, !has_noPointers<obj_type>::value && !std::is_fundamental<obj_type>::value >::type type;
141};
142
153template<typename v, int... prp>
155{
156 typedef typename noPointers_sequence_impl<v,prp...>::type type;
157};
158
159
171template<typename v>
172struct object
173{
174 typedef v type;
175 typedef typename boost::fusion::result_of::size<v>::type size_tpy;
176
177 type data;
178
179 static bool noPointers()
180 {
181 size_t ret;
182 check_types<v> ct(ret);
183
184 boost::mpl::for_each_ref< boost::mpl::range_c<int,0, boost::fusion::result_of::size<v>::type::value > > (ct);
185
186 return ret;
187 }
188
189 static const int max_prop = size_tpy::value;
190};
191
199template<typename v, typename vc, int... prp>
201{
202};
203
212template<typename v, typename vc, int p1, int... prp>
213struct object_creator_impl<v,vc,p1,prp...>
214{
215 typedef typename object_creator_impl<v,vc,prp... >::type vc_step;
216
217 typedef typename boost::remove_reference< typename boost::mpl::at< v,boost::mpl::int_<p1> >::type>::type ele;
218
219 // push on the vector the element p1
220 typedef typename boost::mpl::push_front<vc_step, ele >::type type;
221};
222
229template<typename v, typename vc, int prp>
230struct object_creator_impl<v,vc,prp>
231{
232 typedef typename boost::remove_reference< typename boost::mpl::at< v,boost::mpl::int_<prp> >::type>::type ele;
233
234 // push on the vector the element p1
235 typedef typename boost::mpl::push_front<vc, ele >::type type;
236};
237
254template<typename v, int... prp>
256{
257 typedef typename boost::fusion::result_of::as_vector<typename object_creator_impl<v,boost::mpl::vector<>,prp... >::type>::type type;
258};
259
261template<typename v>
263{
264 typedef v type;
265};
266
268
276template<typename v, typename vc, int... prp>
278{
279};
280
289template<typename v, typename vc, int p1, int... prp>
290struct object_creator_chunking_impl<v,vc,p1,prp...>
291{
292 typedef typename object_creator_chunking_impl<v,vc,prp... >::type vc_step;
293
294 typedef typename boost::remove_reference< typename boost::mpl::at< v,boost::mpl::int_<p1> >::type>::type ele_array;
295
296 // Element without array
297 typedef typename ele_array::value_type ele;
298
299 // push on the vector the element p1
300 typedef typename boost::mpl::push_front<vc_step, ele >::type type;
301};
302
303template <typename T>
305{
306 typedef T type;
307};
308
309template <typename type>
311{
313};
314
315
316template <unsigned int N1, std::size_t N2, typename T>
317struct get_base_type_for_object_creator_chunking< std::array<T, N2>[N1] >
318{
320};
321
322
329template<typename v, typename vc, int prp>
331{
332 typedef typename boost::remove_reference< typename boost::mpl::at< v,boost::mpl::int_<prp> >::type>::type ele_array;
333
334 // Element without array
336
337 // push on the vector the element p1
338 typedef typename boost::mpl::push_front<vc, typename ele::type >::type type;
339};
340
341
342template<typename v, int... prp>
344{
345 typedef typename boost::fusion::result_of::as_vector<typename object_creator_chunking_impl<v,boost::mpl::vector<>,prp... >::type>::type type;
346};
347
348
350template<typename v>
352{
353 typedef v type;
354};
355
356#endif
This class check if the type T has pointers inside.
functor for for_each algorithm
push p_ele into v only of to_push is true
Implementation of noPointer_sequence_impl.
it return a boost::mpl::vector of integers where each integer identify one object without the method ...
Implementation of object creator.
Implementation of object creator.
It create a boost::fusion vector with the selected properties.
This is a container to create a general object.