library of assembled shared sources

http://lass.cocamware.com

lass::io::ProxyOStream Class Reference

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

#include <proxy_o_stream.h>


Data Structures

class  Lock

Public Types

typedef unsigned TMask

Public Member Functions

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

Static Public Attributes

static const TMask acceptAll = static_cast<TMask>(-1)

Private Types

typedef std::map< std::ostream
*, TMask
TDestinations

Private Attributes

TDestinations destinations_

Friends

class Lock


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 94 of file proxy_o_stream.h.


Member Typedef Documentation

Definition at line 98 of file proxy_o_stream.h.

typedef std::map<std::ostream*, TMask> lass::io::ProxyOStream::TDestinations [private]

Definition at line 220 of file proxy_o_stream.h.


Constructor & Destructor Documentation

lass::io::ProxyOStream::ProxyOStream ( std::ostream *  iDestination = &std::cout,
TMask  iMessageMask = 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.


Member Function Documentation

void lass::io::ProxyOStream::add ( std::ostream *  iDestination,
TMask  iMessageMask = 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 nothing will happen, it will appear only once in the proxy (and some word to the log will be written).

Definition at line 76 of file proxy_o_stream.cpp.

References destinations_, and LASS_WARNING.

Referenced by lass::io::Logger::subscribeTo().

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

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 97 of file proxy_o_stream.cpp.

References destinations_, and LASS_WARNING.

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

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

Return accept mask on destination stream.

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

Definition at line 116 of file proxy_o_stream.cpp.

References destinations_, and LASS_THROW.

void lass::io::ProxyOStream::setFilter ( std::ostream *  iDestination,
TMask  iFilterMask 
)

Set filter on destination stream.

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

Definition at line 133 of file proxy_o_stream.cpp.

References destinations_, and LASS_THROW.

ProxyOStream::Lock lass::io::ProxyOStream::operator() ( TMask  iFilterMask = acceptAll  ) 

Definition at line 147 of file proxy_o_stream.cpp.

References Lock.

template<typename T >
Lock lass::io::ProxyOStream::operator<< ( const T &  iIn  )  [inline]

Lock 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) << iIn;

Definition at line 196 of file proxy_o_stream.h.

Lock lass::io::ProxyOStream::operator<< ( std::ostream &(*)(std::ostream &)  iIn  )  [inline]

Lock 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) << iIn;

Definition at line 207 of file proxy_o_stream.h.

void lass::io::ProxyOStream::flush (  ) 

flush all destination streams.

Definition at line 156 of file proxy_o_stream.cpp.

References destinations_.


Friends And Related Function Documentation

friend class Lock [friend]

Definition at line 218 of file proxy_o_stream.h.

Referenced by operator()().


Field Documentation

const TMask lass::io::ProxyOStream::acceptAll = static_cast<TMask>(-1) [static]

Definition at line 99 of file proxy_o_stream.h.

Definition at line 222 of file proxy_o_stream.h.

Referenced by add(), filter(), flush(), remove(), and setFilter().


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

Generated on Mon Nov 10 14:22:09 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo