Public Member Functions | |
this (IWriter writer) | |
CompositeWriter | put (IWritable source) |
void | flush () |
Private Attributes | |
IWriter | writer |
The approach leverages the exisiting IWritable interface which, when implemented, exposes a class that writes a related set of data. For instance:
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.
|
Construct a CompositeWriter with the provided IWriter. Definition at line 132 of file CompositeWriter.d. |
|
Write the source Definition at line 145 of file CompositeWriter.d. |
|
Flush the output Definition at line 160 of file CompositeWriter.d. References IWriter::flush(). |
|
Definition at line 124 of file CompositeWriter.d. |