1 //===- Flags.h ------------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #ifndef MCLD_ADT_FLAGS_H_ 10 #define MCLD_ADT_FLAGS_H_ 11 12 namespace mcld { 13 14 template <typename Enum> 15 class Flags { 16 public: 17 typedef Enum enum_type; 18 19 public: Flags(const Flags & pOther)20 Flags(const Flags& pOther) : m_Data(pOther.m_Data) {} 21 Flags(Enum pFlag)22 explicit Flags(Enum pFlag) : m_Data(pFlag) {} 23 m_Data(pFlag)24 explicit Flags(unsigned int pFlag = 0x0) : m_Data(pFlag) {} 25 26 operator unsigned int() const { return m_Data; } 27 28 bool operator!() const { return (m_Data == 0x0); } 29 30 Flags operator&(int pMask) const { return Flags(m_Data & pMask); } 31 32 Flags operator&(unsigned int pMask) const { return Flags(m_Data & pMask); } 33 34 Flags operator&(Enum pMask) const { return Flags(m_Data & pMask); } 35 36 Flags& operator&=(unsigned int pMask) { 37 m_Data &= pMask; 38 return *this; 39 } 40 41 Flags& operator=(Flags pOther) { 42 m_Data = pOther.m_Data; 43 return *this; 44 } 45 46 Flags operator^(Flags pOther) const { return Flags(m_Data ^ pOther.m_Data); } 47 48 Flags operator^(Enum pOther) const { return Flags(m_Data ^ pOther); } 49 50 Flags& operator^=(Flags pOther) { 51 m_Data ^= pOther.m_Data; 52 return *this; 53 } 54 55 Flags& operator^=(Enum pOther) { 56 m_Data ^= pOther; 57 return *this; 58 } 59 60 Flags operator|(Flags pOther) const { return Flags(m_Data | pOther.m_Data); } 61 62 Flags operator|(Enum pOther) const { return Flags(m_Data | pOther); } 63 64 Flags& operator|=(Flags pOther) { 65 m_Data |= pOther.m_Data; 66 return *this; 67 } 68 69 Flags& operator|=(Enum pOther) { 70 m_Data |= pOther; 71 return *this; 72 } 73 74 Flags operator~() const { return Flags(~m_Data); } 75 76 private: 77 unsigned int m_Data; 78 }; 79 80 } // namespace mcld 81 82 #endif // MCLD_ADT_FLAGS_H_ 83