abstract const classafFancom::Flag
sys::Obj afFancom::Flag
A Flag represents many states by setting and clearing bits on a Int.
Using Ints as flags is still valid, but the Flags class gives superior debugging info. An example Flags class:
const class myFlag : Flags { static const myFlag one := myFlag(1, "one") static const myFlag two := myFlag(2, "two") static const myFlag three := myFlag(3, "three") static const myFlag four := myFlag(4, "four") new make(|This|? f := null) : super(f) { } new makeFromDefinition(Int flag, Str? name) : super(flag, name) { } new makeFromVariant(Variant variant) : super(variant) { } }
Set and clear bits by using +
and -
operators:
(myFlag.two + myFlag.two) .toStr --> two (myFlag.two - myFlag.four).toStr --> two
Multiple flags may be set:
(myFlag.one + myFlag.four).toStr --> one|four (myFlag.two + myFlag.four).toStr --> two|four
Flags are automatically coalesced:
(myFlag.one + myFlag.three) .toStr --> three
Unknown flags are presented as numbers:
(myFlag(16)) .toStr --> (18) (myFlag(10)) .toStr --> two|(8) (myFlag(27)) .toStr --> three|(8)|(16)
Every Flags
subclass needs to declare the following ctor to fulfil the variant surrogate contract:
new makeFromVariant(Variant variant) : super(variant) { }
- contains
@
Deprecated { msg=... }
Bool contains(Flag flag)Same as
containsAll
- containsAll
Returns
true
if all the given flag values are set on this object.- containsAny
Returns
true
if any of the given flag values are set on this object.- equals
- hash
virtual override Int hash()
- make
new make(|This? f := null)
- makeFromDefinition
- makeFromVariant
new makeFromVariant(Variant variant)
Variant surrogate ctor
- minus
Removes Flag b. Shortcut is a - b.
- minusInt
@
Operator
This minusInt(Int b)Removes Flag b. Shortcut is a - b.
- name
Str name { private set }
- plus
Add Flag b. Shortcut is a + b.
- plusInt
Add Flag b. Shortcut is a + b.
- toStr
virtual override Str toStr()
- toVariant
Variant toVariant()
Variant surrogate method
- value
const Int value