|
| Slice () |
| Construct empty slice.
|
|
| Slice (const BufferPtr &buffer) |
| Construct slice pointing to the whole buffer.
|
|
| Slice (Buffer &buffer, size_t from, size_t to) |
| Construct slice pointing to a part of a buffer.
|
|
T * | data () const |
| Get slice data.
|
|
T * | data_end () const |
| Pointer to the next after the last element in slice.
|
|
size_t | size () const |
| Get number of elements in slice.
|
|
size_t | capacity () const |
| Get maximum possible number of elements in slice.
|
|
void | reslice (size_t from, size_t to) |
| Change slice beginning and ending inside the buffer.
|
|
T * | extend (const size_t add_sz) |
| Increase size() by add_sz .
|
|
Slice | subslice (size_t from, size_t to) const |
| Construct a slice pointing to a part of this slice.
|
|
void | print () const |
| Print slice to stderr.
|
|
T & | operator[] (const size_t i) const |
| Access to an element of the Slice with an array style.
|
|
| operator const struct unspecified_bool * () const |
| Convert to bool.
|
|
template<class T>
class roc::core::Slice< T >
Slice.
Slice points to a subrange of data in pool-allocated Buffer. Copying a slice produces a new slice referring the same data.
Slice also acts as a kind of shared pointer to Buffer. A buffer won't be freed (returned to pool) until there are slices referring it. Copying a slice increments the buffer reference counter, and destroying a slice decrements it.
While Buffer works with raw bytes, Slice<T> interprets it as array of elements of type T, and works in terms of those elements.
Slice has two important characteristics:
- size - the difference between the ending end beginning pointer
- capacity - the difference between the actual buffer end and the slice beginning pointer
Buffers are not resizable. They're allocated from pool and have fixed size, defined by the pool parameters.
Slices are reslicable, which means that their pointers to the buffer data may be moved within the buffer.
The beginning pointer may be moved only forward. Once moved, it's not allowed to move it backward again. Moving it decreases the slice size and capacity. Capacity is affected because it's relative to the beginning pointer.
The ending pointer may be freely moved forward and backward within the slice capacity. Moving it affects the slice size, but not capacity.
In other words, slice capacity may be only decreased by moving beginning pointer, and slice size may be freely changed within the slice capacity by moving both beginning and ending pointers.
Definition at line 55 of file slice.h.