PVData C++ 8.0.7
Loading...
Searching...
No Matches
epics::pvData::shared_vector< E, Enable > Class Template Reference

A holder for a contiguous piece of memory. More...

#include <misc/pv/sharedVector.h>

Inheritance diagram for epics::pvData::shared_vector< E, Enable >:
Collaboration diagram for epics::pvData::shared_vector< E, Enable >:

Public Types

typedef E value_type
 
typedef E & reference
 
typedef meta::decorate_const< E >::type & const_reference
 
typedef E * pointer
 
typedef meta::decorate_const< E >::type * const_pointer
 
typedef E * iterator
 
typedef std::reverse_iterator< iterator > reverse_iterator
 
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
 
typedef E element_type
 
typedef std::tr1::shared_ptr< E > shared_pointer_type
 

Public Member Functions

 shared_vector ()
 Empty vector (not very interesting)
 
 shared_vector (size_t c)
 Allocate (with new[]) a new vector of size c.
 
 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 >
 shared_vector (A v, size_t o, size_t c)
 Build vector from a raw pointer.
 
template<typename E1 >
 shared_vector (const std::tr1::shared_ptr< E1 > &d, size_t o, size_t c)
 Build vector from an existing smart pointer.
 
template<typename A , typename B >
 shared_vector (A d, B b, size_t o, size_t c)
 Build vector from raw pointer and cleanup function.
 
 shared_vector (const shared_vector &o)
 Copy an existing vector of same type.
 
template<typename FROM >
 shared_vector (const shared_vector< FROM > &src, detail::_shared_vector_cast_tag)
 
 shared_vector (shared_vector< typename base_t::_E_non_const > &O, detail::_shared_vector_freeze_tag t)
 
 shared_vector (shared_vector< const E > &O, detail::_shared_vector_thaw_tag t)
 
shared_vectoroperator= (const shared_vector &o)
 
size_t max_size () const
 
size_t capacity () const
 
void reserve (size_t i)
 Set array capacity.
 
void resize (size_t i)
 Grow or shrink array.
 
void resize (size_t i, param_type v)
 Grow (and fill) or shrink array.
 
void make_unique ()
 Ensure (by copying) that this shared_vector is the sole owner of the data array.
 
iterator begin () const
 
const_iterator cbegin () const
 
iterator end () const
 
const_iterator cend () const
 
reverse_iterator rbegin () const
 
const_reverse_iterator crbegin () const
 
reverse_iterator rend () const
 
const_reverse_iterator crend () const
 
reference front () const
 
reference back () const
 
void push_back (param_type v)
 
void pop_back ()
 
pointer data () const
 Return Base pointer.
 
reference operator[] (size_t i) const
 Member access Undefined if empty()==true.
 
reference at (size_t i) const
 Member access.
 
- Public Member Functions inherited from epics::pvData::detail::shared_vector_base< E >
 shared_vector_base ()
 Empty vector (not very interesting)
 
template<typename A >
 shared_vector_base (A *v, size_t o, size_t c)
 
 shared_vector_base (const std::tr1::shared_ptr< E > &d, size_t o, size_t c)
 
template<typename A , typename B >
 shared_vector_base (A d, B b, size_t o, size_t c)
 
 shared_vector_base (const shared_vector_base &O)
 
 shared_vector_base (shared_vector_base< _E_non_const > &O, _shared_vector_freeze_tag)
 
 shared_vector_base (shared_vector< const E > &O, _shared_vector_thaw_tag)
 
shared_vector_baseoperator= (const shared_vector_base &o)
 Copy an existing vector.
 
void swap (shared_vector_base &o)
 Swap the contents of this vector with another.
 
void clear ()
 Clear contents. size() becomes 0.
 
bool unique () const
 Data is not shared?
 
size_t size () const
 Number of elements visible through this vector.
 
bool empty () const
 shorthand for size()==0
 
void slice (size_t offset, size_t length=(size_t) -1)
 Reduce the view of this shared_vector.
 
const std::tr1::shared_ptr< E > & dataPtr () const
 
size_t dataOffset () const
 
size_t dataCount () const
 
size_t dataTotal () const
 

Additional Inherited Members

- Protected Types inherited from epics::pvData::detail::shared_vector_base< E >
typedef meta::strip_const< E >::type _E_non_const
 
- Protected Member Functions inherited from epics::pvData::detail::shared_vector_base< E >
void _null_input ()
 
- Protected Attributes inherited from epics::pvData::detail::shared_vector_base< E >
std::tr1::shared_ptr< E > m_sdata
 
size_t m_offset
 Offset in the data array of first visible element.
 
size_t m_count
 Number of visible elements between m_offset and end of data.
 
size_t m_total
 Total number of elements between m_offset and the end of data.
 

Detailed Description

template<typename E, class Enable>
class epics::pvData::shared_vector< E, Enable >

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.

Definition at line 287 of file sharedVector.h.

Member Typedef Documentation

◆ const_iterator

template<typename E , class Enable >
meta::decorate_const<E>::type* epics::pvData::shared_vector< E, Enable >::const_iterator

Definition at line 300 of file sharedVector.h.

◆ const_pointer

template<typename E , class Enable >
meta::decorate_const<E>::type* epics::pvData::shared_vector< E, Enable >::const_pointer

Definition at line 297 of file sharedVector.h.

◆ const_reference

template<typename E , class Enable >
meta::decorate_const<E>::type& epics::pvData::shared_vector< E, Enable >::const_reference

Definition at line 295 of file sharedVector.h.

◆ const_reverse_iterator

template<typename E , class Enable >
std::reverse_iterator<const_iterator> epics::pvData::shared_vector< E, Enable >::const_reverse_iterator

Definition at line 301 of file sharedVector.h.

◆ difference_type

template<typename E , class Enable >
ptrdiff_t epics::pvData::shared_vector< E, Enable >::difference_type

Definition at line 302 of file sharedVector.h.

◆ element_type

template<typename E , class Enable >
E epics::pvData::shared_vector< E, Enable >::element_type

Definition at line 305 of file sharedVector.h.

◆ iterator

template<typename E , class Enable >
E* epics::pvData::shared_vector< E, Enable >::iterator

Definition at line 298 of file sharedVector.h.

◆ pointer

template<typename E , class Enable >
E* epics::pvData::shared_vector< E, Enable >::pointer

Definition at line 296 of file sharedVector.h.

◆ reference

template<typename E , class Enable >
E& epics::pvData::shared_vector< E, Enable >::reference

Definition at line 294 of file sharedVector.h.

◆ reverse_iterator

template<typename E , class Enable >
std::reverse_iterator<iterator> epics::pvData::shared_vector< E, Enable >::reverse_iterator

Definition at line 299 of file sharedVector.h.

◆ shared_pointer_type

template<typename E , class Enable >
std::tr1::shared_ptr<E> epics::pvData::shared_vector< E, Enable >::shared_pointer_type

Definition at line 306 of file sharedVector.h.

◆ size_type

template<typename E , class Enable >
size_t epics::pvData::shared_vector< E, Enable >::size_type

Definition at line 303 of file sharedVector.h.

◆ value_type

template<typename E , class Enable >
E epics::pvData::shared_vector< E, Enable >::value_type

Definition at line 293 of file sharedVector.h.

Constructor & Destructor Documentation

◆ shared_vector() [1/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( )
inline

Empty vector (not very interesting)

Definition at line 315 of file sharedVector.h.

◆ shared_vector() [2/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( size_t c)
inlineexplicit

Allocate (with new[]) a new vector of size c.

Definition at line 329 of file sharedVector.h.

◆ shared_vector() [3/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( size_t c,
param_type e )
inline

Allocate (with new[]) a new vector of size c and fill with value e.

Definition at line 334 of file sharedVector.h.

◆ shared_vector() [4/10]

template<typename E , class Enable >
template<typename A >
epics::pvData::shared_vector< E, Enable >::shared_vector ( A v,
size_t o,
size_t c )
inline

Build vector from a raw pointer.

Parameters
vA raw pointer allocated with new[].
oThe offset in v or the first element visible to the vector
cThe number of elements pointed to by v+o

Definition at line 347 of file sharedVector.h.

◆ shared_vector() [5/10]

template<typename E , class Enable >
template<typename E1 >
epics::pvData::shared_vector< E, Enable >::shared_vector ( const std::tr1::shared_ptr< E1 > & d,
size_t o,
size_t c )
inline

Build vector from an existing smart pointer.

Parameters
dAn existing smart pointer
oThe offset in v or the first element visible to the vector
cThe number of elements pointed to by v+o

Definition at line 356 of file sharedVector.h.

◆ shared_vector() [6/10]

template<typename E , class Enable >
template<typename A , typename B >
epics::pvData::shared_vector< E, Enable >::shared_vector ( A d,
B b,
size_t o,
size_t c )
inline

Build vector from raw pointer and cleanup function.

Parameters
dAn existing raw pointer
bAn function/functor used to free d. Invoked as b(d).
oThe offset in v or the first element visible to the vector
cThe number of elements pointed to by v+o

Definition at line 367 of file sharedVector.h.

◆ shared_vector() [7/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( const shared_vector< E, Enable > & o)
inline

Copy an existing vector of same type.

Definition at line 371 of file sharedVector.h.

◆ shared_vector() [8/10]

template<typename E , class Enable >
template<typename FROM >
epics::pvData::shared_vector< E, Enable >::shared_vector ( const shared_vector< FROM > & src,
detail::_shared_vector_cast_tag  )
inline

Definition at line 381 of file sharedVector.h.

◆ shared_vector() [9/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( shared_vector< typename base_t::_E_non_const > & O,
detail::_shared_vector_freeze_tag t )
inline

Definition at line 389 of file sharedVector.h.

◆ shared_vector() [10/10]

template<typename E , class Enable >
epics::pvData::shared_vector< E, Enable >::shared_vector ( shared_vector< const E > & O,
detail::_shared_vector_thaw_tag t )
inline

Definition at line 394 of file sharedVector.h.

Member Function Documentation

◆ at()

template<typename E , class Enable >
reference epics::pvData::shared_vector< E, Enable >::at ( size_t i) const
inline

Member access.

Exceptions
std::out_of_rangeif i>=size().

Definition at line 624 of file sharedVector.h.

◆ back()

template<typename E , class Enable >
reference epics::pvData::shared_vector< E, Enable >::back ( ) const
inline

Definition at line 573 of file sharedVector.h.

◆ begin()

template<typename E , class Enable >
iterator epics::pvData::shared_vector< E, Enable >::begin ( ) const
inline

Definition at line 560 of file sharedVector.h.

◆ capacity()

template<typename E , class Enable >
size_t epics::pvData::shared_vector< E, Enable >::capacity ( ) const
inline

Definition at line 415 of file sharedVector.h.

◆ cbegin()

template<typename E , class Enable >
const_iterator epics::pvData::shared_vector< E, Enable >::cbegin ( ) const
inline

Definition at line 561 of file sharedVector.h.

◆ cend()

template<typename E , class Enable >
const_iterator epics::pvData::shared_vector< E, Enable >::cend ( ) const
inline

Definition at line 564 of file sharedVector.h.

◆ crbegin()

template<typename E , class Enable >
const_reverse_iterator epics::pvData::shared_vector< E, Enable >::crbegin ( ) const
inline

Definition at line 567 of file sharedVector.h.

◆ crend()

template<typename E , class Enable >
const_reverse_iterator epics::pvData::shared_vector< E, Enable >::crend ( ) const
inline

Definition at line 570 of file sharedVector.h.

◆ data()

template<typename E , class Enable >
pointer epics::pvData::shared_vector< E, Enable >::data ( ) const
inline

Return Base pointer.

Definition at line 616 of file sharedVector.h.

◆ end()

template<typename E , class Enable >
iterator epics::pvData::shared_vector< E, Enable >::end ( ) const
inline

Definition at line 563 of file sharedVector.h.

◆ front()

template<typename E , class Enable >
reference epics::pvData::shared_vector< E, Enable >::front ( ) const
inline

Definition at line 572 of file sharedVector.h.

◆ make_unique()

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::make_unique ( )
inline

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());
constexpr _OI copy(_II __first, _II __last, _OI __result)
A holder for a contiguous piece of memory.
Exceptions
std::bad_allocif requested allocation can not be made
otherexceptions from element copy ctor

Definition at line 526 of file sharedVector.h.

◆ max_size()

template<typename E , class Enable >
size_t epics::pvData::shared_vector< E, Enable >::max_size ( ) const
inline

Definition at line 413 of file sharedVector.h.

◆ operator=()

template<typename E , class Enable >
shared_vector & epics::pvData::shared_vector< E, Enable >::operator= ( const shared_vector< E, Enable > & o)
inline

Definition at line 399 of file sharedVector.h.

◆ operator[]()

template<typename E , class Enable >
reference epics::pvData::shared_vector< E, Enable >::operator[] ( size_t i) const
inline

Member access Undefined if empty()==true.

Definition at line 620 of file sharedVector.h.

◆ pop_back()

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::pop_back ( )
inline

Definition at line 608 of file sharedVector.h.

◆ push_back()

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::push_back ( param_type v)
inline

Definition at line 602 of file sharedVector.h.

◆ rbegin()

template<typename E , class Enable >
reverse_iterator epics::pvData::shared_vector< E, Enable >::rbegin ( ) const
inline

Definition at line 566 of file sharedVector.h.

◆ rend()

template<typename E , class Enable >
reverse_iterator epics::pvData::shared_vector< E, Enable >::rend ( ) const
inline

Definition at line 569 of file sharedVector.h.

◆ reserve()

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::reserve ( size_t i)
inline

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().

Exceptions
std::bad_allocif requested allocation can not be made
otherexceptions from element copy ctor

Definition at line 428 of file sharedVector.h.

◆ resize() [1/2]

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::resize ( size_t i)
inline

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().

Exceptions
std::bad_allocif requested allocation can not be made
otherexceptions from element copy ctor

Definition at line 457 of file sharedVector.h.

◆ resize() [2/2]

template<typename E , class Enable >
void epics::pvData::shared_vector< E, Enable >::resize ( size_t i,
param_type v )
inline

Grow (and fill) or shrink array.

see resize(size_t)

Definition at line 498 of file sharedVector.h.

Friends And Related Symbol Documentation

◆ shared_vector

template<typename E , class Enable >
template<typename E1 , class Enable1 >
friend class shared_vector
friend

Definition at line 309 of file sharedVector.h.


The documentation for this class was generated from the following file: