Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2002-01-23 14:48:23


The marg_ostream class allows adjustment of the margin for each
output line with operator++ and operator--. It also allows specification
of the margin contents (with the marg_ostream::margin(char const*)).

Attached is test code and test output.

I've found it useful to formating code and revealing the structure
of data (e.g. a graph).

Is there any interest in adding this to boost?


#include "marg_ostream.hpp"
  int
main(void)
  { const char* line = "line"
  ; int num=0
  ; ostream& fout=cout
  ; fout<<num++<<endl
  ; fout<<line<<endl
  ; fout<<"begin marg_test"<<endl
  ; {
    ; marg_ostream mout(fout)
    ; mout<<num++<<endl
    ; mout<<"????"<<endl
    ; ++mout
    ; mout<<num++<<endl
    ; mout<<line<<endl
    ; ++mout
    ; mout.margin("xxx")
    ; mout<<num++<<endl
    ; mout<<line<<endl
    ; --mout
    ; mout<<num++<<endl
    ; mout<<"!!!"<<endl
    ; --mout
    ; mout.margin("")
    ; mout<<num++<<endl
    ; mout<<line<<endl
    ; {
      ; unsigned const n=5
      ; char const* long_line =
"1234567890123456789012345678901234567890123456789012345678901234567890"
      ; mout<<n<<" long lines="<<endl
      ; for(unsigned i=0; i<n; ++i)
        { mout<<long_line<<endl
        ;}
      ;}
    ;}
  ; fout<<"end marg_test"<<endl
  ; fout<<num++<<endl
  ; fout<<line<<endl
  ; return 0
  ;}

0
line
begin marg_test
1
????
  2
  line
 xxx3
 xxxline
xxx4
xxx!!!
5
line
5 long lines=
1234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890
end marg_test
6
line


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk