Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Related Functions
Sundance::Tabs Class Reference

Tabbing utility for output. More...

List of all members.

Public Member Functions

 Tabs (bool jump=true)
 Constructor increments tab level.
 ~Tabs ()
 Destructor decrements tab level.
void print (std::ostream &os) const
 Print to stream.

Static Public Member Functions

static void setTabSize (int ts)
 Change the tab size.
static bool & showDepth ()
 Indicate whether to print the tab depth as a header for each line.

Static Private Member Functions

static int & tabLevel ()
static int & tabSize ()

Private Attributes

bool jump_
int myLevel_

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const Tabs &t)

Detailed Description

Tabbing utility for output.

Constructing a new Tabs object automatically increments the number of tabs to be written. When the Tabs object goes out of scope, the original tabs level is restored.

The tab size and character can be specified through the setTabSize() and setTabChar() methods, for example,

 Tabs::setTabChar('*');
 Tabs::setTabSize(4);

The tab character can be set on an object-by-object basis through a constructor argument.

By default, a header giving the depth of tabs is written to each line; this can simplify scanning by eye for when a given tab level is reached. This header can be turned off by calling

 Tabs::showDepth() = false;

Example: the code

 void f()
 {
   Tabs tab;
   cout << tab << "in f()" << std::endl;
   g();
   cout << tab << "leaving f()" << std::endl;
 }

 void g()
 {
   Tabs tab0;
   cout << tab0 << "in g()" << std::endl;
   for (int i=0; i<3; i++)
     {
       Tabs tab1();
       cout << tab1 << "i=" << i << std::endl;
     }
   cout << tab0 << "leaving g()" << std::endl;
 }

writes the following output

 [0]  in f()
 [1]    in g()
 [2]------i=0
 [2]------i=1
 [2]------i=2
 [1]    leaving g()
 [0]  leaving f()

Definition at line 92 of file SundanceTabs.hpp.


Constructor & Destructor Documentation

Tabs::Tabs ( bool  jump = true)

Constructor increments tab level.

Definition at line 36 of file SundanceTabs.cpp.

References myLevel_, and tabLevel().

Tabs::~Tabs ( )

Destructor decrements tab level.

Definition at line 43 of file SundanceTabs.cpp.

References jump_, and tabLevel().


Member Function Documentation

void Tabs::print ( std::ostream &  os) const
static void Sundance::Tabs::setTabSize ( int  ts) [inline, static]

Change the tab size.

Default is 2.

Definition at line 108 of file SundanceTabs.hpp.

References tabSize().

static bool& Sundance::Tabs::showDepth ( ) [inline, static]

Indicate whether to print the tab depth as a header for each line.

Definition at line 111 of file SundanceTabs.hpp.

Referenced by print().

static int& Sundance::Tabs::tabLevel ( ) [inline, static, private]

Definition at line 115 of file SundanceTabs.hpp.

Referenced by print(), Tabs(), and ~Tabs().

static int& Sundance::Tabs::tabSize ( ) [inline, static, private]

Definition at line 118 of file SundanceTabs.hpp.

Referenced by print(), and setTabSize().


Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  os,
const Tabs t 
) [related]

stream insertion operator for tab

Definition at line 129 of file SundanceTabs.hpp.

References print().


Member Data Documentation

bool Sundance::Tabs::jump_ [private]

Definition at line 120 of file SundanceTabs.hpp.

Referenced by ~Tabs().

int Sundance::Tabs::myLevel_ [private]

Definition at line 122 of file SundanceTabs.hpp.

Referenced by print(), and Tabs().

Site Contact