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)
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 /// @class Flags Flags.h "lldb/Core/Flags.h"
22 /// @brief A class to manage flags.
24 /// The Flags class managed flag bits and allows testing and
25 /// modification of individual or multiple flag bits.
26 //----------------------------------------------------------------------
30 //----------------------------------------------------------------------
31 /// The value type for flags is a 32 bit unsigned integer type.
32 //----------------------------------------------------------------------
33 typedef uint32_t ValueType;
35 //----------------------------------------------------------------------
36 /// Construct with initial flag bit values.
38 /// Constructs this object with \a mask as the initial value for all
42 /// The initial value for all flags.
43 //----------------------------------------------------------------------
44 Flags (ValueType flags = 0) :
49 //----------------------------------------------------------------------
52 /// Construct and copy the flags from \a rhs.
55 /// A const Flags object reference to copy.
56 //----------------------------------------------------------------------
57 Flags (const Flags& rhs) :
62 //----------------------------------------------------------------------
64 //----------------------------------------------------------------------
69 //----------------------------------------------------------------------
70 /// Get accessor for all flags.
73 /// Returns all of the flags as a Flags::ValueType.
74 //----------------------------------------------------------------------
81 //----------------------------------------------------------------------
82 /// Return the number of flags that can be represented in this
86 /// The maximum number bits in this flag object.
87 //----------------------------------------------------------------------
91 return sizeof (ValueType) * 8;
94 //----------------------------------------------------------------------
95 /// Set accessor for all flags.
98 /// The bits with which to replace all of the current flags.
99 //----------------------------------------------------------------------
101 Reset (ValueType flags)
106 //----------------------------------------------------------------------
107 /// Clear one or more flags.
110 /// A bitfield containing one or more flags.
113 /// The new flags after clearing all bits from \a mask.
114 //----------------------------------------------------------------------
116 Clear (ValueType mask = ~(ValueType)0)
123 //----------------------------------------------------------------------
124 /// Set one or more flags by logical OR'ing \a mask with the current
128 /// A bitfield containing one or more flags.
131 /// The new flags after setting all bits from \a mask.
132 //----------------------------------------------------------------------
141 //----------------------------------------------------------------------
142 /// Test if all bits in \a mask are 1 in the current flags
145 /// \b true if all flags in \a mask are 1, \b false
147 //----------------------------------------------------------------------
149 AllSet (ValueType mask) const
151 return (m_flags & mask) == mask;
154 //----------------------------------------------------------------------
155 /// Test one or more flags.
158 /// \b true if any flags in \a mask are 1, \b false
160 //----------------------------------------------------------------------
162 AnySet (ValueType mask) const
164 return (m_flags & mask) != 0;
167 //----------------------------------------------------------------------
168 /// Test a single flag bit.
171 /// \b true if \a bit is set, \b false otherwise.
172 //----------------------------------------------------------------------
174 Test (ValueType bit) const
176 return (m_flags & bit) != 0;
179 //----------------------------------------------------------------------
180 /// Test if all bits in \a mask are clear.
183 /// \b true if \b all flags in \a mask are clear, \b false
185 //----------------------------------------------------------------------
187 AllClear (ValueType mask) const
189 return (m_flags & mask) == 0;
193 AnyClear (ValueType mask) const
195 return (m_flags & mask) != mask;
198 //----------------------------------------------------------------------
199 /// Test a single flag bit to see if it is clear (zero).
202 /// \b true if \a bit is 0, \b false otherwise.
203 //----------------------------------------------------------------------
205 IsClear (ValueType bit) const
207 return (m_flags & bit) == 0;
210 //----------------------------------------------------------------------
211 /// Get the number of zero bits in \a m_flags.
214 /// The number of bits that are set to 0 in the current flags.
215 //----------------------------------------------------------------------
220 for (ValueType shift = 0; shift < sizeof(ValueType)*8; ++shift)
222 if ((m_flags & (1u << shift)) == 0)
228 //----------------------------------------------------------------------
229 /// Get the number of one bits in \a m_flags.
232 /// The number of bits that are set to 1 in the current flags.
233 //----------------------------------------------------------------------
238 for (ValueType mask = m_flags; mask; mask >>= 1)
247 ValueType m_flags; ///< The flags.
250 } // namespace lldb_private
252 #endif // #if defined(__cplusplus)
253 #endif // liblldb_Flags_h_