Container for tabulated data suitable for reading/writing to delimited text files. More...
#include <mbl_table.h>
Public Member Functions | |
mbl_table (const char delim='\t') | |
Constructor. | |
mbl_table (const char delim, const vcl_vector< vcl_string > &headers) | |
Constructor. | |
unsigned | num_cols () const |
Return the number of columns. | |
unsigned | num_rows () const |
Return the number of rows. | |
bool | get_column (const vcl_string &header, vcl_vector< double > &column) const |
Get the column of data corresponding to a particular heading. | |
bool | column_exists (const vcl_string &header) const |
Returns true if column exists. | |
bool | get_row (const unsigned &r, vcl_vector< double > &row) const |
Get a specified row of data. | |
void | get_column_headers (vcl_vector< vcl_string > &headers) const |
Get the list of column headers (in column order). | |
bool | append_column (const vcl_string &header, const vcl_vector< double > &column) |
Append a column of data with its own heading. | |
bool | append_column (const vcl_string &header, const double val=0) |
Append an empty column with its own heading. | |
bool | append_row (const vcl_vector< double > &row) |
Append a row of data. | |
bool | append_row (const double val=0) |
Append an empty row. | |
bool | set_element (const vcl_string &header, const unsigned r, const double value) |
Set the value of an existing element. | |
double | get_element (const vcl_string &header, const unsigned r, bool *success=0) const |
Get the value of an existing element. | |
bool | read (vcl_istream &is) |
Load this table's data from specified text stream. | |
void | write (vcl_ostream &os) const |
Save this table's data to specified text stream. | |
bool | subtable (mbl_table &new_table, const vcl_vector< vcl_string > &headers) const |
Create a new table of subset of columns defined by headers. | |
bool | operator== (const mbl_table &rhs) const |
Is another table identical to this one?. | |
bool | operator!= (const mbl_table &rhs) const |
Is another table different from this one?. | |
Static Public Member Functions | |
static void | set_tolerance (const double &tol, const bool &fract=false) |
Set the tolerance used to determine whether table entries are equal. | |
static void | set_verbosity (const int &v) |
Set the level of verbosity used for error output. | |
Protected Member Functions | |
bool | read_delimited_string (vcl_istream &is, vcl_string &str, bool &eol, bool &eof) |
Read a series of characters from the stream until a delimiter character or eol. | |
Protected Attributes | |
char | delimiter_ |
The character delimiting each column. | |
vcl_vector< vcl_string > | column_headers_ |
The column headers (in order). | |
vcl_map< vcl_string, unsigned > | header_to_column_index_ |
Map a column header string to column index. | |
vcl_vector< vcl_vector< double > > | columns_ |
The table data, arranged as column vectors of double data. |
Container for tabulated data suitable for reading/writing to delimited text files.
Table comprises a number of columns of double-precision data. Each column is headed by a text string (which may contain whitespace but not end-of-line). Column headers must be unique. Columns are separated by a delimiter character (e.g. "\t"). The delimiter character must not occur in any of the entries! The delimiter character is optional at the end of a row. Each row must be terminated by an end-of-line (including the last row). Each column of data is stored as a vector of doubles and associated with the column header string.
Definition at line 24 of file mbl_table.h.
mbl_table::mbl_table | ( | const char | delim = '\t' | ) |
mbl_table::mbl_table | ( | const char | delim, |
const vcl_vector< vcl_string > & | headers | ||
) |
Constructor.
delim | The delimiter character. |
headers | The column headers (in order). |
Definition at line 34 of file mbl_table.cxx.
bool mbl_table::append_column | ( | const vcl_string & | header, |
const vcl_vector< double > & | column | ||
) |
Append a column of data with its own heading.
header | String identifying the column. |
column | A vector containing the values of the column. |
Definition at line 236 of file mbl_table.cxx.
bool mbl_table::append_column | ( | const vcl_string & | header, |
const double | val = 0 |
||
) |
Append an empty column with its own heading.
header | String identifying the column. |
val | Default value to initialize all elements of the new column. |
Definition at line 270 of file mbl_table.cxx.
bool mbl_table::append_row | ( | const vcl_vector< double > & | row | ) |
Append a row of data.
row | A vector containing the values of the new row. |
Definition at line 297 of file mbl_table.cxx.
bool mbl_table::append_row | ( | const double | val = 0 | ) |
Append an empty row.
val | Default value to initialize all elements of the new row. |
Definition at line 322 of file mbl_table.cxx.
bool mbl_table::column_exists | ( | const vcl_string & | header | ) | const |
Returns true if column exists.
Definition at line 76 of file mbl_table.cxx.
bool mbl_table::get_column | ( | const vcl_string & | header, |
vcl_vector< double > & | column | ||
) | const |
Get the column of data corresponding to a particular heading.
header | String identifying the desired column. |
column | A vector containing the values of the requested column. |
Definition at line 88 of file mbl_table.cxx.
void mbl_table::get_column_headers | ( | vcl_vector< vcl_string > & | headers | ) | const |
Get the list of column headers (in column order).
headers | The list of column headers. |
Definition at line 146 of file mbl_table.cxx.
double mbl_table::get_element | ( | const vcl_string & | header, |
const unsigned | r, | ||
bool * | success = 0 |
||
) | const |
Get the value of an existing element.
header | The string identifying the column of interest. |
r | The row index of the element of interest. |
success | If provided, will be used to indicate whether the specified element existed. |
Definition at line 194 of file mbl_table.cxx.
bool mbl_table::get_row | ( | const unsigned & | r, |
vcl_vector< double > & | row | ||
) | const |
Get a specified row of data.
r | Index of the desired row. |
row | A vector containing the values of the requested row. |
Definition at line 117 of file mbl_table.cxx.
unsigned mbl_table::num_cols | ( | ) | const |
Return the number of columns.
Definition at line 55 of file mbl_table.cxx.
unsigned mbl_table::num_rows | ( | ) | const |
Return the number of rows.
Definition at line 64 of file mbl_table.cxx.
bool mbl_table::operator!= | ( | const mbl_table & | rhs | ) | const |
Is another table different from this one?.
Definition at line 593 of file mbl_table.cxx.
bool mbl_table::operator== | ( | const mbl_table & | rhs | ) | const |
Is another table identical to this one?.
Definition at line 501 of file mbl_table.cxx.
bool mbl_table::read | ( | vcl_istream & | is | ) |
Load this table's data from specified text stream.
Any existing data is lost.
Definition at line 338 of file mbl_table.cxx.
bool mbl_table::read_delimited_string | ( | vcl_istream & | is, |
vcl_string & | str, | ||
bool & | eol, | ||
bool & | eof | ||
) | [protected] |
Read a series of characters from the stream until a delimiter character or eol.
is | The input stream. |
str | The string which was read. |
eol | Whether the stream is at end-of-line after reading the string. |
eof | Whether the stream is at end-of-file after reading the string. |
Definition at line 456 of file mbl_table.cxx.
bool mbl_table::set_element | ( | const vcl_string & | header, |
const unsigned | r, | ||
const double | value | ||
) |
Set the value of an existing element.
header | The string identifying the column to be modified. |
r | The row index of the element to be modified. |
value | The new value to use for the modified element. |
Definition at line 155 of file mbl_table.cxx.
void mbl_table::set_tolerance | ( | const double & | tol, |
const bool & | fract = false |
||
) | [static] |
Set the tolerance used to determine whether table entries are equal.
tol | The tolerance should be a small positive number, eg 1e-19. |
frac | Whether the tolerance is applied as a fractional difference. |
Definition at line 602 of file mbl_table.cxx.
void mbl_table::set_verbosity | ( | const int & | v | ) | [static] |
Set the level of verbosity used for error output.
v | The verbosity should be a small integer, eg -3 to 3. Larger values cause more detailed output. Default level is 0. |
Definition at line 613 of file mbl_table.cxx.
bool mbl_table::subtable | ( | mbl_table & | new_table, |
const vcl_vector< vcl_string > & | headers | ||
) | const |
Create a new table of subset of columns defined by headers.
Create a new table with as subset of columns defined by headers.
new_table | a subtable |
headers | subset of column headers |
Definition at line 425 of file mbl_table.cxx.
void mbl_table::write | ( | vcl_ostream & | os | ) | const |
Save this table's data to specified text stream.
Definition at line 398 of file mbl_table.cxx.
vcl_vector<vcl_string> mbl_table::column_headers_ [protected] |
The column headers (in order).
Definition at line 193 of file mbl_table.h.
vcl_vector<vcl_vector<double> > mbl_table::columns_ [protected] |
The table data, arranged as column vectors of double data.
Definition at line 199 of file mbl_table.h.
char mbl_table::delimiter_ [protected] |
The character delimiting each column.
Definition at line 190 of file mbl_table.h.
vcl_map<vcl_string, unsigned> mbl_table::header_to_column_index_ [protected] |
Map a column header string to column index.
Definition at line 196 of file mbl_table.h.