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

Reader Class Reference

Inheritance diagram for Reader:

IReader IArrayAllocator EndianReader HttpReader TextReader List of all members.

Public Member Functions

 this (IBuffer buffer)
 this (IConduit conduit)
IBuffer getBuffer ()
bool isTextBased ()
IArrayAllocator getAllocator ()
void setAllocator (IArrayAllocator memory)
void setDecoder (AbstractDecoder d)
void wait ()
IReader get (IReadable x)
IReader get (inout bool x)
IReader get (inout ubyte x)
IReader get (inout byte x)
IReader get (inout ushort x)
IReader get (inout short x)
IReader get (inout uint x)
IReader get (inout int x)
IReader get (inout ulong x)
IReader get (inout long x)
IReader get (inout float x)
IReader get (inout double x)
IReader get (inout real x)
IReader get (inout char x)
IReader get (inout wchar x)
IReader get (inout dchar x)
IReader get (inout ubyte[] x, uint elements=uint.max)
IReader get (inout byte[] x, uint elements=uint.max)
IReader get (inout ushort[] x, uint elements=uint.max)
IReader get (inout short[] x, uint elements=uint.max)
IReader get (inout uint[] x, uint elements=uint.max)
IReader get (inout int[] x, uint elements=uint.max)
IReader get (inout ulong[] x, uint elements=uint.max)
IReader get (inout long[] x, uint elements=uint.max)
IReader get (inout float[] x, uint elements=uint.max)
IReader get (inout double[] x, uint elements=uint.max)
IReader get (inout real[] x, uint elements=uint.max)
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)

Protected Member Functions

IReader decode (void *x, uint bytes, uint type)
IReader decodeArray (void[]*x, uint bytes, uint width, uint type)
uint read (void *dst, uint bytes, uint type)
uint count (uint elements)
final void reset ()
final void bind (IReader reader)
final bool isMutable (void *x)
final void allocate (void[]*x, uint bytes, uint width, uint type, IBuffer.Converter decoder)

Protected Attributes

IBuffer buffer

Private Types

typedef get opShr
typedef get opCall

Private Attributes

IArrayAllocator memory
IBuffer Converter textDecoder

Detailed Description

Reader base-class. Each reader operates upon an IBuffer, which is provided at construction time. Said buffer is intended to remain consistent over the reader lifetime.

All readers support the full set of native data types, plus a full selection of array types. The latter can be configured to produce either a copy (.dup) of the buffer content, or a slice. See class SimpleAllocator, BufferAllocator and SliceAllocator for more on this topic.

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

int count; char[] verse;

read (verse) (count);

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);

Note that certain Readers, such as the basic binary implementation, expect to retrieve the number of array elements from the source. For example; when reading an array from a file, the number of elements is read from the file also. If the content is not arranged in such a manner, you may specify how many elements to read via a second argument:

                read (myArray, 11);

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

Lastly, each Reader may be configured with a text decoder. These decoders 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.

Definition at line 139 of file Reader.d.


Member Typedef Documentation

typedef get opShr [inherited]
 

Definition at line 79 of file IReader.d.

typedef get opCall [inherited]
 

Definition at line 80 of file IReader.d.


Member Function Documentation

this IBuffer  buffer  )  [inline]
 

Construct a Reader upon the provided buffer

Reimplemented in HttpReader, and EndianReader.

Definition at line 158 of file Reader.d.

References buffer, IBuffer::error(), IBuffer::getStyle(), isTextBased(), read(), setAllocator(), and textDecoder.

this IConduit  conduit  )  [inline]
 

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

Definition at line 178 of file Reader.d.

References Buffer.

IBuffer getBuffer  )  [inline]
 

Return the buffer associated with this reader

Reimplemented from IReader.

Definition at line 189 of file Reader.d.

References buffer.

bool isTextBased  )  [inline]
 

Is this Reader text oriented?

Reimplemented in TextReader.

Definition at line 200 of file Reader.d.

Referenced by TextReaderTemplate(), and this().

IArrayAllocator getAllocator  )  [inline]
 

Return the allocator associated with this reader. See ArrayAllocator for more information.

Reimplemented from IReader.

Definition at line 212 of file Reader.d.

References memory.

void setAllocator IArrayAllocator  memory  )  [inline]
 

Set the allocator to use for array management. Arrays are always allocated by the IReader. That is, you cannot read data into an array slice (for example). Instead, a number of IArrayAllocator classes are available to manage memory allocation when reading array content.

By default, an IReader will allocate each array from the heap. You can change that behavior by calling this method with an IArrayAllocator of choice. For instance, there is a BufferAllocator which will slice an array directly from the buffer where possible. Also available is the record-oriented SliceAllocator, which slices memory from within a pre-allocated heap area, and should be reset by the client code after each record has been read (to avoid unnecessary growth).

See ArrayAllocator for more information.

Reimplemented from IReader.

Definition at line 239 of file Reader.d.

References IArrayAllocator::bind().

Referenced by this().

void setDecoder AbstractDecoder  d  )  [inline]
 

Bind an IDecoder to the writer. Decoders are intended to be used as a conversion mechanism between various character representations (encodings).

Reimplemented from IReader.

Definition at line 253 of file Reader.d.

References AbstractDecoder::bind(), buffer, and AbstractDecoder::decoder().

Referenced by this().

void wait  )  [inline]
 

Wait for something to arrive in the buffer. This may stall the current thread forever, although usage of SocketConduit will take advantage of the timeout facilities provided there.

Reimplemented from IReader.

Definition at line 267 of file Reader.d.

References buffer, and IBuffer::get().

IReader get IReadable  x  )  [inline]
 

Extract a readable class from the current read-position

Reimplemented from IReader.

Definition at line 278 of file Reader.d.

References assert(), and IReadable::read().

Referenced by count().

IReader get inout bool  x  )  [inline]
 

Extract a boolean value from the current read-position

Reimplemented from IReader.

Definition at line 291 of file Reader.d.

References read().

IReader get inout ubyte  x  )  [inline]
 

Extract an unsigned byte value from the current read-position

Reimplemented from IReader.

Definition at line 303 of file Reader.d.

References read().

IReader get inout byte  x  )  [inline]
 

Extract a byte value from the current read-position

Reimplemented from IReader.

Definition at line 315 of file Reader.d.

References read().

IReader get inout ushort  x  )  [inline]
 

Extract an unsigned short value from the current read-position

Reimplemented from IReader.

Definition at line 327 of file Reader.d.

References read().

IReader get inout short  x  )  [inline]
 

Extract a short value from the current read-position

Reimplemented from IReader.

Definition at line 339 of file Reader.d.

References read().

IReader get inout uint  x  )  [inline]
 

Extract a unsigned int value from the current read-position

Reimplemented from IReader.

Definition at line 351 of file Reader.d.

References read().

IReader get inout int  x  )  [inline]
 

Extract an int value from the current read-position

Reimplemented from IReader.

Definition at line 363 of file Reader.d.

References read().

IReader get inout ulong  x  )  [inline]
 

Extract an unsigned long value from the current read-position

Reimplemented from IReader.

Definition at line 375 of file Reader.d.

References read().

IReader get inout long  x  )  [inline]
 

Extract a long value from the current read-position

Reimplemented from IReader.

Definition at line 387 of file Reader.d.

References read().

IReader get inout float  x  )  [inline]
 

Extract a float value from the current read-position

Reimplemented from IReader.

Definition at line 399 of file Reader.d.

References read().

IReader get inout double  x  )  [inline]
 

Extract a double value from the current read-position

Reimplemented from IReader.

Definition at line 411 of file Reader.d.

References read().

IReader get inout real  x  )  [inline]
 

Extract a real value from the current read-position

Reimplemented from IReader.

Definition at line 423 of file Reader.d.

References read().

IReader get inout char  x  )  [inline]
 

Extract a char value from the current read-position

Reimplemented from IReader.

Definition at line 435 of file Reader.d.

References decode().

IReader get inout wchar  x  )  [inline]
 

Extract a wide char value from the current read-position

Reimplemented from IReader.

Definition at line 446 of file Reader.d.

References decode().

IReader get inout dchar  x  )  [inline]
 

Extract a double char value from the current read-position

Reimplemented from IReader.

Definition at line 457 of file Reader.d.

References decode().

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

Extract an unsigned byte array from the current read-position

Reimplemented from IReader.

Definition at line 468 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a byte array from the current read-position

Reimplemented from IReader.

Definition at line 481 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract an unsigned short array from the current read-position

Reimplemented from IReader.

Definition at line 494 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a short array from the current read-position

Reimplemented from IReader.

Definition at line 507 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a unsigned int array from the current read-position

Reimplemented from IReader.

Definition at line 520 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract an int array from the current read-position

Reimplemented from IReader.

Definition at line 533 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract an unsigned long array from the current read-position

Reimplemented from IReader.

Definition at line 546 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a long array from the current read-position

Reimplemented from IReader.

Definition at line 559 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a float array from the current read-position

Reimplemented from IReader.

Definition at line 572 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a double array from the current read-position

Reimplemented from IReader.

Definition at line 585 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Extract a real array from the current read-position

Reimplemented from IReader.

Definition at line 598 of file Reader.d.

References IArrayAllocator::allocate(), count(), memory, and read().

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

Reimplemented from IReader.

Reimplemented in TextReader.

Definition at line 609 of file Reader.d.

References count(), and decodeArray().

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

Reimplemented from IReader.

Reimplemented in TextReader.

Definition at line 619 of file Reader.d.

References count(), and decodeArray().

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

Reimplemented from IReader.

Reimplemented in TextReader.

Definition at line 629 of file Reader.d.

References count(), and decodeArray().

IReader decode void *  x,
uint  bytes,
uint  type
[inline, protected]
 

Definition at line 639 of file Reader.d.

References textDecoder, and type().

Referenced by get(), and TextReaderTemplate().

IReader decodeArray void *[]  x,
uint  bytes,
uint  width,
uint  type
[inline, protected]
 

Definition at line 649 of file Reader.d.

References IArrayAllocator::allocate(), memory, textDecoder, and type().

Referenced by get().

uint read void *  dst,
uint  bytes,
uint  type
[inline, protected]
 

Reimplemented in EndianReader, and TextReader.

Definition at line 659 of file Reader.d.

References buffer, IBuffer::error(), IBuffer::fill(), IBuffer::get(), and IBuffer::readable().

Referenced by get(), HttpReader::getPostData(), TextReaderTemplate(), and this().

uint count uint  elements  )  [inline, protected]
 

Read and return an integer from the input stream. This is used to extract the element count of a subsequent array.

Definition at line 693 of file Reader.d.

References get().

Referenced by get(), and TextReaderTemplate().

final void reset  )  [inline, protected]
 

IArrayAllocator method

Reimplemented from IArrayAllocator.

Definition at line 706 of file Reader.d.

final void bind IReader  reader  )  [inline, protected]
 

IArrayAllocator method

Reimplemented from IArrayAllocator.

Definition at line 716 of file Reader.d.

final bool isMutable void *  x  )  [inline, protected]
 

IArrayAllocator method

Reimplemented from IArrayAllocator.

Definition at line 726 of file Reader.d.

final void allocate void *[]  x,
uint  bytes,
uint  width,
uint  type,
IBuffer.Converter  decoder
[inline, protected]
 

IArrayAllocator method

Reimplemented from IArrayAllocator.

Definition at line 737 of file Reader.d.

References type().


Member Data Documentation

IBuffer buffer [protected]
 

Definition at line 144 of file Reader.d.

Referenced by getBuffer(), read(), setDecoder(), this(), and wait().

IArrayAllocator memory [private]
 

Definition at line 147 of file Reader.d.

Referenced by decodeArray(), get(), and getAllocator().

IBuffer Converter textDecoder [private]
 

Definition at line 150 of file Reader.d.

Referenced by decode(), decodeArray(), and this().


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