43 #ifndef __EST_TBUFFER_H__
44 #define __EST_TBUFFER_H__
49 #define TBUFFER_N_OLD (10)
52 #define TBUFFER_DEFAULT_SIZE 0
55 #define TBUFFER_DEFAULT_STEP 100
98 void init(
unsigned int size,
int step);
100 void expand_to(
unsigned int req_size,
bool cpy);
102 void expand_to(
unsigned int req_size,
const T &set_to,
int howmany);
119 unsigned int length(
void)
const {
return p_size;}
122 void set(
const T &set_to,
int howmany=-1);
129 {
if (req_size > p_size) expand_to(req_size, (
bool)TRUE);}
132 void ensure(
unsigned int req_size,
bool copy)
133 {
if (req_size > p_size) expand_to(req_size, copy,-1);}
136 void ensure(
unsigned int req_size,
const T &set_to,
int howmany=-1)
137 {
if (req_size > p_size) expand_to(req_size, set_to, howmany);}
144 T *
b(
void) {
return p_buffer;}
146 const T *
b(
void)
const {
return p_buffer;}
149 const T &
operator() (
unsigned int i)
const {
return p_buffer[i];}
151 T &operator[] (
unsigned int i) {
return p_buffer[i];}
152 const T &operator[] (
unsigned int i)
const {
return p_buffer[i];}
unsigned int length(void) const
Current available space.
void ensure(unsigned int req_size)
Extend if needed, copying existing data.
#define TBUFFER_DEFAULT_STEP
Amount to increment buffer size by.
T * b(void)
Simple access as a pointer.
const T & operator()(unsigned int i) const
operator () is simple access
#define TBUFFER_N_OLD
How many chunks of memory to keep around for re-use.
void ensure(unsigned int req_size, const T &set_to, int howmany=-1)
Make sure there is enough space, setting to a known value.
void set(const T &set_to, int howmany=-1)
Set to the given value. By default sets all values.
struct old_tbuffer EST_old_buffers[TBUFFER_N_OLD]
Memory of old buffers.
EST_TBuffer(unsigned int size=TBUFFER_DEFAULT_SIZE, int step=TBUFFER_DEFAULT_STEP)
const T * b(void) const
Read-only access when the EST_TBuffer is a constant.
~EST_TBuffer(void)
Destructor. Places the memory in EST_old_buffers[] for re-use if there is room.
#define TBUFFER_DEFAULT_SIZE
Initial size for buffers created with no size specified.
void ensure(unsigned int req_size, bool copy)
Make sure there is enough space, copying if requested.