BitMask.h
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
//*****************************************************************************
#ifndef polybori_groebner_BitMask_h_
#define polybori_groebner_BitMask_h_
// include basic definitions
#include "groebner_defs.h"
BEGIN_NAMESPACE_PBORIGB
template <unsigned NBits>
class BitMask;
template <>
class BitMask<0> {
public:
enum { nbits = 0, mask = (unsigned long)0 };
unsigned long low(const unsigned long& value) const { return 0; }
const unsigned long& high(const unsigned long& value) const { return value; }
const unsigned long& shift(const unsigned long& value) const { return value; }
unsigned long back(const unsigned long& value) const { return 0; }
};
template <unsigned NBits>
class BitMask {
public:
enum { nbits = NBits, mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
unsigned long low(const unsigned long& value) const {
return value & mask;
}
unsigned long high(const unsigned long& value) const {
return value >> NBits;
}
unsigned long shift(const unsigned long& value) const {
return value << NBits;
}
unsigned long back(const unsigned long& value) const {
return value << (sizeof(unsigned long)*8 - NBits);
}
};
template <>
class BitMask<sizeof(unsigned long)*8> {
public:
enum { nbits = sizeof(unsigned long)*8,
mask = ((unsigned long)(BitMask<nbits-1>::mask) << 1) | 0x1};
const unsigned long& low(const unsigned long& value) const { return value; }
unsigned long high(const unsigned long& value) const { return 0; }
unsigned long shift(const unsigned long& value) const { return 0; }
const unsigned long& back(const unsigned long& value) const { return value; }
};
END_NAMESPACE_PBORIGB
#endif /* polybori_groebner_BitMask_h_ */
polybori::groebner::BitMask::back
unsigned long back(const unsigned long &value) const
Definition: BitMask.h:58
polybori::groebner::BitMask< sizeof(unsigned long)*8 >::low
const unsigned long & low(const unsigned long &value) const
Definition: BitMask.h:69
polybori::groebner::BitMask< sizeof(unsigned long)*8 >::high
unsigned long high(const unsigned long &value) const
Definition: BitMask.h:70
polybori::groebner::BitMask< 0 >::high
const unsigned long & high(const unsigned long &value) const
Definition: BitMask.h:38
polybori::groebner::BitMask< 0 >::low
unsigned long low(const unsigned long &value) const
Definition: BitMask.h:37
END_NAMESPACE_PBORIGB
#define END_NAMESPACE_PBORIGB
Definition: groebner_defs.h:16
polybori::groebner::BitMask::high
unsigned long high(const unsigned long &value) const
Definition: BitMask.h:52
polybori::groebner::BitMask< 0 >::back
unsigned long back(const unsigned long &value) const
Definition: BitMask.h:40
BEGIN_NAMESPACE_PBORIGB
#define BEGIN_NAMESPACE_PBORIGB
Definition: groebner_defs.h:15
polybori::groebner::BitMask< sizeof(unsigned long)*8 >::back
const unsigned long & back(const unsigned long &value) const
Definition: BitMask.h:72
groebner_defs.h
polybori::groebner::BitMask::shift
unsigned long shift(const unsigned long &value) const
Definition: BitMask.h:55
polybori::groebner::BitMask< 0 >::shift
const unsigned long & shift(const unsigned long &value) const
Definition: BitMask.h:39
polybori::groebner::BitMask::low
unsigned long low(const unsigned long &value) const
Definition: BitMask.h:49
polybori::groebner::BitMask< sizeof(unsigned long)*8 >::shift
unsigned long shift(const unsigned long &value) const
Definition: BitMask.h:71
polybori::groebner::BitMask
This class defines a bit mask and related operations.
Definition: BitMask.h:30