|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2003-09-25 05:55:05
On Sat, 20 Sep 2003 10:31:28 +0200, Lars Gullik Bjønnes wrote
> I see that you have a basic_nullbuf hidden in
> boost/test/detail/nullstream.hpp, it seems to me that this is a
> usefull utility stream class, and that is should be a bit more
> accessible. As it is now, I'd never use this class/file directly in
> my own projects since it is hidden in a detail dir.
I would also like to see this formalized into boost. Previously I have
written an null stream class to simplify the writing of tracing code by just
putting trace statements in the code. During debugging you pop in a regular
stream and get output. When you are done you put in the null stream and like
magic all the output disappears. If you have a logging policy on components
then you can switch in null stream when you want to suppress tracing.
My approach was a bit different in that I didn't bother with the buffer at
all, but created the ostream interface directly in hope that the compiler
could obviously optimize out any calls to the stream output. This would allow
me to insert tracing in time sensitive code and expect that when I replace it
will null ostream the code would be totally optimized away -- costing nothing
in space or time.
//The essence of the idea...
//no char templates for simplicity of illustration
class null_ostream : public std::ostream {
public:
null_ostream() {};
//various required overloads...
null_ostream& operator <<(bool)
{
return *this;
}
null_ostream& operator <<(short)
{
return *this;
}
//... and many more ....
Anyway, food for thought.
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk