/*****************************************************************************
 * $Id: gfx_stream.hh,v 1.7 2006/08/03 02:17:21 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Streams.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#ifndef GFX_STREAM_HH
#define GFX_STREAM_HH 1

#if OLD_CC
#include <streambuf.h>		// g++ 2.9
#else
#include <streambuf>
#endif

namespace gfx {

////////////////////////////////////////////////////////////////////////////////
/// @brief Stream class that writes to two files (a confluence/fork).
/// @remarks Derived from Nicolai Josuttis's STL book.
/// @verbatim
/// Example:
///		FILE* file1 = fopen(...);
///		FILE* file2 = fopen(...);
///     StreambufFile2 streambufFile2( file1, file2 );
///     std::ostream out( &streambufFile2 );
///     out << "hello" << endl;
/// @endverbatim
class StreambufFile2 : public streambuf
{
    PREVENT_COPYING(StreambufFile2)
private:
	typedef streambuf Parent;

public:
	StreambufFile2( FILE* file1, FILE* file2, bool close1, bool close2 );
	~StreambufFile2();

protected:
	//virtual int_type overflow( int_type c );	// more proper but not understood by g++ 2.9
	virtual int			overflow( int c );
	std::streamsize		xsputn( const char* buf, std::streamsize n );

	FILE*	mFile[2];		// stream outputs to both files
	bool	mClose[2];		// true if destructor should close the file
};

} // namespace gfx

#endif // GFX_STREAM_HH
