table.3bobcat

Langue: en

Version: 324858 (ubuntu - 08/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

FBB::Table - Generates row- or column-wise filled tables

SYNOPSIS

#include <bobcat/table>
Linking option: -lbobcat

DESCRIPTION

FBB::Table objects may be used to create tables. The tables are filled either column-wise or row-wise. Many of the table's characteristics may be fine-tuned by a separate FBB::TableSupport object, described in a separate man-page (TableSupport(3bobcat)). When no FBB::TableSupport object is used, a plain row-wise or column-wise table will be constructed which can be inserted into a std::ostream.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

std::ostringstream - Table inherits from std::ostringstream, allowing insertions into a Table object. Each separate insertion adds another element to the Table object.

ENUMERATIONS

The following enumerations are defined in the class FBB::TableSpec, allowing the programmer to specifiy values like FBB::TableSpec::Vertical rather than FBB::Table<std::istream_const_iterator>::Vertical.

enum FillDirection
This enumeration holds two values:

o
ROWWISE:
When this value is specified at construction time, elements are added row-wise to the table. I.e., the second element inserted into the Table will be found in the second column of the first row.
o
COLUMNWISE:
When this value is specified at construction time, elements are added column-wise to the table. I.e., the second element will be found in the second row of the first column.

enum WidthType
This enumeration holds two values:

o
COLUMNWIDTH:
This value may be specified when the columns should be allowed variable widths. In this case each column will be as wide as its widest element. This is the default WidthType used by Table objects.
o
EQUALWIDTH:
This value may be specified when all the table's columns should have equal width (i.e., equal to the width of the widest table element),

CONSTRUCTORS

o
Table(size_t nColumns, Table::FillDirection direction, Table::WidthType widthType = Table::COLUMNWIDTH):
This constructor expects the table's number of columns. The number of rows are implied by the combination of this parameter and the number of elements that will be inserted into the Table object. The direction parameter specifies the way new elements will be added to the Table object: row-wise or column-wise. Finally, the widthType parameter is used to specify the way the width of the table's columns is determined: each column may either have its own width or all columns will have equal widths.
o
Table(TableSupport &tableSupport, Table::FillDirection direction, Table::WidthType widthType = Table::COLUMNWIDTH):
This constructor operates identically to the previous constructor, but expects an additional reference to a TableSupport object. A TableSupport object offers additional formatting features used by the table to define elements like horizontal lines between rows, additional separators between elements etc. Note that the TableSupport object is passed as a non-const reference as the Table object must be able to manipulate its data. The copy constructor is not available.

OVERLOADED OPERATORS

o
std::ostream &operator<<(std::ostream &str, Table &table):
This operator inserts a Table into a std::ostream object. Note that this operator requires a non-const table as it may have to fill out a table with empty elements (i.e., empty strings) to obtain a fully rectangular table.
o
Table &operator<<(Table &obj, Align const &align):
This operator is used to change the default alignment of either a column or an element. It is a wrapper around the member setAlign() (see below for its description). By default, all elements are right-aligned.
o
Table &operator<<(Table &obj, Type const &x):
This overloaded operator is defined as a template: Type is a template type parameter instantiated to a type for which std::ostringstream insertions are possible. It inserts the value/object x into the Table's std::ostringstream base class object as the next element of the table. The overloaded assignment operator is not available.

MEMBER FUNCTIONS

o
Table &append(std::string const &text char const *sep = " \t", bool addEmpty = false):
This member adds all fields in text separated by one of the characters in sep as additional elements to the Table object. Empty fields are ignored unless the parameter addEmpty is initialized to true.
o
void clear():
This member clears the table. All existing elements are removed, and the table will be empty.
o
void fill(InputIterator begin, InputIterator end):
This member is defined as a template; InputIterator is a template type parameter representing any input iterator. It can also be, e.g., a pointer to an insertable type. The iterators must point to data elements which can be inserted into an std::ostream. The range of values implied by the member's iterator pair are inserted into the table as new elements.
o
void push_back(std::string const &element):
This member can be used to add another element to the table (it is also called from a back_inserter adaptor).
o
size_t nRows():
This member returns the currently available number of rows in the table. Its value is only defined after calling def().
o
Table &setAlign(Align const &align):
This member is used to specify the alignment of either a column or an element of the Table object. The standard alignments std::left, std::right and std::internal may be specified, but in addition the alignment FBB::center may be used if elements should be centered into their column. A construction like
 tab << Align(2, FBB::center)
 
requests centering of all elements in table column having index value 2 (i.e., the table's 3rd column), whereas a construction like
 tab << Align(2, 3, FBB::center)
 
requests centering of element [2][3]. It is the responsibility of the programmer to ensure that such elements exist. By default, all elements are right-aligned.
o
Table &def():
This member may be used to `complete' a Table object to a full rectangular object, for which all column widths and alignments have been determined. It is implied by operator<<(ostream, Table). In other situations it may be called explicitly to force the insertion of another row in a table using ROWWISE insertions. With COLUMNWISE insertions its working is complex, since new elements added to a COLUMNWISE filled table will reshuffle its elements over the table's columns.

MANPULATORS

o
Table &def(Table &table):
This manipulator can be inserted into a table to call the table's def() member.

EXAMPLE

 #include <iostream>
 #include <iomanip>
 #include <string>
 #include <algorithm>
 
 #include <bobcat/fnwrap1c>
 #include <bobcat/table>
 
 using namespace std;
 using namespace FBB;
 
 class Support: public TableSupport
 {
     public:
 //        virtual void hline(size_t row) const;
         virtual void vline(size_t col) const;
         virtual void vline() const;
     private:
 //        static void outLine(Element const &element, ostream &out);
 };
 
 //void Support::hline(size_t row) const
 //{
 //    if (row == 0 || row == nRows())
 //        out() << setfill('-') << setw(width()) << "-" << setfill(' ');
 //    else  
 //    {
 //        const_iterator fieldIt = begin(row);
 //
 //        if (fieldIt == end())
 //            return;
 //
 //        for_each(fieldIt, end(), 
 //                FnWrap1c<Element const &, ostream &>(outLine, out()));
 //    }
 //    out() << endl;
 //}
 //
 //void Support::outLine(Element const &element, ostream &out)
 //{
 //    if (element.width == 0)
 //        return;
 //
 //    if (element.type == SKIP)
 //        out << setw(element.width) << " ";
 //    else
 //        out << setfill('-') << setw(element.width) << "-" << setfill(' ');
 //}
 //
 void Support::vline(size_t col) const
 {
     if (col < sep().size())
         out() << sep()[col];
 }
 
 void Support::vline() const
 {
     vline(nColumns());
     out() << "\n";
 }
 
 
 int main(int argc, char **argv)
 {
     Support support;
 
     support << 0 << " | " << " | ";
 
     support << Support::HLine(1, 1, 3); // row[1] separator for cols 1 and 2
 
     Table tab(support, 3, Table::ROWWISE, Table::EQUALWIDTH);
 //    Table tab(support, 3, Table::ROWWISE);
  
     tab << Align(0, std::left);     // set column non-default alignment
     tab.fill(argv + 1, argv + argc);// fill range of values
     cout << tab << endl;            // complete the table and insert
  
     tab << "hello" << "" << "wo";   // add additional elements.
     if (tab.nRows() > 2)
         tab << Align(2, 2, center); // set the layout of a specific element
  
     cout << tab << endl;
 
     return 0;
 }
 
 

FILES

bobcat/table - defines the class interface;

SEE ALSO

bobcat(7), align(3bobcat), manipulator(3bobcat), tablesupport(3bobcat)

BUGS

Note that def() will reshuffle elements over the table's columns when new elements are added to the table subsequent to calling def()

DISTRIBUTION FILES

o
bobcat_2.00.1-x.dsc: detached signature;
o
bobcat_2.00.1-x.tar.gz: source archive;
o
bobcat_2.00.1-x_i386.changes: change log;
o
libbobcat1_2.00.1-x_i386.deb: debian package holding the libraries;
o
libbobcat1-dev_2.00.1-x_i386.deb: debian package holding the libraries, headers and manual pages;
o
http://sourceforge.net/projects/bobcat: public archive location;

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).