8 #ifndef SRC_PACKER_HPP_
9 #define SRC_PACKER_HPP_
11 #include "util/object_util.hpp"
13 #include "Vector/util.hpp"
14 #include "memory/ExtPreAlloc.hpp"
15 #include "util/util_debug.hpp"
17 #ifdef SRC_PACK_SELECTOR_HPP_
21 #include "Grid/grid_sm.hpp"
22 #include "util/Pack_stat.hpp"
23 #include "Pack_selector.hpp"
45 template<typename T, typename Mem, int pack_type=Pack_selector<T>::value >
53 static void pack(ExtPreAlloc<Mem> ,
const T & obj)
55 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" packing for the type " << demangle(
typeid(T).name()) <<
" is not implemented\n";
63 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" packing for the type " << demangle(
typeid(T).name()) <<
" is not implemented\n";
74 template<
typename T,
typename Mem>
86 inline static void pack(ExtPreAlloc<Mem> & ext,
const T & obj,
Pack_stat & sts)
88 ext.allocate(
sizeof(T));
89 *(T *)ext.getPointer() = obj;
102 req.push_back(
sizeof(T));
112 template<
typename T,
typename Mem>
113 class Packer<T,Mem,PACKER_ARRAY_PRIMITIVE>
124 inline static void pack(ExtPreAlloc<Mem> & ext,
const T & obj,
Pack_stat & sts,
size_t n)
130 ext.allocate(
sizeof(
typename T::value_type)*n);
131 memcpy(ext.getPointer(),obj.getPointer(),
sizeof(
typename T::value_type)*n);
144 req.push_back(
sizeof(T));
155 template<
typename T,
typename Mem>
156 class Packer<T,Mem,PACKER_OBJECTS_WITH_WARNING_POINTERS>
171 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
173 std::cerr <<
"Warning: " << __FILE__ <<
":" << __LINE__ <<
" impossible to check the type " << demangle(
typeid(T).name()) <<
" please consider to add a static method \"void noPointers()\" \n" ;
175 ext.allocate(
sizeof(T));
176 memcpy((T *)ext.getPointer(),&obj,
sizeof(T));
189 req.push_back(
sizeof(T));
199 template<
typename T,
typename Mem>
200 class Packer<T,Mem,PACKER_OBJECTS_WITH_POINTER_CHECK>
215 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
217 if (obj.noPointers() ==
false)
218 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" the type " << demangle(
typeid(T).name()) <<
" has pointers inside, sending pointers values has no sense\n";
220 ext.allocate(
sizeof(T));
221 memcpy((T *)ext.getPointer(),&obj,
sizeof(T));
234 req.push_back(
sizeof(T));
244 template<
typename T,
typename Mem>
249 template<
int ... prp>
static void packRequest(T & obj, std::vector<size_t> & v)
254 template<
int ... prp>
static void pack(ExtPreAlloc<Mem> & mem, T & obj,
Pack_stat & sts)
257 std::cout <<
"Inside vector pack() function! (packer.hpp)" << std::endl;
259 obj.template
pack<prp...>(mem, sts);
269 template<
typename T,
typename Mem>
274 template<
int ... prp>
static void packRequest(T & obj, std::vector<size_t> & v)
284 template<
int ... prp>
static void pack(ExtPreAlloc<Mem> & mem, T & obj,
Pack_stat & sts)
286 obj.template
pack<prp...>(mem, sts);
291 obj.template
pack<prp...>(mem, sub_it, sts);
296 template<
typename T,
typename Mem>
305 void pack(ExtPreAlloc<Mem> & mem, T & eobj)
309 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
313 typename T::type obj = eobj;
315 memcpy(mem.getPointer(),&obj,
sizeof(T::type));
324 v.push_back(
sizeof(T::type));
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts)
It pack any C++ primitives.
static void pack(ExtPreAlloc< Mem > &ext, T &obj, Pack_stat &sts)
It pack any object checking that the object does not have pointers inside.
static void packRequest(std::vector< size_t > &req)
It add a request to pack a C++ primitive.
static size_t packRequest(std::vector< size_t > &req)
Error, no implementation.
static void packRequest(std::vector< size_t > &req)
it add a request to pack an object
void incReq()
Increment the request pointer.
static void pack(ExtPreAlloc< Mem > &ext, T &obj, Pack_stat &sts)
It pack an object.
static void packRequest(std::vector< size_t > &req)
it add a request to pack an object
static void pack(ExtPreAlloc< Mem > &ext, const T &obj, Pack_stat &sts, size_t n)
It packs arrays of C++ primitives.
static void packRequestDummy(std::vector< size_t > &req)
It add a request to pack a C++ primitive.
static void pack(ExtPreAlloc< Mem >, const T &obj)
Error, no implementation.