MADARA  3.1.8
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 "ace/Guard_T.h"
7 #include "ace/Recursive_Thread_Mutex.h"
8 #include "madara/LockType.h"
9 
10 namespace madara
11 {
12  namespace utility
13  {
18  template <typename T>
20  {
21  public:
25  ThreadSafeVector (void);
26 
31  ThreadSafeVector (const ThreadSafeVector & rhs);
32 
37  ThreadSafeVector (const std::vector<T> & rhs);
38 
42  virtual ~ThreadSafeVector (void);
43 
48  void operator= (const ThreadSafeVector & rhs);
49 
54  void operator= (const std::vector<T> & rhs);
55 
61  inline T & operator[] (size_t index);
62 
68  inline const T & operator[] (size_t index) const;
69 
75  inline size_t erase (size_t index);
76 
81  inline void push_back (T & value);
82 
87  inline const T & back (void) const;
88 
93  inline T & back (void);
94 
99  inline T pop_back (void);
100 
105  inline void reserve (size_t new_size) const;
106 
111  inline void resize (size_t new_size) const;
112 
117  inline size_t size (void) const;
118 
123  inline size_t max_size (void) const;
124 
128  inline void clear (void);
129 
133  inline void lock (void) const;
134 
138  inline void unlock (void) const;
139 
143  inline void acquire (void) const;
144 
148  inline void release (void) const;
149 
150  private:
151 
152 
153 
155  mutable MADARA_LOCK_TYPE mutex_;
156 
158  std::vector <T> vector_;
159  };
160  }
161 }
163 
164 #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.