Classes | Public Member Functions | Public Attributes | Protected Attributes

chomp::homology::outputstream Class Reference

This class defines an output stream for replacing the standard 'cout'. More...

#include <textfile.h>

List of all members.

Classes

struct  mute
 Local mute of the stream. More...

Public Member Functions

 outputstream (std::ostream &_out=std::cout, bool _show=true, bool _flush=false)
 The default constructor.
 ~outputstream ()
 The destructor.
void logfile (const char *filename)
 Turns on logging to a file.
void logfile (const outputstream &other)
 Turns on logging to the same file as some other stream.
std::ofstream * getlogstream (void)
 Returns a pointer to the stream which is working as a log file.
void keepforever (void)
 Makes this stream keep the allocated file open for ever, and not close it even in the destructor.

Public Attributes

bool show
 If this variable is set to true then everything that is written to this stream is also written to 'cout'.
bool log
 If this variable is set to true then everything that is written to this stream is also written to the log file.
bool flush
 If this variable is set to true then both the output stream 'cout' and the log file are flashed after every write operation.
std::ostream & out
 A reference to the main output stream bound with this stream.

Protected Attributes

std::ofstream * logstream
 A pointer to the log file stream.
bool copied
 This variable is set to true if this log file pointer was copied from another output stream, and therefore it should not be deleted by this stream.

Detailed Description

This class defines an output stream for replacing the standard 'cout'.

It has the additional features of flushing the output after every operation, suppressing the output, or logging the output to a file.

Definition at line 64 of file textfile.h.


Constructor & Destructor Documentation

chomp::homology::outputstream::outputstream ( std::ostream &  _out = std::cout,
bool  _show = true,
bool  _flush = false 
) [inline]

The default constructor.

Definition at line 138 of file textfile.h.

References copied, flush, log, logstream, and show.

                    : out (_out)
{
        show = _show;
        flush = _flush;
        log = false;
        logstream = NULL;
        copied = false;
        return;
} /* outputstream::outputstream */

chomp::homology::outputstream::~outputstream (  )  [inline]

The destructor.

Definition at line 182 of file textfile.h.

References copied, and logstream.

{
        if (!copied && logstream)
                delete logstream;
        return;
} /* outputstream::~outputstream */


Member Function Documentation

std::ofstream * chomp::homology::outputstream::getlogstream ( void   )  [inline]

Returns a pointer to the stream which is working as a log file.

Returns 0 if no such stream is bound with this output stream.

Definition at line 189 of file textfile.h.

References logstream.

{
        return logstream;
} /* outputstream::getlogstream */

void chomp::homology::outputstream::keepforever ( void   )  [inline]

Makes this stream keep the allocated file open for ever, and not close it even in the destructor.

It is assumed then that the file will be closed automatically by the operating system.

Definition at line 194 of file textfile.h.

References copied.

{
        copied = true;
        return;
} /* outputstream::getlogstream */

void chomp::homology::outputstream::logfile ( const char *  filename  )  [inline]

Turns on logging to a file.

If the file exists, its contents is ereased.

Definition at line 149 of file textfile.h.

References copied, log, logstream, and out.

{
        if (logstream && !copied)
                delete logstream;
        copied = false;
        logstream = new std::ofstream (filename);
        if (!logstream || !*logstream)
        {
                out << "WARNING: Can't create '" << filename <<
                        "'. Logging to a file has been turned off." <<
                        std::endl;
                if (logstream)
                        delete logstream;
                logstream = NULL;
        }
        else
                log = true;
        return;
} /* outputstream::logfile */

void chomp::homology::outputstream::logfile ( const outputstream other  )  [inline]

Turns on logging to the same file as some other stream.

Definition at line 169 of file textfile.h.

References copied, log, and logstream.

{
        if (!copied && logstream)
                delete logstream;
        logstream = other. logstream;
        if (logstream)
        {
                copied = true;
                log = true;
        }
        return;
} /* outputstream::logfile */


Member Data Documentation

This variable is set to true if this log file pointer was copied from another output stream, and therefore it should not be deleted by this stream.

Definition at line 132 of file textfile.h.

Referenced by keepforever(), logfile(), outputstream(), and ~outputstream().

If this variable is set to true then both the output stream 'cout' and the log file are flashed after every write operation.

Note that this may slow down the output significantly if the log file is located on a network drive.

Definition at line 95 of file textfile.h.

Referenced by outputstream().

If this variable is set to true then everything that is written to this stream is also written to the log file.

Definition at line 89 of file textfile.h.

Referenced by logfile(), and outputstream().

std::ofstream* chomp::homology::outputstream::logstream [protected]

A pointer to the log file stream.

Definition at line 127 of file textfile.h.

Referenced by getlogstream(), logfile(), outputstream(), and ~outputstream().

A reference to the main output stream bound with this stream.

Definition at line 102 of file textfile.h.

Referenced by logfile().

If this variable is set to true then everything that is written to this stream is also written to 'cout'.

If this variable is set to false then the screen output is suppressed, while logging can still be turned on.

Definition at line 85 of file textfile.h.

Referenced by outputstream().


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