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 ConsoleWriter TextWriter List of all members.

Public Types

typedef put opShl
typedef put opCall

Public Member Functions

 this (IBuffer buffer)
 this (IConduit conduit)
void error (char[] msg)
IBuffer getBuffer ()
void setEncoder (IEncoder e)
IWriter flush ()
IWriter cr ()
void enableArrayPrefix (bool on)
IWriter write (void *x, uint bytes, int type)
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 putw (wchar[] x)
IWriter putd (dchar[] x)

Protected Attributes

IBuffer buffer
Encoder encode

Private Member Functions

final uint length (uint len)
void encoder (void *src, uint bytes, int type)

Private Attributes

bool prefixArray = true

Classes

union  Encoder

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 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 meta-data. This can be utilized in a number of writer-specific ways, but is most commonly used in conjuncion with formatted output (DisplayWriter). For example:

        Stdout ["%d green bottles"] (10);

Definition at line 125 of file Writer.d.


Member Typedef Documentation

typedef put opShl
 

Reimplemented from IWriter.

Definition at line 128 of file Writer.d.

typedef put opCall
 

Reimplemented from IWriter.

Definition at line 129 of file Writer.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 158 of file Writer.d.

References buffer, Writer::Encoder::char16, Writer::Encoder::char32, Writer::Encoder::char8, encode, and encoder().

this IConduit  conduit  )  [inline]
 

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

Reimplemented in DisplayWriter, and FlushWriter.

Definition at line 174 of file Writer.d.

void error char[]  msg  )  [inline]
 

Definition at line 183 of file Writer.d.

Referenced by EndianWriter::write().

IBuffer getBuffer  )  [inline]
 

Return the associated buffer

Reimplemented from IWriter.

Definition at line 194 of file Writer.d.

References buffer.

void setEncoder IEncoder  e  )  [inline]
 

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

An appropriate encoder set should be attached to each IWriter, and thus be available for subsequent use. A raw binary implementation is attached by default (no encoding).

See module mango.icu.UMango for an example of encoder implementation -- those classes bind the ICU converters to this IO package.

Reimplemented from IWriter.

Definition at line 216 of file Writer.d.

References IEncoder::bind(), encode, Writer::Encoder::encoders, and IEncoder::type().

IWriter flush  )  [inline]
 

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

Reimplemented from IWriter.

Definition at line 228 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 241 of file Writer.d.

References CR, and put().

void enableArrayPrefix bool  on  )  [inline]
 

Enable array prefixing. These prefixes represent the number of elements in the array, and are used when reading arrays back in again.

Definition at line 254 of file Writer.d.

References prefixArray.

Referenced by DisplayWriter::this().

final uint length uint  len  )  [inline, private]
 

Emit the length of an array

Definition at line 265 of file Writer.d.

References prefixArray, and put().

Referenced by put(), putd(), and putw().

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

Reimplemented in DisplayWriter, and EndianWriter.

Definition at line 277 of file Writer.d.

References IBuffer::append(), buffer, and x.

Referenced by put().

void encoder void *  src,
uint  bytes,
int  type
[inline, private]
 

Definition at line 287 of file Writer.d.

References IBuffer::append(), and buffer.

Referenced by this().

IWriter put  )  [inline]
 

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

Reimplemented from IWriter.

Definition at line 299 of file Writer.d.

References flush().

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

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 310 of file Writer.d.

References assert(), and x.

IWriter put bool  x  )  [inline]
 

Write a boolean value to the current buffer-position

Reimplemented from IWriter.

Definition at line 323 of file Writer.d.

References write(), and x.

IWriter put ubyte  x  )  [inline]
 

Write an unsigned byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 334 of file Writer.d.

References write(), and x.

IWriter put byte  x  )  [inline]
 

Write a byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 345 of file Writer.d.

References write(), and x.

IWriter put ushort  x  )  [inline]
 

Write an unsigned short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 356 of file Writer.d.

References write(), and x.

IWriter put short  x  )  [inline]
 

Write a short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 367 of file Writer.d.

References write(), and x.

IWriter put uint  x  )  [inline]
 

Write a unsigned int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 378 of file Writer.d.

References write(), and x.

IWriter put int  x  )  [inline]
 

Write an int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 389 of file Writer.d.

References write(), and x.

IWriter put ulong  x  )  [inline]
 

Write an unsigned long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 400 of file Writer.d.

References write(), and x.

IWriter put long  x  )  [inline]
 

Write a long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 411 of file Writer.d.

References write(), and x.

IWriter put float  x  )  [inline]
 

Write a float value to the current buffer-position

Reimplemented from IWriter.

Definition at line 422 of file Writer.d.

References write(), and x.

IWriter put double  x  )  [inline]
 

Write a double value to the current buffer-position

Reimplemented from IWriter.

Definition at line 433 of file Writer.d.

References write(), and x.

IWriter put real  x  )  [inline]
 

Write a real value to the current buffer-position

Reimplemented from IWriter.

Definition at line 444 of file Writer.d.

References write(), and x.

IWriter put char  x  )  [inline]
 

Write a char value to the current buffer-position

Reimplemented from IWriter.

Definition at line 455 of file Writer.d.

References Writer::Encoder::char8, encode, and x.

IWriter put wchar  x  )  [inline]
 

Write a wchar value to the current buffer-position

Reimplemented from IWriter.

Definition at line 467 of file Writer.d.

References Writer::Encoder::char16, encode, and x.

IWriter put dchar  x  )  [inline]
 

Write a dchar value to the current buffer-position

Reimplemented from IWriter.

Definition at line 479 of file Writer.d.

References Writer::Encoder::char32, encode, and x.

IWriter put byte[]  x  )  [inline]
 

Write a byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 491 of file Writer.d.

References length(), write(), and x.

IWriter put ubyte[]  x  )  [inline]
 

Write an unsigned byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 502 of file Writer.d.

References length(), write(), and x.

IWriter put short[]  x  )  [inline]
 

Write a short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 513 of file Writer.d.

References length(), write(), and x.

IWriter put ushort[]  x  )  [inline]
 

Write an unsigned short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 524 of file Writer.d.

References length(), write(), and x.

IWriter put int[]  x  )  [inline]
 

Write an int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 535 of file Writer.d.

References length(), write(), and x.

IWriter put uint[]  x  )  [inline]
 

Write an unsigned int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 546 of file Writer.d.

References length(), write(), and x.

IWriter put long[]  x  )  [inline]
 

Write a long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 557 of file Writer.d.

References length(), write(), and x.

IWriter put ulong[]  x  )  [inline]
 

Write an unsigned long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 568 of file Writer.d.

References length(), write(), and x.

IWriter put float[]  x  )  [inline]
 

Write a float array to the current buffer-position

Reimplemented from IWriter.

Definition at line 579 of file Writer.d.

References length(), write(), and x.

IWriter put double[]  x  )  [inline]
 

Write a double array to the current buffer-position

Reimplemented from IWriter.

Definition at line 590 of file Writer.d.

References length(), write(), and x.

IWriter put real[]  x  )  [inline]
 

Write a real array to the current buffer-position

Reimplemented from IWriter.

Definition at line 601 of file Writer.d.

References length(), write(), and x.

IWriter put char[]  x  )  [inline]
 

Write a char array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in ColumnWriter, FlushWriter, and TextWriter.

Definition at line 612 of file Writer.d.

References Writer::Encoder::char8, encode, length(), and x.

IWriter putw wchar[]  x  )  [inline]
 

Write a wchar array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in TextWriter.

Definition at line 624 of file Writer.d.

References Writer::Encoder::char16, encode, length(), and x.

IWriter putd dchar[]  x  )  [inline]
 

Write a dchar array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in TextWriter.

Definition at line 636 of file Writer.d.

References Writer::Encoder::char32, encode, length(), and x.


Member Data Documentation

IBuffer buffer [protected]
 

Definition at line 145 of file Writer.d.

Referenced by encoder(), flush(), getBuffer(), this(), and write().

Encoder encode [protected]
 

Definition at line 147 of file Writer.d.

Referenced by put(), putd(), putw(), setEncoder(), and this().

bool prefixArray = true [private]
 

Definition at line 149 of file Writer.d.

Referenced by enableArrayPrefix(), and length().


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