Euphoria
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
libs
core
src
core
bitfield.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <type_traits>
4
5
namespace
eu::core
6
{
7
8
9
template
<
typename
T,
typename
I = std::underlying_type_t<T>>
10
struct
Bitfield
11
{
12
T
value
;
13
14
Bitfield
()
15
:
value
(static_cast<T>(0))
16
{
17
}
18
19
void
20
set
(T bit,
bool
new_value)
21
{
22
if
(new_value)
23
{
24
value
=
static_cast<
T
>
(
static_cast<
I
>
(
value
) |
static_cast<
I
>
(bit));
25
}
26
else
27
{
28
value
=
static_cast<
T
>
(
static_cast<
I
>
(
value
) & ~
static_cast<
I
>
(bit));
29
}
30
}
31
32
void
33
toggle
(T bit)
34
{
35
value
=
static_cast<
T
>
(
static_cast<
I
>
(
value
) ^
static_cast<
I
>
(bit));
36
}
37
38
void
39
clear
()
40
{
41
value
=
static_cast<
T
>
(0);
42
}
43
44
[[nodiscard]]
bool
45
get
(T bit)
const
46
{
47
const
I
i
=
static_cast<
I
>
(
value
) &
static_cast<
I
>
(bit);
48
return
bit ==
static_cast<
T
>
(
i
);
49
}
50
51
[[nodiscard]]
bool
52
has_any_values
()
const
53
{
54
return
value
!=
static_cast<
T
>
(0);
55
}
56
};
57
58
}
eu::core
Definition:
argparse.cc:45
eu::core::Key::i
@ i
eu::core::Bitfield
Definition:
bitfield.h:11
eu::core::Bitfield::clear
void clear()
Definition:
bitfield.h:39
eu::core::Bitfield::has_any_values
bool has_any_values() const
Definition:
bitfield.h:52
eu::core::Bitfield::get
bool get(T bit) const
Definition:
bitfield.h:45
eu::core::Bitfield::value
T value
Definition:
bitfield.h:12
eu::core::Bitfield::Bitfield
Bitfield()
Definition:
bitfield.h:14
eu::core::Bitfield::toggle
void toggle(T bit)
Definition:
bitfield.h:33
eu::core::Bitfield::set
void set(T bit, bool new_value)
Definition:
bitfield.h:20