Boost logo

Boost :

From: vonosan (alnsn_at_[hidden])
Date: 2001-12-13 09:34:36


Thank you David,
I started to read these threads and I'll continue later.
I want to note that many problems arise when mixing format
functionality with ostream functionality. I think they shouldn't mix.
First you format and then output result to ostream. Operator << can
be used without any troubles in this case. In one posted message I
read that operator<< is reserved for ostream functionality. IMO, it's
not true, "interaction" between the outputed object and ostream is
reserved! Such "interaction" is defined between my formatter and
formatted object (which is actually redirect output to ostringstream,
possibly several times).
Ok, let me briefly describe the format I used. Two different forms
exist: single param and param block (I'm not strong in English, you
are welcome to improve that names).
Single param is single percent sign followed by sequence of digits,
for example %0 or %123456789. First non-digit character outputed as-
is. Double percent outputed as single percent is usual.
Block param enclosed in curl brackets and has such specification:
{ ['/' fill_char ] [ width ] [.[precision]] [flags] param_sequence }
where flags are letters having the same same effect as ostream
manipulators:
letter ostream manips
----------------------
l left
r right
i internal
d dec
x hex
X hex, uppercase
o oct
g setf ( ios_base::fmtflags (), ios_base::floatfield )
f fixed
e scientific
E scientific, uppercase
a boolalpha
b showbase
p showpoint
+ showpos
u uppercase

param_sequence is sorted sequence of one or more parameters (for
example %0%1%4). Normally, there should be exactly one parameter.
Additional params can be used for manipulators. Example:
formatter fmt ( "{%0%1}, {%0%2}!" );
  fmt << my_manip // my_manip is user defined manipulator
      << "Hello"
      << "world";
  string str = fmt.str ();
  cout << str << endl;

It is equvalent to this code:
  cout << my_manip // %0
       << "Hello" // %1
       << ", "
       << my_manip // %0
       << "world" // %2
       << '!';
  cout << endl;

Unfortunately, I'll go offline till Monday.


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