{$MODE FPC}
{$MODESWITCH RESULT}
{$MODESWITCH TYPEHELPERS}
unit dflags;

interface

const
  FLAG32_0    = 1 shl 0;
  FLAG32_1    = 1 shl 1;
  FLAG32_2    = 1 shl 2;
  FLAG32_3    = 1 shl 3;
  FLAG32_4    = 1 shl 4;
  FLAG32_5    = 1 shl 5;
  FLAG32_6    = 1 shl 6;
  FLAG32_7    = 1 shl 7;
  FLAG32_8    = 1 shl 8;
  FLAG32_9    = 1 shl 9;
  FLAG32_10   = 1 shl 10;
  FLAG32_11   = 1 shl 11;
  FLAG32_12   = 1 shl 12;
  FLAG32_13   = 1 shl 13;
  FLAG32_14   = 1 shl 14;
  FLAG32_15   = 1 shl 15;
  FLAG32_16   = 1 shl 16;
  FLAG32_17   = 1 shl 17;
  FLAG32_18   = 1 shl 18;
  FLAG32_19   = 1 shl 19;
  FLAG32_20   = 1 shl 20;
  FLAG32_21   = 1 shl 21;
  FLAG32_22   = 1 shl 22;
  FLAG32_23   = 1 shl 23;
  FLAG32_24   = 1 shl 24;
  FLAG32_25   = 1 shl 25;
  FLAG32_26   = 1 shl 26;
  FLAG32_27   = 1 shl 27;
  FLAG32_28   = 1 shl 28;
  FLAG32_29   = 1 shl 29;
  FLAG32_30   = 1 shl 30;
  FLAG32_31   = 1 shl 31;

type
TFlagsCardinalHelper = type helper for Cardinal
  procedure Clear; inline;
  procedure SetIf(Mask: Cardinal; Condition: Boolean); inline;
  procedure &On(Mask: Cardinal); inline;
  procedure Off(Mask: Cardinal); inline;
  procedure TurnOn(Mask: Cardinal); inline;
  procedure TurnOff(Mask: Cardinal); inline;
  function Has(Mask: Cardinal): Boolean; inline;
  function Match(Mask: Cardinal): Boolean; inline;
end;

implementation

procedure TFlagsCardinalHelper.Clear;
begin
  Self := 0;
end;

procedure TFlagsCardinalHelper.SetIf(Mask: Cardinal; Condition: Boolean);
begin
  if Condition then
    &On(Mask);
end;

procedure TFlagsCardinalHelper.&On(Mask: Cardinal);
begin
  Self := Self or Mask;
end;

procedure TFlagsCardinalHelper.Off(Mask: Cardinal);
begin
  Self := Self and not Mask;
end;

procedure TFlagsCardinalHelper.TurnOn(Mask: Cardinal);
begin
  Self := Self or Mask;
end;

procedure TFlagsCardinalHelper.TurnOff(Mask: Cardinal);
begin
  Self := Self and not Mask;
end;

function TFlagsCardinalHelper.Has(Mask: Cardinal): Boolean;
begin
  Result := (Self and Mask) <> 0;
end;

function TFlagsCardinalHelper.Match(Mask: Cardinal): Boolean;
begin
  Result := (Self and Mask) = Mask;
end;

end.
