PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Friends | List of all members
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 >:
Inheritance graph
[legend]
Collaboration diagram for epics::pvData::shared_vector< E, Enable >:
Collaboration graph
[legend]

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. More...
 
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. More...
 
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. More...
 
 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. More...
 
void resize (size_t i)
 Grow or shrink array. More...
 
void resize (size_t i, param_type v)
 Grow (and fill) or shrink array. More...
 
void make_unique ()
 Ensure (by copying) that this shared_vector is the sole owner of the data array. More...
 
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. More...
 
- 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. More...
 
const std::tr1::shared_ptr< E > & dataPtr () const
 
size_t dataOffset () const
 
size_t dataCount () const
 
size_t dataTotal () const
 

Friends

template<typename E1 , class Enable1 >
class shared_vector
 

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 = void>
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 27 of file sharedVector.h.

Constructor & Destructor Documentation

template<typename E, class Enable = void>
template<typename A >
epics::pvData::shared_vector< E, Enable >::shared_vector ( 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.

template<typename E, class Enable = void>
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.

template<typename E, class Enable = void>
template<typename A , typename B >
epics::pvData::shared_vector< E, Enable >::shared_vector ( d,
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.

Member Function Documentation

template<typename E, class Enable = void>
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.

template<typename E, class Enable = void>
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());
Exceptions
std::bad_allocif requested allocation can not be made
otherexceptions from element copy ctor

Definition at line 526 of file sharedVector.h.

template<typename E, class Enable = void>
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.

template<typename E, class Enable = void>
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.

template<typename E, class Enable = void>
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.


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