summaryrefslogtreecommitdiff
path: root/src/libcamera/base/flags.cpp
blob: 3e4320ace7c853dfac1ea65a28f1b39daab2f2e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * flags.cpp - Type-safe enum-based bitfields
 */

#include <libcamera/base/flags.h>

/**
 * \file base/flags.h
 * \brief Enum-based bit fields
 */

namespace libcamera {

/**
 * \class Flags
 * \brief Type-safe container for enum-based bitfields
 *
 * The Flags template class provides type-safe bitwise operators on enum values.
 * It allows using enum types for bitfields, while preventing unsafe casts from
 * integer types and mixing of flags from different enum types.
 *
 * To use the Flags class, declare an enum containing the desired bit flags, and
 * use the Flags<enum> class to store bitfields based on the enum. If bitwise
 * operators on the underlying enum are also desired, they can be enabled with
 * the LIBCAMERA_FLAGS_ENABLE_OPERATORS(enum) macro.
 */

/**
 * \typedef Flags::Type
 * \brief The underlying data type of the enum
 */

/**
 * \fn Flags::Flags()
 * \brief Construct a Flags instance with a zero value
 */

/**
 * \fn Flags::Flags(E flag)
 * \brief Construct a Flags instance storing the \a flag
 * \param[in] flag The initial value
 */

/**
 * \fn Flags &Flags::operator&=(E flag)
 * \brief Store the bitwise AND of this Flags and the \a flag in this Flags
 * \param[in] flag The second operand
 * \return A reference to this Flags
 */

/**
 * \fn Flags &Flags::operator&=(Flags other)
 * \brief Store the bitwise AND of this Flags and the \a other Flags in this Flags
 * \param[in] other The second operand
 * \return A reference to this Flags
 */

/**
 * \fn Flags &Flags::operator|=(E flag)
 * \brief Store the bitwise OR of this Flags and the \a flag in this Flags
 * \param[in] flag The second operand
 * \return A reference to this Flags
 */

/**
 * \fn Flags &Flags::operator|=(Flags other)
 * \brief Store the bitwise OR of this Flags and the \a other Flags in this Flags
 * \param[in] other The second operand
 * \return A reference to this Flags
 */

/**
 * \fn Flags &Flags::operator^=(E flag)
 * \brief Store the bitwise XOR of this Flags and the \a flag in this Flags
 * \param[in] flag The second operand
 * \return A reference to this Flags
 */

/**
 * \fn Flags &Flags::operator^=(Flags other)
 * \brief Store the bitwise XOR of this Flags and the \a other Flags in this Flags
 * \param[in] other The second operand
 * \return A reference to this Flags
 */

/**
 * \fn bool Flags::operator==(E flag)
 * \brief Compare flags for equality
 * \param[in] flag The second operand
 * \return True if the Flags and \a flag are equal, false otherwise
 */

/**
 * \fn bool Flags::operator==(Flags other)
 * \brief Compare flags for equality
 * \param[in] other The second operand
 * \return True if the Flags and \a other are equal, false otherwise
 */

/**
 * \fn bool Flags::operator!=(E flag)
 * \brief Compare flags for non-equality
 * \param[in] flag The second operand
 * \return True if the Flags and \a flag are not equal, false otherwise
 */

/**
 * \fn bool Flags::operator!=(Flags other)
 * \brief Compare flags for non-equality
 * \param[in] other The second operand
 * \return True if the Flags and \a other are not equal, false otherwise
 */

/**
 * \fn Flags::operator Type() const
 * \brief Convert the Flags to the underlying integer type
 * \return The Flags value as an integer
 */

/**
 * \fn Flags::operator bool() const
 * \brief Convert the Flags to a boolean
 * \return True if at least one flag is set, false otherwise
 */

/**
 * \fn Flags Flags::operator&(E flag) const
 * \brief Compute the bitwise AND of this Flags and the \a flag
 * \param[in] flag The second operand
 * \return A Flags containing the result of the AND operation
 */

/**
 * \fn Flags Flags::operator&(Flags other) const
 * \brief Compute the bitwise AND of this Flags and the \a other Flags
 * \param[in] other The second operand
 * \return A Flags containing the result of the AND operation
 */

/**
 * \fn Flags Flags::operator|(E flag) const
 * \brief Compute the bitwise OR of this Flags and the \a flag
 * \param[in] flag The second operand
 * \return A Flags containing the result of the OR operation
 */

/**
 * \fn Flags Flags::operator|(Flags other) const
 * \brief Compute the bitwise OR of this Flags and the \a other Flags
 * \param[in] other The second operand
 * \return A Flags containing the result of the OR operation
 */

/**
 * \fn Flags Flags::operator^(E flag) const
 * \brief Compute the bitwise XOR of this Flags and the \a flag
 * \param[in] flag The second operand
 * \return A Flags containing the result of the XOR operation
 */

/**
 * \fn Flags Flags::operator^(Flags other) const
 * \brief Compute the bitwise XOR of this Flags and the \a other Flags
 * \param[in] other The second operand
 * \return A Flags containing the result of the XOR operation
 */

/**
 * \fn Flags Flags::operator~() const
 * \brief Compute the bitwise NOT of this Flags
 * \return A Flags containing the result of the NOT operation
 */

/**
 * \fn bool Flags::operator!() const
 * \brief Check if flags are set
 * \return True if no flags is set, false otherwise
 */

/**
 * \def LIBCAMERA_FLAGS_ENABLE_OPERATORS(enum)
 * \brief Enable bitwise operations on the \a enum enumeration
 *
 * This macro enables the bitwise AND, OR, XOR and NOT operators on the given
 * \a enum. This allows the enum values to be safely used in bitwise operations
 * with the Flags<> class.
 */

} /* namespace libcamera */