Mercurial > projects > mde
view 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 |
line wrap: on
line source
/** This module contains the mergetag DataSet class, used for all reading and writing operations. */ module mde.mergetag.DataSet; // package imports public import mde.mergetag.iface.IDataSection; import mde.mergetag.DefaultData; import mde.mergetag.exception; /************************************************************************************************** * Data class; contains a DataSection class instance for each loaded section of a file. * * Stored data is available for direct access via header and sec; all functions are just helper * functions. * * Any class implementing IDataSection may be used to store data; by default a DefaultData class is * used when reading a file. Another class may be used by creating the sections before reading the * file or passing the reader a function to create the sections (see Reader.dataSecCreator). * * Could be a struct, except that structs are value types (not reference types). */ class DataSet { DefaultData header; /// Header section. IDataSection[ID] sec; /// Dynamic array of sections /// Template to return all sections of a child-class type. T[ID] getSections (T : IDataSection) () { T[ID] ret; foreach (ID id, IDataSection s; sec) { T x = cast(T) s; if (x) ret[id] = x; // if non-null } return ret; } } debug (mdeUnitTest) { import tango.util.log.Log : Log, Logger; private Logger logger; static this() { logger = Log.getLogger ("mde.mergetag.DataSet"); } unittest { // Only covers DataSet really. DataSet ds = new DataSet; ds.sec[cast(ID)"test"] = new DefaultData; assert (ds.getSections!(DefaultData)().length == 1); ds.sec[cast(ID)"test"].addTag ("int",cast(ID)"T"," -543 "); assert (ds.getSections!(DefaultData)()[cast(ID)"test"]._int[cast(ID)"T"] == -543); logger.info ("Unittest complete."); } }