00001 #ifndef _PIECE_MASK_H
00002 #define _PIECE_MASK_H
00003 #include "osl/config.h"
00004
00005 #include "osl/misc/mask.h"
00006 #if OSL_WORDSIZE == 64
00007 # include "osl/container/pieceMask64.h"
00008 #elif OSL_WORDSIZE == 32
00009 # include "osl/container/pieceMask32.h"
00010 #endif
00011
00012 #include <iosfwd>
00013
00014 namespace osl
00015 {
00016 namespace container
00017 {
00018 #if OSL_WORDSIZE == 64
00019 typedef PieceMask64 PieceMaskBase;
00020 #elif OSL_WORDSIZE == 32
00021 typedef PieceMask32 PieceMaskBase;
00022 #endif
00023
00030 class PieceMask : public PieceMaskBase
00031 {
00032 public:
00033 PieceMask() {}
00034 PieceMask(const PieceMaskBase& base) : PieceMaskBase(base) {}
00035 static const mask_t numToMask(int num) {
00036 return mask_t::makeDirect(1) << PieceMask::numToOffset(num);
00037 }
00038 void setMask(int index,mask_t val) {
00039 writableMask(index)=val;
00040 }
00041 private:
00042 mask_t& writableMaskNum(int num) {
00043 return writableMask(numToIndex(num));
00044 }
00045 const mask_t& getMaskNum(int num) const {
00046 return getMask(numToIndex(num));
00047 }
00048 public:
00049 void xorMask(int index,mask_t val) {
00050 writableMask(index)^=val;
00051 }
00052 void orMask(int index,mask_t val) {
00053 writableMask(index)|=val;
00054 }
00055 bool test(int num) const {
00056 return (getMaskNum(num)&numToMask(num)).any();
00057 }
00058 void set(int num) {
00059 writableMaskNum(num)|=numToMask(num);
00060 }
00061 void flip(int num) {
00062 writableMaskNum(num)^=numToMask(num);
00063 }
00064 void reset(int num) {
00065 writableMaskNum(num)&= ~numToMask(num);
00066 }
00067 bool any() const { return ! none(); }
00068 };
00069
00070
00071 inline const PieceMask operator&(const PieceMask &m1, const PieceMask &m2) {
00072 #if OSL_WORDSIZE == 64
00073 return PieceMask64(m1.getMask(0)&m2.getMask(0));
00074 #elif OSL_WORDSIZE == 32
00075 return PieceMask32(m1.getMask(0)&m2.getMask(0),
00076 m1.getMask(1)&m2.getMask(1));
00077 #endif
00078 }
00079
00080
00081 inline const PieceMask operator|(const PieceMask &m1, const PieceMask &m2) {
00082 #if OSL_WORDSIZE == 64
00083 return PieceMask64(m1.getMask(0)|m2.getMask(0));
00084 #elif OSL_WORDSIZE == 32
00085 return PieceMask32(m1.getMask(0)|m2.getMask(0),
00086 m1.getMask(1)|m2.getMask(1));
00087 #endif
00088 }
00089
00090 inline const PieceMask operator~(const PieceMask &m1) {
00091 #if OSL_WORDSIZE == 64
00092 return PieceMask64(~m1.getMask(0));
00093 #elif OSL_WORDSIZE == 32
00094 return PieceMask32(~m1.getMask(0),~m1.getMask(1));
00095 #endif
00096 }
00097
00098 inline bool operator==(const PieceMask &m1, const PieceMask &m2){
00099 return m1.getMask(0)==m2.getMask(0) && m1.getMask(1)==m2.getMask(1);
00100 }
00101 inline bool operator!=(const PieceMask &m1, const PieceMask &m2)
00102 {
00103 return ! (m1 == m2);
00104 }
00105 std::ostream& operator<<(std::ostream& os,PieceMask const& pieceMask);
00106 }
00107 using container::PieceMask;
00108 }
00109
00110
00111 #endif
00112
00113
00114
00115