8 #ifndef MAP_VECTOR_STD_HPP_
9 #define MAP_VECTOR_STD_HPP_
11 #include "se_vector.hpp"
12 #include "map_vector_std_ptr.hpp"
14 #define OBJECT_ADD false
15 #define VECTOR_ADD true
18 template<
bool objv,
typename vect_dst>
36 template <
typename S,
typename M,
typename gp,
unsigned int impl,
unsigned int ...args>
inline static void add(
const vector<S,M,
typename memory_traits_lin<S>::type,
memory_traits_lin,gp,impl> & v_src, vect_dst & v_dst)
39 check_valid(&v_src,8);
40 check_valid(&v_dst,8);
42 for (
size_t i = 0 ; i < v_src.size() ; i++)
49 v_dst.get(v_dst.size()-1) = v_src.get(i);
55 template<
typename vect_dst>
73 template <
typename S,
typename M,
typename gp,
unsigned int impl,
unsigned int ...args>
inline static void add(
const vector<S,M,
typename memory_traits_lin<S>::type,
memory_traits_lin,gp,impl> & v_src, vect_dst & v_dst)
76 check_valid((
void *)&v_dst,8);
77 check_valid((
void *)&v_src,8);
83 v_dst.get(v_dst.size()-1) = v_src;
123 typedef void base_to_copy;
126 #include "vector_std_pack_unpack.ipp"
149 void * ptr_old = &base[0];
155 if (ptr_old != &base[0])
157 check_delete(ptr_old);
158 check_new(&base[0],slot*
sizeof(T),VECTOR_STD_EVENT,1);
183 inline void add(
const T & v)
187 void * ptr_old = &base[0];
194 if (ptr_old != &base[0])
196 check_delete(ptr_old);
197 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
216 void * ptr_old = &base[0];
219 base.emplace_back(v);
223 if (ptr_old != &base[0])
225 check_delete(ptr_old);
226 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
239 void * ptr_old = &base[0];
242 base.emplace_back(T());
246 if (ptr_old != &base[0])
248 check_delete(ptr_old);
249 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
265 void * ptr_old = &base[0];
268 size_t start = base.size();
269 base.resize(base.size() + eles.
size());
272 std::copy(eles.begin(),eles.end(),base.begin()+start);
276 if (ptr_old != &base[0])
278 check_delete(ptr_old);
279 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
294 template<
typename S>
inline void add(
const S & v)
298 void * ptr_old = &base[0];
305 if (ptr_old != &base[0])
307 check_delete(ptr_old);
308 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
323 template<
typename S>
inline void add(
const S && v)
327 void * ptr_old = &base[0];
334 if (ptr_old != &base[0])
336 check_delete(ptr_old);
337 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
357 template <
typename S,
361 template <
typename>
class layout_base,
362 unsigned int ...args>
363 void add_prp(
const vector<S,M,
typename layout_base<S>::type,layout_base,gp,impl> & v)
385 template <
typename S,
389 template <
typename>
class layout_base,
390 unsigned int ...args>
405 void erase(
typename std::vector<T>::iterator start,
typename std::vector<T>::iterator end)
411 base.erase(start,end);
425 vector_overflow(
key);
427 base.erase(base.begin() +
key);
435 inline auto begin() -> decltype(base.begin())
445 inline auto end() -> decltype(base.begin())
455 inline auto begin() const -> const decltype(base.begin())
465 inline auto end() const -> const decltype(base.begin())
481 if (base.size() == 0)
482 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
484 return base[base.size()-1];
498 if (base.size() == 0)
499 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
501 return base[base.size()-1];
540 auto it = std::unique(base.begin(),base.end());
541 base.resize( std::distance(base.begin(),it) );
554 std::sort(base.begin(), base.end());
566 template <
unsigned int p>
inline T&
get(
size_t id)
573 {std::cerr <<
"Error the property does not exist" <<
"\n";}
590 template <
unsigned int p>
inline const T&
get(
size_t id)
const
597 {std::cerr <<
"Error the property does not exist" <<
"\n";}
612 inline T &
get(
size_t id)
630 inline const T &
get(
size_t id)
const
649 inline void fill(
unsigned char fl)
654 memset(&base[0],fl,base.size() *
sizeof(T));
675 check_new(
this,8,VECTOR_STD_EVENT,1);
681 :base(sz),err_code(0)
684 check_new(
this,8,VECTOR_STD_EVENT,1);
685 check_new(&base[0],
sizeof(T)*sz,VECTOR_STD_EVENT,1);
690 vector(
const vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> & v) noexcept
694 check_new(
this,8,VECTOR_STD_EVENT,1);
695 void * ptr_old = &base[0];
702 if (ptr_old != &base[0])
704 check_delete(ptr_old);
705 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
716 vector(
const std::initializer_list<T> & v)
720 check_new(
this,8,VECTOR_STD_EVENT,1);
721 check_new(&base[0],
sizeof(T)*v.size(),VECTOR_STD_EVENT,1);
726 vector(vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> && v) noexcept
730 check_new(
this,8,VECTOR_STD_EVENT,1);
741 check_delete(&base[0]);
778 vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(
const vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
782 void * ptr_old = &base[0];
789 if (ptr_old != &base[0])
791 check_delete(ptr_old);
792 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
805 template<
typename Mem,
typename gp> vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(
const vector<T,Mem,layout,memory_traits_lin,gp,STD_VECTOR> & v)
809 void * ptr_old = &base[0];
814 vector<T,Mem,layout,memory_traits_lin,gp,STD_VECTOR> >::copy(*
this,v);
818 if (ptr_old != &base[0])
820 check_delete(ptr_old);
821 check_new(&base[0],base.size()*
sizeof(T),VECTOR_STD_EVENT,1);
836 vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> && v)
853 template<
typename Mem,
typename gp> vector<T,HeapMemory,layout,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(vector<T,Mem,layout,memory_traits_lin,gp,STD_VECTOR> && v)
870 bool operator!=(
const vector<T, HeapMemory, layout, memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
const
872 return base != v.base;
882 bool operator==(
const vector<T, HeapMemory, layout, memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
const
884 return base == v.base;
897 return vector_key_iterator(base.size());
912 return vector_key_iterator(k);
925 template<
int ... prp>
inline size_t packMem(
size_t n,
size_t e)
const
932 return cm.packMemory(*
this,n,0);
1005 check_valid(
this,8);
1017 if (v1 >= base.size())
1019 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " << v1 <<
"\n";\
1020 size_t * err_code_pointer = (
size_t *)&this->err_code;\
1021 *err_code_pointer = 2001;\
1023 ACTION_ON_ERROR(VECTOR_ERROR_OBJECT);\
1037 return check_whoami(
this,8);
static size_t calculateNMem(size_t n)
How many allocation are required to create n-elements.
bool operator!=(const vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are equal.
openfpm::vector< T > duplicate() const
Duplicate the vector.
Transform the boost::fusion::vector into memory specification (memory_traits)
void add_prp(const vector< S, M, typename layout_base< S >::type, layout_base, gp, impl > &v)
It add the element of a source vector to this vector.
size_t packMem(size_t n, size_t e) const
Calculate the memory size required to allocate n elements.
int yes_i_am_vector
it define that it is a vector
static void add(const vector< S, M, typename memory_traits_lin< S >::type, memory_traits_lin, gp, impl > &v_src, vect_dst &v_dst)
It add the element of a source vector to a destination vector.
~vector() noexcept
destructor
size_t getLastError()
Return the last error.
void vector_overflow(size_t v1) const
check that the id does not overflow the buffer
struct to merge two vectors
void clear()
Remove all the element from the vector.
void swap(openfpm::vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &v)
auto begin() -> decltype(base.begin())
Return an std compatible iterator to the first element.
vector_key_iterator getIteratorTo(size_t k) const
Get iterator until a specified element.
auto end() -> decltype(base.begin())
Return an std compatible iterator to the last element.
const T & last() const
Get the last element.
auto end() const -> const decltype(base.begin())
Return an std compatible iterator to the last element.
vector(size_t sz) noexcept
Constructor, vector of size sz.
auto begin() const -> const decltype(base.begin())
Return an std compatible iterator to the first element.
void add(const S &&v)
It insert a new object on the vector, eventually it reallocate the grid.
This class allocate, and destroy CPU memory.
void add()
Add an empty object (it call the default constructor () ) at the end of the vector.
void sort()
It sort the vector.
void swap(openfpm::vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v)
vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v)
Operator= copy the vector into another.
const void * getPointer() const
Return the pointer to the chunk of memory.
vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(const vector< T, Mem, layout, memory_traits_lin, gp, STD_VECTOR > &v)
Operator= copy the vector into another.
static bool noPointers()
This class has pointer inside.
void * getPointer()
Return the pointer to the chunk of memory.
vector_key_iterator getIterator() const
Get an iterator over all the elements of the vector.
void add_prp(const T &v)
It add the element it is equivalent to add.
vector(const vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) noexcept
Constructor from another vector.
void add(const openfpm::vector< T, Mem, l, lb, gp > &eles)
add elements to the vector
vector(const std::initializer_list< T > &v)
Initializer from constructor.
static size_t calculateMemDummy(size_t n, size_t e)
Calculate the memory size required to allocate n elements.
void erase(typename std::vector< T >::iterator start, typename std::vector< T >::iterator end)
Erase the elements from start to end.
void add(const S &v)
It insert a new object on the vector, eventually it reallocate the grid.
void unique()
It eliminate double entries.
size_t size() const
return the size of the vector
void reserve(size_t ns)
reserve a memory space in advance to avoid reallocation
This class is a trick to indicate the compiler a specific specialization pattern. ...
void swap(std::vector< T > &&v)
swap the memory between the two vector
static void add(const vector< S, M, typename memory_traits_lin< S >::type, memory_traits_lin, gp, impl > &v_src, vect_dst &v_dst)
It add the element of a source vector to this vector.
vector(vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v) noexcept
Constructor from another vector.
bool operator==(const vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are not equal.
vector() noexcept
Constructor, vector of size 0.
This class is a container for the memory interface like HeapMemory CudaMemory.
void add(const T &v)
It insert a new object on the vector, eventually it reallocate the grid.
void fill(unsigned char fl)
it fill all the memory of fl patterns
vector_key_iterator iterator_key
iterator for the vector
Implementation of 1-D std::vector like structure.
std::vector< T > base
1-D static grid
vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(vector< T, Mem, layout, memory_traits_lin, gp, STD_VECTOR > &&v)
Operator= copy the vector into another.
T & last()
Get the last element.
vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(const vector< T, HeapMemory, layout, memory_traits_lin, grow_policy_double, STD_VECTOR > &v)
Operator= copy the vector into another.
void add(T &&v)
It insert a new object on the vector, eventually it reallocate the grid.
T value_type
Type of the value the vector is storing.