DGD Library
Version: 0.1.0.14 | Updated: Thu Aug 10 16:59:32 2006
Home
DGD News
FAQ
Code Documentation
DGD Installation Guide
Bugs-n-Features
DGD at Sourceforge.net
Download DGD
Subversion
Code Documentation
Documentation
Namespaces
Class Hierarchy
Class List
File List
Namespace Members
Functions
Globals
Tutorial
Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

DGD Channels - Ensuring real output

Here we go. DGD::channel makes no physical output, but makes formatting. To get the actual output we need to associate the channel with a physical stream e.g std::cout, sort of std::ofstream or any other object which is derived from std::ostream. There are three assoc() functions for making the association:
 void assoc( std::ostream* s, channel& channel );
 void assoc( std::ostream& s, channel& channel );
 void assoc( std::ostream* s, const std::string& name );

All functions make the same job, but the later one assumes existence of the DGD::Debug factory and queries the channel object from the factory by the given name.

The only remaining tricky question about associations is: what if I make more then one association of the same channel, or more then one with the same physical stream? In fact DGD makes no restrictions on what do you associate, how and when. So, for example, it is legal to associate the same channel with std::cout and std::cerr, the channel will replicate its output into both streams. It is legal to register the same channel twice with the same stream, its output will be duplicated in this stream.

There are two additional association schemes worth to be mentioned here.

It is possible to associate two different channels with the same physical stream. But in this case DGD makes no garanties on validity of the resulting stream formatting. Surely, there is other simple way to avoid the problem and allow output from multiple channels into single physical buffer.

To avoid the problem mentioned above lets remind that assoc() functions accept any std::ostream as a physical stream and DGD::chnnel itself derives from std::ostream. So, it is possible to associate DGD::channel with another DGD::channel. Te problem could be solved by associating a single channel with a physical stream and then associating multiple other channels with that first channel. The example below demonstrates the soulution.

// associate multiple channels with cout

#include <dgChannel.h>

int main( int argc, char** argv ) {
   DGD::channel base( "base" );
   DGD::assoc( std::cout, base );
   base.open();

   DGD::channel a( "channel_a" );
   DGD::assoc( base, a );
   a.open();

   DGD::channel b( "channel_b" );
   DGD::assoc( base, b );
   b.open();
   
   a << "here is channel A" << std::endl;
   b << "here is channel B" << std::endl;

   return 0;
}

Generated on Thu Aug 10 16:48:29 2006 for DGD Library by doxygen1.3

SourceForge.net Logo Powered by Mason Powered by Perl
Web design derived from Pasilda design found on www.oswd.org.
Copyright (c) 2002, 2003. Dimitry Kloper <kloper@users.sourceforge.net>