Mercurial > projects > mde
comparison mde/file/mergetag/iface/IDataSection.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/iface/IDataSection.d@7fc0a8295c83 |
children |
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 interface IDataSection used by DataSet. | |
17 * | |
18 * It has been given its own module to avoid cyclic dependancies and separate out the functionality | |
19 * of mergetag. | |
20 * | |
21 * Also some base mergetag symbols have been moved here. | |
22 */ | |
23 module mde.file.mergetag.iface.IDataSection; | |
24 | |
25 /** Typedef for data & section indexes. | |
26 * | |
27 * Make it an alias, there doesn't appear to be any point having it as a typedef. */ | |
28 alias char[] ID; | |
29 | |
30 /** | |
31 * Interface for data storage classes, generally called DataSections, which contain all data-tags | |
32 * loaded from a single section of a file. | |
33 * | |
34 * A class implementing this may implement the addTag function to do whatever it likes with the | |
35 * data passed. DefaultData is one implementation which separates this data out into supported | |
36 * types and stores it appropriately (allowing merging with existing entries by keeping whichever | |
37 * tag was last loaded), while ignoring unsupported types. A different | |
38 * implementation could filter out the tags desired and use them directly, and ignore the rest. | |
39 * | |
40 * The mde.mergetag.parse.parseTo module provides a useful set of templated functions to | |
41 * convert the data accordingly. It is advised to keep the type definitions as defined in the file- | |
42 * format except for user-defined types, although this isn't necessary for library operation | |
43 * (addTag and writeAll are solely responsible for using and setting the type, ID and data fields). | |
44 * | |
45 * Another idea for a DataSection class: | |
46 * Use a void*[ID] variable to store all data (may also need a type var for each item). | |
47 * addTag should call a templated function which calls parse then casts to a void* and stores the data. | |
48 * Use a templated get(T)(ID) method which checks the type and casts to T. | |
49 */ | |
50 interface IDataSection | |
51 { | |
52 /** Delegate passed to writeAll. */ | |
53 typedef void delegate (char[],ID,char[]) ItemDelg; | |
54 | |
55 /** Handles parsing of data items for all recognised types. | |
56 * | |
57 * Should ignore unsupported types/unwanted tags. | |
58 * | |
59 * TextExceptions (thrown by parseTo/parseFrom) are caught and a warning logged; execution | |
60 * then continues (so the offending tag gets dropped). */ | |
61 void addTag (char[],ID,char[]); | |
62 | |
63 /** Responsible for getting all data tags saved. | |
64 * | |
65 * writeAll should call the ItemDelg once for each tag to be saved with parameters in the same | |
66 * form as received by addTag (char[] type, ID id, char[] data). */ | |
67 void writeAll (ItemDelg); | |
68 } |