Mercurial > projects > mde
view mde/file/mergetag/DataSet.d @ 134:7ababdf97748
Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 14:59:45 +0000 |
parents | 01f4f5f1acc9 |
children |
line wrap: on
line source
/* LICENSE BLOCK Part of mde: a Modular D game-oriented Engine Copyright © 2007-2008 Diggory Hardy This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /** This module contains the mergetag DataSet class, used for all reading and writing operations. */ module mde.file.mergetag.DataSet; // package imports public import mde.file.mergetag.iface.IDataSection; import mde.file.mergetag.DefaultData; /************************************************************************************************** * 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.file.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 ("char[]",cast(ID)"T"," \"ut tag 1 \" "); assert (ds.getSections!(DefaultData)()[cast(ID)"test"]._charA[cast(ID)"T"] == "ut tag 1 "); logger.info ("Unittest complete."); } }