Template Class shared_vector¶
Defined in File sharedVector.h
Inheritance Relationships¶
Base Type¶
public epics::pvData::detail::shared_vector_base< E >
(Template Class shared_vector_base)
Class Documentation¶
-
template<typename E, class Enable>
class shared_vector : public epics::pvData::detail::shared_vector_base<E>¶ A holder for a contiguous piece of memory.
Data is shared, but offset and length are not. This allows one vector to have access to only a subset of a piece of memory.
The ways in which shared_vector is intended to differ from std::vector are outlined in Differences between std::vector and shared_vector .
Also see Memory Management with shared_vector and Value const-ness and shared_vector
Warning
Due to the implementation of std::tr1::shared_ptr, use of shared_vector should not be combined with use of weak_ptr. shared_ptr::unique() and shared_ptr::use_count() do not include weak_ptr instances. This breaks the assumption made by make_unique() that unique()==true implies exclusive ownership.
Public Types
-
typedef meta::decorate_const<E>::type &const_reference¶
-
typedef meta::decorate_const<E>::type *const_pointer¶
-
typedef meta::decorate_const<E>::type *const_iterator¶
-
typedef std::reverse_iterator<const_iterator> const_reverse_iterator¶
-
typedef ptrdiff_t difference_type¶
-
typedef size_t size_type¶
Public Functions
-
inline shared_vector()¶
Empty vector (not very interesting)
-
inline explicit shared_vector(size_t c)¶
Allocate (with new[]) a new vector of size c.
-
inline shared_vector(size_t c, param_type e)¶
Allocate (with new[]) a new vector of size c and fill with value e.
-
template<typename A>
inline shared_vector(A v, size_t o, size_t c)¶ Build vector from a raw pointer.
- Parameters
v – A raw pointer allocated with new[].
o – The offset in v or the first element visible to the vector
c – The number of elements pointed to by v+o
-
template<typename E1>
inline shared_vector(const std::tr1::shared_ptr<E1> &d, size_t o, size_t c)¶ Build vector from an existing smart pointer.
- Parameters
d – An existing smart pointer
o – The offset in v or the first element visible to the vector
c – The number of elements pointed to by v+o
-
template<typename A, typename B>
inline shared_vector(A d, B b, size_t o, size_t c)¶ Build vector from raw pointer and cleanup function.
- Parameters
d – An existing raw pointer
b – An function/functor used to free d. Invoked as b(d).
o – The offset in v or the first element visible to the vector
c – The number of elements pointed to by v+o
-
inline shared_vector(const shared_vector &o)¶
Copy an existing vector of same type.
-
template<typename FROM>
inline shared_vector(const shared_vector<FROM> &src, detail::_shared_vector_cast_tag)¶
-
inline shared_vector(shared_vector<typename base_t::_E_non_const> &O, detail::_shared_vector_freeze_tag t)¶
-
inline shared_vector(shared_vector<const E> &O, detail::_shared_vector_thaw_tag t)¶
-
inline shared_vector &operator=(const shared_vector &o)¶
-
inline size_t max_size() const¶
-
inline size_t capacity() const¶
-
inline void reserve(size_t i)¶
Set array capacity.
A side effect is that array data will be uniquely owned by this instance as if make_unique() was called. This holds even if the capacity does not increase.
For notes on copying see docs for make_unique().
- Throws
std::bad_alloc – if requested allocation can not be made
other – exceptions from element copy ctor
-
inline void resize(size_t i)¶
Grow or shrink array.
A side effect is that array data will be uniquely owned by this instance as if make_unique() were called. This holds even if the size does not change.
For notes on copying see docs for make_unique().
- Throws
std::bad_alloc – if requested allocation can not be made
other – exceptions from element copy ctor
-
inline void resize(size_t i, param_type v)¶
Grow (and fill) or shrink array.
see resize(size_t)
-
inline void make_unique()¶
Ensure (by copying) that this shared_vector is the sole owner of the data array.
If a copy is needed, memory is allocated with new[]. If this is not desirable then do something like the following.
shared_vector<E> original(...); if(!original.unique()){ std::tr1::shared_ptr<E> sptr(myalloc(original.size()), myfree); shared_vector<E> temp(sptr, 0, original.size()); std::copy(original.begin(), original.end(), temp.begin()); original.swap(temp); } assert(original.unique());
- Throws
std::bad_alloc – if requested allocation can not be made
other – exceptions from element copy ctor
-
inline const_iterator cbegin() const¶
-
inline const_iterator cend() const¶
-
inline reverse_iterator rbegin() const¶
-
inline const_reverse_iterator crbegin() const¶
-
inline reverse_iterator rend() const¶
-
inline const_reverse_iterator crend() const¶
-
inline void push_back(param_type v)¶
-
inline void pop_back()¶
Friends
- friend class shared_vector
-
typedef meta::decorate_const<E>::type &const_reference¶