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

Writer Class Reference

Inheritance diagram for Writer:

IWriter DisplayWriter EndianWriter ColumnWriter FlushWriter HttpWriter TextWriter List of all members.

Public Member Functions

 this (IBuffer buffer)
 this (IConduit conduit)
void error (char[] msg)
IBuffer getBuffer ()
IConduit conduit ()
void setEncoder (AbstractEncoder e)
bool isTextBased ()
IWriter flush ()
IWriter cr ()
IWriter put ()
IWriter put (IWritable x)
IWriter put (bool x)
IWriter put (ubyte x)
IWriter put (byte x)
IWriter put (ushort x)
IWriter put (short x)
IWriter put (uint x)
IWriter put (int x)
IWriter put (ulong x)
IWriter put (long x)
IWriter put (float x)
IWriter put (double x)
IWriter put (real x)
IWriter put (char x)
IWriter put (wchar x)
IWriter put (dchar x)
IWriter put (byte[] x)
IWriter put (ubyte[] x)
IWriter put (short[] x)
IWriter put (ushort[] x)
IWriter put (int[] x)
IWriter put (uint[] x)
IWriter put (long[] x)
IWriter put (ulong[] x)
IWriter put (float[] x)
IWriter put (double[] x)
IWriter put (real[] x)
IWriter put (char[] x)
IWriter put (wchar[] x)
IWriter put (dchar[] x)

Protected Member Functions

IWriter write (void *src, uint bytes, int type)
IWriter encode (void *src, uint bytes, int type)

Protected Attributes

IBuffer buffer

Private Types

typedef put opShl
typedef put opCall

Private Member Functions

final uint length (uint len)

Private Attributes

bool prefixArray
IBuffer Converter textEncoder

Detailed Description

Writer base-class. Writers provide the means to append formatted data to an IBuffer, and expose a convenient method of handling a variety of data types. In addition to writing native types such as integer and char[], writers also process any class which has implemented the IWritable interface (one method).

All writers support the full set of native data types, plus their fundamental array variants. Operations may be chained back-to-back.

Writers support a C++ iostream type syntax, along with Java-esque put() notation. However, the Mango style is to place IO elements within their own parenthesis, like so:

write (count) (" green bottles");

Note that each element is distict; this enables "strong typing", which should catch any typo errors at compile-time. The style is affectionately called "whisper".

The code below illustrates basic operation upon a memory buffer:

        Buffer buf = new Buffer (256);

        // map same buffer into both reader and writer
        IReader read = new Reader(buf);
        IWriter write = new Writer(buf);

        int i = 10;
        long j = 20;
        double d = 3.14159;
        char[] c = "fred";

        // write data types out
        write (c) (i) (j) (d);

        // read them back again
        read (c) (i) (j) (d);

        // reset
        buf.clear();

        // same thing again, but using iostream syntax instead
        write << c << i << j << d;

        // read them back again
        read >> c >> i >> j >> d;

        // reset
        buf.clear();

        // same thing again, but using put() syntax instead
        write.put(c).put(i).put(j).put(d);
        read.get(c).get(i).get(j).get(d);

Writers may also be used with any class implementing the IWritable interface. See PickleReader for an example of how this can be put to good use.

Note that 'newlines' are emitted via the standard "\n" approach. However, one might consider using the public CR element instead.

Writers also support formatted output via the DisplayWriter module, which has full support for printf() syntax:

        Stdout.println ("%d green bottles", 10);

Lastly, each Writer may be configured with a text encoder. These encoders convert between an internal text representation, and the char/wchar/dchar representaion. BufferCodec.d contains classes for handling utf8, utf16, and utf32. The icu.UMango module has support for a wide variety of converters. Stdout is pre-configured with utf16 & utf8 encoders for Win32 and Posix respectively.

Definition at line 134 of file Writer.d.


Member Typedef Documentation

typedef put opShl [inherited]
 

Definition at line 91 of file IWriter.d.

typedef put opCall [inherited]
 

Definition at line 92 of file IWriter.d.


Member Function Documentation

this IBuffer  buffer  )  [inline]
 

Construct a Writer upon the provided IBuffer. All formatted output will be directed to this buffer.

Reimplemented in HttpWriter, EndianWriter, and FlushWriter.

Definition at line 147 of file Writer.d.

References buffer, error(), IBuffer::getStyle(), isTextBased(), and prefixArray.

this IConduit  conduit  )  [inline]
 

Construct a Writer on the buffer associated with the given conduit.

Reimplemented in DisplayWriter, and FlushWriter.

Definition at line 165 of file Writer.d.

References Buffer, and conduit().

void error char[]  msg  )  [inline]
 

Definition at line 174 of file Writer.d.

References buffer, and IBuffer::error().

Referenced by this().

IBuffer getBuffer  )  [inline]
 

Return the associated buffer

Reimplemented from IWriter.

Definition at line 185 of file Writer.d.

References buffer.

IConduit conduit  )  [inline]
 

Definition at line 194 of file Writer.d.

References buffer, and IBuffer::getConduit().

Referenced by this().

void setEncoder AbstractEncoder  e  )  [inline]
 

Bind an IEncoder to the writer. Encoders are intended to be used as a conversion mechanism between various character representations (encodings). Each writer may be configured with a distinct encoder.

Reimplemented from IWriter.

Definition at line 208 of file Writer.d.

References AbstractEncoder::bind(), buffer, and AbstractEncoder::encoder().

bool isTextBased  )  [inline]
 

Is this Writer text oriented?

Reimplemented in DisplayWriter.

Definition at line 220 of file Writer.d.

Referenced by this().

IWriter flush  )  [inline]
 

Flush the output of this writer. Returns false if the operation failed, true otherwise.

Reimplemented from IWriter.

Definition at line 232 of file Writer.d.

References buffer, and IBuffer::flush().

Referenced by put(), and FlushWriter::put().

IWriter cr  )  [inline]
 

Output a newline. Do this indirectly so that it can be intercepted by subclasses.

Reimplemented from IWriter.

Definition at line 245 of file Writer.d.

References CR, and put().

IWriter put  )  [inline]
 

Flush this writer. This is a convenience method used by the "whisper" syntax.

Reimplemented from IWriter.

Definition at line 257 of file Writer.d.

References flush().

Referenced by cr(), length(), and DisplayWriter::println().

IWriter put IWritable  x  )  [inline]
 

Write a class to the current buffer-position

Reimplemented from IWriter.

Reimplemented in ColumnWriter, FlushWriter, and TextWriter.

Definition at line 268 of file Writer.d.

References assert(), and IWritable::write().

IWriter put bool  x  )  [inline]
 

Write a boolean value to the current buffer-position

Reimplemented from IWriter.

Definition at line 281 of file Writer.d.

References write().

IWriter put ubyte  x  )  [inline]
 

Write an unsigned byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 292 of file Writer.d.

References write().

IWriter put byte  x  )  [inline]
 

Write a byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 303 of file Writer.d.

References write().

IWriter put ushort  x  )  [inline]
 

Write an unsigned short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 314 of file Writer.d.

References write().

IWriter put short  x  )  [inline]
 

Write a short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 325 of file Writer.d.

References write().

IWriter put uint  x  )  [inline]
 

Write a unsigned int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 336 of file Writer.d.

References write().

IWriter put int  x  )  [inline]
 

Write an int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 347 of file Writer.d.

References write().

IWriter put ulong  x  )  [inline]
 

Write an unsigned long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 358 of file Writer.d.

References write().

IWriter put long  x  )  [inline]
 

Write a long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 369 of file Writer.d.

References write().

IWriter put float  x  )  [inline]
 

Write a float value to the current buffer-position

Reimplemented from IWriter.

Definition at line 380 of file Writer.d.

References write().

IWriter put double  x  )  [inline]
 

Write a double value to the current buffer-position

Reimplemented from IWriter.

Definition at line 391 of file Writer.d.

References write().

IWriter put real  x  )  [inline]
 

Write a real value to the current buffer-position

Reimplemented from IWriter.

Definition at line 402 of file Writer.d.

References write().

IWriter put char  x  )  [inline]
 

Write a char value to the current buffer-position

Reimplemented from IWriter.

Definition at line 413 of file Writer.d.

References encode().

IWriter put wchar  x  )  [inline]
 

Write a wchar value to the current buffer-position

Reimplemented from IWriter.

Definition at line 424 of file Writer.d.

References encode().

IWriter put dchar  x  )  [inline]
 

Write a dchar value to the current buffer-position

Reimplemented from IWriter.

Definition at line 435 of file Writer.d.

References encode().

IWriter put byte[]  x  )  [inline]
 

Write a byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 446 of file Writer.d.

References length(), and write().

IWriter put ubyte[]  x  )  [inline]
 

Write an unsigned byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 457 of file Writer.d.

References length(), and write().

IWriter put short[]  x  )  [inline]
 

Write a short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 468 of file Writer.d.

References length(), and write().

IWriter put ushort[]  x  )  [inline]
 

Write an unsigned short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 479 of file Writer.d.

References length(), and write().

IWriter put int[]  x  )  [inline]
 

Write an int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 490 of file Writer.d.

References length(), and write().

IWriter put uint[]  x  )  [inline]
 

Write an unsigned int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 501 of file Writer.d.

References length(), and write().

IWriter put long[]  x  )  [inline]
 

Write a long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 512 of file Writer.d.

References length(), and write().

IWriter put ulong[]  x  )  [inline]
 

Write an unsigned long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 523 of file Writer.d.

References length(), and write().

IWriter put float[]  x  )  [inline]
 

Write a float array to the current buffer-position

Reimplemented from IWriter.

Definition at line 534 of file Writer.d.

References length(), and write().

IWriter put double[]  x  )  [inline]
 

Write a double array to the current buffer-position

Reimplemented from IWriter.

Definition at line 545 of file Writer.d.

References length(), and write().

IWriter put real[]  x  )  [inline]
 

Write a real array to the current buffer-position

Reimplemented from IWriter.

Definition at line 556 of file Writer.d.

References length(), and write().

IWriter put char[]  x  )  [inline]
 

Write a char array to the current buffer-position

Reimplemented from IWriter.

Definition at line 567 of file Writer.d.

References encode(), and length().

IWriter put wchar[]  x  )  [inline]
 

Write a wchar array to the current buffer-position

Reimplemented from IWriter.

Definition at line 578 of file Writer.d.

References encode(), and length().

IWriter put dchar[]  x  )  [inline]
 

Write a dchar array to the current buffer-position

Reimplemented from IWriter.

Definition at line 589 of file Writer.d.

References encode(), and length().

IWriter write void *  src,
uint  bytes,
int  type
[inline, protected]
 

Dump content into the buffer. This is intercepted by a variety of subclasses

Reimplemented in DisplayWriter, and EndianWriter.

Definition at line 601 of file Writer.d.

References IBuffer::append(), and buffer.

Referenced by put().

IWriter encode void *  src,
uint  bytes,
int  type
[inline, protected]
 

Handle text output. This is intended to be intercepted by subclasses, though they should always pump content through here to take advantage of configured encoding

Reimplemented in ColumnWriter, and TextWriter.

Definition at line 615 of file Writer.d.

References IBuffer::append(), buffer, textEncoder, and type().

Referenced by DisplayWriter::emit(), and put().

final uint length uint  len  )  [inline, private]
 

Emit the length of an array: used for raw binary output of arrays. Array lengths are written into the buffer as a guide for when reading it back again

Definition at line 632 of file Writer.d.

References prefixArray, and put().

Referenced by put().


Member Data Documentation

IBuffer buffer [protected]
 

Definition at line 136 of file Writer.d.

Referenced by conduit(), encode(), error(), flush(), getBuffer(), setEncoder(), this(), and write().

bool prefixArray [private]
 

Definition at line 137 of file Writer.d.

Referenced by length(), and this().

IBuffer Converter textEncoder [private]
 

Definition at line 138 of file Writer.d.

Referenced by encode().


The documentation for this class was generated from the following file:
Generated on Sat Dec 24 17:28:44 2005 for Mango by  doxygen 1.4.0