Mercurial > repos > IBBoard.WarFoundry.API
comparison api/Factories/AbstractWarFoundryFactory.cs @ 0:520818033bb6
Initial commit of WarFoundry code
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 19 Dec 2008 15:57:51 +0000 |
parents | |
children | 613bc5eaac59 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:520818033bb6 |
---|---|
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 | |
29 { | |
30 public bool CanHandleFileFormat (FileInfo file) | |
31 { | |
32 return CheckCanHandleFileFormat(GetFileAsSupportedType(file)); | |
33 } | |
34 | |
35 /// <summary> | |
36 /// 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. | |
37 /// </summary> | |
38 /// <param name="file"> | |
39 /// A <see cref="FileInfo"/> to get the supported source object from. | |
40 /// </param> | |
41 /// <returns> | |
42 /// 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. | |
43 /// </returns> | |
44 protected abstract FILE_TYPE GetFileAsSupportedType(FileInfo file); | |
45 | |
46 /// <summary> | |
47 /// Checks whether the factory thinks it can load data from the file in its paramaterised type. | |
48 /// </summary> | |
49 /// <param name="file"> | |
50 /// An object of the converted <see cref="FILE_TYPE"/> to check support for | |
51 /// </param> | |
52 /// <returns> | |
53 /// <code>true</code> if the factory thinks it can support the file, else <code>false</code> | |
54 /// </returns> | |
55 protected abstract bool CheckCanHandleFileFormat(FILE_TYPE file); | |
56 | |
57 public ICollection<IWarFoundryObject> CreateObjectsFromFile(FileInfo file) | |
58 { | |
59 return DoCreateObjectsFromFile(GetFileAsSupportedType(file)); | |
60 } | |
61 | |
62 /// <summary> | |
63 /// Reads the data from the supplied converted <see cref="FILE_TYPE"/> object and returns it as a collection of loadable objects. | |
64 /// </summary> | |
65 /// <param name="file"> | |
66 /// An object of the converted <see cref="FILE_TYPE"/> for the file to load data from | |
67 /// </param> | |
68 /// <returns> | |
69 /// A <see cref="ICollection`1"/> of <see cref="IWarFoundryObject"/>s that were loaded from the file object | |
70 /// </returns> | |
71 protected abstract ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FILE_TYPE file); | |
72 } | |
73 } |