1 # ifndef CPPAD_LOCAL_POD_VECTOR_HPP
2 # define CPPAD_LOCAL_POD_VECTOR_HPP
15 # if CPPAD_CSTDINT_HAS_8_TO_64
21 # include <cppad/local/is_pod.hpp>
23 namespace CppAD {
namespace local {
67 {
void* v_ptr =
reinterpret_cast<void*
>(
data_ );
68 if( ! is_pod<Type>() )
93 const Type*
data(
void)
const
125 Type* old_data =
data_;
128 size_t length_bytes =
length_ *
sizeof(Type);
129 size_t capacity_bytes;
131 capacity_ = capacity_bytes /
sizeof(Type);
132 data_ =
reinterpret_cast<Type*
>(v_ptr);
136 if( ! is_pod<Type>() )
139 new(
data_ + i) Type();
143 for(i = 0; i < old_length; i++)
144 data_[i] = old_data[i];
147 if( old_capacity > 0 )
148 { v_ptr =
reinterpret_cast<void*
>( old_data );
149 if( ! is_pod<Type>() )
150 {
for(i = 0; i < old_capacity; i++)
151 (old_data + i)->~Type();
189 { v_ptr =
reinterpret_cast<void*
>(
data_ );
190 if( ! is_pod<Type>() )
193 (
data_ + i)->~Type();
199 size_t length_bytes =
length_ *
sizeof(Type);
200 size_t capacity_bytes;
202 capacity_ = capacity_bytes /
sizeof(Type);
203 data_ =
reinterpret_cast<Type*
>(v_ptr);
207 if( ! is_pod<Type>() )
210 new(
data_ + i) Type();
248 {
void* v_ptr =
reinterpret_cast<void*
>(
data_ );
249 if( ! is_pod<Type>() )
253 (
data_ + i)->~Type();
276 {
void* v_ptr =
reinterpret_cast<void*
>(
data_ );
277 if( ! is_pod<Type>() )
280 (
data_ + i)->~Type();
void resize(size_t n)
resize the vector (existing elements preserved when n <= capacity_).
void clear(void)
Remove all the elements from this vector and free its memory.
size_t extend(size_t n)
Increase the number of elements the end of this vector (existing elements are always preserved)...
void push_back(const Type &e)
Add an element to theh back of this vector.
static void return_memory(void *v_ptr)
Return memory that was obtained by get_memory.
A vector class with Type element that does not use element constructors or destructors when Type is P...
Type * data_
pointer to the first type elements (not defined and should not be used when capacity_ = 0) ...
Define the CppAD error checking macros (all of which begin with CPPAD_ASSERT_)
~pod_vector(void)
Destructor: returns allocated memory to thread_alloc; see extend. If this is not plain old data...
const Type & operator[](size_t i) const
constant element access; i.e., we cannot change this element value
static void * get_memory(size_t min_bytes, size_t &cap_bytes)
Use thread_alloc to get a specified amount of memory.
void erase(void)
Remove all the elements from this vector but leave the capacity and data pointer as is...
void operator=(const pod_vector &x)
vector assignment operator
size_t length_
number of elements currently in this vector
size_t size(void) const
current number of elements in this vector.
Type * data(void)
current data pointer is no longer valid after any of the following: extend, erase, operator=, and ~pod_vector. Take extreem care when using this function.
void swap(pod_vector &other)
Swap all properties of this vector with another.
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
File used to define the CppAD multi-threading allocator class.
const Type * data(void) const
const version of data pointer (see non-const documentation)
pod_vector(size_t n)
sizing constructor
pod_vector(const pod_vector &)
do not use the copy constructor
size_t capacity(void) const
current capacity (amount of allocated storage) for this vector.
size_t capacity_
maximum number of Type elements current allocation can hold
pod_vector(void)
default constructor sets capacity_ = length_ = data_ = 0
Type & operator[](size_t i)
non-constant element access; i.e., we can change this element value