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

AbstractWriter Class Reference

Inheritance diagram for AbstractWriter:

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

Public Types

typedef put opShl
typedef put opCall

Public Member Functions

 this (IBuffer buffer)
IBuffer getBuffer ()
void setEncoder (IEncoder e)
IWriter flush ()
IWriter cr ()
void enableArrayPrefix (bool on)
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)

Static Public Member Functions

 this ()

Protected Attributes

IBuffer buffer
Encoder encode

Static Protected Attributes

IOException ovf

Private Member Functions

final uint length (uint len)

Private Attributes

bool prefixArray = true

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, hanging on the wall");

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 should consider using the public CR element instead.

Definition at line 116 of file AbstractWriter.d.


Member Typedef Documentation

typedef put opShl
 

Reimplemented from IWriter.

Definition at line 118 of file AbstractWriter.d.

typedef put opCall
 

Reimplemented from IWriter.

Definition at line 119 of file AbstractWriter.d.


Member Function Documentation

this  )  [inline, static]
 

Construct some static exception instances

Reimplemented in ColumnWriter.

Definition at line 162 of file AbstractWriter.d.

References ovf.

this IBuffer  buffer  )  [inline]
 

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

Reimplemented in HttpWriter, DisplayWriter, FlushWriter, EndianWriter, and Writer.

Definition at line 174 of file AbstractWriter.d.

IBuffer getBuffer  )  [inline]
 

Return the associated buffer

Reimplemented from IWriter.

Definition at line 185 of file AbstractWriter.d.

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), or the translation of any data type from one representation to another. Each data type may be configured with a distinct encoder, covering all native types (15 in total).

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 209 of file AbstractWriter.d.

References IEncoder::bind(), encode, AbstractWriter::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 221 of file AbstractWriter.d.

References IBuffer::flush().

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

IWriter cr  )  [inline]
 

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

Reimplemented from IWriter.

Definition at line 234 of file AbstractWriter.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 247 of file AbstractWriter.d.

References prefixArray.

Referenced by DisplayWriter::this().

final uint length uint  len  )  [inline, private]
 

Emit the length of an array

Definition at line 258 of file AbstractWriter.d.

References len, prefixArray, and put().

IWriter put  )  [inline]
 

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

Reimplemented from IWriter.

Definition at line 272 of file AbstractWriter.d.

References flush().

Referenced by cr(), DisplayWriter::fformat(), DisplayWriter::formatInt(), DisplayWriter::formatLong(), and length().

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 283 of file AbstractWriter.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 296 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int1.

IWriter put ubyte  x  )  [inline]
 

Write an unsigned byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 308 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int8u.

IWriter put byte  x  )  [inline]
 

Write a byte value to the current buffer-position

Reimplemented from IWriter.

Definition at line 320 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int8.

IWriter put ushort  x  )  [inline]
 

Write an unsigned short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 332 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int16u.

IWriter put short  x  )  [inline]
 

Write a short value to the current buffer-position

Reimplemented from IWriter.

Definition at line 344 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int16.

IWriter put uint  x  )  [inline]
 

Write a unsigned int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 356 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int32u.

IWriter put int  x  )  [inline]
 

Write an int value to the current buffer-position

Reimplemented from IWriter.

Definition at line 368 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int32.

IWriter put ulong  x  )  [inline]
 

Write an unsigned long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 380 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int64u.

IWriter put long  x  )  [inline]
 

Write a long value to the current buffer-position

Reimplemented from IWriter.

Definition at line 392 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int64.

IWriter put float  x  )  [inline]
 

Write a float value to the current buffer-position

Reimplemented from IWriter.

Definition at line 404 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float32.

IWriter put double  x  )  [inline]
 

Write a double value to the current buffer-position

Reimplemented from IWriter.

Definition at line 416 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float64.

IWriter put real  x  )  [inline]
 

Write a real value to the current buffer-position

Reimplemented from IWriter.

Definition at line 428 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float80.

IWriter put char  x  )  [inline]
 

Write a char value to the current buffer-position

Reimplemented from IWriter.

Definition at line 440 of file AbstractWriter.d.

References AbstractWriter::Encoder::char8, and encode.

IWriter put wchar  x  )  [inline]
 

Write a wide char value to the current buffer-position

Reimplemented from IWriter.

Definition at line 452 of file AbstractWriter.d.

References AbstractWriter::Encoder::char16, and encode.

IWriter put dchar  x  )  [inline]
 

Write a double char value to the current buffer-position

Reimplemented from IWriter.

Definition at line 464 of file AbstractWriter.d.

References AbstractWriter::Encoder::char32, and encode.

IWriter put byte[]  x  )  [inline]
 

Write a byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 476 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int8.

IWriter put ubyte[]  x  )  [inline]
 

Write an unsigned byte array to the current buffer-position

Reimplemented from IWriter.

Definition at line 488 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int8u.

IWriter put short[]  x  )  [inline]
 

Write a short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 500 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int16.

IWriter put ushort[]  x  )  [inline]
 

Write an unsigned short array to the current buffer-position

Reimplemented from IWriter.

Definition at line 512 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int16u.

IWriter put int[]  x  )  [inline]
 

Write an int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 524 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int32.

IWriter put uint[]  x  )  [inline]
 

Write an unsigned int array to the current buffer-position

Reimplemented from IWriter.

Definition at line 536 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int32u.

IWriter put long[]  x  )  [inline]
 

Write a long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 548 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int64.

IWriter put ulong[]  x  )  [inline]
 

Write an unsigned long array to the current buffer-position

Reimplemented from IWriter.

Definition at line 560 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::int64u.

IWriter put float[]  x  )  [inline]
 

Write a float array to the current buffer-position

Reimplemented from IWriter.

Definition at line 572 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float32.

IWriter put double[]  x  )  [inline]
 

Write a double array to the current buffer-position

Reimplemented from IWriter.

Definition at line 584 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float64.

IWriter put real[]  x  )  [inline]
 

Write a real array to the current buffer-position

Reimplemented from IWriter.

Definition at line 596 of file AbstractWriter.d.

References encode, and AbstractWriter::Encoder::float80.

IWriter put char[]  x  )  [inline]
 

Write a char array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in ColumnWriter, and TextWriter.

Definition at line 608 of file AbstractWriter.d.

References AbstractWriter::Encoder::char8, and encode.

IWriter putw wchar[]  x  )  [inline]
 

Write a char array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in TextWriter.

Definition at line 620 of file AbstractWriter.d.

References AbstractWriter::Encoder::char16, and encode.

IWriter putd dchar[]  x  )  [inline]
 

Write a char array to the current buffer-position

Reimplemented from IWriter.

Reimplemented in TextWriter.

Definition at line 632 of file AbstractWriter.d.

References AbstractWriter::Encoder::char32, and encode.


Member Data Documentation

IOException ovf [static, protected]
 

Definition at line 148 of file AbstractWriter.d.

Referenced by this().

IBuffer buffer [protected]
 

Definition at line 150 of file AbstractWriter.d.

Encoder encode [protected]
 

Definition at line 152 of file AbstractWriter.d.

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

bool prefixArray = true [private]
 

Definition at line 154 of file AbstractWriter.d.

Referenced by enableArrayPrefix(), and length().


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