12#ifndef ROC_CORE_SLICE_H_
13#define ROC_CORE_SLICE_H_
78 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
82 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
83 (
unsigned long)0, (
unsigned long)
buffer.size(), (
unsigned long)
from,
104 return data_ + size_;
117 return buffer_->size() -
size_t(data_ - buffer_->data());
128 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
132 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
133 (
unsigned long)0, (
unsigned long)
cap, (
unsigned long)
from,
137 data_ = data_ +
from;
150 roc_panic(
"slice: extend with zero size");
152 T*
ret = data_ + size_;
163 roc_panic(
"slice: invalid range: [%lu,%lu)", (
unsigned long)
from,
167 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=[%lu,%lu)",
168 (
unsigned long)0, (
unsigned long)size_, (
unsigned long)
from,
172 ret.buffer_ = buffer_;
193 roc_panic(
"slice: out of bounds: available=[%lu,%lu) requested=%lu",
194 (
unsigned long)0, (
unsigned long)size_, (
unsigned long)
i);
Shared ownership intrusive pointer.
Slice subslice(size_t from, size_t to) const
Construct a slice pointing to a part of this slice.
T * extend(const size_t add_sz)
Increase size() by add_sz.
size_t capacity() const
Get maximum possible number of elements in slice.
Slice(const SharedPtr< Buffer< T > > &buffer)
Construct slice pointing to the whole buffer.
T * data_end() const
Pointer to the next after the last element in slice.
T & operator[](const size_t i) const
Access to an element of the Slice with an array style.
void reslice(size_t from, size_t to)
Change slice beginning and ending inside the buffer.
void print() const
Print slice to stderr.
T * data() const
Get slice data.
Slice()
Construct empty slice.
size_t size() const
Get number of elements in slice.
Slice(Buffer< T > &buffer, size_t from, size_t to)
Construct slice pointing to a part of a buffer.
void print_buffer_slice(const uint8_t *inner, size_t inner_size, const uint8_t *outer, size_t outer_size)
Print a slice of a buffer.
#define roc_panic(...)
Print error message and terminate program gracefully.
Shared ownership intrusive pointer.