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(unsigned int pFlag = 0x0) m_Data(pFlag)32 : m_Data(pFlag) {} 33 34 operator unsigned 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&= (unsigned int pMask ) { 50 m_Data &= pMask; 51 return *this; 52 } 53 54 Flags& operator=(Flags pOther) { 55 m_Data = pOther.m_Data; 56 return *this; 57 } 58 59 Flags operator^ (Flags pOther) const 60 { return Flags(m_Data^pOther.m_Data); } 61 62 Flags operator^ (Enum pOther) const 63 { return Flags(m_Data^pOther); } 64 65 Flags& operator^= (Flags pOther) { 66 m_Data ^= pOther.m_Data; 67 return *this; 68 } 69 70 Flags& operator^= (Enum pOther) { 71 m_Data ^= pOther; 72 return *this; 73 } 74 75 Flags operator| (Flags pOther) const 76 { return Flags(m_Data | pOther.m_Data); } 77 78 Flags operator| (Enum pOther ) const 79 { return Flags(m_Data | pOther); } 80 81 Flags& operator|= (Flags pOther) { 82 m_Data |= pOther.m_Data; 83 return *this; 84 } 85 86 Flags& operator|= (Enum pOther) { 87 m_Data |= pOther; 88 return *this; 89 } 90 91 Flags operator~ () const 92 { return Flags(~m_Data); } 93 94 private: 95 unsigned int m_Data; 96 }; 97 98 } // namespace of mcld 99 100 #endif 101 102