Chapter 4. Basic Classes

Classes

Container Classes

Hash Tables

class EST_HashFunctions{}

class EST_HashFunctions

This is just a convinient place to put some useful hash functions

DefaultHash()
static unsigned int DefaultHash(const void *data, size_t size, unsigned int n)

A generally useful hash function.

StringHash()
static unsigned int StringHash(const EST_String &key, unsigned int size)

A hash function for strings.

class EST_Hash_Pair{}

template <class K, class V> class EST_Hash_Pair

This class is used in hash tables to hold a key value pair. Not much to say beyond that.

k;
K k

The key

v;
V v

The value

class EST_THash{}

template <class K, class V> class EST_THash(: protected EST_HashFunctions

An open hash table. The number of buckets should be set to allow enough space that there are relatively few entries per bucket on average.

EST_THash()
EST_THash(int size, unsigned int (*hash_function)(const K &key, unsigned int size)= NULL)

Create a table with the given number of buckets. Optionally setting a custom hash function.

EST_THash()
EST_THash(const EST_THash<K, V> &from)

Create a copy

~EST_THash()
~EST_THash(void)

Destroy the table.

clear()
void clear(void)

Empty the table.

num_entries()
unsigned int num_entries(void) const

Return the total number of entries in the table.

present()
int present(const K &key) const

Does the key have an entry?

val()
V& val(const K &key, int &found) const

Return the value associated with the key. found is set to whether such an entry was found.

val()
V& val(const K &key) const

Return the value associated with the key.

copy()
void copy(const EST_THash<K, V> &from)

Copy all entries

map()
void map(void (*func)(K&, V&))

Apply func to each entry in the table.

add_item()
int add_item(const K &key, const V &value, int no_search = 0)

Add an entry to the table.

remove_item()
int remove_item(const K &rkey, int quiet = 0)

Remove an entry from the table.

operator = ()
EST_THash <K,V> & operator = (const EST_THash<K, V> &from)

Assignment is a copy operation

dump()
void dump(ostream &stream, int all=0)

Print the table to stream in a human readable format.

Pair Iteration

This iterator steps through the table returning key-value pairs.

union IPointer_s{}

struct IPointer_s

A position in the table is given by a bucket number and a pointer into the bucket

skip_blank()
void skip_blank(IPointer &ip) const

Shift to point at something.

point_to_first()
void point_to_first(IPointer &ip) const

Go to start of the table.

move_pointer_forwards()
void move_pointer_forwards(IPointer &ip) const

Move pointer forwards, at the end of the bucket, move down.

points_to_something()
bool points_to_something(const IPointer &ip) const

We are at the end if the pointer ever becomes NULL

points_at()
EST_Hash_Pair <K, V> & points_at(const IPointer &ip)

Return the contents of this entry.

V;
friend class EST_TStructIterator EST_THash K V IPointer EST_Hash_Pair KV

The iterator must be a friend to access this private interface.

Entry;
typedef EST_Hash_Pair <K, V> Entry

An entry returned by the iterator is a key value pair.

Entries;
typedef EST_TStructIterator < EST_THash<K, V>, IPointer, EST_Hash_Pair<K, V> > Entries

Give the iterator a sensible name.

Key Iteration

This iterator steps through the table returning just keys.

union IPointer_k_s{}

struct IPointer_k_s

A position in the table is given by a bucket number and a pointer into the bucket

skip_blank()
void skip_blank(IPointer_k &ip) const

Shift to point at something.

point_to_first()
void point_to_first(IPointer_k &ip) const

Go to start of the table.

move_pointer_forwards()
void move_pointer_forwards(IPointer_k &ip) const

Move pointer forwards, at the end of the bucket, move down.

points_to_something()
bool points_to_something(const IPointer_k &ip) const

We are at the end if the pointer ever becomes NULL

points_at()
K& points_at(const IPointer_k &ip)

Return the key of this entry.

K;
friend class EST_TIterator EST_THash K V IPointer_kK

The iterator must be a friend to access this private interface.

KeyEntry;
typedef K KeyEntry

An entry returned by this iterator is just a key.

KeyEntries;
typedef EST_TIterator < EST_THash<K, V>, IPointer_k, K > KeyEntries

Give the iterator a sensible name.

class EST_TStringHash{}

template <class V> class EST_TStringHash(: public EST_THash<EST_String, V>

A specialised hash table for when the key is an EST_String.

This is just a version of EST_THash which has a different default hash function.

EST_TStringHash()
EST_TStringHash(int size)

Create a string hash table of size buckets.

Entry;
typedef EST_Hash_Pair <EST_String, V> Entry

An entry returned by the iterator is a key value pair.

Entries;
typedef EST_TStructIterator < EST_THash<EST_String, V>, IPointer, EST_Hash_Pair<EST_String, V> > Entries

Give the iterator a sensible name.

class EST_IMatrix{}

class EST_IMatrix(: public EST_TSimpleMatrix<int>

A matrix class for integers. {\tt EST_IMatrix x} should be used instead of {\tt int **x} wherever possible.

EST_IMatrix()

EST_IMatrix(int m, int n)

size constructor

EST_IMatrix()

EST_IMatrix(EST_IMatrix &a)

copy constructor

EST_IMatrix()

EST_IMatrix(EST_IMatrix &a, int b)

CHECK - what does this do???

EST_IMatrix()

EST_IMatrix()

default constructor

class EST_TMatrix{}

(R,C) template <class T> class EST_TMatrix(: public EST_TVector<T>

Template Matrix class.

This is an extension of the EST_TVector class to two dimensions.

EST_TMatrix()

EST_TMatrix()

default constructor

EST_TMatrix()

EST_TMatrix(const EST_TMatrix<T> &m)

copy constructor

EST_TMatrix()

EST_TMatrix(int rows, int cols)

"size" constructor

EST_TMatrix()

EST_TMatrix(int rows, int cols, T *memory, int offset=0, int free_when_destroyed=0)

construct from memory supplied by caller

~EST_TMatrix()

~EST_TMatrix()

EST_TMatrix

access

Basic access methods for matrices.

num_rows()
int num_rows() const

return number of rows

num_columns()
int num_columns() const

return number of columns

a_no_check()
INLINE const T& a_no_check(int row, int col) const

const access with no bounds check, care recommend

a_no_check()
INLINE T& a_no_check(int row, int col)

access with no bounds check, care recommend

a_check()
const T& a_check(int row, int col) const

const element access function

a_check()
T& a_check(int row, int col)

non-const element access function

operator()
const T& operator operator(int row, int col) const

const element access operator

operator()
T& operator operator(int row, int col)

non-const element access operator

resize()

void resize(int rows, int cols, int set=1)

resize matrix. If {\tt set=1}, then the current values in the matirx are preserved up to the new size {\tt n}. If the new size exceeds the old size, the rest of the matrix is filled with the {\tt def_val}

fill()

void fill(const T &v)

fill matrix with value v

operator=()

EST_TMatrix& operator=(const EST_TMatrix &s)

assignment operator

add_rows()

EST_TMatrix& add_rows(const EST_TMatrix &s)

The two versions of what might have been operator +=

Sub-Matrix/Vector Extraction

All of these return matrecies and vectors which share memory with the original, so altering values them alters the original.

row()
void row(EST_TVector<T> &rv, int r, int start_c=0, int len=-1)

Make the vector {\tt rv} a window onto row {\tt r}

column()
void column(EST_TVector<T> &cv, int c, int start_r=0, int len=-1)

Make the vector {\tt cv} a window onto column {\tt c}

sub_matrix()
void sub_matrix(EST_TMatrix<T> &sm, int r=0, int numr=EST_ALL, int c=0, int numc=EST_ALL)

Make the matrix {\tt sm} a window into this matrix.

Copy in and out

Copy data between buffers and the matrix.

copy_row()
void copy_row(int r, T *buf, int offset=0, int num=-1) const

Copy row {\tt r} of matrix to {\tt buf}. {\tt buf} should be pre-malloced to the correct size.

copy_column()
void copy_column(int c, T *buf, int offset=0, int num=-1) const

Copy column {\tt c} of matrix to {\tt buf}. {\tt buf} should be pre-malloced to the correct size.

set_row()
void set_row(int n, const T *buf, int offset=0, int num=-1)

Copy buf into row {\tt n} of matrix

set_column()
void set_column(int n, const T *buf, int offset=0, int num=-1)

Copy buf into column {\tt n} of matrix.

set_memory()
void set_memory(T *buffer, int offset, int rows, int columns, int free_when_destroyed=0)

For when you absolutely have to have access to the memory

io

Matrix file io.

load()
EST_read_status load(const class EST_String &filename)

load Matrix from file - Not currently implemented.

save()
EST_write_status save(const class EST_String &filename) const

save Matrix to file {\tt filename}

operator << ()
friend ostream& operator << (ostream &st, const EST_TMatrix<T> &a)

print matirx.

p_num_rows;

unsigned int p_num_rows

Visible shape

p_row_step;

unsigned int p_row_step

How to access the memory

fast_a_m()

INLINE const T& fast_a_m(int r, int c) const

quick method for returning {\tt x[m][n]}

set_values()

void set_values(const T *data, int r_step, int c_step, int start_r, int num_r, int start_c, int num_c )

Get and set values from array

copy()

void copy(const EST_TMatrix<T> &a)

private resize and copy function.

copy_data()

void copy_data(const EST_TMatrix<T> &a)

just copy data, no resizing, no size check.

just_resize()

void just_resize(int new_rows, int new_cols, T** old_vals)

resize the memory and reset the bounds, but don't set values.

default_vals()

void default_vals()

sets data and length to default values (0 in both cases).

class EST_FMatrix{}

class EST_FMatrix(: public EST_TSimpleMatrix<float>

A matrix class for floating point numbers. EST_FMatrix x should be used instead of float **x wherever possible.

EST_FMatrix()

EST_FMatrix(int m, int n)

size constructor

EST_FMatrix()

EST_FMatrix(const EST_FMatrix &a)

copy constructor

EST_FMatrix()

EST_FMatrix(const EST_FMatrix &a, int b)

CHECK - what does this do???

EST_FMatrix()

EST_FMatrix()

default constructor

save()

EST_write_status save(const EST_String &filename, const EST_String &type = EST_FMatrix::default_file_type )

Save in file (ascii or binary)

load()

EST_read_status load(const EST_String &filename)

Load from file (ascii or binary as defined in file)

est_save()

EST_write_status est_save(const EST_String &filename, const EST_String &type)

Save in file in est format

est_load()

EST_read_status est_load(const EST_String &filename)

Load from file in est format (binary/ascii defined in file itself)

copyin()

void copyin(float **x, int rows, int cols)

Copy 2-d array {\tt x} of size {\tt rows x cols} into matrix.

operator+=()

EST_FMatrix& operator+=(const EST_FMatrix &a)

Add elements of 2 same sized matrices.

operator-=()

EST_FMatrix& operator-=(const EST_FMatrix &a)

Subtract elements of 2 same sized matrices.

operator*=()

EST_FMatrix& operator*=(const float f)

elementwise multiply by scalar

operator/=()

EST_FMatrix& operator/=(const float f)

elementwise divide by scalar

operator*()

friend EST_FMatrix operator*(const EST_FMatrix &a, const float x)

Multiply all elements of matrix by {\tt x}.

operator*()

friend EST_FVector operator*(const EST_FMatrix &a, const EST_FVector &v)

Multiply matrix by vector.

operator*()

friend EST_FVector operator*(const EST_FVector &v, const EST_FMatrix &a)

Multiply vector by matrix

operator*()

friend EST_FMatrix operator*(const EST_FMatrix &a, const EST_FMatrix &b)

Multiply matrix by matrix.

class EST_TList{}

template <class T> class EST_TList(: public EST_UList

A Template doubly linked list class. This class contains doubly linked lists of a type denoted by {\tt T}. A pointer of type \Ref{EST_Litem} is used to access items in the list. The class supports a variety of ways of adding, removing and accessing items in the list. For examples of how to operate lists, see \Ref{list_example}.

Iteration through the list is performed using a pointer of type \Ref{EST_Litem}. See \Ref{Iteration} for example code.

Constructor functions

EST_TList()
EST_TList()

default constructor

EST_TList()
EST_TList(const EST_TList<T> &l)

copy constructor

Access functions for reading and writing items.

See \Ref{EST_TList_Accessing} for examples.

item()
T& item(const EST_Litem *p)

return the value associated with the EST_Litem pointer. This has the same functionality as the overloaded () operator.

item()
const T& item(const EST_Litem *p) const

return a const value associated with the EST_Litem pointer

nth()
T& nth(int n)

return the Nth value

nth()
const T& nth(int n) const

return a const Nth value

first()
const T& first() const

return const reference to first item in list

last()
const T& last() const

return const reference to last item in list

first()
T& first()

return reference to first item in list

last()
T& last()

return reference to last item in list

operator()
const T& operator operator(const EST_Litem *ptr) const

return const reference to item in list pointed to by {\tt ptr}

operator()
T& operator operator(const EST_Litem *ptr)

return const reference to item in list pointed to by {\tt ptr}

Removing items in a list.

more.

remove()
EST_Litem* remove(EST_Litem *ptr)

remove item pointed to by {\tt ptr}, return pointer to previous item. See \Ref{Removing} for example code.

remove_nth()
EST_Litem* remove_nth(int n)

remove nth item, return pointer to previous item

Adding items to a list.

In all cases, a complete copy of the item is made and added to the list. See \Ref{Addition} for examples.

append()
void append(const T &item)

add item onto end of list

prepend()
void prepend(const T &item)

add item onto start of list

insert_after()
EST_Litem* insert_after(EST_Litem *ptr, const T &item)

add {\tt item} after position given by {\tt ptr}, return pointer to added item

insert_before()
EST_Litem* insert_before(EST_Litem *ptr, const T &item)

add {\tt item} before position given by {\tt ptr}, return pointer to added item

Exchange

exchange()
void exchange(EST_Litem *a, EST_Litem *b)

exchange 1

exchange()
void exchange(int i, int j)

exchange 2

exchange_contents()
static void exchange_contents(EST_Litem *a, EST_Litem *b)

exchange 3

General functions

operator=()
EST_TList <T> & operator=(const EST_TList<T> &a)

make full copy of list

operator +=()
EST_TList <T> & operator +=(const EST_TList<T> &a)

Add list onto end of existing list

operator << ()
friend ostream& operator << (ostream &st, EST_TList<T> const &list)

print list

clear()
void clear(void)

remove all items in list

class EST_DVector{}

class EST_DVector(: public EST_TSimpleVector<double>

A vector class for double precision floating point numbers. {\tt EST_DVector x} should be used instead of {\tt float *x} wherever possible.

EST_DVector()

EST_DVector(int n)

Size constructor.

EST_DVector()

EST_DVector(const EST_DVector &a)

Copy constructor.

EST_DVector()

EST_DVector()

Default constructor.

operator*=()

EST_DVector& operator*=(const EST_DVector &s)

elementwise multiply

operator+=()

EST_DVector& operator+=(const EST_DVector &s)

elementwise add

operator*=()

EST_DVector& operator*=(const double d)

elementwise multiply by scalar

operator/=()

EST_DVector& operator/=(const double d)

elementwise divide by scalar

save()

EST_write_status save(const EST_String &filename, const EST_String &type)

save vector to file filename.

load()

EST_read_status load(const EST_String &filename)

load vector from file filename.

est_load()

EST_read_status est_load(const EST_String &filename)

Load from file in est format (binary/ascii defined in file itself)

class EST_FVector{}

class EST_FVector(: public EST_TSimpleVector<float>

A vector class for floating point numbers. {\tt EST_FVector x} should be used instead of {\tt float *x} wherever possible.

EST_FVector()

EST_FVector(int n)

Size constructor.

EST_FVector()

EST_FVector(const EST_FVector &a)

Copy constructor.

EST_FVector()

EST_FVector()

Default constructor.

operator*=()

EST_FVector& operator*=(const EST_FVector &s)

elementwise multiply

operator+=()

EST_FVector& operator+=(const EST_FVector &s)

elementwise add

operator*=()

EST_FVector& operator*=(const float f)

elementwise multiply by scalar

operator/=()

EST_FVector& operator/=(const float f)

elementwise divide by scalar

save()

EST_write_status save(const EST_String &filename, const EST_String &type)

save vector to file filename.

load()

EST_read_status load(const EST_String &filename)

load vector from file filename.

est_load()

EST_read_status est_load(const EST_String &filename)

Load from file in est format (binary/ascii defined in file itself)

class EST_TSimpleVector{}

template <class T> class EST_TSimpleVector(: public EST_TVector<T>

A derived class from EST_TVector which is used for containing simple types, such as float or int

EST_TSimpleMatrix()

EST_TSimpleMatrix(void)

default constructor

p_memory;

T* p_memory

Pointer to the start of the vector. The start of allocated memory is p_memory-p_offset.

p_num_columns;

unsigned int p_num_columns

Visible shape

p_offset;

unsigned int p_offset

How to access the memory

vcell_pos()

INLINE unsigned int vcell_pos(unsigned int c, unsigned int cs) const

The memory access rule, in one place for easy reference

fast_a_v()

INLINE const T& fast_a_v(int c) const

quick method for returning

set_values()

void set_values(const T *data, int step, int start_c, int num_c)

Get and set values from array

copy()

void copy(const EST_TVector<T> &a)

private copy function, called from all other copying functions.

copy_data()

void copy_data(const EST_TVector<T> &a)

just copy data, no resizing, no size check.

just_resize()

void just_resize(int new_cols, T** old_vals)

resize the memory and reset the bounds, but don't set values.

default_vals()

void default_vals()

sets data and length to default values (0 in both cases).

EST_TVector()

EST_TVector()

default constructor

EST_TVector()

EST_TVector(const EST_TVector<T> &v)

copy constructor

EST_TVector()

EST_TVector(int n)

"size" constructor - make vector of size n.

EST_TVector()

EST_TVector(int, T *memory, int offset=0, int free_when_destroyed=0)

construct from memory supplied by caller

~EST_TVector()

~EST_TVector()

destructor.

def_val;

static const T* def_val

default value, used for filling matrix after resizing

error_return;

static T* error_return

A reference to this variable is returned if you try and access beyond the bounds of the matrix. The vaue is undefined, but you can check for the reference you get having the same address as this variable to test for an error.

resize()

void resize(int n, int set=1)

resize vector. If set=1, then the current values in the vector are preserved up to the new length n. If the new length exceeds the old length, the rest of the vector is filled with the def_val

memory()

const T* memory() const

For when you absolutely have to have access to the memory

access

Basic access methods for vectors.

num_columns()
int num_columns() const

number of items in vector.

length()
int length() const

number of items in vector.

n()
int n() const

number of items in vector.

a_no_check()
INLINE const T& a_no_check(int n) const

read-only const access operator: without bounds checking

a_no_check()
INLINE T& a_no_check(int n)

read/write non-const access operator: without bounds checking

a_no_check_1()
INLINE const T& a_no_check_1(int n) const

read-only const access operator: without bounds checking

a_no_check_1()
INLINE T& a_no_check_1(int n)

read/write non-const access operator: without bounds checking

a_check()
const T& a_check(int n) const

read-only const access operator: with bounds checking

a_check()
T& a_check(int n)

read/write non-const access operator: with bounds checking

operator()
const T& operator operator(int n) const

read-only const access operator: return reference to nth member

operator [] ()
T& operator [] (int n)

read/write non const access operator: return reference to nth member

operator=()

EST_TVector& operator=(const EST_TVector &s)

assignment operator

fill()

void fill(const T &v)

Fill entire array will value v.

empty()

void empty()

Fill vector with default value

save()

EST_write_status save(const EST_String &filename)

Save vector to file filename.

operator == ()

int operator == (const EST_TVector &v) const

is true if vectors are equal size and all elements are equal.

operator != ()

int operator != (const EST_TVector &v) const

is true if vectors are not equal size or a single elements isn't equal.

copy_section()

void copy_section(T* dest, int offset=0, int num=-1) const

Copy data in and out. Subclassed by SimpleVector for speed.

sub_vector()

void sub_vector(EST_TVector<T> &sv, int start_c=0, int len=-1)

Create a sub vector.

operator << ()

friend ostream& operator << (ostream &st, const EST_TVector<T> &m)

print out vector.

T;

friend class EST_TMatrixT

Matrix must be friend to set up subvectors

EST_TSimpleMatrix()

EST_TSimpleMatrix(int m, int n)

size constructor

EST_TSimpleMatrix()

EST_TSimpleMatrix(const EST_TSimpleMatrix<T> &m)

copy constructor

copy()

void copy(const EST_TSimpleMatrix<T> &a)

copy one matrix into another

resize()

void resize(int rows, int cols, int set=1)

resize matrix

operator=()

EST_TSimpleMatrix <T> & operator=(const EST_TSimpleMatrix<T> &s)

assignment operator

EST_TSimpleVector()

EST_TSimpleVector()

default constructor

EST_TSimpleVector()

EST_TSimpleVector(int n)

"size" constructor

resize()

void resize(int n, int set=1)

resize vector

operator=()

EST_TSimpleVector& operator=(const EST_TSimpleVector<T> &s)

assignment operator

zero()

void zero(void)

Fill entire array with 0 bits.

empty()

void empty(void)

Fill vector with default value

class EST_TrieNode{}

class EST_TrieNode

An internal class for \Ref{EST_StringTrie} used to hold represent the node in an string index tree.

This basically represents a 128-branching node (on for each character) plus a contents field for strings ending at this point.

EST_TrieNode()

EST_TrieNode(const int width)

lookup()

void* lookup(const unsigned char *key) const

Find the contents for given string, 0 if no current contents

add()

void add(const unsigned char *key, void *item)

add {\tt item} for {\tt key} overwriting previous contents

copy_into()

void copy_into(EST_StringTrie &trie, const EST_String &path) const

copy all entries in trie node into trie

class EST_TDeque{}

template <class T> class EST_TDeque

Double ended queue.

Iter;

typedef EST_TIterator <Container, IPointer, Entry> Iter

Name for an itterator like this

EST_TIterator()

EST_TIterator()

Create an iterator not associated with any specific container.

EST_TIterator()

EST_TIterator(const Container &over)

Create an iterator ready to run over the given container.

operator = ()

Iter& operator = (const Iter &orig)

Copy an iterator by assignment

operator = ()

Iter& operator = (const Container &over)

Assigning a container to an iterator sets it ready to start.

begin()

void begin(const Container &over)

Set the iterator ready to run over this container.

beginning()

void beginning()

Reset to the start of the container.

End Tests

has_more_elements()
bool has_more_elements() const

True if there are more elements to look at.

at_end()
bool at_end() const

True when there are no more.

operator int()
operator int() const

Viewing the iterator as an integer (for instance in a test) sees a non-zero value iff there are elements still to look at

Moving Forward

next()
void next()

Next moves to the next entry.

operator ++()
Iter& operator ++()

The increment operator does the same as next.

Access

current()
const Entry& current() const

Return the element currentl pointed to.

operator *()
const Entry& operator *() const

The * operator returns the current element.

next_element()
const Entry& next_element()

Return the current element and move the pointer forwards.

n()
unsigned int n() const

Return the current position

EST_TStructIterator()

EST_TStructIterator()

Create an iterator not associated with any specific container.

operator = ()

Iter& operator = (const Iter &orig)

Copy an iterator by assignment

EST_TStructIterator()

EST_TStructIterator(const Container &over)

Create an iterator ready to run over the given container.

Can't access constant containers this way.

EST_TRwIterator()

EST_TRwIterator()

Create an iterator not associated with any specific container.

operator = ()

Iter& operator = (const Iter &orig)

Copy an iterator by assignment

EST_TRwIterator()

EST_TRwIterator(Container &over)

Create an iterator ready to run over the given container.

begin()

void begin(Container &over)

Set the iterator ready to run over this container.

Access

current()
Entry& current() const

Return the element currentl pointed to.

operator *()
Entry& operator *() const

The * operator returns the current element.

next_element()
Entry& next_element()

Return the current element and move the pointer forwards.

EST_TRwStructIterator()

EST_TRwStructIterator()

Create an iterator not associated with any specific container.

operator = ()

Iter& operator = (const Iter &orig)

Copy an iterator by assignment

EST_TRwStructIterator()

EST_TRwStructIterator(Container &over)

Create an iterator ready to run over the given container.

Filler;

static const T* Filler

Used to fill empty spaces when possible.

clear()

void clear(void)

Empty it out.

is_empty()

bool is_empty(void) const

Is there anything to get?

print()

ostream& print(ostream &s) const

print picture of state. Mostly useful for debugging.

stack

An interface looking like a stack.

inverse stack

The other end as a stack.

queue

An interface looking like a queue.

perl

For people who think in perl

cont;

Container* cont

The container we are looking at.

pos;

unsigned int pos

Position in the structure. May or may not be useful.

pointer;

IPointer pointer

Structure defined by the container class whcih contains the current state of the iteration

class EST_TKVI{}

template <class K, class V> class EST_TKVI

Templated Key-Value Item. Serves as the items in the list of the EST_TKVL class.

class EST_TKVL{}

template <class K, class V> class EST_TKVL

Templated Key-Value list. Objects of type EST_TKVL contain lists which are accessed by a key of type {\bf K}, which returns a value of type {\bf V}.

Constructor functions

EST_TKVL()
EST_TKVL()

default constructor

EST_TKVL()
EST_TKVL(const EST_TKVL<K, V> &kv)

copy constructor

default_val;

static V* default_val

default value, returned when there is no such entry.

default_key;

static K* default_key

default value, returned when there is no such entry.

Linked list of key-val pairs. Don't use

list;

EST_TList < EST_TKVI<K,V> > list

this as it will be made private in the future

length()

const int length() const

number of key value pairs in list

head()

EST_Litem* head() const

Return First key value pair in list

clear()

void clear()

Empty list.

Access functions.

val()
const V& val(const K &rkey, bool m=0) const

return value according to key (const)

val()
V& val(const K &rkey, bool m=0)

return value according to key (non-const)

val()
const V& val(EST_Litem *ptr, bool m=0) const

return value according to ptr

val()
V& val(EST_Litem *ptr, bool m=0)

return value according to ptr

val_def()
const V& val_def(const K &rkey, const V &def) const

value or default

key()
const K& key(EST_Litem *ptr, int m=1) const

find key, reference by ptr

key()
K& key(EST_Litem *ptr, int m=1)

find key, reference by ptr

key()
const K& key(const V &v, int m=1) const

return first matching key, referenced by val

change_val()
int change_val(const K &rkey, const V &rval)

change key-val pair. If no corresponding entry is present, add to end of list.

change_val()
int change_val(EST_Litem *ptr, const V &rval)

change key-val pair. If no corresponding entry is present, add to end of list.

change_key()
int change_key(EST_Litem *ptr, const K &rkey)

change name of key pair.

add_item()
int add_item(const K &rkey, const V &rval, int no_search = 0)

add key-val pair to list

remove_item()
int remove_item(const K &rkey, int quiet = 0)

remove key and val pair from list

present()

const int present(const K &rkey) const

Returns true if key is present.

map()

void map(void (*func)(K&, V&))

apply function to each pair

operator = ()

EST_TKVL <K, V> & operator = (const EST_TKVL<K, V> &kv)

full copy of KV list.

operator += ()

EST_TKVL <K, V> & operator += (const EST_TKVL<K, V> &kv)

add kv after existing list.

operator + ()

EST_TKVL <K, V> operator + (const EST_TKVL<K, V> &kv)

make new concatenated list

class EST_TList{}

template <class T> class EST_TList(: public EST_UList

A Template doubly linked list class. This class contains doubly linked lists of a type denoted by {\tt T}. A pointer of type \Ref{EST_Litem} is used to access items in the list. The class supports a variety of ways of adding, removing and accessing items in the list. For examples of how to operate lists, see \Ref{list_example}.

Iteration through the list is performed using a pointer of type \Ref{EST_Litem}. See \Ref{Iteration} for example code.

Constructor functions

EST_TList()
EST_TList()

default constructor

EST_TList()
EST_TList(const EST_TList<T> &l)

copy constructor

Access functions for reading and writing items.

See \Ref{EST_TList_Accessing} for examples.

item()
T& item(const EST_Litem *p)

return the value associated with the EST_Litem pointer. This has the same functionality as the overloaded () operator.

item()
const T& item(const EST_Litem *p) const

return a const value associated with the EST_Litem pointer

nth()
T& nth(int n)

return the Nth value

nth()
const T& nth(int n) const

return a const Nth value

first()
const T& first() const

return const reference to first item in list

last()
const T& last() const

return const reference to last item in list

first()
T& first()

return reference to first item in list

last()
T& last()

return reference to last item in list

operator()
const T& operator operator(const EST_Litem *ptr) const

return const reference to item in list pointed to by {\tt ptr}

operator()
T& operator operator(const EST_Litem *ptr)

return const reference to item in list pointed to by {\tt ptr}

Removing items in a list.

more.

remove()
EST_Litem* remove(EST_Litem *ptr)

remove item pointed to by {\tt ptr}, return pointer to previous item. See \Ref{Removing} for example code.

remove_nth()
EST_Litem* remove_nth(int n)

remove nth item, return pointer to previous item

Adding items to a list.

In all cases, a complete copy of the item is made and added to the list. See \Ref{Addition} for examples.

append()
void append(const T &item)

add item onto end of list

prepend()
void prepend(const T &item)

add item onto start of list

insert_after()
EST_Litem* insert_after(EST_Litem *ptr, const T &item)

add {\tt item} after position given by {\tt ptr}, return pointer to added item

insert_before()
EST_Litem* insert_before(EST_Litem *ptr, const T &item)

add {\tt item} before position given by {\tt ptr}, return pointer to added item

Exchange

exchange()
void exchange(EST_Litem *a, EST_Litem *b)

exchange 1

exchange()
void exchange(int i, int j)

exchange 2

exchange_contents()
static void exchange_contents(EST_Litem *a, EST_Litem *b)

exchange 3

General functions

operator=()
EST_TList <T> & operator=(const EST_TList<T> &a)

make full copy of list

operator +=()
EST_TList <T> & operator +=(const EST_TList<T> &a)

Add list onto end of existing list

operator << ()
friend ostream& operator << (ostream &st, EST_TList<T> const &list)

print list

clear()
void clear(void)

remove all items in list

class EST_TMatrix{}

(R,C) template <class T> class EST_TMatrix(: public EST_TVector<T>

Template Matrix class.

This is an extension of the EST_TVector class to two dimensions.

EST_TMatrix()

EST_TMatrix()

default constructor

EST_TMatrix()

EST_TMatrix(const EST_TMatrix<T> &m)

copy constructor

EST_TMatrix()

EST_TMatrix(int rows, int cols)

"size" constructor

EST_TMatrix()

EST_TMatrix(int rows, int cols, T *memory, int offset=0, int free_when_destroyed=0)

construct from memory supplied by caller

~EST_TMatrix()

~EST_TMatrix()

EST_TMatrix

access

Basic access methods for matrices.

num_rows()
int num_rows() const

return number of rows

num_columns()
int num_columns() const

return number of columns

a_no_check()
INLINE const T& a_no_check(int row, int col) const

const access with no bounds check, care recommend

a_no_check()
INLINE T& a_no_check(int row, int col)

access with no bounds check, care recommend

a_check()
const T& a_check(int row, int col) const

const element access function

a_check()
T& a_check(int row, int col)

non-const element access function

operator()
const T& operator operator(int row, int col) const

const element access operator

operator()
T& operator operator(int row, int col)

non-const element access operator

resize()

void resize(int rows, int cols, int set=1)

resize matrix. If {\tt set=1}, then the current values in the matirx are preserved up to the new size {\tt n}. If the new size exceeds the old size, the rest of the matrix is filled with the {\tt def_val}

fill()

void fill(const T &v)

fill matrix with value v

operator=()

EST_TMatrix& operator=(const EST_TMatrix &s)

assignment operator

add_rows()

EST_TMatrix& add_rows(const EST_TMatrix &s)

The two versions of what might have been operator +=

Sub-Matrix/Vector Extraction

All of these return matrecies and vectors which share memory with the original, so altering values them alters the original.

row()
void row(EST_TVector<T> &rv, int r, int start_c=0, int len=-1)

Make the vector {\tt rv} a window onto row {\tt r}

column()
void column(EST_TVector<T> &cv, int c, int start_r=0, int len=-1)

Make the vector {\tt cv} a window onto column {\tt c}

sub_matrix()
void sub_matrix(EST_TMatrix<T> &sm, int r=0, int numr=EST_ALL, int c=0, int numc=EST_ALL)

Make the matrix {\tt sm} a window into this matrix.

Copy in and out

Copy data between buffers and the matrix.

copy_row()
void copy_row(int r, T *buf, int offset=0, int num=-1) const

Copy row {\tt r} of matrix to {\tt buf}. {\tt buf} should be pre-malloced to the correct size.

copy_column()
void copy_column(int c, T *buf, int offset=0, int num=-1) const

Copy column {\tt c} of matrix to {\tt buf}. {\tt buf} should be pre-malloced to the correct size.

set_row()
void set_row(int n, const T *buf, int offset=0, int num=-1)

Copy buf into row {\tt n} of matrix

set_column()
void set_column(int n, const T *buf, int offset=0, int num=-1)

Copy buf into column {\tt n} of matrix.

set_memory()
void set_memory(T *buffer, int offset, int rows, int columns, int free_when_destroyed=0)

For when you absolutely have to have access to the memory

io

Matrix file io.

load()
EST_read_status load(const class EST_String &filename)

load Matrix from file - Not currently implemented.

save()
EST_write_status save(const class EST_String &filename) const

save Matrix to file {\tt filename}

operator << ()
friend ostream& operator << (ostream &st, const EST_TMatrix<T> &a)

print matirx.

p_num_rows;

unsigned int p_num_rows

Visible shape

p_row_step;

unsigned int p_row_step

How to access the memory

fast_a_m()

INLINE const T& fast_a_m(int r, int c) const

quick method for returning {\tt x[m][n]}

set_values()

void set_values(const T *data, int r_step, int c_step, int start_r, int num_r, int start_c, int num_c )

Get and set values from array

copy()

void copy(const EST_TMatrix<T> &a)

private resize and copy function.

copy_data()

void copy_data(const EST_TMatrix<T> &a)

just copy data, no resizing, no size check.

just_resize()

void just_resize(int new_rows, int new_cols, T** old_vals)

resize the memory and reset the bounds, but don't set values.

default_vals()

void default_vals()

sets data and length to default values (0 in both cases).

class EST_TSimpleVector{}

template <class T> class EST_TSimpleVector(: public EST_TVector<T>

A derived class from EST_TVector which is used for containing simple types, such as float or int

EST_TSimpleMatrix()

EST_TSimpleMatrix(void)

default constructor

p_memory;

T* p_memory

Pointer to the start of the vector. The start of allocated memory is p_memory-p_offset.

p_num_columns;

unsigned int p_num_columns

Visible shape

p_offset;

unsigned int p_offset

How to access the memory

vcell_pos()

INLINE unsigned int vcell_pos(unsigned int c, unsigned int cs) const

The memory access rule, in one place for easy reference

fast_a_v()

INLINE const T& fast_a_v(int c) const

quick method for returning

set_values()

void set_values(const T *data, int step, int start_c, int num_c)

Get and set values from array

copy()

void copy(const EST_TVector<T> &a)

private copy function, called from all other copying functions.

copy_data()

void copy_data(const EST_TVector<T> &a)

just copy data, no resizing, no size check.

just_resize()

void just_resize(int new_cols, T** old_vals)

resize the memory and reset the bounds, but don't set values.

default_vals()

void default_vals()

sets data and length to default values (0 in both cases).

EST_TVector()

EST_TVector()

default constructor

EST_TVector()

EST_TVector(const EST_TVector<T> &v)

copy constructor

EST_TVector()

EST_TVector(int n)

"size" constructor - make vector of size n.

EST_TVector()

EST_TVector(int, T *memory, int offset=0, int free_when_destroyed=0)

construct from memory supplied by caller

~EST_TVector()

~EST_TVector()

destructor.

def_val;

static const T* def_val

default value, used for filling matrix after resizing

error_return;

static T* error_return

A reference to this variable is returned if you try and access beyond the bounds of the matrix. The vaue is undefined, but you can check for the reference you get having the same address as this variable to test for an error.

resize()

void resize(int n, int set=1)

resize vector. If set=1, then the current values in the vector are preserved up to the new length n. If the new length exceeds the old length, the rest of the vector is filled with the def_val

memory()

const T* memory() const

For when you absolutely have to have access to the memory

access

Basic access methods for vectors.

num_columns()
int num_columns() const

number of items in vector.

length()
int length() const

number of items in vector.

n()
int n() const

number of items in vector.

a_no_check()
INLINE const T& a_no_check(int n) const

read-only const access operator: without bounds checking

a_no_check()
INLINE T& a_no_check(int n)

read/write non-const access operator: without bounds checking

a_no_check_1()
INLINE const T& a_no_check_1(int n) const

read-only const access operator: without bounds checking

a_no_check_1()
INLINE T& a_no_check_1(int n)

read/write non-const access operator: without bounds checking

a_check()
const T& a_check(int n) const

read-only const access operator: with bounds checking

a_check()
T& a_check(int n)

read/write non-const access operator: with bounds checking

operator()
const T& operator operator(int n) const

read-only const access operator: return reference to nth member

operator [] ()
T& operator [] (int n)

read/write non const access operator: return reference to nth member

operator=()

EST_TVector& operator=(const EST_TVector &s)

assignment operator

fill()

void fill(const T &v)

Fill entire array will value v.

empty()

void empty()

Fill vector with default value

save()

EST_write_status save(const EST_String &filename)

Save vector to file filename.

operator == ()

int operator == (const EST_TVector &v) const

is true if vectors are equal size and all elements are equal.

operator != ()

int operator != (const EST_TVector &v) const

is true if vectors are not equal size or a single elements isn't equal.

copy_section()

void copy_section(T* dest, int offset=0, int num=-1) const

Copy data in and out. Subclassed by SimpleVector for speed.

sub_vector()

void sub_vector(EST_TVector<T> &sv, int start_c=0, int len=-1)

Create a sub vector.

operator << ()

friend ostream& operator << (ostream &st, const EST_TVector<T> &m)

print out vector.

T;

friend class EST_TMatrixT

Matrix must be friend to set up subvectors

EST_TSimpleMatrix()

EST_TSimpleMatrix(int m, int n)

size constructor

EST_TSimpleMatrix()

EST_TSimpleMatrix(const EST_TSimpleMatrix<T> &m)

copy constructor

copy()

void copy(const EST_TSimpleMatrix<T> &a)

copy one matrix into another

resize()

void resize(int rows, int cols, int set=1)

resize matrix

operator=()

EST_TSimpleMatrix <T> & operator=(const EST_TSimpleMatrix<T> &s)

assignment operator

EST_TSimpleVector()

EST_TSimpleVector()

default constructor

EST_TSimpleVector()

EST_TSimpleVector(int n)

"size" constructor

resize()

void resize(int n, int set=1)

resize vector

operator=()

EST_TSimpleVector& operator=(const EST_TSimpleVector<T> &s)

assignment operator

zero()

void zero(void)

Fill entire array with 0 bits.

empty()

void empty(void)

Fill vector with default value

class EST_StringTrie{}

class EST_StringTrie

A string tree index class for indexing arbitrary objects by strings of characters.

Note this only deals with 7 but characters, and can only hold one item per index key.

copy()

void copy(const EST_StringTrie &trie)

lookup()

void* lookup(const EST_String &key) const

Find contents index by {\tt key}, 0 if there is not contents

add()

void add(const EST_String &key, void *item)

Add {\tt item} indexed by {\tt key}, overwriting previous contents

clear()

void clear(void)

Delete the tree

clear()

void clear(void (*deletenode)(void *n))

Delete the tree, apply {\tt deletenote} function to each {\tt contents}

String Classes

class EST_String{}

class EST_String

A non-copyleft implementation of a string class to use with compilers that aren't GNU C++.

Strings are reference-counted and reasonably efficiant (eg you can pass them around, into and out of functions and so on without worrying too much about the cost).

The associated class EST_Regex can be used to represent regular expressions.

version;

(S) static const char* version

Global version string.

Empty;

static const EST_String Empty

Constant empty string

EST_string_size;

typedef int EST_string_size

Type of string size field.

#define MAX_STRING_SIZE()

#defineMAX_STRING_SIZE(INT_MAX)

Maximum string size.

EST_String()

EST_String(void)

Construct an empty string.

EST_String()

EST_String(const char *s)

Construct from char *

EST_String()

EST_String(const char *s, int start_or_fill, int len)

Construct from part of char * or fill with given character.

EST_String()

EST_String(const char *s, int s_size, int start, int len)

Construct from C string.

EST_String()

EST_String(const EST_String &s)

Copy constructor We have to declare our own copy constructor to lie to the compier about the constness of the RHS

EST_String()

EST_String(const char c)

Construct from single char. This constructor is not usually included as it can mask errors.

~EST_String()

~EST_String()

Destructor.

length()

int length(void) const

Length of string ({\em not} length of underlying chunk)

space()

int space(void) const

Size of underlying chunk.

str()

const char* str(void) const

Get a const-pointer to the actual memory.

updatable_str()

char* updatable_str(void)

Get a writable pointer to the actual memory.

FromChar()

static EST_String FromChar(const char c)

Build string from a single character.

Number()

static EST_String Number(int i, int base=10)

Build string from an integer.

Number()

static EST_String Number(long i, int base=10)

Build string from a long integer.

Number()

static EST_String Number(double d)

Build string from a double.

Number()

static EST_String Number(float f)

Build string from a float

Int()

int Int(bool &ok) const

Convert to an integer

Long()

long Long(bool &ok) const

Convert to a long

Float()

float Float(bool &ok) const

Convert to a float

Double()

double Double(bool &ok) const

Convert to a double

Before

before()
EST_String before(int pos, int len=0) const

Part before position

before()
EST_String before(const char *s, int pos=0) const

Part before first matching substring after pos.

before()
EST_String before(const EST_String &s, int pos=0) const

Part before first matching substring after pos.

before()
EST_String before(EST_Regex &e, int pos=0) const

Part before first match of regexp after pos.

At

at()
EST_String at(int from, int len=0) const

Return part at position

at()
EST_String at(const char *s, int pos=0) const

Return part where substring found (not useful, included for completeness)

at()
EST_String at(const EST_String &s, int pos=0) const

Return part where substring found (not useful, included for completeness)

at()
EST_String at(EST_Regex &e, int pos=0) const

Return part matching regexp.

After

after()
EST_String after(int pos, int len=1) const

Part after pos+len

after()
EST_String after(const char *s, int pos=0) const

Part after substring.

after()
EST_String after(const EST_String &s, int pos=0) const

Part after substring.

after()
EST_String after(EST_Regex &e, int pos=0) const

Part after match of regular expression.

Search for something

search()
int search(const char *s, int len, int &mlen, int pos=0) const

Find a substring.

search()
int search(const EST_String s, int &mlen, int pos=0) const

Find a substring.

search()
int search(EST_Regex &re, int &mlen, int pos=0, int *starts=NULL, int *ends=NULL) const

Find a match of the regular expression.

Get position of something

index()
int index(const char *s, int pos=0) const

Position of substring (starting at pos)

index()
int index(const EST_String &s, int pos=0) const

Position of substring (starting at pos)

index()
int index(EST_Regex &ex, int pos=0) const

Position of match of regexp (starting at pos)

Does string contain something?

contains()
int contains(const char *s, int pos=-1) const

Does it contain this substring?

contains()
int contains(const EST_String &s, int pos=-1) const

Does it contain this substring?

contains()
int contains(const char c, int pos=-1) const

Does it contain this character?

contains()
int contains(EST_Regex &ex, int pos=-1) const

Does it contain a match for this regular expression?

Does string exactly match?

matches()
int matches(const char *e, int pos=0) const

Exatly match this string?

matches()
int matches(const EST_String &e, int pos=0) const

Exatly match this string?

matches()
int matches(EST_Regex &e, int pos=0, int *starts=NULL, int *ends=NULL) const

Exactly matches this regular expression, can return ends of sub-expressions.

Global replacement

gsub()
int gsub(const char *os, const EST_String &s)

Substitute one string for another.

gsub()
int gsub(const char *os, const char *s)

Substitute one string for another.

gsub()
int gsub(const EST_String &os, const EST_String &s)

Substitute one string for another.

gsub()
int gsub(const EST_String &os, const char *s)

Substitute one string for another.

gsub()
int gsub(EST_Regex &ex, const EST_String &s)

Substitute string for matches of regular expression.

gsub()
int gsub(EST_Regex &ex, const char *s)

Substitute string for matches of regular expression.

gsub()
int gsub(EST_Regex &ex, int bracket_num)

Substitute string for matches of regular expression.

subst()
int subst(EST_String source, int (&starts)[EST_Regex_max_subexpressions], int (&ends)[EST_Regex_max_subexpressions])

Substitute the result of a match into a string.

Frequency counts

freq()
int freq(const char *s) const

Number of occurances of substring

freq()
int freq(const EST_String &s) const

Number of occurances of substring

freq()
int freq(EST_Regex &s) const

Number of matches of regular expression.

Quoting

quote()
EST_String quote(const char quotec) const

Return the string in quotes with internal quotes protected.

quote_if_needed()
EST_String quote_if_needed(const char quotec) const

Return in quotes if there is something to protect (e.g. spaces)

unquote()
EST_String unquote(const char quotec) const

Remove quotes and unprotect internal quotes.

unquote_if_needed()
EST_String unquote_if_needed(const char quotec) const

Remove quotes if any.

Operators

operator()
const char operator operator(int i) const

Function style access to constant strings.

operator [] ()
char& operator [] (int i)

Array style access to writable strings.

operator const char*()
operator const char*() const

Cast to const char * by simply giving access to pointer.

operator char*()
operator char*()

Cast to char *, may involve copying.

Add to end of string.
operator += ()
EST_String& operator += (const char *b)

Add C string to end of EST_String

operator += ()
EST_String& operator += (const EST_String b)

Add EST_String to end of EST_String

Asignment
operator = ()
EST_String& operator = (const char *str)

Assign C string to EST_String

operator = ()
EST_String& operator = (const char c)

Assign single character to EST_String

operator = ()
EST_String& operator = (const EST_String &s)

Assign EST_String to EST_String.

Concatenation
operator + ()
friend EST_String operator + (const EST_String &a, const EST_String &b)

Concatenate two EST_Strings

operator + ()
friend EST_String operator + (const char *a, const EST_String &b)

Concatenate C String with EST_String

operator + ()
friend EST_String operator + (const EST_String &a, const char *b)

Concatenate EST_String with C String

operator * ()
friend EST_String operator * (const EST_String &s, int n)

Repeat string N times

relational operators
operator == ()
friend int operator == (const char *a, const EST_String &b)
operator == ()
friend int operator == (const EST_String &a, const char *b)
operator == ()
friend int operator == (const EST_String &a, const EST_String &b)
operator != ()
friend int operator != (const char *a, const EST_String &b)
operator != ()
friend int operator != (const EST_String &a, const char *b)
operator != ()
friend int operator != (const EST_String &a, const EST_String &b)
operator < ()
friend inline int operator < (const char *a, const EST_String &b)
operator < ()
friend inline int operator < (const EST_String &a, const char *b)
operator < ()
friend inline int operator < (const EST_String &a, const EST_String &b)
operator > ()
friend inline int operator > (const char *a, const EST_String &b)
operator > ()
friend inline int operator > (const EST_String &a, const char *b)
operator > ()
friend inline int operator > (const EST_String &a, const EST_String &b)
operator <= ()
friend inline int operator <= (const char *a, const EST_String &b)
operator <= ()
friend inline int operator <= (const EST_String &a, const char *b)
operator <= ()
friend inline int operator <= (const EST_String &a, const EST_String &b)
operator >= ()
friend inline int operator >= (const char *a, const EST_String &b)
operator >= ()
friend inline int operator >= (const EST_String &a, const char *b)
operator >= ()
friend inline int operator >= (const EST_String &a, const EST_String &b)

String comparison.

All these operators return -1, 0 or 1 to indicate the sort order of the strings.

compare()
friend int compare(const EST_String &a, const EST_String &b)
compare()
friend int compare(const EST_String &a, const char *b)
compare()
friend inline int compare(const char *a, const EST_String &b)

Case folded comparison.

The table argument can defined how upper and lower case characters correspond. The default works for ASCII.

fcompare()
friend inline int fcompare(const EST_String &a, const EST_String &b, const EST_String &table)

Split a string into parts.

These functions divide up a string producing an array of substrings.

split()
friend int split(const EST_String & s, EST_String result[], int max, const EST_String& seperator, char quote=0)

Split at a given separator.

split()
friend int split(const EST_String &s, EST_String result[], int max, const char *seperator, char quote=0)

Split at a given separator.

split()
friend int split(const EST_String & s, EST_String result[], int max, EST_Regex& seperator, char quote=0)

Split at each match of the regular expression.

upcase()

friend EST_String upcase(const EST_String &s)

Convert to upper case.

downcase()

friend EST_String downcase(const EST_String &s)

Convert to lower case.

cat()

static EST_String cat(const EST_String s1, const EST_String s2 = Empty, const EST_String s3 = Empty, const EST_String s4 = Empty, const EST_String s5 = Empty, const EST_String s6 = Empty, const EST_String s7 = Empty, const EST_String s8 = Empty, const EST_String s9 = Empty )

Concatenate a number of strings. This is more efficiant than multiple uses of + or +=

operator << ()

friend ostream& operator << (ostream &s, const EST_String &str)

Stream output for EST_String.

class EST_Token{}

class EST_Token

This class is similar to EST_String but also maintains the original punctuation and whitespace found around the token.

EST_Token's primary use is with EST_TokenStream class which allows easy tokenizing of ascii files.

A token consists of four parts, any of which may be empty: a name, the actual token, preceding whitespace, preceding punctuation, the name and succeeding punctuation.

Construction and Initialisation

init()
void init()

Basic access to fields

set_token()
void set_token(const EST_String &p)

set token from a string

set_token()
void set_token(const char *p)
set_whitespace()
void set_whitespace(const EST_String &p)

set whitespace of token.

set_whitespace()
void set_whitespace(const char *p)
set_punctuation()
void set_punctuation(const EST_String &p)

set (post) punctuation of token.

set_punctuation()
void set_punctuation(const char *p)
set_prepunctuation()
void set_prepunctuation(const EST_String &p)

set prepunction

set_prepunctuation()
void set_prepunctuation(const char *p)
whitespace()
const EST_String& whitespace()
punctuation()
const EST_String& punctuation()
prepunctuation()
const EST_String& prepunctuation()

Token Access

string()
const EST_String& string() const

Access token as a string

S()
const EST_String& S() const

Access token as a string

String()
const EST_String& String() const

Access token as a string

operator EST_String()
operator EST_String() const

For automatic coercion to a EST_String

Int()
int Int(bool &valid) const

Access token as an int

Int()
int Int() const

Access token as an int

I()
int I(bool &valid) const

Access token as an int

I()
int I() const

Access token as an int

operator int()
operator int() const

Access token as an int

Long()
long Long(bool &valid) const

Access token as a long

Long()
long Long() const

Access token as a long

L()
long L(bool &valid) const

Access token as a long

L()
long L() const

Access token as a long

operator long()
operator long() const

Access token as a long

Float()
float Float(bool &valid) const

Access token as a float

Float()
float Float() const

Access token as a float

F()
float F(bool &valid) const

Access token as a float

F()
float F() const

Access token as a float

operator float()
operator float() const

Access token as a float

Double()
double Double(bool &valid) const

Access token as a double

Double()
double Double() const

Access token as a double

D()
double D(bool &valid) const

Access token as a double

D()
double D() const

Access token as a double

operator double()
operator double() const

Access token as a double

set_quoted()
void set_quoted(int q)

Note that this token was quoted (or not)

quoted()
int quoted() const

TRUE is token was quoted

set_row()
void set_row(int r)

set row

set_col()
void set_col(int c)

set column

set_filepos()
void set_filepos(int c)

Set file position in original \Ref{EST_TokenStream}

lstring()
EST_String lstring()

Return lower case version of token name

ustring()
EST_String ustring()

Return upper case version of token name

row()
int row(void) const

Line number in original EST_TokenStream.

col()
int col(void) const

Line position in original EST_TokenStream.

filepos()
int filepos(void) const

file position in original EST_TokenStream.

pos_description()
const EST_String pos_description() const

A string describing current position, suitable for error messages

Operators

operator = ()
EST_Token& operator = (const EST_Token &a)
operator = ()
EST_Token& operator = (const EST_String &a)
operator == ()
int operator == (const EST_String &a)
operator != ()
int operator != (const EST_String &a)
operator == ()
int operator == (const char *a)
operator != ()
int operator != (const char *a)

class EST_Regex{}

class EST_Regex(: protected EST_String

A Regular expression class to go with the CSTR EST_String class.

The regular expression syntax is the FSF syntax used in emacs and in the FSF String library. This is translated into the syntax supported by Henry Spensor's regular expression library, this translation is a place to look if you find regular expressions not matching where expected.

EST_Regex()

EST_Regex(void)

Empty constructor, just for form.

EST_Regex()

EST_Regex(EST_String s)

Construct from EST_String.

EST_Regex()

EST_Regex(const char *ex)

Construct from C string.

EST_Regex()

EST_Regex(const EST_Regex &ex)

Copy constructor.

~EST_Regex()

~EST_Regex()

Destructor.

size()

int size() const

Size of the expression.

run()

int run(const char *on, int from, int &start, int &end, int *starts=NULL, int *ends=NULL)

Run to find a matching substring

run_match()

int run_match(const char *on, int from=0, int *starts=NULL, int *ends=NULL)

Run to see if it matches the entire string.

tostring()

EST_String tostring(void) const

Get the expression as a string.

operator const char *()

operator const char *() const

Cast operator, disambiguates it for some compilers

Assignment

operator = ()
EST_Regex& operator = (const EST_Regex ex)
operator = ()
EST_Regex& operator = (const EST_String s)
operator = ()
EST_Regex& operator = (const char *s)

operator << ()

friend ostream& operator << (ostream &s, const EST_Regex &str)

Stream output of regular expression.

compile()

void compile()

Compile expression.

compile_match()

void compile_match()

Compile expression in a form which only matches whole string.

regularize()

char* regularize(int match) const

Translate the expression into the internally used syntax.

Support Classes

EST_TStructIterator;

template <class Container, class IPointer, class Entry> class EST_TStructIterator

Template class defining interface to an iterator, i.e an object which returns elements from a structure one at a time.

This is template is usually hidden in the declaration of the container classes with a typedef for Entries providing a more convinient name for the iterator. However the interface is that defined here.

We support two interfaces, a pointer like interface similar to specialised iteratiion code elsewhere in the speech tools library and to the iterators in the C++ standard template library and an interface similar to that of Enumerations in Java.

MyContainer::Entries them;

for(them.begin(container); them; them++) { MyContainer::Entry = *them; // Do Something With it }

MyContainer::Entries them;

them.begin(container); while (them.has_more_entries()) { MyContainer::Entry = them.next_entry(); // Do Something With it }

union EST_TTI_Entry{}

template <class CONTAINER> struct EST_TTI_Entry

A time index for a container. The container defines how to get an object and so on, this lets you find a point in the container not far before the entry you want.

class EST_THandle{}

template <class BoxT, class ObjectT> class EST_THandle

A `smart' pointer which does reference counting.

Behaves almost like a pointer as far as naive code is concerned, but keeps count of how many handles are holding on to the conents and deletes it when there are none.

You need to be careful there are no dumb C++ pointers to things which are being handled this way.

Things to be handled should implement the same interface as EST_Handleable (either by taking that as a superclass or by reimplementing it) and in addition define {\tt object_ptr()}. See EST_TBox for an example.

There are two parameter types. In most cases the thing which contains the reference count and the data it represents will be the same object, but in the case of boxed values it may not be, so you can specify the type of both independently.

class EST_Handleable{}

class EST_Handleable

Reference Counting Interface.

This simple class does most of the things an object which is to be maniputated by EST_THandle style smart pointers needs to provide.