ADOL-C: Automatic Differentiation in C/C++ 2.7.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ADOLC::detail::BufferState< T > Class Template Reference

Buffer and cursor state used by the ADOL-C tape implementation. More...

#include <bufferstate.h>

Public Member Functions

 ~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.
 

Detailed Description

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:

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:

Template Parameters
TElement type stored by this tape buffer.

Constructor & Destructor Documentation

◆ ~BufferState()

template<typename T >
ADOLC::detail::BufferState< T >::~BufferState ( )
inline

Deletes the owned buffer and closes the owned file handle, if present.

◆ BufferState() [1/5]

template<typename T >
ADOLC::detail::BufferState< T >::BufferState ( )
default

◆ BufferState() [2/5]

template<typename T >
ADOLC::detail::BufferState< T >::BufferState ( T *  buffer,
size_t  capacity 
)
inline

Takes ownership of an existing heap buffer with the given capacity.

◆ BufferState() [3/5]

template<typename T >
ADOLC::detail::BufferState< T >::BufferState ( const BufferState< T > &  other)
inline

Creates an independent owning copy. File handles are not copied.

◆ BufferState() [4/5]

template<typename T >
ADOLC::detail::BufferState< T >::BufferState ( const BufferState< T > &  other,
BufferViewTag   
)
inline

Creates a non-owning view of other's allocation.

The cursor and tape counter are copied by value, while the buffer pointer is shared. The view does not observe later cursor changes and does not keep the source alive. The file handle is not shared.

◆ BufferState() [5/5]

template<typename T >
ADOLC::detail::BufferState< T >::BufferState ( BufferState< T > &&  other)
inlinenoexcept

Moves the file handle, buffer, position, capacity, and tape counter.

Member Function Documentation

◆ advance()

template<typename T >
void ADOLC::detail::BufferState< T >::advance ( )
inline

Advances the current position by one element.

◆ allocateAndOwn()

template<typename T >
void ADOLC::detail::BufferState< T >::allocateAndOwn ( )
inline

Replaces a view with an uninitialized owned allocation.

Existing elements are intentionally not copied. This operation is used immediately before loading a different tape block into the buffer.

◆ allocIfNull()

template<typename T >
void ADOLC::detail::BufferState< T >::allocIfNull ( size_t  capacity)
inline

Allocates a new owned buffer if no buffer is currently present.

◆ begin() [1/2]

template<typename T >
T * ADOLC::detail::BufferState< T >::begin ( )
inline

Returns the beginning of the owned or viewed buffer.

◆ begin() [2/2]

template<typename T >
const T * ADOLC::detail::BufferState< T >::begin ( ) const
inline

◆ capacity()

template<typename T >
size_t ADOLC::detail::BufferState< T >::capacity ( ) const
inline

Returns the capacity of the owned or viewed buffer.

◆ closeFile()

template<typename T >
void ADOLC::detail::BufferState< T >::closeFile ( )
inline

Closes the owned FILE handle, if present.

◆ current() [1/2]

template<typename T >
T * ADOLC::detail::BufferState< T >::current ( )
inline

Returns a pointer to the element at position().

◆ current() [2/2]

template<typename T >
const T * ADOLC::detail::BufferState< T >::current ( ) const
inline

◆ file() [1/2]

template<typename T >
FILE * ADOLC::detail::BufferState< T >::file ( )
inline

Returns the owned FILE handle without transferring ownership.

◆ file() [2/2]

template<typename T >
FILE * ADOLC::detail::BufferState< T >::file ( ) const
inline

◆ isOwner()

template<typename T >
bool ADOLC::detail::BufferState< T >::isOwner ( ) const
inline

Returns whether this object owns and will delete its buffer allocation.

◆ numOnTape() [1/2]

template<typename T >
size_t ADOLC::detail::BufferState< T >::numOnTape ( ) const
inline

Returns the number of elements recorded on the tape.

◆ numOnTape() [2/2]

template<typename T >
void ADOLC::detail::BufferState< T >::numOnTape ( size_t  num)
inline

Sets the number of elements recorded on the tape.

◆ openFile()

template<typename T >
void ADOLC::detail::BufferState< T >::openFile ( const char *  fileName,
const char *  mode 
)
inline

Opens fileName with mode and owns the resulting FILE handle.

◆ operator=() [1/2]

template<typename T >
BufferState & ADOLC::detail::BufferState< T >::operator= ( BufferState< T > &&  other)
inlinenoexcept

Releases current resources, then moves all resources from other.

◆ operator=() [2/2]

template<typename T >
BufferState & ADOLC::detail::BufferState< T >::operator= ( const BufferState< T > &  other)
inline

◆ operator[]() [1/2]

template<typename T >
T & ADOLC::detail::BufferState< T >::operator[] ( size_t  idx)
inline

Returns a mutable reference to the element at idx.

◆ operator[]() [2/2]

template<typename T >
const T & ADOLC::detail::BufferState< T >::operator[] ( size_t  idx) const
inline

Returns a copy of the element at idx.

◆ position() [1/2]

template<typename T >
size_t ADOLC::detail::BufferState< T >::position ( ) const
inline

Returns the current buffer index.

◆ position() [2/2]

template<typename T >
void ADOLC::detail::BufferState< T >::position ( size_t  pos)
inline

Sets the current buffer index.

◆ readAndAdvance()

template<typename T >
T ADOLC::detail::BufferState< T >::readAndAdvance ( )
inline

Returns the current element, then advances position().

◆ releaseBuffer()

template<typename T >
T * ADOLC::detail::BufferState< T >::releaseBuffer ( )
inline

Releases the owned buffer without deleting it.

The capacity and current position are reset because the wrapper no longer has a valid in-memory buffer. numOnTape() is left unchanged.

◆ releaseFile()

template<typename T >
FILE * ADOLC::detail::BufferState< T >::releaseFile ( )
inline

Releases the FILE handle without closing it.

◆ remainingCapacity()

template<typename T >
size_t ADOLC::detail::BufferState< T >::remainingCapacity ( ) const
inline

Returns how many elements fit between position() and capacity().

◆ resetBuffer()

template<typename T >
void ADOLC::detail::BufferState< T >::resetBuffer ( T *  buffer,
size_t  capacity 
)
inline

Replaces the buffer pointer.

The new pointer is treated as owned by BufferState.

◆ resetFile()

template<typename T >
void ADOLC::detail::BufferState< T >::resetFile ( FILE *  file)
inline

Takes ownership of file, closing any previously owned file handle.

◆ retreat()

template<typename T >
void ADOLC::detail::BufferState< T >::retreat ( )
inline

Moves the current position back by one element.

◆ retreatAndRead()

template<typename T >
T ADOLC::detail::BufferState< T >::retreatAndRead ( )
inline

Moves to the previous element, then returns it.

◆ writeAndAdvance()

template<typename T >
void ADOLC::detail::BufferState< T >::writeAndAdvance ( T  val)
inline

Stores val at position(), then advances to the next element.

◆ writeCurrent()

template<typename T >
void ADOLC::detail::BufferState< T >::writeCurrent ( T  val)
inline

Stores val at position().


The documentation for this class was generated from the following file: