removed Ijw.DirectX, Ijw.Framework deps

This commit is contained in:
Chris Forbes
2010-02-16 18:52:26 +13:00
parent 95ae493dc4
commit 4258e78049
38 changed files with 250 additions and 54 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Collections;
namespace OpenRa.FileFormats
{
public class Cache<T, U> : IEnumerable<KeyValuePair<T, U>>
{
Dictionary<T, U> hax = new Dictionary<T, U>();
Func<T,U> loader;
public Cache(Func<T,U> loader)
{
if (loader == null)
throw new ArgumentNullException();
this.loader = loader;
}
public U this[T key]
{
get
{
U result;
if (!hax.TryGetValue(key, out result))
hax.Add(key, result = loader(key));
return result;
}
}
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return hax.GetEnumerator(); }
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
public IEnumerable<T> Keys { get { return hax.Keys; } }
public IEnumerable<U> Values { get { return hax.Values; } }
}
}