Created
May 30, 2014 12:07
-
-
Save Beeblerox/40f79991c453c2e12f1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef FlxGraphicAsset = AcceptOneOfFive<String, Class<Dynamic>, CachedGraphics, TextureRegion, BitmapData>; | |
abstract AcceptOneOfFive<T1, T2, T3, T4, T5>(EitherOfFive<T1, T2, T3, T4, T5>) | |
{ | |
public inline function new(e:EitherOfFive<T1, T2, T3, T4, T5>) | |
{ | |
this = e; | |
} | |
public var value(get, never):Dynamic; | |
public var type(get,never):EitherOfFive<T1, T2, T3, T4, T5>; | |
inline function get_value() | |
{ | |
switch (this) | |
{ | |
case First(v) | Second(v) | Third(v) | Fourth(v) | Fifth(v): return v; | |
} | |
} | |
@:to inline function get_type() return this; | |
@:from static function fromT1(v:T1) | |
{ | |
return new AcceptOneOfFive(First(v) ); | |
} | |
@:from static function fromT2(v:T2) | |
{ | |
return new AcceptOneOfFive(Second(v)); | |
} | |
@:from static function fromT3(v:T3) | |
{ | |
return new AcceptOneOfFive(Third(v)); | |
} | |
@:from static function fromT4(v:T4) | |
{ | |
return new AcceptOneOfFive(Fourth(v)); | |
} | |
@:from static function fromT5(v:T5) | |
{ | |
return new AcceptOneOfFive(Fifth(v)); | |
} | |
} | |
enum EitherOfFive<T1, T2, T3, T4, T5> { | |
First( v:T1 ); | |
Second( v:T2 ); | |
Third( v:T3 ); | |
Fourth( v:T4 ); | |
Fifth( v:T5 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment