Last active
August 29, 2015 14:04
-
-
Save back2dos/b31b0de7e37a4ac03baf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| abstract Flags(Int) { | |
| public inline function new(i = 0) { | |
| this = i; | |
| } | |
| public inline function has( index : Int ) : Bool { | |
| return this & (1 << index) != 0; | |
| } | |
| public inline function set( index: Int ) : Void { | |
| this |= 1 << index; | |
| } | |
| public inline function unset( index: Int ) : Void { | |
| this &= 0xFFFFFFF - (1 << index); | |
| } | |
| macro static public function make(exprs:Array<haxe.macro.Expr>) { | |
| var ret = 0; | |
| exprs.reverse(); | |
| for (e in exprs) | |
| ret = (ret << 1) + | |
| switch e { | |
| case macro true, macro 1: 1; | |
| case macro false, macro 0: 0; | |
| default: haxe.macro.Context.error('should be either of true, false, 1 or 0', e.pos); | |
| } | |
| return macro new Flags($v{ret}); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment