Math Utilities

Bitwise

class CommonBitwiseUtils

Bases: object

Utilities for performing bitwise operations, so you do not have to remember how they are done.

static add_flags(value, flags)

Add Flags to a value.

Parameters:
  • value (CommonEnumFlagsTypeValueType) – A flags enum or an integer.

  • flags (Union[CommonIntFlags, int, Tuple[CommonEnumFlagsTypeValueType]]) – A flags enum, an integer, or a collection of flags enums or integers.

Returns:

The new value.

Return type:

CommonEnumFlagsTypeValueType

static contains_all_flags(value, flags)

Determine if all of the Flags are found within a value.

Parameters:
  • value (CommonEnumFlagsTypeValueType) – A flags enum or an integer.

  • flags (Union[CommonIntFlags, int, Tuple[CommonEnumFlagsTypeValueType]]) – A flags enum, an integer, or a collection of flags enums or integers.

Returns:

True, if all of the specified Flags are found within the value. False, if not.

Return type:

bool

static contains_any_flags(value, flags)

Determine if any of the Flags are found within a value.

Parameters:
  • value (CommonEnumFlagsTypeValueType) – A flags enum or an integer.

  • flags (Union[CommonIntFlags, int, Tuple[CommonEnumFlagsTypeValueType]]) – A flags enum, an integer, or a collection of flags enums or integers.

Returns:

True, if any of the specified Flags are found within the value. False, if not.

Return type:

bool

static contains_no_flags(value, flags)

Determine if none of the Flags are found within a value.

Parameters:
  • value (CommonEnumFlagsTypeValueType) – A flags enum or an integer.

  • flags (Union[CommonIntFlags, int, Tuple[CommonEnumFlagsTypeValueType]]) – A flags enum, an integer, or a collection of flags enums or integers.

Returns:

True, if none of the specified Flags are found within the value. False, if not.

Return type:

bool

static remove_flags(value, flags)

Remove Flags from a value.

Parameters:
  • value (CommonEnumFlagsTypeValueType) – A flags enum or an integer.

  • flags (Union[CommonIntFlags, int, Tuple[CommonEnumFlagsTypeValueType]]) – A flags enum, an integer, or a collection of flags enums or integers.

Returns:

The new value.

Return type:

CommonEnumFlagsTypeValueType

static to_flags(flags, base_flag, exclude_base_flag=True)

Convert a collection of Flags to a single Flag value.

Parameters:
  • flags (Union[CommonIntFlags, int, Tuple[Union[CommonIntFlags, int]]]) – A flags enum, an integer, or a collection of flags enums or integers.

  • base_flag (Union[CommonIntFlags, int]) – The base flag to use when creating the flags.

  • exclude_base_flag (bool, optional) – Whether to exclude the base flag from the final value. Default is True.

Returns:

The collection of flags converted to a single flag value.

Return type:

CommonEnumFlagsTypeValueType