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

Source

@Deprecated { msg=... }
Bool contains(Flag flag)

Same as containsAll

containsAll

Source

Bool containsAll(Flag flag)

Returns true if all the given flag values are set on this object.

containsAny

Source

Bool containsAny(Flag flag)

Returns true if any of the given flag values are set on this object.

equals

Source

virtual override Bool equals(Obj? obj)

hash

Source

virtual override Int hash()

make

Source

new make(|This? f := null)

makeFromDefinition

Source

new makeFromDefinition(Int value, Str? name)

makeFromVariant

Source

new makeFromVariant(Variant variant)

Variant surrogate ctor

minus

Source

@Operator
This minus(Flag b)

Removes Flag b. Shortcut is a - b.

minusInt

Source

@Operator
This minusInt(Int b)

Removes Flag b. Shortcut is a - b.

name

Source

Str name { private set }

plus

Source

@Operator
This plus(Flag b)

Add Flag b. Shortcut is a + b.

plusInt

Source

@Operator
This plusInt(Int b)

Add Flag b. Shortcut is a + b.

toStr

Source

virtual override Str toStr()

toVariant

Source

Variant toVariant()

Variant surrogate method

value

Source

const Int value