Library of Assembled Shared Sources
lass::io::ProxyOStream Class Reference

A proxy output stream can distribute output to multiple destination streams. More...

#include <proxy_o_stream.h>

Public Member Functions

 ProxyOStream (std::ostream *destination=&std::cout, TMask filterMask=acceptAll)
 Construct a proxy with a destination, and set a filter for it.
 
void add (std::ostream *destination, TMask filterMask=acceptAll)
 Add a std::ostream to the list of destination streams.
 
void remove (std::ostream *destination)
 Remove a std::ostream from the list of destination streams.
 
TMask filter (std::ostream *destination) const
 Return accept mask on destination stream.
 
void setFilter (std::ostream *destination, TMask filterMask)
 Set filter on destination stream.
 
template<typename T>
impl::ProxyOStreamLock operator<< (const T &x)
 ProxyOStreamLock proxy stream for output on 'acceptAll' and distribute input.
 
impl::ProxyOStreamLock operator<< (std::ostream &(*x)(std::ostream &))
 ProxyOStreamLock proxy stream for output on 'acceptAll' and distribute the std manipulator.
 
void flush ()
 flush all destination streams.
 

Detailed Description

A proxy output stream can distribute output to multiple destination streams.

Author
BdG
Date
2003

You can add multiple destination streams to a proxy stream, and all output to the proxy stream will be redirected to all these destinations.

You can also assign a filter to the proxy, and only messages with levels set in the filter will pass. e.g. if you set the filter of the proxy as proxy.setFilter() = 0, then only messages of warning or error levels will pass.

How do you tell what level your message has? Simple, before you use the insertor, you call the function operator on the stream with the correct level. This returns a lock on the proxy, and now you send the message to the lock (by the insertor) Wheter this message will pass or not, is determined by the lock. At the end of the lifetime of the lock, the proxy is also flushed.

proxy(Warning) << "This is a warning: " << theWarning;

In the above example, the proxy is locked in warning level, and the string and theWarning is passed to the lock. At the end, the lock flushes te proxy.

If you don't use the function operator to set the message level, the level is implicit set to ProxyOStream::Note.

OK, seriously, i have no longer any idea why we need this ... get rid of it?

Definition at line 123 of file proxy_o_stream.h.

Constructor & Destructor Documentation

◆ ProxyOStream()

lass::io::ProxyOStream::ProxyOStream ( std::ostream * destination = &std::cout,
TMask destinationMask = acceptAll )

Construct a proxy with a destination, and set a filter for it.

Construct a proxy with a destination, and set a filter for it

Definition at line 63 of file proxy_o_stream.cpp.

References add().

Member Function Documentation

◆ add()

void lass::io::ProxyOStream::add ( std::ostream * destination,
TMask destinationMask = acceptAll )

Add a std::ostream to the list of destination streams.

  • Proxy stream does NOT take ownership of destination stream, it stays your own.
  • If destination stream is already added to proxy, then it's not added again. i.e. You can safely add the same destination twice, but it will only set the mask.

Definition at line 75 of file proxy_o_stream.cpp.

Referenced by ProxyOStream(), and lass::io::Logger::subscribeTo().

◆ remove()

void lass::io::ProxyOStream::remove ( std::ostream * destination)

Remove a std::ostream from the list of destination streams.

  • Proxy stream does not deallocate destination stream, it stays your own responsibility.
  • If you try to remove a destination that's not there, nothing happens. i.e. it's safe to remove a stream that the proxy doesn't has.

Definition at line 96 of file proxy_o_stream.cpp.

Referenced by lass::io::Logger::unsubscribeTo(), and lass::io::Logger::~Logger().

◆ filter()

ProxyOStream::TMask lass::io::ProxyOStream::filter ( std::ostream * destination) const

Return accept mask on destination stream.

If destination stream does not exists in proxy, it throws an exception.

Definition at line 111 of file proxy_o_stream.cpp.

◆ setFilter()

void lass::io::ProxyOStream::setFilter ( std::ostream * destination,
TMask destinationMask )

Set filter on destination stream.

If destination stream does not exists, it throws an exception.

Definition at line 129 of file proxy_o_stream.cpp.

◆ operator<<() [1/2]

template<typename T>
impl::ProxyOStreamLock lass::io::ProxyOStream::operator<< ( const T & x)
inline

ProxyOStreamLock proxy stream for output on 'acceptAll' and distribute input.

This command will give command to a lock, as if the message mask is acceptAll. This has the same effect as (*this)(acceptAll) << x;

Definition at line 147 of file proxy_o_stream.h.

◆ operator<<() [2/2]

impl::ProxyOStreamLock lass::io::ProxyOStream::operator<< ( std::ostream &(* )(std::ostream &))

ProxyOStreamLock proxy stream for output on 'acceptAll' and distribute the std manipulator.

This command will give command to a lock, as if the message mask is acceptAll. This has the same effect as (*this)(acceptAll) << x;

Definition at line 152 of file proxy_o_stream.cpp.


The documentation for this class was generated from the following files: