LIEF: Library to Instrument Executable Formats
Version 2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
LIEF
enums.hpp
Go to the documentation of this file.
1
/* Copyright 2021 - 2026 R. Thomas
2
* Copyright 2021 - 2026 Quarkslab
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
#ifndef LIEF_ENUMS_H
17
#define LIEF_ENUMS_H
18
#include <type_traits>
19
20
#define _LIEF_EN(N) class N : size_t
21
#define _LIEF_EN_2(N, TYPE) class N : TYPE
22
#define _LIEF_EI(X) X
23
24
#define ENABLE_BITMASK_OPERATORS(X) \
25
template<> \
26
struct EnableBitMaskOperators<X> { \
27
static const bool bit_mask_enabled = true; \
28
}
29
30
template
<
typename
Enum>
31
struct
EnableBitMaskOperators
{
32
static
const
bool
bit_mask_enabled
=
false
;
33
};
34
35
template
<
typename
Enum>
36
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>
37
operator|
(Enum lhs, Enum rhs) {
38
using
underlying = std::underlying_type_t<Enum>;
39
return
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) |
40
static_cast<
underlying
>
(rhs));
41
}
42
43
template
<
typename
Enum>
44
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>
45
operator&
(Enum lhs, Enum rhs) {
46
using
underlying = std::underlying_type_t<Enum>;
47
return
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) &
48
static_cast<
underlying
>
(rhs));
49
}
50
51
template
<
typename
Enum>
52
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>
53
operator~
(Enum e) {
54
using
underlying = std::underlying_type_t<Enum>;
55
return
static_cast<
Enum
>
(~static_cast<underlying>(e));
56
}
57
58
template
<
typename
Enum>
59
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled,
60
std::add_lvalue_reference_t<Enum>>
61
operator|=
(Enum& lhs, Enum rhs) {
62
using
underlying = std::underlying_type_t<Enum>;
63
lhs =
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) |
64
static_cast<
underlying
>
(rhs));
65
return
lhs;
66
}
67
68
template
<
typename
Enum>
69
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled,
70
std::add_lvalue_reference_t<Enum>>
71
operator&=
(Enum& lhs, Enum rhs) {
72
using
underlying = std::underlying_type_t<Enum>;
73
lhs =
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) &
74
static_cast<
underlying
>
(rhs));
75
return
lhs;
76
}
77
78
template
<
typename
Enum>
79
std::enable_if_t<EnableBitMaskOperators<Enum>::bit_mask_enabled,
bool
>
80
is_true
(Enum e) {
81
using
underlying = std::underlying_type_t<Enum>;
82
return
static_cast<
underlying
>
(e) > 0;
83
}
84
#endif
operator&
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum > operator&(Enum lhs, Enum rhs)
Definition
enums.hpp:45
operator|=
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, std::add_lvalue_reference_t< Enum > > operator|=(Enum &lhs, Enum rhs)
Definition
enums.hpp:61
is_true
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, bool > is_true(Enum e)
Definition
enums.hpp:80
operator~
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum > operator~(Enum e)
Definition
enums.hpp:53
operator|
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum > operator|(Enum lhs, Enum rhs)
Definition
enums.hpp:37
operator&=
std::enable_if_t< EnableBitMaskOperators< Enum >::bit_mask_enabled, std::add_lvalue_reference_t< Enum > > operator&=(Enum &lhs, Enum rhs)
Definition
enums.hpp:71
EnableBitMaskOperators
Definition
enums.hpp:31
EnableBitMaskOperators::bit_mask_enabled
static const bool bit_mask_enabled
Definition
enums.hpp:32
Generated by
1.18.0