|
Boost : |
From: Patrick Bennett (patrick.bennett_at_[hidden])
Date: 2004-03-18 22:19:20
Darren Cook wrote:
> The problem comes when I have a function that takes an ostream; then I
> have to expose the internals:
>
> LOG("Here is data:");LOG(obj->debug_info(*logfile,true,false));
>
> Is there a better way?
>
Yes,
#define SOME_LOG_MACRO( MiscParams) \
if ( ! ShouldLog( MiscParams) ) \
{ /* Don't execute, or log anything */ \
} \
else /* create something that returns an ostream& derived
instance */ (MiscParams).GetStream ()
You can then use:
SOME_LOG_MACRO( xxx) << "foo:" << foo << " bar:" << bar;
and it will only execute the << methods if logging is enabled, or if
it's necessary based on whatever you define. Plus, the streamed data
doesn't have to be included in the macro as a parameter.
Cheers...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk