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 15 template<typename Enum> 16 class Flags 17 { 18 public: 19 typedef Enum enum_type; 20 21 public: Flags(const Flags & pOther)22 Flags(const Flags& pOther) 23 : m_Data(pOther.m_Data) {} 24 Flags(Enum pFlag)25 Flags(Enum pFlag) 26 : m_Data(pFlag) {} 27 28 Flags(unsigned int pFlag = 0x0) m_Data(pFlag)29 : m_Data(pFlag) {} 30 31 operator unsigned int () const 32 { return m_Data; } 33 34 bool operator! () const 35 { return (m_Data == 0x0); } 36 37 Flags operator& (int pMask ) const 38 { return Flags(m_Data & pMask); } 39 40 Flags operator& (unsigned int pMask ) const 41 { return Flags(m_Data & pMask); } 42 43 Flags operator& (Enum pMask ) const 44 { return Flags(m_Data & pMask); } 45 46 Flags& operator&= (unsigned int pMask ) { 47 m_Data &= pMask; 48 return *this; 49 } 50 51 Flags& operator=(Flags pOther) { 52 m_Data = pOther.m_Data; 53 return *this; 54 } 55 56 Flags operator^ (Flags pOther) const 57 { return Flags(m_Data^pOther.m_Data); } 58 59 Flags operator^ (Enum pOther) const 60 { return Flags(m_Data^pOther); } 61 62 Flags& operator^= (Flags pOther) { 63 m_Data ^= pOther.m_Data; 64 return *this; 65 } 66 67 Flags& operator^= (Enum pOther) { 68 m_Data ^= pOther; 69 return *this; 70 } 71 72 Flags operator| (Flags pOther) const 73 { return Flags(m_Data | pOther.m_Data); } 74 75 Flags operator| (Enum pOther ) const 76 { return Flags(m_Data | pOther); } 77 78 Flags& operator|= (Flags pOther) { 79 m_Data |= pOther.m_Data; 80 return *this; 81 } 82 83 Flags& operator|= (Enum pOther) { 84 m_Data |= pOther; 85 return *this; 86 } 87 88 Flags operator~ () const 89 { return Flags(~m_Data); } 90 91 private: 92 unsigned int m_Data; 93 }; 94 95 } // namespace of mcld 96 97 #endif 98 99