annotate mde/mergetag/Reader.d @ 67:108d123238c0

Changes to work with tango r3700 (post 0.99.6). Changes to logging. Replaced many uses of PathView with FilePath.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 03 Jul 2008 12:40:31 +0100
parents e0839643ff52
children ea58f277f487
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: 24
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: 24
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: 24
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: 24
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: 24
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 reading 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 module mde.mergetag.Reader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 // package imports
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 public import mde.mergetag.iface.IReader;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 import mde.mergetag.DataSet;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24 import mde.mergetag.DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
25 import mde.mergetag.exception;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26 import mde.mergetag.internal;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28 import tango.core.Exception;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
29
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 // tango imports
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
31 import tango.io.FilePath;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32 import tango.io.UnicodeFile;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 import Util = tango.text.Util;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 import ConvInt = tango.text.convert.Integer;
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
35 //import tango.util.collection.model.View : View;
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 import tango.util.collection.HashSet : HashSet;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 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
38
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39 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
40 static this() {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 logger = Log.getLogger ("mde.mergetag.Reader");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 }
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 // TODO: allow compressing with zlib for both binary and text? (.mtz, .mtt, .mtb extensions)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46 /** Make an IReader class.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47 *
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
48 * Create an appropriate reader: MTTReader or MTBReader.
14
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 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 * $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52 * $(TR $(TH Exception) $(TH Thrown when))
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
53 * $(TR $(TD MTFileIOException) $(TD When extension given is neither mtt nor mtb))
14
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 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 */
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
57 IReader makeReader (FilePath path, DataSet ds = null, bool rdHeader = false) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 if (path.ext == "mtb") return new MTBReader (path, ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 else if (path.ext == "mtt") return new MTTReader (path, ds, rdHeader);
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
60 else throw new MTFileIOException ("Invalid mergetag extension");
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
61 }
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
62
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
63 /** Resolve a file path.
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
64 *
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
65 * Tries adding both ".mtt" and ".mtb" extensions, returning whichever exists (the most recently
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
66 * modified if both exist), or returns null if neither exist. */
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
67 FilePath findFile (char[] path) {
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
68 if (path is null) return null;
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
69
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
70 FilePath tPath = new FilePath (path ~ ".mtt");
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
71 FilePath bPath = new FilePath (path ~ ".mtb");
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
72
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
73 bool bPathExists = bPath.exists;
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
74
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
75 if (tPath.exists) {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
76 if (bPathExists) {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
77 // take the latest version (roughly speaking...)
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
78 return (tPath.modified > bPath.modified ? tPath : bPath);
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
79 } else return tPath;
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
80 } else {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
81 if (bPathExists) return bPath;
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
82 else return null;
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
83 }
14
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
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
86 /**
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
87 * Class for reading a mergetag text file.
14
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 * 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
90 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 * IReader foo;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 * try {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 * foo = new MTTReader("foo.mtt");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 * foo.read();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 * }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96 * 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
97 * // get your data from foo.dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 * -----------------------
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 * Throws:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 * $(TABLE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 * $(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
103 * $(TR $(TD MTFileIOException) $(TD An error occurs while opening 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
104 * $(TR $(TD MTFileFormatException) $(TD The file doesn't start with a recognised header/version))
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
105 * $(TR $(TD MTSyntaxException) $(TD A file syntax 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
106 * $(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
107 * )
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 * Note that all exceptions extend MTException and when any exception is thrown the class is
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 * rendered unusable: any subsequent calls to read will be ignored.
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 * Threading: Separate instances of Reader should be thread-safe provided access to the same
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 * dataset is synchronized; i.e. no two readers refering to the same dataset should run
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 * simultaneously. (The Reader class could be made thread-safe w.r.t. datasets, but
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
114 * performance-wise I doubt it would be worth it.)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 * Do not run a single instance of Reader in multiple threads simultaneously.
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 class MTTReader : IReader
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 //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
120 /** Get or set the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 * A container for all read data.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 * This may be accessed from here; however it may be preferable to use an external reference
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 * (passed to the class on initialisation).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 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
128 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
129 { _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
130
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 /** A delegate for creating new DataSections within the dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 * Allows a user-made class to be used in the DataSet instead of DefaultData (used if no
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 * dataSecCreator exists). Also allows an existing class instance to be used instead of a new
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135 * one.
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 * This works by supplying a function which returns a reference to an instance of a class
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
138 * implementing IDataSection. The function is passed the ID of the new section and may use this
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
139 * to use different IDataSection classes for different sections.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141 * The function may also return null, in which case the section will be skipped. In the version
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
142 * of read taking a set of sections to read, the section will not be marked as read and may
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
143 * still be read later (assuming dataSecCreator returns non-null). However, in the version of
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
144 * read not taking the set argument, all sections are set as read regardless, and the section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
145 * cannot be read later.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147 void dataSecCreator (IDataSection delegate (ID) dSC) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 _dataSecCreator = dSC;
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
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
151 private:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 static 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
153
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
154 // Non-static symbols:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
155 final char[] ErrFile; // added after ErrInFile to do the same without the "in " bit.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 final char[] ErrInFile; // something like "in \"path/file.mtt\""
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
157
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158 final char[] fbuf; // file is read into this
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
159 MTFormatVersion.VERS fileVer = MTFormatVersion.VERS.INVALID; // Remains INVALID until set otherwise by CTOR.
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 IDataSection delegate (ID) _dataSecCreator = null; // see property setter above
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
162
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
163 size_t endOfHeader;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
164 bool allRead = false; // true if endOfHeader == fbuf.length or read([]) has run
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
165 bool fatal = false; // a fatal file error occured; don't try to recover
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166 /* If the file is scanned for sections, the starting position of all sections are stored
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 * in secTable. If this is empty, either no sections exist (and endOfHeader == fbuf.length)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 * or a section scan has not been run (read() with no section names doesn't need to do so).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 struct SecMD { // sec meta data
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
171 static SecMD opCall (size_t _pos, bool _read) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172 SecMD ret;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
173 ret.pos = _pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
174 ret.read = _read;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 return ret;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 }
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
177 size_t pos; // position to start reading
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
178 bool read; // true if already read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 SecMD [ID] secTable;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
182 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
183 //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
184
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 //BEGIN METHODS: 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
186 static this () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 logger = Log.getLogger ("mde.mergetag.read.Reader");
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
188 }
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 /** Tries to open file path and read it into a buffer.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
192 * Params:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
193 * path = The name or FilePath of the file to open.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
194 * 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
195 * ds = If null create a new DataSet, else use existing DataSet ds 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
196 * 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
197 * rdHeader = If true, read the header like a standard section. Doesn't read the header by
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
198 * default since if it's not requested it's likely not wanted.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
199 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200 * Memory:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
201 * This currently works by loading the whole file into memory at once. This should be fine most
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 * of the time, but could potentially be a problem. Changing this would mean significantly
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203 * changes to the way the code works.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205 /* Ideas for implementing a partial-loading memory model:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 * Use a conduit directly.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 * Use a fiber to do the parsing; let it switch back when it runs 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
208 * Redesign the code so it never needs to look backwards in the buffer?
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 * Major problem: reading only some sections and keeping references to other sections
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211 * would no longer be possible.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
212 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
213 public this (char[] path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
214 this (new FilePath (path), ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
215 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 /** ditto */
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 47
diff changeset
217 public this (FilePath path, DataSet ds = null, bool rdHeader = false) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
218 // Create a dataset or use an existing one
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 if (ds !is null) _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
220 else _dataset = new DataSet();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
222 // Open & read 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
223 try { // Supports unicode files with a BOM; defaults to UTF8 when there isn't a BOM:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
224 scope file = new UnicodeFile!(char) (path, Encoding.Unknown);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 fbuf = cast(char[]) file.read();
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226 } 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
227 throwMTErr ("Error reading 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
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 // Remember the file name so that we can report errors (somewhat) informatively:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
230 ErrFile = path.path ~ path.file;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 ErrInFile = " in \"" ~ ErrFile ~ '"';
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
232
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
233 // Version checking & matching header section tag:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
234 if (fbuf.length < 6 || fbuf[0] != '{' || fbuf[1] != 'M' || fbuf[2] != 'T' || fbuf[5] != '}')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 throwMTErr("Not a valid MergeTag text file" ~ ErrInFile, 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
236 fileVer = MTFormatVersion.parseString (fbuf[3..5]);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 if (fileVer == MTFormatVersion.VERS.INVALID)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238 throwMTErr("Unrecognised MergeTag version: MT" ~ fbuf[3..5] ~ ErrInFile, 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
239
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
240 // Header reading/skipping:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
241 if (rdHeader) { // only bother actually reading it if it was requested
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
242 // If already existing, merge; else create a new DefaultData.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
243 if (!_dataset.header) _dataset.header = new DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
244 endOfHeader = parseSection (6, cast(IDataSection) _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
245 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
246 else endOfHeader = parseSection (6,null);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
247 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
248 //END METHODS: 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
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 //BEGIN METHODS: PUBLIC
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 /** Scans for sections if not already done and returns a list of IDs.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 * Won't work (will return an empty array) if all sections have already been read without
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
254 * scanning for sections.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
255 */
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
256 public ID[] getSectionNames () {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 if (fatal) return [];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
258 if (!secTable.length) read([]); // scan for sections
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
259 return secTable.keys;
14
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
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
262 /** Reads (some) sections of the file into data. Note that sections will never be _read twice.
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 * To be more accurate, the file is copied into a buffer by this(). read() then parses the
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
265 * contents of this buffer, and stores the contents in 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 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
267 * Each section read is stored in a DataSection class. By default this is an instance of
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
268 * DefaultData; this can be customised (see dataSecCreator).
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
270 * If secSet is provided, reading is restricted to sections given in secSet, otherwise all
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271 * sections are read. Sections given in secSet but not found in the file are not reported as an
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272 * error. Suggested: supply a HashSet!(uint) as the View!(ID). An ArrayBag!(ID) as used is not a
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273 * good choice, except that in this case it's empty.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275 * Merging:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 * Where a section already exists in the DataSet (when either the section is given more than
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
277 * once in the file, or it was read from a different file by another reader) it is merged.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278 * Entries already in the DataSet take priority.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
279 *
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
280 * Performance:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
281 * Note that loading only desired sections like this still parses the sections not
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
282 * read (although it does not try to understand the type or data fields), so there is only a
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
283 * small performance advantage to this where other sections do exist in the file. There is also
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
284 * some overhead in only partially reading the file to keep track of where other sections are so
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
285 * that the entire file need not be re-read if further (or all remaining) sections are read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
286 * later.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
287 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
288 public void read () {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
289 if (secTable.length) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
290 foreach (ID id, ref SecMD smd; secTable) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
291 if (!smd.read) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
292 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
293 parseSection (smd.pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
294 // allRead is set true so there's no point setting smd.read = true
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
295 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
296 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
297 } else { // this time we don't need to use secTable
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
298 for (size_t pos = endOfHeader; pos < fbuf.length;) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
299 ID id = fbufReadSecMarker (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
300 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
301 pos = parseSection (pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
302 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
303 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
304
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
305 allRead = true;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
306 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
307 /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
308 public void read (ID[] secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
309 HashSet!(ID) hs = new HashSet!(ID);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
310 foreach (id; secSet) hs.add(id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
311 read (hs);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
312 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
313 /** ditto */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
314 public void read (View!(ID) secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
315 if (allRead || fatal) return; // never do anything in either case
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
316
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
317 if (secTable.length) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
318 foreach (ID id; secSet) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
319 SecMD* psmd = id in secTable;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
320 if (psmd && !psmd.read) { // may not exist
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
321 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
322 parseSection (psmd.pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
323 if (ds !is null) psmd.read = true; // getOrCreateSec may 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
324 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
325 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
326 } else {
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
327 for (size_t pos = endOfHeader; pos < fbuf.length;) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
328 ID id = fbufReadSecMarker (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
329 secTable[id] = SecMD(pos,false); // add to table
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
330 if (secSet.contains(id)) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
331 IDataSection ds = getOrCreateSec (id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
332 pos = parseSection (pos, ds);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
333 if (ds !is null) secTable[id].read = true;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
334 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
335 pos = parseSection (pos, null); // skip section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
336 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
337 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
338 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
339 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
340 //END METHODS: PUBLIC
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
341
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
342 //BEGIN METHODS: PRIVATE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
343 /* Utility function for read
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
344 * Look for a section; return it if it exists otherwise create a new section:
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
345 * use _dataSecCreator if it exists or just create a DefaultData 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
346 * However if _dataSecCreator returns null don't add it to the dataset.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
347 */
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
348 private IDataSection getOrCreateSec (ID id) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
349 IDataSection* i = id in _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
350 if (i) return *i;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
351 else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
352 IDataSection s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
353 if (_dataSecCreator !is null) s = _dataSecCreator(id);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
354 else s = new DefaultData;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
355 if (s !is null) _dataset.sec[id] = s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
356 return s;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
357 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
358 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
359
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
360 /* Reads a section, starting from index pos, finishing at the next section marker (returning
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
361 the position of the start of the marker). pos should start after the section marker.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
362
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
363 After analysing tags, the function passes the type, ID and data to addTag.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
364
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
365 NOTE: from performance tests on indexing char[]'s and dereferencing char*'s, the char*'s are
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
366 slightly faster, but a tiny difference isn't worth the extra effort/risk of using char*'s.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
367 */
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
368 private size_t parseSection (size_t pos, IDataSection dsec) {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
369 debug scope (failure)
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
370 logger.trace ("MTTReader.parseSection: failure");
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
371 /* Searches fbuf starting from start to find one of <=>| and stops at its index.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
372
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
373 If quotable then be quote-aware for single and double quotes.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
374 Note: there's no length restriction for the content of the quote since it could be a single
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
375 non-ascii UTF-8 char which would look like several chars.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
376 */
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
377 void fbufLocateDataTagChar (ref size_t pos, bool quotable) {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
378 while (true) {
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
379 fbufIncrement (pos);
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
380
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
381 if ((fbuf[pos] >= '<' && fbuf[pos] <= '>') || fbuf[pos] == '|') return;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
382 else if (quotable) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
383 char c = fbuf[pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
384 if (c == '\'' || c == '"') {
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
385 fbufIncrement(pos);
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
386 while (fbuf[pos] != c) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
387 if (fbuf[pos] == '\\') ++pos; // escape seq.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
388 fbufIncrement(pos);
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
389 }
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
390 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
391 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
392 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
393 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
394
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
395 // Used to ignore a tag (if it starts !< or !{ or should otherwise be ignored):
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
396 bool comment = false;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
397 for (; pos < fbuf.length; ++pos) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
398 if (Util.isSpace(fbuf[pos])) continue; // whitespace
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
399 else if (fbuf[pos] == '<') { // data tag
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
400 char[] ErrDTAG = "Bad data tag format: not <type|id=data>" ~ ErrInFile;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
401
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
402 // Type section of tag:
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
403 size_t pos_s = pos + 1;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
404 fbufLocateDataTagChar (pos, false); // find end of type section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
405 if (fbuf[pos] != '|') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
406 char[] type = fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
407
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
408 // ID section of tag:
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
409 pos_s = pos + 1;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
410 fbufLocateDataTagChar (pos, false); // find end of type section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
411 if (fbuf[pos] != '=') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
412 ID tagID = cast(ID) fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
413
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
414 // Data section of tag:
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
415 pos_s = pos + 1;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
416 fbufLocateDataTagChar (pos, true); // find end of data section
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
417 if (fbuf[pos] != '>') throwMTErr (ErrDTAG, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
418 char[] data = fbuf[pos_s..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
419
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
420 if (!comment && dsec !is null) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
421 type = Util.trim(type);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
422 try {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
423 dsec.addTag (type, tagID, data);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
424 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
425 catch (TextException e) {
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
426 logger.error ("TextException while reading " ~ ErrFile ~ ":"); // following a parse error
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 17
diff changeset
427 logger.error (e.msg);
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
428 // No throw: tag is just ignored
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
429 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
430 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
431 logger.error ("Unknown error occured" ~ ErrInFile ~ ':');
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
432 logger.error (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
433 throwMTErr (e.msg); // Fatal to Reader
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
434 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
435 } else comment = false; // cancel comment status now
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
436 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
437 else if (fbuf[pos] == '{') {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
438 if (comment) { // simple block comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
439 uint depth = 0; // depth of embedded comment blocks
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
440 while (true) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
441 fbufIncrement (pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
442 if (fbuf[pos] == '}') {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
443 if (depth == 0) break;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
444 else --depth;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
445 } else if (fbuf[pos] == '{')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
446 ++depth;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
447 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
448 comment = false; // end of this comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
449 } else {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
450 return pos; // next section coming up; we are done
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
451 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
452 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
453 else if (fbuf[pos] == '!') { // possibly a comment; check next char
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
454 comment = true; // starting a comment (or an error)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
455 // variable is reset at end of comment
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
456 } else // must be an error
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
457 throwMTErr ("Invalid character (or sequence starting \"!\") outside of tag" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
458 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
459 // if code execution reaches here, we're at EOF
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
460 // possible error: last character was ! (but don't bother checking since it's inconsequential)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
461 return pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
462 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
463
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
464 /* Parses fbuf for a section marker. Already knows fbuf[pos] == '{'.
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
465 */
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
466 private ID fbufReadSecMarker (ref size_t pos) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
467 // at this point pos is whatever a parseSection run returned
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
468 // since we haven't hit EOF, fbuf[pos] MUST be '{' so no need to check
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
469 fbufIncrement(pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
470
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
471 size_t start = pos;
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
472 for (; pos < fbuf.length; ++pos)
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
473 if (fbuf[pos] == '}' || fbuf[pos] == '{') break;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
474
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
475 if (pos >= fbuf.length || fbuf[pos] != '}')
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
476 throwMTErr ("Bad section tag format: not {id}" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
477
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
478 ID id = cast(ID) fbuf[start..pos];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
479 fbufIncrement(pos);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
480 return id;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
481 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
482
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
483 /* Increments pos and checks it hasn't hit fbuf.length . */
47
e0839643ff52 New mtcp utility and changes to paths.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
484 private void fbufIncrement(ref size_t pos) {
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
485 ++pos;
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
486 if (pos >= fbuf.length) throwMTErr("Unexpected EOF" ~ ErrInFile, new MTSyntaxException);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
487 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
488
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
489 private void throwMTErr (char[] msg, MTException 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
490 fatal = true; // if anyone catches the error and tries to do anything --- we're dead now
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
491 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
492 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
493 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
494 //END METHODS: PRIVATE
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
495 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
496
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
497
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
498 /**
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
499 * Class for reading a mergetag text file.
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
500 *
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
501 * Currently only a dummy class: a MTNotImplementedException will be thrown if created.
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
502 */
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
503 class MTBReader : IReader
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
504 {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
505 public this (char[] path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
506 this (new FilePath (path), ds, rdHeader);
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
507 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
508 public this (PathView path, DataSet ds = null, bool rdHeader = false) {
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
509 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
510 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
511
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
512 DataSet dataset () { /// Get the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
513 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
514 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
515 void dataset (DataSet) {} /// Set the DataSet
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
516
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
517 void dataSecCreator (IDataSection delegate (ID)) {} /// Set the dataSecCreator
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
518
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
519 ID[] getSectionNames () { /// Get identifiers for all sections
14
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
520 return [];
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
521 }
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
522 void read () {} /// Commence reading
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
523 void read (ID[] secSet) {} /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
524 void read (View!(ID) secSet) {} /// ditto
0047b364b6d9 Changed much of the mergetag structure and some functionality. First tests on windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
525 }