00001
00002
00014
00015
00016 #ifndef polybori_groebner_BitMask_h_
00017 #define polybori_groebner_BitMask_h_
00018
00019
00020 #include "groebner_defs.h"
00021
00022 BEGIN_NAMESPACE_PBORIGB
00023
00029 template <unsigned NBits>
00030 class BitMask;
00031
00032 template <>
00033 class BitMask<0> {
00034 public:
00035 enum { nbits = 0, mask = (unsigned long)0 };
00036
00037 unsigned long low(const unsigned long& value) const { return 0; }
00038 const unsigned long& high(const unsigned long& value) const { return value; }
00039 const unsigned long& shift(const unsigned long& value) const { return value; }
00040 unsigned long back(const unsigned long& value) const { return 0; }
00041 };
00042
00043
00044 template <unsigned NBits>
00045 class BitMask {
00046 public:
00047 enum { nbits = NBits, mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
00048
00049 unsigned long low(const unsigned long& value) const {
00050 return value & mask;
00051 }
00052 unsigned long high(const unsigned long& value) const {
00053 return value >> NBits;
00054 }
00055 unsigned long shift(const unsigned long& value) const {
00056 return value << NBits;
00057 }
00058 unsigned long back(const unsigned long& value) const {
00059 return value << (sizeof(unsigned long)*8 - NBits);
00060 }
00061 };
00062
00063 template <>
00064 class BitMask<sizeof(unsigned long)*8> {
00065 public:
00066 enum { nbits = sizeof(unsigned long)*8,
00067 mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
00068
00069 const unsigned long& low(const unsigned long& value) const { return value; }
00070 unsigned long high(const unsigned long& value) const { return 0; }
00071 unsigned long shift(const unsigned long& value) const { return 0; }
00072 const unsigned long& back(const unsigned long& value) const { return value; }
00073 };
00074
00075 END_NAMESPACE_PBORIGB
00076
00077 #endif