view API/WarFoundryLoader.cs @ 379:04f4c2fea356

Re #351: Add extensible requirement handling method * Extract common IRequirementFactory interface * Drop back to just returning IRequirement from factory to simplify generics * Add initial registration of requirement factories
author IBBoard <dev@ibboard.co.uk>
date Sat, 23 Jul 2011 19:53:42 +0000
parents 3c4a6403a88c
children 1a632b133606
line source
1 // This file (WarFoundryLoader.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
2 //
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
4 using System;
5 using ICSharpCode.SharpZipLib.Zip;
6 using System.Collections.Generic;
7 using IBBoard.WarFoundry.API.Factories.Requirement;
8 using IBBoard.WarFoundry.API.Objects.Requirement;
10 namespace IBBoard.WarFoundry.API
11 {
12 public class WarFoundryLoader
13 {
14 private static AbstractWarFoundryLoader loader;
15 private static Dictionary<string, IRequirementFactory> requirementFactories = new Dictionary<string, IRequirementFactory>();
17 /// <summary>
18 /// Gets the default <see cref="WarFoundryLoader"/> used to load WarFoundry data files.
19 /// </summary>
20 /// <returns>
21 /// The default <see cref="WarFoundryLoader"/>
22 /// </returns>
23 public static AbstractWarFoundryLoader GetDefault()
24 {
25 if (loader == null)
26 {
27 loader = new DefaultWarFoundryLoader();
28 }
30 return loader;
31 }
33 public static void SetDefault(AbstractWarFoundryLoader newLoader)
34 {
35 loader = newLoader;
36 }
38 private WarFoundryLoader()
39 {
40 //Hide constructor
41 }
43 public static void RegisterRequirementFactory(IRequirementFactory factory)
44 {
45 requirementFactories[factory.AppliesToID] = factory;
46 }
48 public static IRequirementFactory GetRequirementFactory(string requirementID)
49 {
50 return DictionaryUtils.GetValue(requirementFactories, requirementID);
51 }
52 }
53 }