comparison mde/file/mergetag/Writer.d @ 114:b16a534f5302

Changes for tango r4201. Added override keyword in a lot of places.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 19 Dec 2008 15:15:06 +0000
parents 79d816b3e2d2
children 4084f07f2c7a
comparison
equal deleted inserted replaced
113:9824bee909fd 114:b16a534f5302
34 import mde.file.mergetag.internal; 34 import mde.file.mergetag.internal;
35 import mde.file.mergetag.exception; 35 import mde.file.mergetag.exception;
36 36
37 // tango imports 37 // tango imports
38 import tango.core.Exception; 38 import tango.core.Exception;
39 import tango.io.device.FileConduit; 39 import tango.io.device.File;
40 import tango.io.Buffer : Buffer, IBuffer; 40 import tango.io.stream.Buffer;
41 import tango.io.Print : Print;
42 import convInt = tango.text.convert.Integer; 41 import convInt = tango.text.convert.Integer;
43 import tango.util.log.Log : Log, Logger; 42 import tango.util.log.Log : Log, Logger;
44 43
45 private Logger logger; 44 private Logger logger;
46 static this () { 45 static this () {
176 public void write () 175 public void write ()
177 { 176 {
178 if (!_dataset) throwMTErr ("write(): no Dataset available to write from!", new MTNoDataSetException ()); 177 if (!_dataset) throwMTErr ("write(): no Dataset available to write from!", new MTNoDataSetException ());
179 178
180 try { 179 try {
181 FileConduit conduit; // actual conduit; don't use directly when there's content in the buffer 180 scope File conduit; // actual conduit; don't use directly when there's content in the buffer
182 IBuffer buffer; // write strings directly to this (use opCall(void[]) ) 181 scope BufferOutput buffer; // write strings directly to this (use opCall(void[]) )
183 182
184 // Open a conduit on the file: 183 // Open a conduit on the file:
185 conduit = new FileConduit (_path, FileConduit.WriteCreate); 184 conduit = new File (_path, File.WriteCreate);
186 scope(exit) conduit.close(); 185 scope(exit) conduit.close();
187 186
188 buffer = new Buffer(conduit); // And a buffer 187 buffer = new BufferOutput(conduit); // And a buffer
189 scope(exit) buffer.flush(); 188 scope(exit) buffer.flush();
190 189
191 // Write the header: 190 // Write the header:
192 buffer ("{MT" ~ MTFormatVersion.CurrentString ~ "}" ~ Eol); 191 buffer.append ("{MT" ~ MTFormatVersion.CurrentString ~ "}" ~ Eol);
193 if (_dataset.header !is null) writeSection (buffer, _dataset.header); 192 if (_dataset.header !is null) writeSection (buffer, _dataset.header);
194 193
195 // Write the rest: 194 // Write the rest:
196 foreach (ID id, IDataSection sec; _dataset.sec) { 195 foreach (ID id, IDataSection sec; _dataset.sec) {
197 writeSectionIdentifier (buffer, id); 196 writeSectionIdentifier (buffer, id);
207 catch (Exception e) { 206 catch (Exception e) {
208 throwMTErr ("Unexpected exception when writing file: " ~ e.msg); 207 throwMTErr ("Unexpected exception when writing file: " ~ e.msg);
209 } 208 }
210 } 209 }
211 210
212 private void writeSectionIdentifier (IBuffer buffer, ID id) { 211 private void writeSectionIdentifier (BufferOutput buffer, ID id) {
213 char[] tp = "{" ~ cast(char[])id ~ "}" ~ Eol; 212 char[] tp = "{" ~ cast(char[])id ~ "}" ~ Eol;
214 buffer (tp); 213 buffer.append (tp);
215 } 214 }
216 215
217 private void writeSection (IBuffer buffer, IDataSection sec) { 216 private void writeSection (BufferOutput buffer, IDataSection sec) {
218 void writeItem (char[] tp, ID id, char[] dt) { // actually writes an item 217 void writeItem (char[] tp, ID id, char[] dt) { // actually writes an item
219 buffer ("<" ~ tp ~ "|" ~ cast(char[])id ~"=" ~ dt ~ ">" ~ Eol); 218 buffer.append ("<" ~ tp ~ "|" ~ cast(char[])id ~"=" ~ dt ~ ">" ~ Eol);
220 } 219 }
221 sec.writeAll (&writeItem); 220 sec.writeAll (&writeItem);
222 221
223 buffer (Eol); // blank line at end of each section 222 buffer.append (Eol); // blank line at end of each section
224 } 223 }
225 224
226 private void throwMTErr (char[] msg, Exception exc = new MTException) { 225 private void throwMTErr (char[] msg, Exception exc = new MTException) {
227 logger.error (msg); // report the error 226 logger.error (msg); // report the error
228 throw exc; // and signal our error 227 throw exc; // and signal our error