Mercurial > projects > mde
comparison mde/mergetag/DataSet.d @ 14:0047b364b6d9
Changed much of the mergetag structure and some functionality. First tests on windows.
Changes to mergetag Reader methods. New functionality allowing a dataSecCreator to cause sections to be skipped.
Moved several of the mergetag modules and some of their contents around. Moved all interfaces to separate modules in iface/ .
IReader & IWriter interfaces exist; MTTReader, MTBReader, MTTWriter, MTBWriter & DualWriter all now exist and implement IReader/IWriter (although the MTB variants are dummy classes); makeReader & makeWriter should both be fully functional.
Tested building on windows with partial success (works but window won't open).
Included a temporary hack from windows to get supported resolutions information.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 07 Mar 2008 17:51:02 +0000 |
parents | |
children | 5f90774ea1ef |
comparison
equal
deleted
inserted
replaced
13:914fed025adb | 14:0047b364b6d9 |
---|---|
1 /** This module contains the mergetag DataSet class, used for all reading and writing operations. | |
2 */ | |
3 module mde.mergetag.DataSet; | |
4 | |
5 // package imports | |
6 public import mde.mergetag.iface.IDataSection; | |
7 import mde.mergetag.DefaultData; | |
8 import mde.mergetag.exception; | |
9 | |
10 | |
11 /************************************************************************************************** | |
12 * Data class; contains a DataSection class instance for each loaded section of a file. | |
13 * | |
14 * Stored data is available for direct access via header and sec; all functions are just helper | |
15 * functions. | |
16 * | |
17 * Any class implementing IDataSection may be used to store data; by default a DefaultData class is | |
18 * used when reading a file. Another class may be used by creating the sections before reading the | |
19 * file or passing the reader a function to create the sections (see Reader.dataSecCreator). | |
20 * | |
21 * Could be a struct, except that structs are value types (not reference types). | |
22 */ | |
23 class DataSet | |
24 { | |
25 DefaultData header; /// Header section. | |
26 IDataSection[ID] sec; /// Dynamic array of sections | |
27 | |
28 /// Template to return all sections of a child-class type. | |
29 T[ID] getSections (T : IDataSection) () { | |
30 T[ID] ret; | |
31 foreach (ID id, IDataSection s; sec) { | |
32 T x = cast(T) s; | |
33 if (x) ret[id] = x; // if non-null | |
34 } | |
35 return ret; | |
36 } | |
37 } | |
38 | |
39 debug (mdeUnitTest) { | |
40 import tango.util.log.Log : Log, Logger; | |
41 | |
42 private Logger logger; | |
43 static this() { | |
44 logger = Log.getLogger ("mde.mergetag.DataSet"); | |
45 } | |
46 | |
47 unittest { // Only covers DataSet really. | |
48 DataSet ds = new DataSet; | |
49 ds.sec[cast(ID)"test"] = new DefaultData; | |
50 assert (ds.getSections!(DefaultData)().length == 1); | |
51 ds.sec[cast(ID)"test"].addTag ("int",cast(ID)"T"," -543 "); | |
52 assert (ds.getSections!(DefaultData)()[cast(ID)"test"]._int[cast(ID)"T"] == -543); | |
53 | |
54 logger.info ("Unittest complete."); | |
55 } | |
56 } |