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_);
50 MADARA_GUARD_TYPE guard (mutex_);
52 if (this->vector_ != &rhs)
61 MADARA_GUARD_TYPE guard (mutex_);
62 return vector_[index];
68 MADARA_GUARD_TYPE guard (mutex_);
69 return vector_[index];
75 MADARA_GUARD_TYPE guard (mutex_);
76 vector_.push_back (value);
82 MADARA_GUARD_TYPE guard (mutex_);
83 return vector_.back ();
89 MADARA_GUARD_TYPE guard (mutex_);
90 T result (vector_.back ());
99 MADARA_GUARD_TYPE guard (mutex_);
101 if (index < vector_.size ())
102 vector_.erase (vector_.begin () + index);
104 return vector_.size ();
107 template <
typename T>
110 MADARA_GUARD_TYPE guard (mutex_);
111 return vector_.back ();
114 template <
typename T>
117 MADARA_GUARD_TYPE guard (mutex_);
118 vector_.resize (new_size);
121 template <
typename T>
124 MADARA_GUARD_TYPE guard (mutex_);
125 vector_.reserve (new_size);
128 template <
typename T>
131 MADARA_GUARD_TYPE guard (mutex_);
132 return vector_.size ();
135 template <
typename T>
138 MADARA_GUARD_TYPE guard (mutex_);
139 return vector_.max_size ();
142 template <
typename T>
145 MADARA_GUARD_TYPE guard (mutex_);
149 template <
typename T>
152 mutex_.MADARA_LOCK_LOCK ();
155 template <
typename T>
158 mutex_.MADARA_LOCK_LOCK ();
161 template <
typename T>
164 mutex_.MADARA_LOCK_UNLOCK ();
167 template <
typename T>
170 mutex_.MADARA_LOCK_UNLOCK ();
MADARA_LOCK_TYPE mutex_
mutex for updating refcount_
void lock(void) const
Locks the mutex.
void resize(size_t new_size) const
Resizes the vector.
void push_back(T &value)
Pushes a value onto the end of the vector.
void acquire(void) const
Locks the mutex.
size_t max_size(void) const
returns the max size of the vector
void release(void) const
Unlocks the mutex.
virtual ~ThreadSafeVector(void)
Destructor.
void unlock(void) const
Unlocks the mutex.
ThreadSafeVector(void)
Constructor.
const T & back(void) const
Returns the last element of the vector.
size_t size(void) const
returns the current size of the vector
T & operator[](size_t index)
Accesses an element of the vector.
T pop_back(void)
Returns the last element before removing it.
void clear(void)
Clears the vector.
void reserve(size_t new_size) const
Reserves a number of elements the vector.
size_t erase(size_t index)
Erases an element.
Manages a thread safe STL vector.
std::vector< T > vector_
the encapsulated vector
void operator=(const ThreadSafeVector &rhs)
Assignment operator.