List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
utl::TabularStream Class Reference

class to format data in tabular form More...

#include "utl/TabularStream.h"

Public Member Functions

void Clear ()
 
void Clear (const std::string &format)
 
template<typename T >
TabularStreamoperator<< (const T &junk)
 
TabularStreamoperator<< (const EndColumn)
 
TabularStreamoperator<< (const EndRow)
 
TabularStreamoperator<< (const HLine hl)
 
TabularStreamoperator<< (const DeleteRow)
 
std::string Str ()
 
 TabularStream (const std::string &format)
 

Private Types

typedef std::vector< TableColumnColumns
 

Private Member Functions

void CheckFirst ()
 
void MakeFormat (const std::string &format)
 
void NextColumn ()
 
void NextRow ()
 

Private Attributes

Columns fColumns
 
Columns::iterator fCurrentColumn
 
bool fMakeNewRow
 

Detailed Description

class to format data in tabular form

TabularStream tab(". r l");
tab << 3 << ".14" << endc << "bla" << endc << 1111U << endr
<< 13.07 << endc << "foobar" << endc << 22 << endr
<< 123.456 << endc << 'a' << endc << 333;
cout << tab;

gives you

3.14 bla 1111
13.07 foobar 22
123.456 a 333

Use "endc" to end filling the current cell, use "endr" to end a row. Filling the TabularStream in a for-loop will produce one "endr" too many. Use "delr" to delete the last row (useful if one line too many is added in loops). More lines around columns or rows you can add as in the following example:

TabularStream tab("|l|.|r|");
tab << hline
<< "gain" << endc << 1.23 << endc << "ok" << endr
<< HLine('=')
<< "jitter" << endc << 0.2 << endc << "+1" << endr
<< "adc" << endc << 13 << endc << "aha" << endr
<< hline;
cout << tab;

which produces

+------+-----+---+
|gain | 1.23| ok|
==================
|jitter| 0.2 | +1|
|adc |13 |aha|
+------+-----+---+

Note that every row of the table will be terminated with a newline.

In short, "endc" has the same meaning as "&" in LaTeX tabular environment, "endr" behaves as LaTeX newline "\\", and "hline" even has the same name...

Author
Darko Veberic
Date
14 Aug 2007

Definition at line 192 of file TabularStream.h.

Member Typedef Documentation

typedef std::vector<TableColumn> utl::TabularStream::Columns
private

Definition at line 275 of file TabularStream.h.

Constructor & Destructor Documentation

utl::TabularStream::TabularStream ( const std::string &  format)
inline

Definition at line 194 of file TabularStream.h.

References Clear().

Member Function Documentation

void utl::TabularStream::CheckFirst ( )
inlineprivate

Definition at line 248 of file TabularStream.h.

References fMakeNewRow, and NextRow().

Referenced by operator<<().

void utl::TabularStream::Clear ( )
inline

Definition at line 197 of file TabularStream.h.

References fColumns, and fMakeNewRow.

Referenced by Clear(), and TabularStream().

void utl::TabularStream::Clear ( const std::string &  format)
inline

Definition at line 199 of file TabularStream.h.

References Clear(), and MakeFormat().

void TabularStream::MakeFormat ( const std::string &  format)
private
void utl::TabularStream::NextColumn ( )
inlineprivate

Definition at line 257 of file TabularStream.h.

References ERROR, fColumns, and fCurrentColumn.

Referenced by operator<<().

void utl::TabularStream::NextRow ( )
inlineprivate

Definition at line 267 of file TabularStream.h.

References fColumns, and fCurrentColumn.

Referenced by CheckFirst(), and operator<<().

template<typename T >
TabularStream& utl::TabularStream::operator<< ( const T &  junk)
inline

Definition at line 204 of file TabularStream.h.

References CheckFirst(), and fCurrentColumn.

TabularStream& utl::TabularStream::operator<< ( const EndColumn  )
inline

Definition at line 211 of file TabularStream.h.

References CheckFirst(), and NextColumn().

TabularStream& utl::TabularStream::operator<< ( const EndRow  )
inline

Definition at line 214 of file TabularStream.h.

References CheckFirst(), and NextRow().

TabularStream& utl::TabularStream::operator<< ( const HLine  hl)
inline

Definition at line 218 of file TabularStream.h.

References CheckFirst(), fColumns, fCurrentColumn, fMakeNewRow, and utl::HLine::GetChar().

TabularStream& utl::TabularStream::operator<< ( const DeleteRow  )
inline

Definition at line 233 of file TabularStream.h.

References fColumns, and fMakeNewRow.

string TabularStream::Str ( )

Member Data Documentation

Columns utl::TabularStream::fColumns
private

Definition at line 277 of file TabularStream.h.

Referenced by Clear(), NextColumn(), NextRow(), and operator<<().

Columns::iterator utl::TabularStream::fCurrentColumn
private

Definition at line 276 of file TabularStream.h.

Referenced by NextColumn(), NextRow(), and operator<<().

bool utl::TabularStream::fMakeNewRow
private

Definition at line 278 of file TabularStream.h.

Referenced by CheckFirst(), Clear(), and operator<<().


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

, generated on Tue Sep 26 2023.