12#include "util/cudify/cudify.hpp"
14#include "util/object_util.hpp"
16#include "Vector/util.hpp"
17#include "memory/ExtPreAlloc.hpp"
18#include "util/util_debug.hpp"
20#include "Grid/grid_sm.hpp"
21#include "util/Pack_stat.hpp"
22#include "Pack_selector.hpp"
23#include "has_pack_encap.hpp"
24#include "Packer_util.hpp"
27template <
typename>
struct Debug;
48template<
typename T,
typename Mem,
int pack_type >
58#ifndef DISABLE_ALL_RTTI
59 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" packing for the type " << demangle(
typeid(T).name()) <<
" is not implemented\n";
68#ifndef DISABLE_ALL_RTTI
69 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" packing for the type " << demangle(
typeid(T).name()) <<
" is not implemented\n";
81template<
typename T,
typename Mem>
96 *(
typename std::remove_const<T>::type *)ext.
getPointer() = obj;
131template<
typename T,
typename Mem>
132class Packer<T,Mem,PACKER_ARRAY_PRIMITIVE>
149 ext.
allocate(
sizeof(
typename T::value_type)*n);
150 memcpy(ext.
getPointer(),obj.getPointer(),
sizeof(
typename T::value_type)*n);
163 req +=
sizeof(
typename T::value_type)*obj.size();
168template<
typename T,
typename Mem>
169class Packer<T,Mem,PACKER_ARRAY_CP_PRIMITIVE>
182 typedef typename std::remove_extent<T>::type prim_type;
200 template<
typename tp,
long unsigned int dim,
typename vmpl>
205 typedef typename std::remove_extent<T>::type prim_type;
231 template<
typename tp,
long unsigned int dim,
typename vmpl>
245template<
typename T,
typename Mem>
246class Packer<T,Mem,PACKER_OBJECTS_WITH_WARNING_POINTERS>
261 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
263 if (!(std::is_array<T>::value ==
true && std::is_fundamental<
typename std::remove_all_extents<T>::type>::value ==
true))
264 std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" impossible to check the type " << demangle(
typeid(T).name()) <<
" please consider to add a static method like \"static bool noPointers() {return true;}\" \n" ;
267 memcpy((
typename std::remove_reference<T>::type *)ext.
getPointer(),&obj,
sizeof(T));
300template<
typename T,
typename Mem>
301class Packer<T,Mem,PACKER_OBJECTS_WITH_POINTER_CHECK>
316 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
318 if (obj.noPointers() ==
false)
319 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" the type " << demangle(
typeid(T).name()) <<
" has pointers inside, sending pointers values has no sense\n";
322 memcpy((
typename std::remove_const<T>::type *)ext.
getPointer(),&obj,
sizeof(T));
355template<
typename T,
typename Mem>
360 template<
int ... prp>
static void packRequest(
const T & obj,
size_t & req)
367 obj.template
pack<prp...>(mem, sts);
377template<
typename T,
typename Mem>
382 template<
int ... prp>
static void packRequest(
const T & obj,
size_t & req)
387 template<
typename grid_sub_it_type,
int ... prp>
static void packRequest(T & obj, grid_sub_it_type & sub,
size_t & req)
394 obj.template
pack<prp...>(mem, sts);
397 template<
typename grid_sub_it_type,
int ... prp>
static void pack(
ExtPreAlloc<Mem> & mem, T & obj, grid_sub_it_type & sub_it,
Pack_stat & sts)
399 obj.template
pack<prp...>(mem, sub_it, sts);
403template<
typename T,
typename Mem>
416 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
423 if (
sizeof...(prp) == 0)
425 mem.
allocate(
sizeof(
typename T::T_type));
431 typedef object<
typename object_creator<
typename T::type,prp...>::type> prp_object;
434 object_si_d<T,
decltype(enc),OBJ_ENCAP,prp ... >(eobj,enc);
446 template<
int ... prp>
void packRequest(T & eobj,
size_t & req)
452 if (
sizeof...(prp) == 0)
455 typedef object<
typename object_creator<
typename T::type,prp...>::type> prp_object;
457 req +=
sizeof(prp_object);
464template<
typename Timpl>
467 template<
typename T,
typename e_src,
typename e_dst>
468 static inline void call(
const e_src & src,
size_t sub_id, e_dst & dst)
471 typedef typename boost::remove_reference<
decltype(dst.template get< T::value >())>::type copy_rtype;
477template<
unsigned int N1,
typename Timpl>
480 template<
typename T,
typename e_src,
typename e_dst>
481 static inline void call(
const e_src & src,
size_t sub_id, e_dst & dst)
484 typedef typename boost::remove_reference<
decltype(dst.template get< T::value >()[0])>::type copy_rtype;
486 for (
int i = 0 ; i < N1 ; i++)
492template<
typename e_src,
typename e_dst>
521 typedef typename boost::remove_reference<
decltype(
dst.template get< T::value >())>::type copy_rtype;
529template <
typename>
struct Debug;
531template<
bool is_not_zero,
typename T,
typename T_nc,
int ... prp>
534 template<
typename Mem>
static inline void select(
ExtPreAlloc<Mem> & mem,
const T & eobj,
size_t sub_id)
540 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::T_type::max_prop>>(cp);
545template<
typename T,
typename T_nc,
int ... prp>
548 template<
typename Mem>
static inline void select(
ExtPreAlloc<Mem> & mem,
const T & eobj,
size_t sub_id)
554 object_si_d<T,
decltype(enc),OBJ_ENCAP_CHUNKING,prp ... >(eobj,sub_id,enc);
558template<
typename T,
typename Mem>
559class Packer<T,Mem,PACKER_ENCAP_OBJECTS_CHUNKING>
572 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
590 template<
int ... prp>
void packRequest(T & eobj,
size_t & req)
596 if (
sizeof...(prp) == 0)
599 typedef object<
typename object_creator<
typename T::type,prp...>::type> prp_object;
601 req +=
sizeof(prp_object);
virtual void * getPointer()
Return the pointer of the last allocation.
virtual long int ref()
Return the reference counter.
virtual bool allocate(size_t sz)
Allocate a chunk of memory.
virtual size_t size() const
Get the size of the LAST allocated memory.
void incReq()
Increment the request pointer.
static void pack(ExtPreAlloc< Mem > &ext, const openfpm::detail::multi_array::sub_array_openfpm< tp, dim, vmpl > &obj, Pack_stat &sts)
It packs arrays of C++ primitives.
static void packRequest(T &obj, size_t &req)
It add a request to pack a C++ primitive.
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts)
It packs arrays of C++ primitives.
static void packRequest(const openfpm::detail::multi_array::sub_array_openfpm< tp, dim, vmpl > &obj, size_t &req)
It add a request to pack a C++ primitive.
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts, size_t n)
It packs arrays of C++ primitives.
static void packRequest(T &obj, size_t &req)
It add a request to pack a C++ primitive.
static void pack(ExtPreAlloc< Mem > &mem, const T &eobj, size_t sub_id, Pack_stat &sts)
Pack the encapsulkated object.
static void packRequest(const T &obj, size_t &req)
it add a request to pack an object
static void packRequest(size_t &req)
it add a request to pack an object
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts)
It pack any object checking that the object does not have pointers inside.
static void packRequest(const T &obj, size_t &req)
it add a request to pack an object
static void packRequest(size_t &req)
it add a request to pack an object
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts)
It pack an object.
static void packRequest(const T &obj, size_t &req)
It add a request to pack a C++ primitive.
static void packRequest(size_t &req)
It add a request to pack a C++ primitive.
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts)
It pack any C++ primitives.
static void pack(ExtPreAlloc< Mem >, const T &obj)
Error, no implementation.
static size_t packRequest(const T &obj, size_t &req)
Error, no implementation.
static void call_packRequest(encap &obj, size_t &req)
pack/serialize
It copy one element of the chunk for each property.
e_dst & dst
encapsulated object destination
const e_src & src
encapsulated object source
void operator()(T &t) const
It call the copy function for each property.
size_t sub_id
element to copy
copy_packer_chunk(const e_src &src, size_t sub_id, e_dst &dst)
constructor
It create a boost::fusion vector with the selected properties.
It copy the properties from one object to another.