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

CompositeWriter Class Reference

List of all members.

Public Member Functions

 this (IWriter writer)
CompositeWriter put (IWritable source)
void flush ()

Private Attributes

IWriter writer

Detailed Description

CompositeWriter brackets the writing of a data set, providing a basic framework that can be extended to support commit semantics.

The approach leverages the exisiting IWritable interface which, when implemented, exposes a class that writes a related set of data. For instance:

class Foo : IWritable { int x, y; char[] text; void write (IWriter writer) { writer.put(x).put(y).put(text); } }

In the above example, we set up a class that implements IWritable (via the write() method). The class may write whatever it chooses, and may also invoke the write() method of other IWritable classes. Thus, the initial IWritable has control over a potential writable cluster, all of which is bracketed within the CompositeWriter. CompositeWriter could be extended to support commit and rollback semantics with little effort.

This particular CompositeWriter simply flushes the output buffer after a data-set has been written to it (option). In general usage this will be measurably more efficient than using a FlushBuffer.

Here's an expanded example of how this is intended to operate:

// define a serializable class (via interfaces) class Wumpus : IReadable, IWritable { private int x = 11, y = 112, z = 1024; void write(IWriter writer) { writer.put(x).put(y).put(z); } void read(IReader reader) { reader.get(x).get(y).get(z); } } // construct a Wumpus Wumpus wumpus = new Wumpus(); // open a file for IO FileConduit fc = new FileConduit ("random.bin", FileStyle.ReadWriteCreate); // construct composite reader & writer upon the file, with binary IO CompositeWriter cw = new CompositeWriter (new Writer(fc)); CompositeReader cr = new CompositeReader (new Reader(fc)); // write the Wumpus (and flush it) cw.put (wumpus); // rewind to file start fc.seek (0); // read Wumpus back again cr.get (wumpus);

Definition at line 122 of file CompositeWriter.d.


Member Function Documentation

this IWriter  writer  )  [inline]
 

Construct a CompositeWriter with the provided IWriter.

Definition at line 132 of file CompositeWriter.d.

CompositeWriter put IWritable  source  )  [inline]
 

Write the source

Definition at line 145 of file CompositeWriter.d.

void flush  )  [inline]
 

Flush the output

Definition at line 160 of file CompositeWriter.d.

References IWriter::flush().


Member Data Documentation

IWriter writer [private]
 

Definition at line 124 of file CompositeWriter.d.


The documentation for this class was generated from the following file:
Generated on Sun Oct 24 22:31:22 2004 for Mango by doxygen 1.3.6