![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsFlag.hpp 00003 00004 Flag class (hpp file). 00005 00006 SUKITTI PUNAK (07/01/2008) 00007 ******************************************************************************/ 00008 #ifndef TAPs_FLAG_HPP 00009 #define TAPs_FLAG_HPP 00010 00025 #include "../Core/TAPsStdLib.hpp" 00026 00027 // ANSI compatible version 00028 #include <cstdio> 00029 #include <cstdarg> 00030 00031 BEGIN_NAMESPACE_TAPs__DS 00032 //============================================================================= 00033 namespace FLAG { 00034 template< 00035 int Bits, 00036 int Type = Bits <= sizeof(char)*8 ? 1 : ( Bits <= sizeof(short)*8 ? 2 : ( Bits <= sizeof(int)*8 ? 3 : 4 ) ) 00037 > struct BestFit; 00038 00039 template< int Bits > struct BestFit< Bits, 1 > { typedef unsigned char Type; }; 00040 template< int Bits > struct BestFit< Bits, 2 > { typedef unsigned short Type; }; 00041 template< int Bits > struct BestFit< Bits, 3 > { typedef unsigned int Type; }; 00042 template< int Bits > struct BestFit< Bits, 4 > { typedef unsigned int Type; }; 00043 }; 00044 //============================================================================= 00045 00046 //============================================================================= 00047 template <typename T, int Bits = sizeof(char)*8, 00048 typename Holder = typename FLAG::BestFit<Bits>::Type > 00049 class Flag { 00050 public: 00051 // Member Functions ------------------------------------------------------- 00053 friend std::ostream & operator<< ( std::ostream &output, Flag<T,Bits,Holder> const &obj ) 00054 { 00055 output << obj.StrInfo(); 00056 return output; 00057 } 00058 //------------------------------------------------------------------------- 00060 Flag ( T f1 = T(0) ); 00061 Flag ( Holder flags ); 00062 Flag ( Flag<T,Bits,Holder> const &flag ); 00063 ~Flag (); 00064 //------------------------------------------------------------------------- 00066 virtual std::string StrInfo () const; 00067 //------------------------------------------------------------------------- 00069 inline Flag<T,Bits,Holder> & operator= ( Flag<T,Bits,Holder> const &flag ); 00070 //------------------------------------------------------------------------- 00072 inline bool operator== ( Flag<T,Bits,Holder> const & flag ) const; 00073 inline bool operator!= ( Flag<T,Bits,Holder> const & flag ) const; 00074 inline bool operator< ( Flag<T,Bits,Holder> const & flag ) const; 00075 inline bool operator>= ( Flag<T,Bits,Holder> const & flag ) const; 00076 inline bool operator> ( Flag<T,Bits,Holder> const & flag ) const; 00077 inline bool operator<= ( Flag<T,Bits,Holder> const & flag ) const; 00078 //------------------------------------------------------------------------- 00080 inline Flag<T,Bits,Holder> operator~ () const; 00081 inline Flag<T,Bits,Holder> operator& ( Flag<T,Bits,Holder> const & flag ) const; 00082 inline Flag<T,Bits,Holder> operator| ( Flag<T,Bits,Holder> const & flag ) const; 00083 inline Flag<T,Bits,Holder> & operator&= ( Flag<T,Bits,Holder> const & flag ); 00084 inline Flag<T,Bits,Holder> & operator|= ( Flag<T,Bits,Holder> const & flag ); 00085 //------------------------------------------------------------------------- 00087 inline void ClearAll (); 00088 inline void SetAll (); 00089 inline void ClearFlagNumber ( int i ); 00090 inline void SetFlagNumber ( int i ); 00091 inline void ClearFlag ( T flag ); 00092 inline void SetFlag ( T flag ); 00093 //------------------------------------------------------------------------- 00094 00096 inline bool CheckFlagNumber ( int i ) const; 00097 00100 // one flag, then the result is true if one flag or more is set. 00101 inline bool CheckFlag ( T flag ) const; 00102 00104 inline unsigned int FlagsToUnsignedInt () const { return static_cast<unsigned int>( m_flags ); } 00105 00107 inline bool IsCleared () const { return static_cast<unsigned int>( m_flags ) == 0 ? true : false; } 00108 00109 //------------------------------------------------------------------------- 00110 // Data Members ----------------------------------------------------------- 00111 //============================================================================= 00112 protected: 00113 // Member Functions ------------------------------------------------------- 00114 // Data Members ----------------------------------------------------------- 00115 Holder m_flags; 00116 //============================================================================= 00117 private: 00118 // Member Functions ------------------------------------------------------- 00119 // Data Members ----------------------------------------------------------- 00120 //============================================================================= 00121 }; // END CLASS Flag 00122 //============================================================================= 00123 //----------------------------------------------------------------------------- 00124 //============================================================================= 00125 END_NAMESPACE_TAPs__DS 00126 //----------------------------------------------------------------------------- 00127 #include "TAPsFlag.cpp" 00128 //----------------------------------------------------------------------------- 00129 #endif 00130 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00131 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----