MADARA  3.2.3
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 
29  ThreadSafeVector (const ThreadSafeVector & rhs);
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:
149 
150 
151 
153  mutable MADARA_LOCK_TYPE mutex_;
154 
156  std::vector <T> vector_;
157  };
158  }
159 }
161 
162 #endif /* _MADARA_UTILITY_THREADSAFE_VECTOR_H_ */
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.
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.
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
Manages a thread safe STL vector.
Copyright (c) 2015 Carnegie Mellon University.
std::vector< T > vector_
the encapsulated vector
void operator=(const ThreadSafeVector &rhs)
Assignment operator.