|
| | ~BufferState () |
| | Deletes the owned buffer and closes the owned file handle, if present.
|
| |
| | BufferState ()=default |
| |
| | BufferState (T *buffer, size_t capacity) |
| | Takes ownership of an existing heap buffer with the given capacity.
|
| |
| | BufferState (const BufferState &other) |
| | Creates an independent owning copy. File handles are not copied.
|
| |
| | BufferState (const BufferState &other, BufferViewTag) |
| | Creates a non-owning view of other's allocation.
|
| |
| BufferState & | operator= (const BufferState &other) |
| |
| | BufferState (BufferState &&other) noexcept |
| | Moves the file handle, buffer, position, capacity, and tape counter.
|
| |
| BufferState & | operator= (BufferState &&other) noexcept |
| | Releases current resources, then moves all resources from other.
|
| |
| bool | isOwner () const |
| | Returns whether this object owns and will delete its buffer allocation.
|
| |
| void | allocateAndOwn () |
| | Replaces a view with an uninitialized owned allocation.
|
| |
| void | resetFile (FILE *file) |
| | Takes ownership of file, closing any previously owned file handle.
|
| |
| FILE * | file () |
| | Returns the owned FILE handle without transferring ownership.
|
| |
| FILE * | file () const |
| |
| void | closeFile () |
| | Closes the owned FILE handle, if present.
|
| |
| FILE * | releaseFile () |
| | Releases the FILE handle without closing it.
|
| |
| void | openFile (const char *fileName, const char *mode) |
| | Opens fileName with mode and owns the resulting FILE handle.
|
| |
| void | resetBuffer (T *buffer, size_t capacity) |
| | Replaces the buffer pointer.
|
| |
| T * | begin () |
| | Returns the beginning of the owned or viewed buffer.
|
| |
| const T * | begin () const |
| |
| T * | releaseBuffer () |
| | Releases the owned buffer without deleting it.
|
| |
| void | allocIfNull (size_t capacity) |
| | Allocates a new owned buffer if no buffer is currently present.
|
| |
| size_t | position () const |
| | Returns the current buffer index.
|
| |
| void | position (size_t pos) |
| | Sets the current buffer index.
|
| |
| size_t | remainingCapacity () const |
| | Returns how many elements fit between position() and capacity().
|
| |
| size_t | capacity () const |
| | Returns the capacity of the owned or viewed buffer.
|
| |
| size_t | numOnTape () const |
| | Returns the number of elements recorded on the tape.
|
| |
| void | numOnTape (size_t num) |
| | Sets the number of elements recorded on the tape.
|
| |
| const T & | operator[] (size_t idx) const |
| | Returns a copy of the element at idx.
|
| |
| T & | operator[] (size_t idx) |
| | Returns a mutable reference to the element at idx.
|
| |
| void | writeCurrent (T val) |
| | Stores val at position().
|
| |
| void | writeAndAdvance (T val) |
| | Stores val at position(), then advances to the next element.
|
| |
| T * | current () |
| | Returns a pointer to the element at position().
|
| |
| const T * | current () const |
| |
| void | advance () |
| | Advances the current position by one element.
|
| |
| void | retreat () |
| | Moves the current position back by one element.
|
| |
| T | readAndAdvance () |
| | Returns the current element, then advances position().
|
| |
| T | retreatAndRead () |
| | Moves to the previous element, then returns it.
|
| |
template<typename T>
class ADOLC::detail::BufferState< T >
Buffer and cursor state used by the ADOL-C tape implementation.
BufferState groups the state that is common to the operation, value, location, and Taylor tapes:
- a FILE handle for disk-backed tape blocks,
- an owned heap buffer or a non-owning view of another BufferState,
- the current position inside that buffer,
- the buffer capacity,
- the number of elements currently recorded on the complete tape.
The buffer behaves like a small pointer abstraction. position() is the index of the current element. Writing usually stores into current() and then advances the buffer; reading in reverse usually retreats first and then consumes the returned element.
A regular copy creates an independent, owning buffer. Constructing with bufferView creates a non-owning view that shares the source's allocation but has independent cursor and tape-count state. allocateAndOwn() replaces a view with a new, uninitialized owned allocation when a tape block must be loaded without modifying the viewed buffer.
A view is deliberately lightweight and does not track its source. In particular, BufferState does not invalidate existing views when the owner is reset, moved, released, reallocated, or destroyed. The caller must guarantee that the owner and its allocation outlive every view. Tape evaluations provide this guarantee through the tape's data-access lock.
Resource ownership:
- owned buffers are deleted by the destructor,
- viewed buffers are never deleted by the view,
- FILE handles are closed by the unique_ptr deleter,
- file handles are never shared when a buffer view is created,
- releaseBuffer() is valid only for an owning BufferState,
- releaseBuffer() and releaseFile() transfer ownership to the caller.
- Template Parameters
-
| T | Element type stored by this tape buffer. |