2 #ifndef _MADARA_THREADSAFE_VECTOR_CPP_
3 #define _MADARA_THREADSAFE_VECTOR_CPP_
16 MADARA_GUARD_TYPE rhs_guard(rhs.
mutex_);
22 const std::vector<T>& rhs)
37 MADARA_GUARD_TYPE guard(mutex_);
38 MADARA_GUARD_TYPE rhs_guard(rhs.
mutex_);
49 MADARA_GUARD_TYPE guard(mutex_);
51 if (this->vector_ != &rhs)
60 MADARA_GUARD_TYPE guard(mutex_);
61 return vector_[index];
67 MADARA_GUARD_TYPE guard(mutex_);
68 return vector_[index];
74 MADARA_GUARD_TYPE guard(mutex_);
75 vector_.push_back(value);
81 MADARA_GUARD_TYPE guard(mutex_);
82 return vector_.back();
88 MADARA_GUARD_TYPE guard(mutex_);
89 T result(vector_.back());
98 MADARA_GUARD_TYPE guard(mutex_);
100 if (index < vector_.size())
101 vector_.erase(vector_.begin() + index);
103 return vector_.size();
109 MADARA_GUARD_TYPE guard(mutex_);
110 return vector_.back();
116 MADARA_GUARD_TYPE guard(mutex_);
117 vector_.resize(new_size);
123 MADARA_GUARD_TYPE guard(mutex_);
124 vector_.reserve(new_size);
130 MADARA_GUARD_TYPE guard(mutex_);
131 return vector_.size();
137 MADARA_GUARD_TYPE guard(mutex_);
138 return vector_.max_size();
144 MADARA_GUARD_TYPE guard(mutex_);
151 mutex_.MADARA_LOCK_LOCK();
157 mutex_.MADARA_LOCK_LOCK();
163 mutex_.MADARA_LOCK_UNLOCK();
169 mutex_.MADARA_LOCK_UNLOCK();
Manages a thread safe STL vector.
ThreadSafeVector(void)
Constructor.
void release(void) const
Unlocks the mutex.
T pop_back(void)
Returns the last element before removing it.
size_t max_size(void) const
returns the max size of the vector
T & operator[](size_t index)
Accesses an element of the vector.
size_t size(void) const
returns the current size of the vector
void resize(size_t new_size) const
Resizes the vector.
size_t erase(size_t index)
Erases an element.
void unlock(void) const
Unlocks the mutex.
void lock(void) const
Locks the mutex.
void acquire(void) const
Locks the mutex.
std::vector< T > vector_
the encapsulated vector
void clear(void)
Clears the vector.
void push_back(T &value)
Pushes a value onto the end of the vector.
void reserve(size_t new_size) const
Reserves a number of elements the vector.
const T & back(void) const
Returns the last element of the vector.
void operator=(const ThreadSafeVector &rhs)
Assignment operator.
MADARA_LOCK_TYPE mutex_
mutex for updating refcount_