8 #ifndef OPENFPM_DATA_SRC_VECTOR_MAP_VECTOR_STD_PTR_HPP_
9 #define OPENFPM_DATA_SRC_VECTOR_MAP_VECTOR_STD_PTR_HPP_
12 template<
typename T,
typename gp>
63 if (slot > mem->size()/
sizeof(T))
64 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: this vector cannot be bigger than " << mem->size()/
sizeof(T) <<
" elements\n";
88 inline void add(
const T & v)
93 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: you cannot add a new element to this vector \n";
110 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: you cannot add new element to this vector \n";
124 if (v_size > mem->size()/
sizeof(T))
125 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: you cannot resize a PtrMemory vector over the size stored by PtrMemory";
134 void erase(
typename std::vector<T>::iterator start,
typename std::vector<T>::iterator end)
139 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: you cannot erase element from this vector \n";
153 vector_overflow(
key);
155 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: you cannot remove elements from this vector \n";
165 return mem->getPointer();
175 return &((T *)mem->getPointer())[v_size];
185 return (T *)mem->getPointer();
193 inline const T *
end()
const
195 return &((T *)mem->getPointer())[v_size];
210 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
212 return ((T *)mem->getPointer())[v_size-1];
227 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0" << std::endl;
229 return ((T *)mem->getPointer())[v_size-1];
241 template <
unsigned int p>
inline T&
get(
size_t id)
248 {std::cerr <<
"Error the property does not exist" <<
"\n";}
253 return ((T *)mem->getPointer())[
id];
270 template <
unsigned int p>
inline const T&
get(
size_t id)
const
277 {std::cerr <<
"Error the property does not exist" <<
"\n";}
282 return ((T *)mem->getPointer())[
id];
292 inline T &
get(
size_t id)
299 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " <<
id <<
"\n";
301 return ((T *)mem->getPointer())[
id];
311 inline const T &
get(
size_t id)
const
319 return ((T *)mem->getPointer())[
id];
331 inline void fill(
unsigned char fl)
336 memset(mem->getPointer(),fl,v_size *
sizeof(T));
354 :v_size(0),mem(NULL),err_code(0)
357 check_new(
this,8,VECTOR_STD_EVENT,1);
363 :v_size(sz),err_code(0)
366 check_new(
this,8,VECTOR_STD_EVENT,1);
371 vector(
const vector<T,PtrMemory,layout,layout_base,gp,STD_VECTOR> & v) noexcept
372 :v_size(0),err_code(0)
375 check_new(
this,8,VECTOR_STD_EVENT,1);
378 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: copy constructor is not supported by this vector \n";
383 vector(vector<T,PtrMemory,layout,layout_base,gp,STD_VECTOR> && v) noexcept
384 :v_size(0),err_code(0)
387 check_new(
this,8,VECTOR_STD_EVENT,1);
390 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: copy constructor is not supported by this vector \n";
411 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: swap is not supported by this vector \n";
419 vector<T,HeapMemory,layout,layout_base,grow_policy_double,STD_VECTOR> &
operator=(
const vector<T,HeapMemory,layout,layout_base,grow_policy_double,STD_VECTOR> & v)
424 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: operator= is not supported by this vector \n";
436 vector<T,HeapMemory,layout,layout_base,grow_policy_double,STD_VECTOR> &
operator=(vector<T,HeapMemory,layout,layout_base,grow_policy_double,STD_VECTOR> && v)
441 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: operator= is not supported by this vector \n";
453 bool operator!=(
const vector<T, HeapMemory, layout, layout_base,grow_policy_double,STD_VECTOR> & v)
const
455 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: operator!= is not supported by this vector \n";
467 bool operator==(
const vector<T, HeapMemory, layout, layout_base,grow_policy_double,STD_VECTOR> & v)
const
469 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error: operator== is not supported by this vector \n";
484 return vector_key_iterator(v_size);
498 return mem->getPointer();
508 return mem->getPointer();
543 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " << v1 <<
"\n";\
544 size_t * err_code_pointer = (
size_t *)&this->err_code;\
545 *err_code_pointer = 2001;\
546 ACTION_ON_ERROR(VECTOR_ERROR_OBJECT);\
560 return check_whoami(
this,8);
size_t err_code
Error code.
T * end()
Return an std compatible iterator to the past the last element.
void vector_overflow(size_t v1) const
check that the id does not overflow the buffer
Transform the boost::fusion::vector into memory specification (memory_traits)
const T * begin() const
Return an std compatible iterator to the first element.
void clear()
Remove all the element from the vector.
PtrMemory * mem
1-D static grid
size_t size() const
return the size of the vector
vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > & operator=(const vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > &v)
Operator= copy the vector into another.
bool operator==(const vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are not equal.
vector() noexcept
Constructor, vector of size 0.
const T * end() const
Return an std compatible iterator to the past the last element.
void erase(typename std::vector< T >::iterator start, typename std::vector< T >::iterator end)
Erase the elements from start to end.
void add()
Add an empty object (it call the default constructor () ) at the end of the vector.
const T & last() const
Get the last element.
void add(const 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.
vector(const vector< T, PtrMemory, layout, layout_base, gp, STD_VECTOR > &v) noexcept
Constructor from another vector.
vector_key_iterator iterator_key
iterator for the vector
void fill(unsigned char fl)
it fill all the memory of fl patterns
T * begin()
Return an std compatible iterator to the first element.
void * getPointer()
Return the pointer to the chunk of memory.
void add(T &&v)
It insert a new object on the vector, eventually it reallocate the grid.
vector_key_iterator getIterator() const
Get iterator.
static bool noPointers()
This class has pointer inside.
size_t getLastError()
Return the last error.
void reserve(size_t ns)
reserve a memory space in advance to avoid reallocation
vector(vector< T, PtrMemory, layout, layout_base, gp, STD_VECTOR > &&v) noexcept
Constructor from another vector.
int yes_i_am_vector
it define that it is a vector
const void * getPointer() const
Return the pointer to the chunk of memory.
This class is a trick to indicate the compiler a specific specialization pattern. ...
T & last()
Get the last element.
bool operator!=(const vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are equal.
void swap(openfpm::vector< T, PtrMemory, layout, layout_base, gp, STD_VECTOR > &v)
memory_traits_lin< T >::type layout
Memory layout.
This class is a container for the memory interface like HeapMemory CudaMemory.
vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > & operator=(vector< T, HeapMemory, layout, layout_base, grow_policy_double, STD_VECTOR > &&v)
Operator= copy the vector into another.
vector(size_t sz) noexcept
Constructor, vector of size sz.
Implementation of 1-D std::vector like structure.
~vector() noexcept
destructor
This class give memory from a preallocated memory, memory destruction is not performed.