Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
databuf< T > Struct Template Reference

Public Types

enum  { OVERREAD = 1<<0 , OVERWROTE = 1<<1 }
 

Public Member Functions

template<class U >
 databuf (T *buf, U maxlen)
 
void reset ()
 
void reset (T *buf_, int maxlen_)
 
const T & get ()
 Adds an existing value in the underlying buffer to the databuf.
 
databuf subbuf (int sz)
 Returns a databuf<T> object containing the first n entries.
 
T * pad (int numvals)
 Adds N empty elements to the end of the array and returns a pointer.
 
void put (const T &val)
 Adds an entry to the databuf if space is available.
 
void put (const T *vals, int numvals)
 
int get (T *vals, int numvals)
 
void offset (int n)
 
T * getbuf () const
 Returns a pointer to the internal data array.
 
bool empty () const
 Returns whether any entries have been assigned to the array.
 
int length () const
 Returns the number of allocated entries in the databuf.
 
int remaining () const
 Returns the number of values remaining before the databuf overflows.
 
bool overread () const
 Returns whether the databuf has been accessed with too large of an index.
 
bool overwrote () const
 Returns whether the databuf has had invalid writes to it.
 
bool check (int n)
 
void forceoverread ()
 

Public Attributes

T * buf
 
int len
 
int maxlen
 
uchar flags
 

Member Function Documentation

◆ empty()

template<class T >
bool databuf< T >::empty ( ) const
inline

Returns whether any entries have been assigned to the array.

Returns
true if the array has not been assigned to
false if the array has assigned values

◆ get()

template<class T >
const T & databuf< T >::get ( )
inline

Adds an existing value in the underlying buffer to the databuf.

Increases the length of the databuf by one and incorporates the value at the address after the end of the databuf's values.

If the length is equal to or greater than the buffer's maximum length, applies the OVERREAD flag and returns a null value.

◆ getbuf()

template<class T >
T * databuf< T >::getbuf ( ) const
inline

Returns a pointer to the internal data array.

This is a naked pointer to the internal data array and can therefore be used to potentially break this container, if used carelessly.

Returns
A pointer the data array

◆ length()

template<class T >
int databuf< T >::length ( ) const
inline

Returns the number of allocated entries in the databuf.

Returns the number of entries which have been added to the databuf (not the overall databuf size).

Returns
the number of entries allocated in the databuf.

◆ overread()

template<class T >
bool databuf< T >::overread ( ) const
inline

Returns whether the databuf has been accessed with too large of an index.

Returns whether the OVERREAD flag has been set. If the databuf was attempted to be accessed with an index larger than the number of allocated members, this value will be set.

Returns
true if the array has been overread
false if all read operations have been to valid entries

◆ overwrote()

template<class T >
bool databuf< T >::overwrote ( ) const
inline

Returns whether the databuf has had invalid writes to it.

Returns whether the OVERWROTE flag has been set. If the databuf was attempted to be wrote to while the databuf is already full, this flag will be set.

Returns
true if the databuf has not been overwritten
false if the databuf has had only valid writes

◆ pad()

template<class T >
T * databuf< T >::pad ( int numvals)
inline

Adds N empty elements to the end of the array and returns a pointer.

Creates an array of size sz which is then pointed to and returned as a naked pointer.

Parameters
szthe size of the buffer
Returns
a pointer to the sub-array created

◆ put()

template<class T >
void databuf< T >::put ( const T & val)
inline

Adds an entry to the databuf if space is available.

If no space is available, applies the OVERWROTE flag to the flags field.

Parameters
valA const reference to the object to add

◆ remaining()

template<class T >
int databuf< T >::remaining ( ) const
inline

Returns the number of values remaining before the databuf overflows.

Returns the allocatable space remaining within the databuf object, in terms of the number of entires which can be put into it before it becomes OVERWROTE.

Returns
the number of available entries in the databuf.

◆ subbuf()

template<class T >
databuf databuf< T >::subbuf ( int sz)
inline

Returns a databuf<T> object containing the first n entries.

Returns a databuf object of type T which represents the first n elements inside the databuf's array.

If the size passed is larger than the databuf, the entire databuf object is copied and returned.

Parameters
szthe size of the output array (aka get the first sz entries)
Returns
the sub-buffer of this object

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