tom_usenet said:
How do you manage to have cout calls in the code then? If your classes
don't implement operator<< for ostream, then cout calls won't work. Or
perhaps the cout calls only use the built in types?
Well, this is exactly the point.
There should not be any calls to cout directly, but a lot of developers
just give a damn about design rules, and exchanging them is not an option.
So something has to be done to get rid of the problem.
If I just search and replace this won't keep any of them from adding new
couts and thus this would be a never ending stuff
Well, I won't chastise you for reinventing the wheel (and making it a
bit less round than current wheel designs), but instead tell you that
you can't redirect std::cout to anything but another streambuf.
But I can (and am working on that currently) write a dummy stream class
derived from streambuf as a wrapper.
Not nice, and i just cross my fingers that this will be portable (I do
have bad experiences about such stuff, this is why we wrote as much
ourselves as possible in the first place)
Where
exactly do you want to redirect it to? You obviously can't direct it
to your stream class, but you can get it to write to the same thing
that your stream class is writing to, but creating a streambuf class
that outputs to that (note this can be unbuffered if you choose -
streambuf is a slightly misleading name).
You can supress cout output with a call to:
std::streambuf* oldcout = std::cout.rdbuf(0);
//reset before exit:
std::cout.rdbuf(oldcout);
Well, what i'll do is write a wrapper using a class derived from
streambuf and then distribute it to appropriate calls in our framework
Its not nice what I'm doing, and I am aware that such a situation should
never happen if just everyone would follow design guidelines, but if
you've ever worked in mid size projects you might know that you can't
just make everyone do what you want him to do.
with kind regards Philip