Mercurial > projects > mde
comparison mde/file/mergetag/DataSet.d @ 81:d8fccaa45d5f
Moved file IO code from mde/mergetag to mde/file[/mergetag] and changed how some errors are caught.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 29 Aug 2008 11:59:43 +0100 |
parents | mde/mergetag/DataSet.d@61ea26abe4dd |
children | ac1e3fd07275 |
comparison
equal
deleted
inserted
replaced
80:ea58f277f487 | 81:d8fccaa45d5f |
---|---|
1 /* LICENSE BLOCK | |
2 Part of mde: a Modular D game-oriented Engine | |
3 Copyright © 2007-2008 Diggory Hardy | |
4 | |
5 This program is free software: you can redistribute it and/or modify it under the terms | |
6 of the GNU General Public License as published by the Free Software Foundation, either | |
7 version 2 of the License, or (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 See the GNU General Public License for more details. | |
12 | |
13 You should have received a copy of the GNU General Public License | |
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
15 | |
16 /** This module contains the mergetag DataSet class, used for all reading and writing operations. | |
17 */ | |
18 module mde.file.mergetag.DataSet; | |
19 | |
20 // package imports | |
21 public import mde.file.mergetag.iface.IDataSection; | |
22 import mde.file.mergetag.DefaultData; | |
23 | |
24 | |
25 /************************************************************************************************** | |
26 * Data class; contains a DataSection class instance for each loaded section of a file. | |
27 * | |
28 * Stored data is available for direct access via header and sec; all functions are just helper | |
29 * functions. | |
30 * | |
31 * Any class implementing IDataSection may be used to store data; by default a DefaultData class is | |
32 * used when reading a file. Another class may be used by creating the sections before reading the | |
33 * file or passing the reader a function to create the sections (see Reader.dataSecCreator). | |
34 * | |
35 * Could be a struct, except that structs are value types (not reference types). | |
36 */ | |
37 class DataSet | |
38 { | |
39 DefaultData header; /// Header section. | |
40 IDataSection[ID] sec; /// Dynamic array of sections | |
41 | |
42 /// Template to return all sections of a child-class type. | |
43 T[ID] getSections (T : IDataSection) () { | |
44 T[ID] ret; | |
45 foreach (ID id, IDataSection s; sec) { | |
46 T x = cast(T) s; | |
47 if (x) ret[id] = x; // if non-null | |
48 } | |
49 return ret; | |
50 } | |
51 } | |
52 | |
53 debug (mdeUnitTest) { | |
54 import tango.util.log.Log : Log, Logger; | |
55 | |
56 private Logger logger; | |
57 static this() { | |
58 logger = Log.getLogger ("mde.mergetag.DataSet"); | |
59 } | |
60 | |
61 unittest { // Only covers DataSet really. | |
62 DataSet ds = new DataSet; | |
63 ds.sec[cast(ID)"test"] = new DefaultData; | |
64 assert (ds.getSections!(DefaultData)().length == 1); | |
65 ds.sec[cast(ID)"test"].addTag ("char[]",cast(ID)"T"," \"ut tag 1 \" "); | |
66 assert (ds.getSections!(DefaultData)()[cast(ID)"test"].Arg!(char[])[cast(ID)"T"] == "ut tag 1 "); | |
67 | |
68 logger.info ("Unittest complete."); | |
69 } | |
70 } |