package cs; /** Use this type to have access to the bitwise operators of C# enums that have a `cs.system.FlagsAttribute` attribute. Usage example: ```haxe import cs.system.reflection.BindingFlags; var binding = new Flags(BindingFlags.Public) | BindingFlags.Static | BindingFlags.NonPublic; ``` **/ abstract Flags(T) from T to T { /** Creates a new `Flags` type with an optional initial value. If no initial value was specified, the default enum value for an empty flags attribute is specified **/ @:extern inline public function new(?initial:T) this = initial; /** Accessible through the bitwise OR operator (`|`). Returns a new `Flags` type with the flags passed at `flags` added to it. **/ @:op(A|B) @:extern inline public function add(flags:Flags):Flags { return new Flags(underlying() | flags.underlying()); } /** Accessible through the bitwise AND operator (`&`). Returns a new `Flags` type with the flags that are set on both `this` and `flags` **/ @:op(A&B) @:extern inline public function bitAnd(flags:Flags):Flags { return new Flags(underlying() & flags.underlying()); } /** Accessible through the bitwise XOR operator (`^`). **/ @:op(A^B) @:extern inline public function bitXor(flags:Flags):Flags { return new Flags(underlying() & flags.underlying()); } /** Accesible through the bitwise negation operator (`~`). Returns a new `Flags` type with all unset flags as set - but the ones that are set already. **/ @:op(~A) @:extern inline public function bitNeg():Flags { return new Flags(~underlying()); } /** Returns a new `Flags` type with all flags set by `flags` unset **/ @:extern inline public function remove(flags:Flags):Flags { return new Flags(underlying() & ~flags.underlying()); } /** Returns whether `flag` is present on `this` type **/ @:extern inline public function has(flag:T):Bool { return underlying() & new Flags(flag).underlying() != null; } /** Returns whether `this` type has any flag set by `flags` also set **/ @:extern inline public function hasAny(flags:Flags):Bool { return underlying() & flags.underlying() != null; } /** Returns whether `this` type has all flags set by `flags` also set **/ @:extern inline public function hasAll(flags:Flags):Bool { return underlying() & flags.underlying() == flags.underlying(); } @:extern inline private function underlying():EnumUnderlying return this; } @:coreType private abstract EnumUnderlying from T to T { @:op(A|B) public static function or(lhs:EnumUnderlying, rhs:EnumUnderlying):T; @:op(A^B) public static function xor(lhs:EnumUnderlying, rhs:EnumUnderlying):T; @:op(A&B) public static function and(lhs:EnumUnderlying, rhs:EnumUnderlying):T; @:op(~A) public static function bneg(t:EnumUnderlying):T; }