LIEF: Library to Instrument Executable Formats
Version 1.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
{ \
28
static const bool bit_mask_enabled = true; \
29
}
30
31
template
<
typename
Enum>
32
struct
EnableBitMaskOperators
33
{
34
static
const
bool
bit_mask_enabled
=
false
;
35
};
36
37
template
<
typename
Enum>
38
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>::type
39
operator |
(Enum lhs, Enum rhs)
40
{
41
using
underlying =
typename
std::underlying_type<Enum>::type;
42
return
static_cast<
Enum
>
(
43
static_cast<
underlying
>
(lhs) |
44
static_cast<
underlying
>
(rhs)
45
);
46
}
47
48
template
<
typename
Enum>
49
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>::type
50
operator &
(Enum lhs, Enum rhs)
51
{
52
using
underlying =
typename
std::underlying_type<Enum>::type;
53
return
static_cast<
Enum
>
(
54
static_cast<
underlying
>
(lhs) &
55
static_cast<
underlying
>
(rhs)
56
);
57
}
58
59
template
<
typename
Enum>
60
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled, Enum>::type
61
operator ~
(Enum e)
62
{
63
using
underlying =
typename
std::underlying_type<Enum>::type;
64
return
static_cast<
Enum
>
(~static_cast<underlying>(e));
65
}
66
67
template
<
typename
Enum>
68
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled,
typename
std::add_lvalue_reference<Enum>::type>::type
69
operator |=
(Enum& lhs, Enum rhs)
70
{
71
using
underlying =
typename
std::underlying_type<Enum>::type;
72
lhs =
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) |
static_cast<
underlying
>
(rhs));
73
return
lhs;
74
}
75
76
template
<
typename
Enum>
77
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled,
typename
std::add_lvalue_reference<Enum>::type>::type
78
operator &=
(Enum& lhs, Enum rhs)
79
{
80
using
underlying =
typename
std::underlying_type<Enum>::type;
81
lhs =
static_cast<
Enum
>
(
static_cast<
underlying
>
(lhs) &
static_cast<
underlying
>
(rhs));
82
return
lhs;
83
}
84
85
template
<
typename
Enum>
86
typename
std::enable_if<EnableBitMaskOperators<Enum>::bit_mask_enabled,
bool
>::type
87
is_true
(Enum e)
88
{
89
using
underlying =
typename
std::underlying_type<Enum>::type;
90
return
static_cast<
underlying
>
(e) > 0;
91
}
92
#endif
is_true
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, bool >::type is_true(Enum e)
Definition
enums.hpp:87
operator|
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum >::type operator|(Enum lhs, Enum rhs)
Definition
enums.hpp:39
operator&
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum >::type operator&(Enum lhs, Enum rhs)
Definition
enums.hpp:50
operator&=
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, typenamestd::add_lvalue_reference< Enum >::type >::type operator&=(Enum &lhs, Enum rhs)
Definition
enums.hpp:78
operator|=
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, typenamestd::add_lvalue_reference< Enum >::type >::type operator|=(Enum &lhs, Enum rhs)
Definition
enums.hpp:69
operator~
std::enable_if< EnableBitMaskOperators< Enum >::bit_mask_enabled, Enum >::type operator~(Enum e)
Definition
enums.hpp:61
EnableBitMaskOperators
Definition
enums.hpp:33
EnableBitMaskOperators::bit_mask_enabled
static const bool bit_mask_enabled
Definition
enums.hpp:34
Generated by
1.17.0