annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
1 /* LICENSE BLOCK
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
2 Part of mde: a Modular D game-oriented Engine
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
4
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
7 version 2 of the License, or (at your option) any later version.
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
8
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
11 See the GNU General Public License for more details.
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
12
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
13 You should have received a copy of the GNU General Public License
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
5f90774ea1ef Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 15
diff changeset
15
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /**************************************************************************************************
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * This module contains all writing functions, for both binary and text MergeTag files.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 * Files can be written in a text or binary form; binary is faster and smaller while text allows
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 * editing with an ordinary text editor. TextWriter and BinaryWriter are the main classes, both of
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 * which implement the interface IWriter. DualWriter is another class implementing IWriter, which
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 * contains a private instance of a TextWriter and a BinaryWriter and implements all methods in the
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 * interface simply by chaining the appropriate method from each of these classes, thus performing
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 * two writes at once.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 * Any of these three classes may be used directly, or makeWriter may be invoked to create an
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 * instance of the appropriate class.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 *************************************************************************************************/
81
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 67
diff changeset
29 module mde.file.mergetag.Writer;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 // package imports
81
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 67
diff changeset
32 public import mde.file.mergetag.iface.IWriter;
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 67
diff changeset
33 import mde.file.mergetag.DataSet;
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 67
diff changeset
34 import mde.file.mergetag.internal;
d8fccaa45d5f Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 67
diff changeset
35 import mde.file.mergetag.exception;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 // tango imports
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 import tango.core.Exception;
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
39 import tango.io.device.File;
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
40 import tango.io.stream.Buffer;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 import convInt = tango.text.convert.Integer;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 import tango.util.log.Log : Log, Logger;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 private Logger logger;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 static this () {
82
ac1e3fd07275 New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 81
diff changeset
46 logger = Log.getLogger ("mde.file.mergetag.Writer");
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
50 /** Method to create and return either a MTTWriter or a MTBWriter.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 * Has two modes of operation: if method is FromExtension, examines the existing extension and
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 * creates a MTT/MTB writer if the extension is mtt or mtb (throwing if not).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 * Otherwise, writing format is determined directly by method, and appropriate extensions are
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * added to the file name without checking for an existing extension.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 * Params:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 * path = File path
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 * dataset = Dataset passed to Writer to write from (if null, must be set before write() is called)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 * method = $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 * $(TR $(TH Value) $(TH Writer returned) $(TH Suffix added))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 * $(TR $(TD FromExtension) $(TD MTBWriter or MTTWriter)$(TD $(I none)))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 * $(TR $(TD Binary) $(TD MTBWriter) $(TD .mtb))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
65 * $(TR $(TD Text) $(TD MTTWriter) $(TD .mtt))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 * $(TR $(TD Both) $(TD DualWriter) $(TD .mtb / .mtt))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 * )
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 * MTFileFormatException if neither test can deduce the writing method, the supplied writing
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 * method is invalid or the determined/supplied method is not yet implemented.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
73 * Use as:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
74 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 * DataSet dataset; // contains data to write
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 * IWriter foo;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 * try {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 * foo = makeWriter(...);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 * foo.write();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
80 * }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
81 * catch (MTException) {}
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 * Where the makeWriter line has one of the following forms:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 * foo = makeWriter("foo.mtt", dataset);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 * foo = makeWriter("foo", dataset, WriterMethod.Text);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 * MTFileFormatException if unable to determine writing format or use requested format.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 */
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
92 //FIXME: separate functions for separate functionality, like in Reader?
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
93 IWriter makeWriter (char[] path, DataSet dataset = null,
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
94 WriterMethod method = WriterMethod.FromExtension) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 if (method == WriterMethod.FromExtension) {
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
96 if (path.length > 4 && path[$-4..$] == ".mtt")
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
97 return new MTTWriter (path, dataset);
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
98 else if (path.length > 4 && path[$-4..$] == ".mtb")
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
99 return new MTBWriter (path, dataset);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 logger.error ("Unable to determine writing format: text or binary");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 throw new MTFileFormatException;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
103 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 if (method == WriterMethod.Binary) return new MTBWriter (path~".mtb", dataset);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 else if (method == WriterMethod.Text) return new MTTWriter (path~".mtt", dataset);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 else if (method == WriterMethod.Both) return new DualWriter (path, dataset);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 else throw new MTFileFormatException;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
111 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 /**
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 * Class to write a dataset to a file.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
116 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
117 * Files are only actually open for writing while the write() method is running.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
118 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
119 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 * $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 * $(TR $(TH Exception) $(TH Thrown when))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 * $(TR $(TD MTNoDataSetException) $(TD No dataset is available to write from))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 * $(TR $(TD MTFileIOException) $(TD An error occurs while attemting to write the file))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 * $(TR $(TD MTException) $(TD An unexpected error occurs))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 * )
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 * Note that all exceptions extend MTException; unlike Reader exceptions don't block further calls.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 class MTTWriter : IWriter
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
129 {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
130 //BEGIN DATA
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 /// Get or set the DataSet (i.e. the container from which all data is written).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 DataSet dataset () { return _dataset; }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 void dataset (DataSet ds) /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 { _dataset = ds; }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137 private:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
138 // taken from tango.io.Console, mostly to make sure notepad can read our files:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
139 version (Win32)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 const char[] Eol = "\r\n";
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141 else
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142 const char[] Eol = "\n";
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 /* The container where data is written from. */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 DataSet _dataset;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
147 char[] _path;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 //END DATA
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
149
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
150 //BEGIN CTOR / DTOR
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 /** Prepares to open file path for writing.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
153 * The call doesn't actually execute any code so cannot fail (unless out of memory).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 * Params:
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
156 * path = The name of the file to open.
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157 * Standard extensions are .mtt and .mtb for text and binary files respectively.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 * dataset_ = If null create a new DataSet, else use existing DataSet *dataset_ and merge read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 * data into it.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
160 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
161 public this (char[] path, DataSet ds = null) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162 _path = path;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
163 _dataset = ds;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 //END CTOR / DTOR
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 /** Writes the header and all DataSections.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 * Firstly writes the header unless it has already been written. Then writes all DataSections
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 * to the file. Thus if write is called more than once with or without changing the DataSet the
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 * header should be written only once. This behaviour could, for instance, be used to write
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 * multiple DataSets into one file without firstly merging them. Note that this behaviour may
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173 * be changed when binary support is added.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 public void write ()
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
177 if (!_dataset) throwMTErr ("write(): no Dataset available to write from!", new MTNoDataSetException ());
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 try {
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
180 scope File conduit; // actual conduit; don't use directly when there's content in the buffer
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
181 scope BufferOutput buffer; // write strings directly to this (use opCall(void[]) )
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 // Open a conduit on the file:
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
184 conduit = new File (_path, File.WriteCreate);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 scope(exit) conduit.close();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
187 buffer = new BufferOutput(conduit); // And a buffer
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 scope(exit) buffer.flush();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190 // Write the header:
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
191 buffer.append ("{MT" ~ MTFormatVersion.CurrentString ~ "}" ~ Eol);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 if (_dataset.header !is null) writeSection (buffer, _dataset.header);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 // Write the rest:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
195 foreach (ID id, IDataSection sec; _dataset.sec) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
196 writeSectionIdentifier (buffer, id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
197 writeSection (buffer, sec);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198 }
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 82
diff changeset
199
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200 buffer.flush();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203 catch (IOException e) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 throwMTErr ("Error writing to file: " ~ e.msg, new MTFileIOException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 catch (Exception e) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 throwMTErr ("Unexpected exception when writing file: " ~ e.msg);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
208 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
209 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
211 private void writeSectionIdentifier (BufferOutput buffer, ID id) {
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 82
diff changeset
212 char[] tp = "{" ~ cast(char[])id ~ "}" ~ Eol;
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
213 buffer.append (tp);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
216 private void writeSection (BufferOutput buffer, IDataSection sec) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 void writeItem (char[] tp, ID id, char[] dt) { // actually writes an item
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
218 buffer.append ("<" ~ tp ~ "|" ~ cast(char[])id ~"=" ~ dt ~ ">" ~ Eol);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
220 sec.writeAll (&writeItem);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
222 buffer.append (Eol); // blank line at end of each section
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 private void throwMTErr (char[] msg, Exception exc = new MTException) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226 logger.error (msg); // report the error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227 throw exc; // and signal our error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
229 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
230
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 /*
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
232 * Implement MTBWriter (and move both writers to own modules?).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
233 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
234 class MTBWriter : IWriter {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 public this (char[] path, DataSet ds = null) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
236 throw new MTNotImplementedException;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238 /+_path = path;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
239 _dataset = ds;+/
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
240 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
241
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
242 DataSet dataset () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
243 return null;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
244 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
245 void dataset (DataSet) {}
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
246
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
247 void write () {}
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
248 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
249
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
250 /* Basic implementation for mtt only.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 *Implement std CTORs which add extensions to each filename and extra CTORs which take two filenames.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
254 class DualWriter : IWriter {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
255 /** The individual writers.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
256 *
15
4608be19ebe2 Use OS paths (linux only for now), merging multiple paths. Init changes regarding options.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 14
diff changeset
257 * Potentially could be used directly, but there should be no need. */
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
258 MTTWriter mtt;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
259 //MTBWriter mtb; /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
260
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
261 public this (char[] path, DataSet ds = null) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
262 mtt = new MTTWriter (path~".mtt", ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
263 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
264
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
265 DataSet dataset () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
266 return mtt.dataset;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
267 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
268 void dataset (DataSet ds) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269 mtt.dataset = ds;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272 /** Write.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 * Write text then binary, so the mtb file will be the most recent.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 void write () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
277 mtt.write();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
279 }