Boost logo

Boost :

Subject: Re: [boost] [iostreams]ANNOUNCE:indent_filtering_ostream.zip in vault
From: dherring_at_[hidden]
Date: 2010-01-12 12:29:14


On Mon, 11 Jan 2010, vicente.botet wrote:
> From: "Larry Evans" <cppljevans_at_[hidden]>
>>
>> The .zip file in subject is here:
>>
>> http://www.boostpro.com/vault/index.php?&directory=Input%20-%20Output
>>
>> It includes a boost/iostreams/filter/indent.hpp and
>> boost/iostreams/utility/indent_filtering_ostream.hpp.
>>
>> The latter uses the former to allow indenting and undenting
>> a stream.
>
> On the example I see that the ++ and -- are not pairwised.
> int main(void)
> {
> boost::iostreams::indent_filtering_ostream<> mout(std::cout);
> mout<<"line1\n";
> + ++mout;
> mout<<"line1.1"<<std::endl;
> + ++mout;
> mout<<"line1.1.1"<<std::endl;
> test_conversion(mout);
> - --mout;
> unsigned u=22;
> mout<<"line1.2:unsigned="<<u<<std::endl;
> float f=3.1416;
> mout<<"line1.3:float="<<f<<std::endl;
> - --mout;
> - --mout;
> mout<<"line2\n";
> return 0;
> }

I wrote a similar utility, but made different tradeoffs. The basic usage
looks like

Indentation nl; // takes optional max depth and depth/level params
Indentation::Indent in(nl); // could have used a reference notation
Indentation::Outdent out(nl);
std::ostream os;
os << nl "class x
    << nl << '{' << in /* or nl.in */
    << nl << "int x;"
    << nl << "int y;" << out
    << nl << "};"

Rationale:
- operator++ and operator-- don't mix "as expected" with operator<<
- distinguishes between indenting and normal newlines
- possible to maintain several indentation systems

Later,
Daniel


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