Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:57

0001 //===-- Flags.h -------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_FLAGS_H
0010 #define LLDB_UTILITY_FLAGS_H
0011 
0012 #include <cstddef>
0013 #include <cstdint>
0014 
0015 namespace lldb_private {
0016 
0017 /// \class Flags Flags.h "lldb/Utility/Flags.h"
0018 /// A class to manage flags.
0019 ///
0020 /// The Flags class managed flag bits and allows testing and modification of
0021 /// individual or multiple flag bits.
0022 class Flags {
0023 public:
0024   /// The value type for flags is a 32 bit unsigned integer type.
0025   typedef uint32_t ValueType;
0026 
0027   /// Construct with initial flag bit values.
0028   ///
0029   /// Constructs this object with \a mask as the initial value for all of the
0030   /// flags.
0031   ///
0032   /// \param[in] flags
0033   ///     The initial value for all flags.
0034   Flags(ValueType flags = 0) : m_flags(flags) {}
0035 
0036   /// Get accessor for all flags.
0037   ///
0038   /// \return
0039   ///     Returns all of the flags as a Flags::ValueType.
0040   ValueType Get() const { return m_flags; }
0041 
0042   /// Return the number of flags that can be represented in this object.
0043   ///
0044   /// \return
0045   ///     The maximum number bits in this flag object.
0046   size_t GetBitSize() const { return sizeof(ValueType) * 8; }
0047 
0048   /// Set accessor for all flags.
0049   ///
0050   /// \param[in] flags
0051   ///     The bits with which to replace all of the current flags.
0052   void Reset(ValueType flags) { m_flags = flags; }
0053 
0054   /// Clear one or more flags.
0055   ///
0056   /// \param[in] mask
0057   ///     A bitfield containing one or more flags.
0058   ///
0059   /// \return
0060   ///     The new flags after clearing all bits from \a mask.
0061   ValueType Clear(ValueType mask = ~static_cast<ValueType>(0)) {
0062     m_flags &= ~mask;
0063     return m_flags;
0064   }
0065 
0066   /// Set one or more flags by logical OR'ing \a mask with the current flags.
0067   ///
0068   /// \param[in] mask
0069   ///     A bitfield containing one or more flags.
0070   ///
0071   /// \return
0072   ///     The new flags after setting all bits from \a mask.
0073   ValueType Set(ValueType mask) {
0074     m_flags |= mask;
0075     return m_flags;
0076   }
0077 
0078   /// Test if all bits in \a mask are 1 in the current flags
0079   ///
0080   /// \return
0081   ///     \b true if all flags in \a mask are 1, \b false
0082   ///     otherwise.
0083   bool AllSet(ValueType mask) const { return (m_flags & mask) == mask; }
0084 
0085   /// Test one or more flags.
0086   ///
0087   /// \return
0088   ///     \b true if any flags in \a mask are 1, \b false
0089   ///     otherwise.
0090   bool AnySet(ValueType mask) const { return (m_flags & mask) != 0; }
0091 
0092   /// Test a single flag bit.
0093   ///
0094   /// \return
0095   ///     \b true if \a bit is set, \b false otherwise.
0096   bool Test(ValueType bit) const { return (m_flags & bit) != 0; }
0097 
0098   /// Test if all bits in \a mask are clear.
0099   ///
0100   /// \return
0101   ///     \b true if \b all flags in \a mask are clear, \b false
0102   ///     otherwise.
0103   bool AllClear(ValueType mask) const { return (m_flags & mask) == 0; }
0104 
0105   bool AnyClear(ValueType mask) const { return (m_flags & mask) != mask; }
0106 
0107   /// Test a single flag bit to see if it is clear (zero).
0108   ///
0109   /// \return
0110   ///     \b true if \a bit is 0, \b false otherwise.
0111   bool IsClear(ValueType bit) const { return (m_flags & bit) == 0; }
0112 
0113 protected:
0114   ValueType m_flags; ///< The flags.
0115 };
0116 
0117 } // namespace lldb_private
0118 
0119 #endif // LLDB_UTILITY_FLAGS_H