libtenum
|
00001 00008 #ifndef TENUM_DETAIL_OPERATOR_HPP_ 00009 #define TENUM_DETAIL_OPERATOR_HPP_ 00010 00011 #ifndef IN_TENUM_HPP_ 00012 # error "This header should not be included directly. Please use tenum.hpp." 00013 #endif 00014 00015 #include <boost/integer.hpp> 00016 #include <tenum/detail/type.hpp> 00017 00022 #define TENUM_CAST_UINT(value_m) \ 00023 static_cast< ::boost::uint64_t > (value_m) 00024 00029 #define TENUM_CAST_ENUM(type_m,value_m) \ 00030 static_cast< TENUM_TYPE(type_m) > (value_m) 00031 00036 #define TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,operator_m) \ 00037 TENUM_CAST_ENUM(type_m, TENUM_CAST_UINT(lhs_m) operator_m TENUM_CAST_UINT(rhs_m)) 00038 00043 #define TENUM_OPERATOR_ADD(type_m,lhs_m,rhs_m) \ 00044 TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,+) 00045 00050 #define TENUM_OPERATOR_SUB(type_m,lhs_m,rhs_m) \ 00051 TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,-) 00052 00057 #define TENUM_OPERATOR_BIT_OR(type_m,lhs_m,rhs_m) \ 00058 TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,|) 00059 00064 #define TENUM_OPERATOR_BIT_AND(type_m,lhs_m,rhs_m) \ 00065 TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,&) 00066 00071 #define TENUM_OPERATOR_BIT_XOR(type_m,lhs_m,rhs_m) \ 00072 TENUM_OPERATOR_BINARY(type_m,lhs_m,rhs_m,^) 00073 00101 #ifdef BOOST_NO_SCOPED_ENUMS 00102 00103 # define TENUM_ENUM_OPERATORS_DECLARATION(type_m) 00104 # define TENUM_ENUM_OPERATORS_DEFINITION(type_m) 00105 # define TENUM_DYNAMIC_ENUM_OPERATORS_DECLARATION(type_m) 00106 # define TENUM_DYNAMIC_ENUM_OPERATORS_DEFINITION(type_m) 00107 # define TENUM_BIT_FIELD_OPERATORS_DECLARATION(type_m) 00108 # define TENUM_BIT_FIELD_OPERATORS_DEFINITION(type_m) 00109 00110 #else 00111 00112 # define TENUM_ENUM_OPERATORS_DECLARATION(type_m) \ 00113 template< typename IntegerType > \ 00114 static inline bool operator!=(IntegerType const lhs_in, TENUM_TYPE(type_m) const& rhs_in); \ 00115 template< typename IntegerType > \ 00116 static inline bool operator!=(TENUM_TYPE(type_m) const& lhs_in, IntegerType const rhs_in); \ 00117 template< typename IntegerType > \ 00118 static inline bool operator==(IntegerType const lhs_in, TENUM_TYPE(type_m) const& rhs_in); \ 00119 template< typename IntegerType > \ 00120 static inline bool operator==(TENUM_TYPE(type_m) const& lhs_in, IntegerType const rhs_in); \ 00121 template< typename IntegerType > \ 00122 static inline IntegerType operator&(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00123 template< typename IntegerType > \ 00124 static inline IntegerType operator&(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in); \ 00125 template< typename IntegerType > \ 00126 static inline IntegerType operator|(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00127 template< typename IntegerType > \ 00128 static inline IntegerType operator|(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in); \ 00129 template< typename IntegerType > \ 00130 static inline IntegerType operator^(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00131 template< typename IntegerType > \ 00132 static inline IntegerType operator^(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in); \ 00133 template< typename IntegerType > \ 00134 static inline IntegerType& operator&=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00135 template< typename IntegerType > \ 00136 static inline IntegerType& operator|=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00137 template< typename IntegerType > \ 00138 static inline IntegerType& operator^=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00139 00140 # define TENUM_ENUM_OPERATORS_DEFINITION(type_m) \ 00141 template< typename IntegerType > \ 00142 static inline bool operator!=(IntegerType const lhs_in, TENUM_TYPE(type_m) const& rhs_in) { \ 00143 return lhs_in != TENUM_CAST_UINT(rhs_in); \ 00144 } \ 00145 template< typename IntegerType > \ 00146 static inline bool operator!=(TENUM_TYPE(type_m) const& lhs_in, IntegerType const rhs_in) { \ 00147 return TENUM_CAST_UINT(lhs_in) != rhs_in; \ 00148 } \ 00149 template< typename IntegerType > \ 00150 static inline bool operator==(IntegerType const lhs_in, TENUM_TYPE(type_m) const& rhs_in) { \ 00151 return lhs_in == TENUM_CAST_UINT(rhs_in); \ 00152 } \ 00153 template< typename IntegerType > \ 00154 static inline bool operator==(TENUM_TYPE(type_m) const& lhs_in, IntegerType const rhs_in) { \ 00155 return TENUM_CAST_UINT(lhs_in) == rhs_in; \ 00156 } \ 00157 template< typename IntegerType > \ 00158 static inline IntegerType operator&(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00159 return lhs_in & TENUM_CAST_UINT(rhs_in); \ 00160 } \ 00161 template< typename IntegerType > \ 00162 static inline IntegerType operator&(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in) { \ 00163 return TENUM_CAST_UINT(lhs_in) & rhs_in; \ 00164 } \ 00165 template< typename IntegerType > \ 00166 static inline IntegerType operator|(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00167 return lhs_in | TENUM_CAST_UINT(rhs_in); \ 00168 } \ 00169 template< typename IntegerType > \ 00170 static inline IntegerType operator|(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in) { \ 00171 return TENUM_CAST_UINT(lhs_in) | rhs_in; \ 00172 } \ 00173 template< typename IntegerType > \ 00174 static inline IntegerType operator^(IntegerType const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00175 return lhs_in ^ TENUM_CAST_UINT(rhs_in); \ 00176 } \ 00177 template< typename IntegerType > \ 00178 static inline IntegerType operator^(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in) { \ 00179 return TENUM_CAST_UINT(lhs_in) ^ rhs_in; \ 00180 } \ 00181 template< typename IntegerType > \ 00182 static inline IntegerType& operator&=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00183 return lhs_in = lhs_in & rhs_in; \ 00184 } \ 00185 template< typename IntegerType > \ 00186 static inline IntegerType& operator|=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00187 return lhs_in = lhs_in | rhs_in; \ 00188 } \ 00189 template< typename IntegerType > \ 00190 static inline IntegerType& operator^=(IntegerType& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00191 return lhs_in = lhs_in ^ rhs_in; \ 00192 } \ 00193 00194 # define TENUM_DYNAMIC_ENUM_OPERATORS_DECLARATION(type_m) \ 00195 template< typename IntegerType > \ 00196 static inline TENUM_TYPE(type_m) operator+(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in); \ 00197 template< typename IntegerType > \ 00198 static inline TENUM_TYPE(type_m) operator-(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in); \ 00199 template< typename IntegerType > \ 00200 static inline TENUM_TYPE(type_m)& operator+=(TENUM_TYPE(type_m)& lhs_in, IntegerType const rhs_in); \ 00201 template< typename IntegerType > \ 00202 static inline TENUM_TYPE(type_m)& operator-=(TENUM_TYPE(type_m)& lhs_in, IntegerType const rhs_in); 00203 00204 # define TENUM_DYNAMIC_ENUM_OPERATORS_DEFINITION(type_m) \ 00205 template< typename IntegerType > \ 00206 static inline TENUM_TYPE(type_m) operator+(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in) { \ 00207 return TENUM_OPERATOR_ADD(type_m,lhs_in,rhs_in); \ 00208 } \ 00209 template< typename IntegerType > \ 00210 static inline TENUM_TYPE(type_m) operator-(TENUM_TYPE(type_m) const lhs_in, IntegerType const rhs_in) { \ 00211 return TENUM_OPERATOR_SUB(type_m,lhs_in,rhs_in); \ 00212 } \ 00213 template< typename IntegerType > \ 00214 static inline TENUM_TYPE(type_m)& operator+=(TENUM_TYPE(type_m)& lhs_in, IntegerType const rhs_in) { \ 00215 return lhs_in = lhs_in + rhs_in; \ 00216 } \ 00217 template< typename IntegerType > \ 00218 static inline TENUM_TYPE(type_m)& operator-=(TENUM_TYPE(type_m)& lhs_in, IntegerType const rhs_in) { \ 00219 return lhs_in = lhs_in - rhs_in; \ 00220 } 00221 00222 # define TENUM_BIT_FIELD_OPERATORS_DECLARATION(type_m) \ 00223 static inline TENUM_TYPE(type_m) operator&(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00224 static inline TENUM_TYPE(type_m) operator|(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00225 static inline TENUM_TYPE(type_m) operator^(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00226 static inline TENUM_TYPE(type_m)& operator&=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00227 static inline TENUM_TYPE(type_m)& operator|=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in); \ 00228 static inline TENUM_TYPE(type_m)& operator^=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in); 00229 00230 # define TENUM_BIT_FIELD_OPERATORS_DEFINITION(type_m) \ 00231 static inline TENUM_TYPE(type_m) operator&(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00232 return TENUM_OPERATOR_BIT_AND(type_m,lhs_in,rhs_in); \ 00233 } \ 00234 static inline TENUM_TYPE(type_m) operator|(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00235 return TENUM_OPERATOR_BIT_OR(type_m,lhs_in,rhs_in); \ 00236 } \ 00237 static inline TENUM_TYPE(type_m) operator^(TENUM_TYPE(type_m) const lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00238 return TENUM_OPERATOR_BIT_XOR(type_m,lhs_in,rhs_in); \ 00239 } \ 00240 static inline TENUM_TYPE(type_m)& operator&=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00241 return lhs_in = lhs_in & rhs_in; \ 00242 } \ 00243 static inline TENUM_TYPE(type_m)& operator|=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00244 return lhs_in = lhs_in | rhs_in; \ 00245 } \ 00246 static inline TENUM_TYPE(type_m)& operator^=(TENUM_TYPE(type_m)& lhs_in, TENUM_TYPE(type_m) const rhs_in) { \ 00247 return lhs_in = lhs_in ^ rhs_in; \ 00248 } 00249 00250 #endif /* BOOST_NO_SCOPED_ENUMS */ 00251 00252 #endif /* TENUM_DETAIL_OPERATOR_HPP_ */