Files
ChanSort/ChanSort.Api/Utils/MappingPool.cs
hbeham 961f3be305 - reworked UI
- fixed various issues with incorrect selection and program# assignment
2013-04-06 01:46:28 +02:00

34 lines
926 B
C#

using System.Collections.Generic;
using System.IO;
namespace ChanSort.Api
{
public class MappingPool<T> where T : DataMapping
{
private const string ERR_unknownACTChannelDataLength = "Configuration doesn't contain a {0} data mapping for length {1}";
private readonly Dictionary<int, T> mappings = new Dictionary<int, T>();
private readonly string caption;
public MappingPool(string caption)
{
this.caption = caption;
}
public void AddMapping(int dataLength, T mapping)
{
mappings[dataLength] = mapping;
}
public T GetMapping(int dataLength, bool throwException = true)
{
if (dataLength == 0)
return null;
T mapping;
if (!mappings.TryGetValue(dataLength, out mapping) && throwException)
throw new FileLoadException(string.Format(ERR_unknownACTChannelDataLength, this.caption, dataLength));
return mapping;
}
}
}