Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

ConsoleWriter Class Reference

Inheritance diagram for ConsoleWriter:

FlushWriter List of all members.

Public Attributes

FileConduit conduit

Private Types

typedef DisplayWriter put put

Private Member Functions

 this (int device)
IWriter put (IWritable x)
 this (IBuffer buffer)
 this (IConduit conduit)

Static Private Member Functions

 this ()

Detailed Description

The ubiquitous console IO support. These are standard FileConduit instances, with Reader/Writer wrappers applied appropriately. Note that the outputs use FlushBuffer to automatically flush data as it is added to the buffer. The basic usage of this module is illustrated below:

char[] msg = "on the console"; Stdout ("print ") (1) (' ') ("message ") (msg) (CR);

An alternative is to use put() notation like so:

char[] msg = "on the console"; Stdout.put ("print ") .put (1) .put (' ') .put ("message ") .put (msg) .put (CR);

Another alternative is to use the C++ iostream operators like so:

char[] msg = "on the console"; Stdout << "print " << 1 << ' ' << "message " << msg << CR;

Since console idioms are based upon FileConduit, you can use them as direct targets for Conduit operations. For example, the code:

FileConduit fc = new FileConduit ("myfile.txt"); Stdout.conduit.copy (fc);

copies a text file directly to the console. Likewise, you can copy console input directly to a FileConduit or a SocketConduit. Input via Stdin is similar in nature, but uses the Token classes to isolate and parse each token on an input line:

Stdout ("please input a number: ") (); int x; Stdin (x);

Stdout ("please enter your name: ") (); char[] you; Stdin (you); Stdout ("Hello ") (you) (CR);

Stdout automatically flushes the output when it sees a CR, so you may need to flush the output manually where a CR is not desired. This is the case in the above example, so we use the empty () to request a flush (which is actually an alias for the flush method).

Note that Stdin awaits a carriage-return before parsing the input into the targets. Note also that the Stdout and Stderr are not written to be thread-safe. As such you may find that output from two threads intersect across each other. If this is a problem you should wrap a synchronized block around the offending entity, like so:

synchronized (Stdout) Stdout ("this is ") ("'atomic' ") (" output") (CR);

Alternatively, please consider using the mango.log (Logger) package to provide detailed runtime diagnostics from your application. The functionality exposed there is likely sufficient for most application needs.

Redirecting the standard IO handles (via a shell) operates as one would expect.

Definition at line 140 of file Stdout.d.


Member Typedef Documentation

typedef DisplayWriter put put [inherited]
 

Definition at line 391 of file DisplayWriter.d.


Member Function Documentation

this int  device  )  [inline, private]
 

Prohibit instantiation of this class

Definition at line 156 of file Stdout.d.

References FileConduit.

IWriter put IWritable  x  )  [inline, inherited]
 

Intercept the IWritable method to catch newlines, and flush the buffer whenever one is emitted

Reimplemented from AbstractWriter.

Definition at line 422 of file DisplayWriter.d.

References AbstractWriter::flush(), and IWriter::put().

this IBuffer  buffer  )  [inline, inherited]
 

Construct a FlushWriter upon the specified IBuffer

Reimplemented from DisplayWriter.

Definition at line 399 of file DisplayWriter.d.

this IConduit  conduit  )  [inline, inherited]
 

Construct a FlushWriter upon the specified IConduit

Reimplemented from DisplayWriter.

Definition at line 410 of file DisplayWriter.d.

this  )  [inline, static, inherited]
 

Construct some static exception instances

Reimplemented in ColumnWriter.

Definition at line 162 of file AbstractWriter.d.

References AbstractWriter::ovf.


Member Data Documentation

FileConduit conduit
 

Standard output conduits.

Definition at line 148 of file Stdout.d.


The documentation for this class was generated from the following file:
Generated on Sat Apr 9 20:11:36 2005 for Mango by doxygen 1.3.6