ROSE
0.11.54.0
|
In-memory representation of a database table.
These can be used to hold results of a database table, to build a table in memory, or (mostly) for printing a table in an easy-to-read format. For instance, here's a very simple, no-frills way to print the results from a query:
Tables can also be used to operate on the results of a query. For instance, to calculate the average number of instructions and bytes per function, one could use a counting-loop-over-array paradigm, which is more comfortable to some programmers than iterators:
Tables can also accumulate the results from more than one query as long as those queries return the same number of columns and column types:
If you want headers at the top of a printed table, give the columns names like this:
It is also possible to specify a rendering for certain columns. For instance, the query above returns an address of type rose_addr_t for column #3 (column numbering is always zero-origin). If we want the address to be formatted as a zero-padded, eight character hexadecimal number with a "0x" prefix, then we could do that with code like this (building from the previous example):
If we want the headers to be printed again every 50th row, we can do that with a PrePostRow functor. These functors have row info available to them so they can do fancier things too, like printing separators between major portions of a table.
Definition at line 716 of file SqlDatabase.h.
#include <SqlDatabase.h>
Classes | |
struct | Renderers |
Functors for rendering column values. More... | |
struct | Tuple |
One row of a table. More... | |
Public Types | |
enum | { MAXCOLS =16 } |
typedef std::vector< Tuple > | Rows |
All rows of a table. More... | |
Public Member Functions | |
Table () | |
Creates a new, empty table. More... | |
Table (const StatementPtr &stmt) | |
Creates a new table and initializes it by running the specified database query. More... | |
size_t | size () const |
Return the number of rows in the table. More... | |
bool | empty () const |
Returns true if table has no rows. More... | |
void | clear () |
Clear the table by removing all rows. More... | |
void | insert (const StatementPtr &stmt) |
Insert more rows into a table by running the specified query. More... | |
template<typename T > | |
std::string | render (const Renderer< T > *r, const T &value, size_t width=0) const |
Render a single value. | |
std::vector< size_t > | colsizes () const |
Compute column widths. More... | |
void | print_headers (std::ostream &out, const std::vector< size_t > &widths) const |
Print the headers for a table. More... | |
void | print_rowsep (std::ostream &out, const std::vector< size_t > &widths) const |
Print the row separator that goes between the headers and the data. More... | |
void | print_row (std::ostream &out, const Tuple &t, const std::vector< size_t > &widths) const |
Print one row of a table. More... | |
void | print (std::ostream &out) const |
Print all rows of the table to the specified stream. More... | |
void | header (int colnum, const std::string &hdr) |
Headers to use when printing the table. | |
const std::string & | header (int colnum) const |
Headers to use when printing the table. | |
void | headers (const std::string &h0, const std::string &h1="", const std::string &h2="", const std::string &h3="", const std::string &h4="", const std::string &h5="", const std::string &h6="", const std::string &h7="", const std::string &h8="", const std::string &h9="", const std::string &h10="", const std::string &h11="", const std::string &h12="", const std::string &h13="", const std::string &h14="", const std::string &h15="") |
Headers to use when printing the table. | |
void | reprint_headers (size_t nrows) |
How often should headers be reprinted? | |
size_t | reprint_headers () const |
How often should headers be reprinted? | |
Renderers & | renderers () |
Accessor for value renderers. More... | |
const Renderers & | renderers () const |
Accessor for value renderers. More... | |
void | prepost (PrePostRow< Table > *pre, PrePostRow< Table > *post) |
Accessor for functors called before and after each row is printed. | |
std::pair< PrePostRow< Table > *, PrePostRow< Table > * > | prepost () const |
Accessor for functors called before and after each row is printed. | |
Tuple & | operator[] (size_t i) |
Return a reference to a particular row. | |
const Tuple & | operator[] (size_t i) const |
Return a reference to a particular row. | |
void | insert (const Tuple &tuple) |
Add a new row to the end of the table. | |
void | insert (const T00 &v00, const T01 &v01=T01(), const T02 &v02=T02(), const T03 &v03=T03(), const T04 &v04=T04(), const T05 &v05=T05(), const T06 &v06=T06(), const T07 &v07=T07(), const T08 &v08=T08(), const T09 &v09=T09(), const T10 &v10=T10(), const T11 &v11=T11(), const T12 &v12=T12(), const T13 &v13=T13(), const T14 &v14=T14(), const T15 &v15=T15()) |
Add a new row to the end of the table. | |
void | line_prefix (const std::string &s) |
String to print at the beginning of every line of output. | |
const std::string & | line_prefix () const |
String to print at the beginning of every line of output. | |
typedef std::vector<Tuple> SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::Rows |
All rows of a table.
Definition at line 753 of file SqlDatabase.h.
anonymous enum |
Enumerator | |
---|---|
MAXCOLS |
Maximum number of columns allowed in a table. |
Definition at line 718 of file SqlDatabase.h.
|
inline |
Creates a new, empty table.
Definition at line 756 of file SqlDatabase.h.
|
inlineexplicit |
Creates a new table and initializes it by running the specified database query.
Definition at line 759 of file SqlDatabase.h.
|
inline |
Accessor for value renderers.
Use these to change how values are displayed. For instance, if a column has values that are addresses and you want to display them with StringUtility::addrToString(), then use code like this:
The render pointer should not be deleted before the table is done being used.
Definition at line 807 of file SqlDatabase.h.
|
inline |
Accessor for value renderers.
Use these to change how values are displayed. For instance, if a column has values that are addresses and you want to display them with StringUtility::addrToString(), then use code like this:
The render pointer should not be deleted before the table is done being used.
Definition at line 808 of file SqlDatabase.h.
|
inline |
Return the number of rows in the table.
Definition at line 823 of file SqlDatabase.h.
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Returns true if table has no rows.
Definition at line 826 of file SqlDatabase.h.
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Clear the table by removing all rows.
Definition at line 829 of file SqlDatabase.h.
|
inline |
Insert more rows into a table by running the specified query.
The table is not cleared first.
Definition at line 850 of file SqlDatabase.h.
|
inline |
Compute column widths.
Column widths are computed by internally printing the rows of the table and measuring the maximum width for each column. The renderers are called with zero for the column widths.
Definition at line 879 of file SqlDatabase.h.
References SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::MAXCOLS, and SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::render().
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Print the headers for a table.
Definition at line 903 of file SqlDatabase.h.
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Print the row separator that goes between the headers and the data.
Definition at line 924 of file SqlDatabase.h.
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Print one row of a table.
Definition at line 954 of file SqlDatabase.h.
Referenced by SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print().
|
inline |
Print all rows of the table to the specified stream.
Definition at line 976 of file SqlDatabase.h.
References SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::colsizes(), SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::empty(), SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::MAXCOLS, SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print_headers(), SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print_row(), SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::print_rowsep(), and SqlDatabase::Table< T00, T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15 >::size().