MADARA  3.4.1
ThreadSafeVector.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 #ifndef _MADARA_UTILITY_THREADSAFE_VECTOR_H_
3 #define _MADARA_UTILITY_THREADSAFE_VECTOR_H_
4 
5 #include <vector>
6 #include "madara/LockType.h"
7 
8 namespace madara
9 {
10 namespace utility
11 {
16 template<typename T>
18 {
19 public:
23  ThreadSafeVector(void);
24 
30 
35  ThreadSafeVector(const std::vector<T>& rhs);
36 
40  virtual ~ThreadSafeVector(void);
41 
46  void operator=(const ThreadSafeVector& rhs);
47 
52  void operator=(const std::vector<T>& rhs);
53 
59  inline T& operator[](size_t index);
60 
66  inline const T& operator[](size_t index) const;
67 
73  inline size_t erase(size_t index);
74 
79  inline void push_back(T& value);
80 
85  inline const T& back(void) const;
86 
91  inline T& back(void);
92 
97  inline T pop_back(void);
98 
103  inline void reserve(size_t new_size) const;
104 
109  inline void resize(size_t new_size) const;
110 
115  inline size_t size(void) const;
116 
121  inline size_t max_size(void) const;
122 
126  inline void clear(void);
127 
131  inline void lock(void) const;
132 
136  inline void unlock(void) const;
137 
141  inline void acquire(void) const;
142 
146  inline void release(void) const;
147 
148 private:
150  mutable MADARA_LOCK_TYPE mutex_;
151 
153  std::vector<T> vector_;
154 };
155 }
156 }
158 
159 #endif /* _MADARA_UTILITY_THREADSAFE_VECTOR_H_ */
Manages a thread safe STL vector.
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.
virtual ~ThreadSafeVector(void)
Destructor.
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_
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:15
Copyright(c) 2020 Galois.