Template Class vector_t

Inheritance Relationships

Base Type

  • public std::vector< type >

Class Documentation

template<typename type>
class vector_t : public std::vector<type>

Thread-safe wrapper around std::vector.

This container is used across SLAM modules and protects concurrent access with a shared mutex.

Public Types

using shared_ptr = std::shared_ptr<vector_t<type>>

Shared pointer type.

Public Functions

inline vector_t()

Empty constructor for the Visualization Vector object.

inline vector_t(type data_)

Constructor with initial data

Parameters:

data_ – First element inserted during construction.

inline vector_t(const vector_t<type> &other_)

Copy constructor

Parameters:

other_ – Source vector copied while holding a shared read lock.

inline ~vector_t()

Destroy the Visualization Vector object.

inline vector_t<type> &operator=(const vector_t<type> &other_)

Equal operator

Parameters:

other_ – Source vector whose contents replace the current vector.

Returns:

Reference to this vector after synchronized assignment.

inline vector_t<type> &operator=(std::vector<type> other_)

Assignment operator from std::vector

Parameters:

other_ – Standard vector copied into this container.

Returns:

Reference to this vector after assignment.

inline void push_back_(type item_)

Add new item to the vector in a thread-safe manner

Parameters:

item_ – Element appended to the end of the vector.

inline void clear_(const std::vector<type> &itemsToRemove_ = std::vector<type>())

Remove specific items from the vector in a thread-safe manner

Parameters:

itemsToRemove_ – Elements to erase; empty input clears all elements.

inline void clear_(type itemToRemove_)

Remove a specific item from the vector in a thread-safe manner

Parameters:

itemToRemove_ – Element value to erase from the vector.

inline type at_(size_t pos_)

Access an element in a thread-safe manner

Parameters:

pos_ – Zero-based index of the element to read.

Returns:

Copy of the element stored at pos_.

inline void assign_(typename vector_t<type>::const_iterator first_, typename vector_t<type>::const_iterator last_)

Assign from iterators in a thread-safe manner

Parameters:
  • first_ – Iterator to the first element of the source range.

  • last_ – Iterator one past the last element of the source range.

inline void shared_lock() const

This function is used to lock the entire vector for reading.

inline void unlock_shared() const

This function is used to unlock the vector after it was.

inline void unique_lock() const

This function is used to lock the entire vector for writing.

inline void unlock_unique() const

This function is used to unlock the vector after it was.

inline int get_size_safe() const

Get the size of the vector in a thread-safe manner

Returns:

Number of elements currently stored in the vector.

inline vector_t<type> to_vector(const size_t size_ = 0) const

Convert the vector to a standard vector in a thread-safe manner

Parameters:

size_ – Maximum number of elements to copy; 0 means copy all.

Returns:

New vector containing up to size_ elements from the front.

Public Static Functions

static inline vector_t<type>::shared_ptr make_shared()

Make shared pointer function

Returns:

Shared pointer owning a new empty thread-safe vector.

static inline vector_t<type>::shared_ptr make_shared(vector_t<type> data_)

Make shared pointer function from data

Parameters:

data_ – Initial contents copied into the new shared vector.

Returns:

Shared pointer owning a copy of data_.

static inline vector_t<type>::shared_ptr make_shared(std::vector<type> data_)

Make shared pointer function from std::vector

Parameters:

data_ – Initial standard vector contents to copy.

Returns:

Shared pointer owning a vector initialized from data_.

Private Members

mutable std::shared_mutex _mutex

Mutex that is used to lock the vector for reading and writing.