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_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 
22 template<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 
37 
38  typedef typename std::remove_all_extents< typename boost::mpl::at<v,boost::mpl::int_<T::value> >::type>::type tpy;
39 
40  // if it is a pointer make no sense
41  if (std::is_pointer<tpy>::value == true)
42  {ret = PNP::POINTERS;return;}
43 
44  // if it is an l-value reference make no send
45  if (std::is_lvalue_reference<tpy>::value == true)
46  {ret = PNP::POINTERS;return;}
47 
48  // if it is an r-value reference make no send
49  if (std::is_rvalue_reference<tpy>::value == true)
50  {ret = PNP::POINTERS;return;}
51 
52  if (std::is_fundamental<tpy>::value == true)
53  return;
54 
55  // check that T has a method called noPointers
57  {
58  case PNP::UNKNOWN:
59  {
60  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" ;
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 
84 template<typename v,typename p_ele,bool to_push>
86 {
87  typedef typename boost::mpl::push_front<v,p_ele>::type type;
88 };
89 
97 template<typename v,typename p_ele>
98 struct conditional_push<v,p_ele,false>
99 {
100  typedef v type;
101 };
102 
112 template<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 
133 template<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 
153 template<typename v, int... prp>
155 {
156  typedef typename noPointers_sequence_impl<v,prp...>::type type;
157 };
158 
159 
171 template<typename v>
172 struct 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 
199 template<typename v, typename vc, int... prp>
201 {
202 };
203 
212 template<typename v, typename vc, int p1, int... prp>
213 struct 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 
229 template<typename v, typename vc, int prp>
230 struct 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 
254 template<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 
261 template<typename v>
262 struct object_creator<v>
263 {
264  typedef typename boost::fusion::vector<> type;
265 };
266 
267 #endif
Implementation of noPointer_sequence_impl.
This is a container to create a general object.
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
it return a boost::mpl::vector of integers where each integer identify one object without the method ...
Implementation of object creator.
It create a boost::fusion vector with the selected properties.