# Bitwise

<a id="bitwise"></a>

# Bitwise

```cpp
#include <icy/bitwise.h>

struct Bitwise
```

[Defined in src/base/include/icy/bitwise.h:22](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L22)

Container for smart management of bitwise integer flags.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `unsigned` | [`data`](#data)  | Backing storage for the flag bits. |

---

<a id="data"></a>

### data

```cpp
unsigned data
```

[Defined in src/base/include/icy/bitwise.h:24](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L24)

Backing storage for the flag bits.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Bitwise`](#bitwise-1) `inline` | Constructs a [Bitwise](#bitwise) with optional initial flags. |
| `void` | [`reset`](#reset) `virtual` `inline` | Clears all flags (sets data to 0). |
| `void` | [`set`](#set) `virtual` `inline` | Sets the given flag only if it is not already set. |
| `void` | [`add`](#add) `virtual` `inline` | Unconditionally sets (OR) the given flag bits. |
| `void` | [`remove`](#remove) `virtual` `inline` | Clears the given flag bits. |
| `void` | [`toggle`](#toggle) `virtual` `inline` | Toggles (XOR) the given flag bits. |
| `bool` | [`has`](#has) `virtual` `const` `inline` | Returns true if all bits in flag are set. |

---

<a id="bitwise-1"></a>

### Bitwise

`inline`

```cpp
inline Bitwise(unsigned flags = 0)
```

[Defined in src/base/include/icy/bitwise.h:28](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L28)

Constructs a [Bitwise](#bitwise) with optional initial flags.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flags` | `unsigned` | Initial flag value (default: 0). |

---

<a id="reset"></a>

### reset

`virtual` `inline`

```cpp
virtual inline void reset()
```

[Defined in src/base/include/icy/bitwise.h:34](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L34)

Clears all flags (sets data to 0).

---

<a id="set"></a>

### set

`virtual` `inline`

```cpp
virtual inline void set(unsigned flag)
```

[Defined in src/base/include/icy/bitwise.h:38](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L38)

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

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flag` | `unsigned` | The flag bit(s) to set. |

---

<a id="add"></a>

### add

`virtual` `inline`

```cpp
virtual inline void add(unsigned flag)
```

[Defined in src/base/include/icy/bitwise.h:46](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L46)

Unconditionally sets (OR) the given flag bits.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flag` | `unsigned` | The flag bit(s) to add. |

---

<a id="remove"></a>

### remove

`virtual` `inline`

```cpp
virtual inline void remove(unsigned flag)
```

[Defined in src/base/include/icy/bitwise.h:50](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L50)

Clears the given flag bits.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flag` | `unsigned` | The flag bit(s) to remove. |

---

<a id="toggle"></a>

### toggle

`virtual` `inline`

```cpp
virtual inline void toggle(unsigned flag)
```

[Defined in src/base/include/icy/bitwise.h:54](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L54)

Toggles (XOR) the given flag bits.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flag` | `unsigned` | The flag bit(s) to toggle. |

---

<a id="has"></a>

### has

`virtual` `const` `inline`

```cpp
virtual inline bool has(unsigned flag) const
```

[Defined in src/base/include/icy/bitwise.h:59](https://github.com/auscaster/icey/blob/main/src/base/include/icy/bitwise.h#L59)

Returns true if all bits in flag are set. 
#### Returns
true if every bit in flag is present in data.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `flag` | `unsigned` | The flag bit(s) to test. |
