Top Description Inners Fields Constructors Methods
org.python.core.buffer

public Class Strided1DWritableBuffer

extends Strided1DBuffer
Class Inheritance
Known Direct Subclasses
org.python.core.buffer.Strided1DWritableBuffer.SlicedView
Imports
org.python.core.BufferProtocol, .PyBuffer, .PyException

Read-write buffer API over a one-dimensional array of one-byte items, that are evenly-spaced in a storage array. The storage conventions are described in Strided1DBuffer of which this is an extension providing write operations and a writable slice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Strided1DWritableBuffer.SlicedView

A Strided1DWritableBuffer.SlicedView represents a non-contiguous subsequence of a simple buffer.

Field Summary

Inherited from org.python.core.buffer.Strided1DBuffer:
stride

Constructor Summary

AccessConstructor and Description
public
Strided1DWritableBuffer(int
consumer requirements
flags
,
BufferProtocol
exporting object (or null)
obj
,
byte[]
raw byte array containing exported data
storage
,
int
index into storage of item[0]
index0
,
int
number of items in the slice
count
,
int
byte-index distance from one element to the next in the new PyBuffer
stride
)

Provide an instance of Strided1DWritableBuffer on a particular array of bytes specifying a starting index, the number of items in the result, and a byte-indexing stride.

Method Summary

Modifier and TypeMethod and Description
protected final void
checkWritable()

Overrides org.python.core.buffer.BaseBuffer.checkWritable.

Do nothing: the buffer is writable.

public PyBuffer
getBufferSlice(int
specifying features demanded and the navigational capabilities of the consumer
flags
,
int
index in the current buffer
start
,
int
number of items in the required slice
count
,
int
index-distance in the current buffer between consecutive items in the slice
stride
)

Overrides org.python.core.buffer.Strided1DBuffer.getBufferSlice.

Implements org.python.core.PyBuffer.getBufferSlice.

Get a PyBuffer that represents a slice of the current one described in terms of a start index, number of items to include in the slice, and the stride in the current buffer.

public final boolean
isReadonly()

Overrides org.python.core.buffer.Strided1DBuffer.isReadonly.

Implements org.python.core.PyBUF.isReadonly.

Determine whether the consumer is entitled to write to the exported storage.

protected void
storeAtImpl(byte
to store
value
,
int
byte-index of location to retrieve
byteIndex
)

Overrides org.python.core.buffer.BaseArrayBuffer.storeAtImpl.

Store the byte at the given index in the underlying storage treated as a flat sequence of bytes.

Inherited from org.python.core.buffer.Strided1DBuffer:
byteIndexgetPointergetPointer

Constructor Detail

Strided1DWritableBufferback to summary
public Strided1DWritableBuffer(int flags, BufferProtocol obj, byte[] storage, int index0, int count, int stride) throws ArrayIndexOutOfBoundsException, NullPointerException, PyException

Provide an instance of Strided1DWritableBuffer on a particular array of bytes specifying a starting index, the number of items in the result, and a byte-indexing stride. The result of byteAt(i) will be equal to storage[index0+stride*i] (whatever the sign of stride), valid for 0≤i<count.

The constructed PyBuffer meets the consumer's expectations as expressed in the flags argument, or an exception will be thrown if these are incompatible with the type (e.g. the consumer does not specify that it understands the strides array). Note that the actual range in the storage array, the lowest and highest index, is not explicitly passed, but is implicit in index0, count and stride. The caller is responsible for checking these fall within the array, or the sub-range the caller is allowed to use.

Parameters
flags:int

consumer requirements

obj:BufferProtocol

exporting object (or null)

storage:byte[]

raw byte array containing exported data

index0:int

index into storage of item[0]

count:int

number of items in the slice

stride:int

byte-index distance from one element to the next in the new PyBuffer

Exceptions
ArrayIndexOutOfBoundsException:
if index0, count and stride are inconsistent with storage.length
NullPointerException:
if storage is null
PyException:
BufferError when expectations do not correspond with the type

Method Detail

checkWritableback to summary
protected final void checkWritable()

Overrides org.python.core.buffer.BaseBuffer.checkWritable.

Do nothing: the buffer is writable.

Annotations
@Override
getBufferSliceback to summary
public PyBuffer getBufferSlice(int flags, int start, int count, int stride)

Overrides org.python.core.buffer.Strided1DBuffer.getBufferSlice.

Implements org.python.core.PyBuffer.getBufferSlice.

Doc from org.python.core.buffer.Strided1DBuffer.getBufferSlice.

Get a PyBuffer that represents a slice of the current one described in terms of a start index, number of items to include in the slice, and the stride in the current buffer. A consumer that obtains a PyBuffer with getBufferSlice must release it with PyBuffer#release just as if it had been obtained with PyBuffer#getBuffer(int)

Suppose that x(i) denotes the ith element of the current buffer, that is, the byte retrieved by this.byteAt(i) or the unit indicated by this.getPointer(i). A request for a slice where start = s, count = N and stride = m, results in a buffer y such that y(k) = x(s+km) where k=0..(N-1). In Python terms, this is the slice x[s : s+(N-1)m+1 : m] (if m>0) or the slice x[s : s+(N-1)m-1 : m] (if m<0). Implementations should check that this range is entirely within the current buffer.

In a simple buffer backed by a contiguous byte array, the result is a strided PyBuffer on the same storage but where the offset is adjusted by s and the stride is as supplied. If the current buffer is already strided and/or has an item size larger than single bytes, the new start index, count and stride will be translated from the arguments given, through this buffer's stride and item size. The caller always expresses start and strides in terms of the abstract view of this buffer.

Strided1DBuffer provides an implementation for slicing already-strided bytes in one dimension. In that case, x(i) = u(r+ip) for i = 0..L-1 where u is the underlying buffer, and r, p and L are the start, stride and count with which x was created from u. Thus y(k) = u(r+sp+kmp), that is, the composite index0 is r+sp and the composite stride is mp.

Strided1DWritableBuffer provides an implementation that returns a writable slice.

Parameters
flags:int

Doc from org.python.core.PyBuffer.getBufferSlice.

specifying features demanded and the navigational capabilities of the consumer

start:int

Doc from org.python.core.PyBuffer.getBufferSlice.

index in the current buffer

count:int

Doc from org.python.core.PyBuffer.getBufferSlice.

number of items in the required slice

stride:int

Doc from org.python.core.PyBuffer.getBufferSlice.

index-distance in the current buffer between consecutive items in the slice

Returns:PyBuffer

Doc from org.python.core.PyBuffer.getBufferSlice.

a buffer representing the slice

Annotations
@Override

isReadonlyback to summary
public final boolean isReadonly()

Overrides org.python.core.buffer.Strided1DBuffer.isReadonly.

Implements org.python.core.PyBUF.isReadonly.

Doc from org.python.core.PyBUF.isReadonly.

Determine whether the consumer is entitled to write to the exported storage.

Declared final returning true in Strided1DWritableBuffer to make checks unnecessary.

Returns:boolean

true if writing is not allowed, false if it is.

Annotations
@Override

storeAtImplback to summary
protected void storeAtImpl(byte value, int byteIndex)

Overrides org.python.core.buffer.BaseArrayBuffer.storeAtImpl.

Doc from org.python.core.buffer.BaseBuffer.storeAtImpl.

Store the byte at the given index in the underlying storage treated as a flat sequence of bytes. This byte-index will have been computed from the item index (which may have been multi-dimensional), taking into account index0, shape, strides, and the item size. The caller is responsible for validating the original item-index and raising (typically) an IndexOutOfBoundsException. Misuse of this method may still result in unchecked exceptions characteristic of the storage implementation. This method must implement the check for read-only character, raising a BufferError in the case of a violation.

Parameters
value:byte

to store

byteIndex:int

byte-index of location to retrieve

Annotations
@Override
org.python.core.buffer back to summary

pack-priv Class Strided1DWritableBuffer.SlicedView

extends Strided1DWritableBuffer
Class Inheritance

A Strided1DWritableBuffer.SlicedView represents a non-contiguous subsequence of a simple buffer.

Field Summary

Modifier and TypeField and Description
pack-priv PyBuffer
root

The buffer on which this is a slice view

Constructor Summary

AccessConstructor and Description
public
SlicedView(PyBuffer
on which release must be called when this is released
root
,
int
consumer requirements
flags
,
byte[]
raw byte array containing exported data
storage
,
int
index into storage of item[0]
index0
,
int
number of items in the sliced view
count
,
int
in between successive elements of the new PyBuffer
stride
)

Construct a slice of a one-dimensional byte buffer.

Method Summary

Modifier and TypeMethod and Description
protected PyBuffer
getRoot()

Overrides org.python.core.buffer.BaseBuffer.getRoot.

Some PyBuffers, those created by slicing a PyBuffer, are related to a root PyBuffer.

Inherited from org.python.core.buffer.Strided1DWritableBuffer:
checkWritablegetBufferSliceisReadonlystoreAtImpl

Field Detail

rootback to summary
pack-priv PyBuffer root

The buffer on which this is a slice view

Constructor Detail

SlicedViewback to summary
public SlicedView(PyBuffer root, int flags, byte[] storage, int index0, int count, int stride) throws PyException

Construct a slice of a one-dimensional byte buffer.

Parameters
root:PyBuffer

on which release must be called when this is released

flags:int

consumer requirements

storage:byte[]

raw byte array containing exported data

index0:int

index into storage of item[0]

count:int

number of items in the sliced view

stride:int

in between successive elements of the new PyBuffer

Exceptions
PyException:
BufferError when expectations do not correspond with the type

Method Detail

getRootback to summary
protected PyBuffer getRoot()

Overrides org.python.core.buffer.BaseBuffer.getRoot.

Doc from org.python.core.buffer.BaseBuffer.getRoot.

Some PyBuffers, those created by slicing a PyBuffer, are related to a root PyBuffer. During creation of such a slice, we need to supply a value for this root. If the present object is not itself a slice, this root is the object itself; if the buffer is already a slice, it is the root it was given at creation time. Often this is the only difference between a slice-view and a directly-exported buffer. Override this method in slices to return the root buffer of the slice.

Returns:PyBuffer

this buffer (or the root buffer if this is a sliced view)

Annotations
@Override