C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdx::FormattedPageOstream Class Reference

This class helps a user easily format console output. It provides facilities for left hand margins, indentation, vertical separators, fixed width wrap around, and hanging indents. Note that arbitrary flushes (ie using flush instead of endl) can cause weird formatting results when mixed with a non-zero fixed width.

 vector<int> intVec(100);
 stdx::generate( iseq(intVec), genSeq<int>(0,1) );  
 
 stdx::AlignedNameValuePairs pairSeq;
 pairSeq.addPair( "name",     "test-list" ); 
 pairSeq.addPair( "int-list", stdx::iseq(intVec) );
 
 stdx::FormattedPageOstream fpout(cout);
 fpout.setLeftMargin(1);
 fpout.enableOpenCloseSep();
 fpout.setFixedWidth(40);
 fpout.setIndentUnit(2);
 fpout.setHangingIndentChars(":");
 
 fpout << separator('=');
 fpout << "Section Three" << stdx::nl;
 fpout << separator('-') << separator();
 fpout << inc_indent;
 
 fpout << separator() << iseq(intVec) << stdx::nl << separator();
 fpout << separator() << pairSeq << separator();
 
 fpout << dec_indent;
 fpout << separator('-');

This code produces the following output:


 =======================================
 Section Three
 ---------------------------------------

   0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
   11, 12, 13, 14, 15, 16, 17, 18, 19, 
   20, 21, 22, 23, 24, 25, 26, 27, 28, 
   29, 30, 31, 32, 33, 34, 35, 36, 37, 
   38, 39, 40, 41, 42, 43, 44, 45, 46, 
   47, 48, 49, 50, 51, 52, 53, 54, 55, 
   56, 57, 58, 59, 60, 61, 62, 63, 64, 
   65, 66, 67, 68, 69, 70, 71, 72, 73, 
   74, 75, 76, 77, 78, 79, 80, 81, 82, 
   83, 84, 85, 86, 87, 88, 89, 90, 91, 
   92, 93, 94, 95, 96, 97, 98, 99

   name     : test-list
   int-list : 0, 1, 2, 3, 4, 5, 6, 7, 
              8, 9, 10, 11, 12, 13, 14, 
              15, 16, 17, 18, 19, 20, 
              21, 22, 23, 24, 25, 26, 
              27, 28, 29, 30, 31, 32, 
              33, 34, 35, 36, 37, 38, 
              39, 40, 41, 42, 43, 44, 
              45, 46, 47, 48, 49, 50, 
              51, 52, 53, 54, 55, 56, 
              57, 58, 59, 60, 61, 62, 
              63, 64, 65, 66, 67, 68, 
              69, 70, 71, 72, 73, 74, 
              75, 76, 77, 78, 79, 80, 
              81, 82, 83, 84, 85, 86, 
              87, 88, 89, 90, 91, 92, 
              93, 94, 95, 96, 97, 98, 
              99

 ---------------------------------------

 

List of all members.

Public Methods

Constructors and Destructors
Accessor Functions
Mutator Functions

Detailed Documentation

Constructor & Destructor Documentation

stdx::FormattedPageOstream::FormattedPageOstream std::ostream &    os
 

Member Function Documentation

std::ostream& stdx::FormattedPageOstream::getWrappedStream   const
 

virtual FormattedPageStreambuf* stdx::FormattedPageOstream::rdbuf   const [virtual]
 

void stdx::FormattedPageOstream::addSeparator char    c = '\0'
 

character) are _not_ duplicated. Why do we want this? Assume we want to write several functions where each one outputs a bunch of lines of stuff. To keep each functions output separate from others we probably want an extra newline before and after the function output. Now assume we call a bunch of these functions consecutively: the result will be one newline at the top, two newlines between each function's output and then one newline at the bottom. This can be a little ugly and using addSeparator eliminates the duplicate vertical separators.

void stdx::FormattedPageOstream::setIndentUnit int    numSpaces
 

Change the current indent unit to the given numSpaces. The indent level times the indent unit is the number of spaces currently being used for indentation.

void stdx::FormattedPageOstream::setIndentLevel int    indentLevel
 

Set the indentation level to an absolute number. The give indentLevel should be positive.

void stdx::FormattedPageOstream::incIndent  
 

Increases the current indent level by one. The indent level times the indent unit is the number of spaces currently being used for indentation.

void stdx::FormattedPageOstream::decIndent  
 

Decreases the current indent level by one. The indent level times the indent unit is the number of spaces currently being used for indentation.

void stdx::FormattedPageOstream::enableOpenCloseSep  
 

Enables an initial and final newline bracketing all output to the formatted page stream.

void stdx::FormattedPageOstream::setLeftMargin int    leftMargin
 

Changes the left margin. The left margin is always part of the displayed left hand space regardless of indent level. The left margin must be non-negative.

void stdx::FormattedPageOstream::setFixedWidth int    fixedWidth
 

Set the fixed width of the output stream. If a line is longer than this, that line will be word wrapped appropriately so that it fits within the given fixed width. Single words which are longer than the fixed width can cause weird formatting output. The fixedWidth must be non-negative and less than 1000. A fixed width of zero means that the current page has no fixed width.

void stdx::FormattedPageOstream::setHangingIndentChars const std::string &    hangingIndentChars
 

Set characters which to use as indicating hanging indent location. The fixed width must be non-zero for this to have any effect. For example, assume the hangingIndentChars is set to ":=" and that we output a very long line with a ':' in character position 10 and a '=' in character position 20. Then when the long line word wraps, the word wrapped lines will begin in position 12 (the extra 2 characters make things look nice for the majority of cases when there are spaces around the hanging indent character). The ':' is ignored since it is not the first hanging indent character on the line. An example is below:

 vector<int> intVec(100);
 stdx::generate( iseq(intVec), genSeq<int>(0,1) );  
 
 stdx::FormattedPageOstream fpout(cout);
 fpout.setFixedWidth(40);
 fpout.setHangingIndentChars(":");
 
 fpout << "int-list : " << pairSeq;

This code produces the following output:

 int-list : 0, 1, 2, 3, 4, 5, 6, 7, 
            8, 9, 10, 11, 12, 13, 14, 
            15, 16, 17, 18, 19, 20, 
            21, 22, 23, 24, 25, 26, 
            27, 28, 29, 30, 31, 32, 
            33, 34, 35, 36, 37, 38, 
            39, 40, 41, 42, 43, 44, 
            45, 46, 47, 48, 49, 50, 
            51, 52, 53, 54, 55, 56, 
            57, 58, 59, 60, 61, 62, 
            63, 64, 65, 66, 67, 68, 
            69, 70, 71, 72, 73, 74, 
            75, 76, 77, 78, 79, 80, 
            81, 82, 83, 84, 85, 86, 
            87, 88, 89, 90, 91, 92, 
            93, 94, 95, 96, 97, 98, 
            99
 


The documentation for this class was generated from the following file:
Generated on Mon Aug 15 21:43:09 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002