1 //===-- Flags.h -------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Flags_h_
11 #define liblldb_Flags_h_
12 #if defined(__cplusplus)
17 namespace lldb_private {
19 //----------------------------------------------------------------------
20 /// @class Flags Flags.h "lldb/Core/Flags.h"
21 /// @brief A class to manage flags.
23 /// The Flags class managed flag bits and allows testing and
24 /// modification of individual or multiple flag bits.
25 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 /// The value type for flags is a 32 bit unsigned integer type.
31 //----------------------------------------------------------------------
32 typedef uint32_t ValueType;
34 //----------------------------------------------------------------------
35 /// Construct with initial flag bit values.
37 /// Constructs this object with \a mask as the initial value for all
41 /// The initial value for all flags.
42 //----------------------------------------------------------------------
43 Flags (ValueType flags = 0) :
48 //----------------------------------------------------------------------
51 /// Construct and copy the flags from \a rhs.
54 /// A const Flags object reference to copy.
55 //----------------------------------------------------------------------
56 Flags (const Flags& rhs) :
61 //----------------------------------------------------------------------
63 //----------------------------------------------------------------------
68 //----------------------------------------------------------------------
69 /// Get accessor for all flags.
72 /// Returns all of the flags as a Flags::ValueType.
73 //----------------------------------------------------------------------
80 //----------------------------------------------------------------------
81 /// Return the number of flags that can be represented in this
85 /// The maximum number bits in this flag object.
86 //----------------------------------------------------------------------
90 return sizeof (ValueType) * 8;
93 //----------------------------------------------------------------------
94 /// Set accessor for all flags.
97 /// The bits with which to replace all of the current flags.
98 //----------------------------------------------------------------------
100 Reset (ValueType flags)
105 //----------------------------------------------------------------------
106 /// Clear one or more flags.
109 /// A bitfield containing one or more flags.
112 /// The new flags after clearing all bits from \a mask.
113 //----------------------------------------------------------------------
115 Clear (ValueType mask = ~(ValueType)0)
122 //----------------------------------------------------------------------
123 /// Set one or more flags by logical OR'ing \a mask with the current
127 /// A bitfield containing one or more flags.
130 /// The new flags after setting all bits from \a mask.
131 //----------------------------------------------------------------------
140 //----------------------------------------------------------------------
141 /// Test if all bits in \a mask are 1 in the current flags
144 /// \b true if all flags in \a mask are 1, \b false
146 //----------------------------------------------------------------------
148 AllSet (ValueType mask) const
150 return (m_flags & mask) == mask;
153 //----------------------------------------------------------------------
154 /// Test one or more flags.
157 /// \b true if any flags in \a mask are 1, \b false
159 //----------------------------------------------------------------------
161 AnySet (ValueType mask) const
163 return (m_flags & mask) != 0;
166 //----------------------------------------------------------------------
167 /// Test a single flag bit.
170 /// \b true if \a bit is set, \b false otherwise.
171 //----------------------------------------------------------------------
173 Test (ValueType bit) const
175 return (m_flags & bit) != 0;
178 //----------------------------------------------------------------------
179 /// Test if all bits in \a mask are clear.
182 /// \b true if \b all flags in \a mask are clear, \b false
184 //----------------------------------------------------------------------
186 AllClear (ValueType mask) const
188 return (m_flags & mask) == 0;
192 AnyClear (ValueType mask) const
194 return (m_flags & mask) != mask;
197 //----------------------------------------------------------------------
198 /// Test a single flag bit to see if it is clear (zero).
201 /// \b true if \a bit is 0, \b false otherwise.
202 //----------------------------------------------------------------------
204 IsClear (ValueType bit) const
206 return (m_flags & bit) == 0;
209 //----------------------------------------------------------------------
210 /// Get the number of zero bits in \a m_flags.
213 /// The number of bits that are set to 0 in the current flags.
214 //----------------------------------------------------------------------
219 for (ValueType shift = 0; shift < sizeof(ValueType)*8; ++shift)
221 if ((m_flags & (1u << shift)) == 0)
227 //----------------------------------------------------------------------
228 /// Get the number of one bits in \a m_flags.
231 /// The number of bits that are set to 1 in the current flags.
232 //----------------------------------------------------------------------
237 for (ValueType mask = m_flags; mask; mask >>= 1)
246 ValueType m_flags; ///< The flags.
249 } // namespace lldb_private
251 #endif // #if defined(__cplusplus)
252 #endif // liblldb_Flags_h_