Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Factories/AbstractWarFoundryFactory.cs @ 8:613bc5eaac59
Re #9 - Make WarFoundry loading granular
* Remove specific staged loading classes
* Rework category loading for GameSystem and Race to make it use AddCategory(Category) method
* Promote staged loading from Native Factory to all Factories level
* Refactor XML Factory to use smaller methods
Also removed some commented code that isn't used any more
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Jan 2009 19:24:13 +0000 |
parents | 520818033bb6 |
children | 0770e5cbba7c |
rev | line source |
---|---|
0 | 1 // AbstractWarFoundryFactory.cs |
2 // | |
3 // Copyright (C) 2008 IBBoard | |
4 // | |
5 // This library is free software; you can redistribute it and/or | |
6 // modify it under the terms of the GNU Lesser General Public | |
7 // License as published by the Free Software Foundation; either | |
8 // version 2.1 of the License, or (at your option) any later version. | |
9 // | |
10 // This library is distributed in the hope that it will be useful, | |
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 // Lesser General Public License for more details. | |
14 // | |
15 // You should have received a copy of the GNU Lesser General Public | |
16 // License along with this library; if not, write to the Free Software | |
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 // | |
19 // | |
20 | |
21 using System; | |
22 using System.IO; | |
23 using System.Collections.Generic; | |
24 using IBBoard.WarFoundry.API.Objects; | |
25 | |
26 namespace IBBoard.WarFoundry.API.Factories | |
27 { | |
28 public abstract class AbstractWarFoundryFactory<FILE_TYPE> : IWarFoundryFactory | |
8
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
29 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
30 public virtual void CompleteLoading(IWarFoundryStagedLoadObject obj) |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
31 { |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
32 //Default to doing nothing as this will probably be standard for non-native factories and some native factories |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
33 } |
613bc5eaac59
Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
34 |
0 | 35 public bool CanHandleFileFormat (FileInfo file) |
36 { | |
37 return CheckCanHandleFileFormat(GetFileAsSupportedType(file)); | |
38 } | |
39 | |
40 /// <summary> | |
41 /// Converts the <see cref="FileInfo"/> object in to the appropriate type for this class so that it can perform its checks. If no conversion is required (the test can be performed on a <see cref="FileInfo"/> object) the object should be returned with no modification. | |
42 /// </summary> | |
43 /// <param name="file"> | |
44 /// A <see cref="FileInfo"/> to get the supported source object from. | |
45 /// </param> | |
46 /// <returns> | |
47 /// An object of type <see cref="FILE_TYPE"/> that has been converted from the input <see cref="FileInfo"/> object, or <code>null</code> if the conversion cannot be made. | |
48 /// </returns> | |
49 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file); | |
50 | |
51 /// <summary> | |
52 /// Checks whether the factory thinks it can load data from the file in its paramaterised type. | |
53 /// </summary> | |
54 /// <param name="file"> | |
55 /// An object of the converted <see cref="FILE_TYPE"/> to check support for | |
56 /// </param> | |
57 /// <returns> | |
58 /// <code>true</code> if the factory thinks it can support the file, else <code>false</code> | |
59 /// </returns> | |
60 protected abstract bool CheckCanHandleFileFormat(FILE_TYPE file); | |
61 | |
62 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file) | |
63 { | |
64 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); | |
65 } | |
66 | |
67 /// <summary> | |
68 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. | |
69 /// </summary> | |
70 /// <param name="file"> | |
71 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from | |
72 /// </param> | |
73 /// <returns> | |
74 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object | |
75 /// </returns> | |
76 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); | |
77 } | |
78 } |