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

ConsoleReader Class Reference

Inheritance diagram for ConsoleReader:

TextReader List of all members.

Public Attributes

ConsoleConduit conduit

Private Types

typedef Reader get get

Private Member Functions

 this (ConsoleConduit conduit)
IReader get (inout char[] x, uint elements=uint.max)
IReader get (inout wchar[] x, uint elements=uint.max)
IReader get (inout dchar[] x, uint elements=uint.max)
 this (IBuffer buffer, ITokenizer tokenizer=Tokenizers.line)
 this (IConduit conduit, ITokenizer tokenizer=Tokenizers.line)
 this (IBuffer buffer)
 this (IConduit conduit)
uint read (void *src, uint bytes, uint type)

Detailed Description

The ubiquitous console IO support. These are standard Conduit 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 Conduit, you can use them as direct targets for stream-oriented 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 enter your name: ") ();
        char[] you;
        Stdin (you);           
        Stdout ("Hello ") (you) (CR);

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 131 of file Stdin.d.


Member Typedef Documentation

typedef Reader get get [inherited]
 

Definition at line 59 of file TextReader.d.


Member Function Documentation

this ConsoleConduit  conduit  )  [inline, private]
 

Prohibit instantiation of this class

Definition at line 148 of file Stdin.d.

References conduit.

IReader get inout char[]  x,
uint  elements = uint.max
[inline, inherited]
 

Reimplemented from Reader.

Definition at line 163 of file TextReader.d.

References TextReader::nextToken(), Token::toString(), and x.

IReader get inout wchar[]  x,
uint  elements = uint.max
[inline, inherited]
 

Todo:
  • Tokenizer needs to handle wchar[] before this will operate correctly

Reimplemented from Reader.

Definition at line 177 of file TextReader.d.

References assert().

IReader get inout dchar[]  x,
uint  elements = uint.max
[inline, inherited]
 

Todo:
  • Tokenizer needs to handle dchar[] before this will operate correctly

Reimplemented from Reader.

Definition at line 190 of file TextReader.d.

References assert().

this IBuffer  buffer,
ITokenizer  tokenizer = Tokenizers.line
[inline, inherited]
 

Construct a TextReader on the provided buffer, using the specified Tokenizer instead of the default one.

Definition at line 76 of file TextReader.d.

References TextReader::tokenizer.

this IConduit  conduit,
ITokenizer  tokenizer = Tokenizers.line
[inline, inherited]
 

Construct a TextReader upon the buffer associated with the given conduit.

Definition at line 90 of file TextReader.d.

References TextReader::tokenizer.

this IBuffer  buffer  )  [inline, inherited]
 

Construct a Reader upon the provided buffer

Reimplemented in HttpReader, and EndianReader.

Definition at line 164 of file Reader.d.

References Reader::buffer, Reader::Decoder::char16, Reader::Decoder::char32, Reader::Decoder::char8, Reader::decode, Reader::read(), and Reader::setAllocator().

this IConduit  conduit  )  [inline, inherited]
 

Construct a Reader upon the buffer associated with the given conduit.

Definition at line 182 of file Reader.d.

uint read void *  src,
uint  bytes,
uint  type
[inline, inherited]
 

Reimplemented from Reader.

Definition at line 99 of file TextReader.d.

References TextReader::error(), TextReader::next(), Token::toInt(), Token::toLong(), Token::toReal(), and Token::toString().


Member Data Documentation

ConsoleConduit conduit
 

Standard output conduit. This is inside the namespace to reduce clutter

Definition at line 140 of file Stdin.d.

Referenced by this().


The documentation for this class was generated from the following file:
Generated on Fri Nov 11 18:44:32 2005 for Mango by  doxygen 1.4.0