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