nis-util  1.0.D108
Public Member Functions | Private Member Functions | Private Attributes
rcstring_accumulator Class Reference

#include <accumulator.h>

Public Member Functions

 ~rcstring_accumulator ()
 rcstring_accumulator ()
 rcstring_accumulator (const rcstring_accumulator &rhs)
rcstring_accumulatoroperator= (const rcstring_accumulator &rhs)
void push_back (char c)
void push_back (unsigned char c)
void push_back (const char *text)
void push_back (const char *text, size_t text_size)
void push_back (const rcstring &text)
void pop_back (void)
unsigned char back (void) const
void push_front (unsigned char c)
void pop_front (void)
void pop_front (size_t nbytes)
unsigned char front (void) const
rcstring mkstr (void) const
void clear (void)
size_t size (void) const
bool empty (void) const
const char * get_data (void) const

Private Member Functions

void grow (size_t nbytes)

Private Attributes

char * data
size_t data_size
size_t data_alloc

Detailed Description

The rcstring_accumulator class is used to represent an efficient buffer for accumulating strings.

Definition at line 28 of file accumulator.h.


Constructor & Destructor Documentation

The destructor. It is not virtual, thou shalt not derive from this class.

Definition at line 22 of file accumulator.cc.

The default constructor.

Definition at line 22 of file default_constructor.cc.

The copy constructor.

Parameters:
rhsThe right hand side of the initialization.

Definition at line 24 of file copy_constructor.cc.


Member Function Documentation

unsigned char rcstring_accumulator::back ( void  ) const

The back method is used to obtain the last byte of the data, or NUL if the accumulator is empty.

Definition at line 23 of file back.cc.

void rcstring_accumulator::clear ( void  ) [inline]

The clear method is used to discard the contents of the accumulator.

The allocated data of the accumulator is not discarded, so re-using an accumulator is more time-efficient than repeatedly instantiating accumulator instances.

Definition at line 167 of file accumulator.h.

bool rcstring_accumulator::empty ( void  ) const [inline]

The empty method is used to determine whether or not the accumulator is empty.

Definition at line 179 of file accumulator.h.

unsigned char rcstring_accumulator::front ( void  ) const

The front method is used to obtain the first byte in the data, or NUL if the accumulator is empty.

Definition at line 23 of file front.cc.

const char* rcstring_accumulator::get_data ( void  ) const [inline]

The get_data method is used to obtain the pointer to the base of the data array.

Definition at line 185 of file accumulator.h.

void rcstring_accumulator::grow ( size_t  nbytes) [private]

The grow method is used to increase the allocation size of data until it is at least as big as requested.

The algorithm used to determine the actualy buffer size increase is O(1) averaged over the lifetime of the accumulator.

Parameters:
nbytesHow large the data needs to be, at least.

Definition at line 25 of file grow.cc.

The mkstr method is used to make a string from the current contents of the buffer. The size is analtered.

Definition at line 23 of file mkstr.cc.

rcstring_accumulator & rcstring_accumulator::operator= ( const rcstring_accumulator rhs)

The assignment operator.

Parameters:
rhsThe right hand side of the assignment.

Definition at line 25 of file assignment_operator.cc.

The pop_back method is used to discard a single byte from the end of the data. It is safe to do this to an empty accumulator.

Definition at line 23 of file pop_back.cc.

The pop_front method is used to discard a single byte from the start of the data. This is expensive, use sparingly. It is safe to call this on an empty accumulator.

Definition at line 25 of file pop_front.cc.

void rcstring_accumulator::pop_front ( size_t  nbytes)

The pop_front method is used to discard a number of bytes from the start of the data. This is expensive, use sparingly.

It is safe to request that more bytes be removed from the accumulator than the accumulator contains, the result will be an empty accumulator.

Parameters:
nbytesThe number of bytes to discard.

Definition at line 25 of file pop_front_n.cc.

The push_back method is used to append a single byte to the end of the accumulated text, in data.

Parameters:
cThe byte value to be appended.

Definition at line 23 of file push_back_5.cc.

void rcstring_accumulator::push_back ( unsigned char  c)

The push_back method is used to append a single byte to the end of the accumulated text, in data.

Parameters:
cThe byte value to be appended.

Definition at line 23 of file push_back_4.cc.

void rcstring_accumulator::push_back ( const char *  text)

The push_back method is used to append a C string to the end of the accumulated text, in data.

Parameters:
textThe bytes to be appended, NUL terminated.

Definition at line 25 of file push_back_2.cc.

void rcstring_accumulator::push_back ( const char *  text,
size_t  text_size 
)

The push_back method is used to append a C string to the end of the accumulated text, in data.

Parameters:
textThe bytes to be appended.
text_sizeThe number of bytes to be appended.

Definition at line 25 of file push_back_3.cc.

void rcstring_accumulator::push_back ( const rcstring text)

The push_back method is used to append a C string to the end of the accumulated text, in data.

Parameters:
textThe bytes to be appended.

Definition at line 23 of file push_back_1.cc.

void rcstring_accumulator::push_front ( unsigned char  c)

The push_front method is used to insert a byte at the start of the accumulator. This is expensive, use sparingly.

Parameters:
cThe byte to be inserted.

Definition at line 25 of file push_front.cc.

size_t rcstring_accumulator::size ( void  ) const [inline]

The size method is used to obtain the current size of the accumulator, in bytes.

Definition at line 173 of file accumulator.h.


Field Documentation

char* rcstring_accumulator::data [private]

The data instance variable is used to remember the base address of a dynamically allocated array of bytes, used to hold the accumulated text.

assert(!data == !data_alloc);

Definition at line 195 of file accumulator.h.

The data_alloc instance variable is used to remember how many bytes have been allocated for the data array.

assert(!data == !data_alloc);

Definition at line 212 of file accumulator.h.

The data_size instance variable is used to remember how many bytes of the data array have been used.

assert(!data == !data_size); assert(data_size <= data_alloc);

Definition at line 204 of file accumulator.h.


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