SliceBuffer

Slice buffer class template. Extends ConcatBuffer, encapsulating a buffer with a list of slices to the concatenated items.

Constructors

this
this(size_t len)

Constructor.

Members

Functions

add
T[] add(const(T)[] data)

Appends a new piece of data to the end of the buffer. The item is also added to the slices list.

clear
void clear()

Empties the buffer.

length
size_t length()
opApply
int opApply(int delegate(ref size_t, ref T[]) dg)

foreach iterator over the items which have been added to the buffer and their indices.

opApply
int opApply(int delegate(ref T[]) dg)

foreach iterator over the items which have been added to the buffer.

opIndex
T[] opIndex(size_t index)

Gets an indexed item in the items list.

opSlice
T[][] opSlice()

Get the stored slices.

removeSlice
T[] removeSlice(size_t index)

Removes an indexed item in the items list, maintaining the order of the list.

Parameters

T

element type of buffer

This template is useful for situations where you need to build up a list of arrays of type T[], and be able to repeatedly fill and empty the list without recurring memory allocation. Note that once an item is added to the buffer, it is *not* possible to modify its length, as each item is only stored as a slice (though it is possible to modify the contents of a slice). (For situations where you want to be able to modify the lengths of the individual arrays after adding them to the collection, a Pool of structs containing arrays would be a suitable solution -- see ocean.core.ObjectPool.)

Usage example:

import ocean.util.container.ConcatBuffer;

// Create a slice buffer
auto buff = new SliceBuffer!(char);

// Repeatedly...
while ( application_running )
{
    // Empty the buffer
    buff.clear();

    // Add stuff to the buffer
    buff.add("hello");
    buff.add("world");

    // Iterate over the items in the buffer
    foreach ( index, item; buff )
    {
    }
}

Meta