Base module

Bitwise

Container for smart management of bitwise integer flags.

Bitwise

#include <icy/bitwise.h>

Container for smart management of bitwise integer flags.

Public Attributes

ReturnNameDescription
unsigneddataBacking storage for the flag bits.

data

unsigned data

Backing storage for the flag bits.

Public Methods

ReturnNameDescription
Bitwise inlineConstructs a Bitwise with optional initial flags.
voidreset virtual inlineClears all flags (sets data to 0).
voidset virtual inlineSets the given flag only if it is not already set.
voidadd virtual inlineUnconditionally sets (OR) the given flag bits.
voidremove virtual inlineClears the given flag bits.
voidtoggle virtual inlineToggles (XOR) the given flag bits.
boolhas virtual const inlineReturns true if all bits in flag are set.

Bitwise

inline

inline Bitwise(unsigned flags)

Constructs a Bitwise with optional initial flags.

Parameters

  • flags Initial flag value (default: 0).

reset

virtual inline

virtual inline void reset()

Clears all flags (sets data to 0).


set

virtual inline

virtual inline void set(unsigned flag)

Sets the given flag only if it is not already set.

Parameters

  • flag The flag bit(s) to set.

add

virtual inline

virtual inline void add(unsigned flag)

Unconditionally sets (OR) the given flag bits.

Parameters

  • flag The flag bit(s) to add.

remove

virtual inline

virtual inline void remove(unsigned flag)

Clears the given flag bits.

Parameters

  • flag The flag bit(s) to remove.

toggle

virtual inline

virtual inline void toggle(unsigned flag)

Toggles (XOR) the given flag bits.

Parameters

  • flag The flag bit(s) to toggle.

has

virtual const inline

virtual inline bool has(unsigned flag) const

Returns true if all bits in flag are set.

Parameters

  • flag The flag bit(s) to test.

Returns

true if every bit in flag is present in data.