osu/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs

25 lines
812 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
namespace osu.Game.Beatmaps.Formats
{
public abstract class BeatmapDecoder
{
2016-10-10 18:35:44 +00:00
private static Dictionary<string, Type> decoders { get; } = new Dictionary<string, Type>();
public static BeatmapDecoder GetDecoder(TextReader stream)
{
var line = stream.ReadLine().Trim();
2016-10-10 18:00:33 +00:00
if (!decoders.ContainsKey(line))
2016-10-12 17:36:10 +00:00
throw new IOException(@"Unknown file format");
2016-10-10 18:00:33 +00:00
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
}
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder
{
2016-10-10 18:00:33 +00:00
decoders[magic] = typeof(T);
}
2016-10-13 14:29:30 +00:00
public abstract void Decode(TextReader stream, Beatmap beatmap);
}
}