00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BITMASK_H
00020 #define BITMASK_H
00021
00022 #include <pandabase.h>
00023
00024 #include "numeric_types.h"
00025 #include "typedObject.h"
00026 #include "indent.h"
00027
00028 #include <checksumHashGenerator.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037 template<class WordType, int num_bits>
00038 class BitMask {
00039 PUBLISHED:
00040 INLINE BitMask();
00041 INLINE BitMask(WordType init_value);
00042 INLINE BitMask(const BitMask<WordType, num_bits> ©);
00043 INLINE void operator = (const BitMask<WordType, num_bits> ©);
00044
00045 INLINE static BitMask<WordType, num_bits> all_on();
00046 INLINE static BitMask<WordType, num_bits> all_off();
00047 INLINE static BitMask<WordType, num_bits> lower_on(int on_bits);
00048 INLINE static BitMask<WordType, num_bits> bit(int index);
00049
00050 INLINE ~BitMask();
00051
00052 INLINE int get_num_bits() const;
00053 INLINE bool get_bit(int index) const;
00054 INLINE void set_bit(int index);
00055 INLINE void clear_bit(int index);
00056 INLINE void set_bit_to(int index, bool value);
00057 INLINE bool is_zero() const;
00058
00059 INLINE WordType extract(int low_bit, int size) const;
00060 INLINE void store(WordType value, int low_bit, int size);
00061 INLINE WordType get_word() const;
00062 INLINE void set_word(WordType value);
00063
00064 INLINE void invert_in_place();
00065 INLINE void clear();
00066
00067 void output(ostream &out) const;
00068 void output_binary(ostream &out, int spaces_every = 4) const;
00069 void output_hex(ostream &out, int spaces_every = 4) const;
00070 void write(ostream &out, int indent_level = 0) const;
00071
00072 INLINE bool operator == (const BitMask<WordType, num_bits> &other) const;
00073 INLINE bool operator != (const BitMask<WordType, num_bits> &other) const;
00074 INLINE bool operator < (const BitMask<WordType, num_bits> &other) const;
00075 INLINE int compare_to(const BitMask<WordType, num_bits> &other) const;
00076
00077 INLINE BitMask<WordType, num_bits>
00078 operator & (const BitMask<WordType, num_bits> &other) const;
00079
00080 INLINE BitMask<WordType, num_bits>
00081 operator | (const BitMask<WordType, num_bits> &other) const;
00082
00083 INLINE BitMask<WordType, num_bits>
00084 operator ^ (const BitMask<WordType, num_bits> &other) const;
00085
00086 INLINE BitMask<WordType, num_bits>
00087 operator ~ () const;
00088
00089 INLINE BitMask<WordType, num_bits>
00090 operator << (int shift) const;
00091
00092 INLINE BitMask<WordType, num_bits>
00093 operator >> (int shift) const;
00094
00095 INLINE void operator &= (const BitMask<WordType, num_bits> &other);
00096 INLINE void operator |= (const BitMask<WordType, num_bits> &other);
00097 INLINE void operator ^= (const BitMask<WordType, num_bits> &other);
00098 INLINE void operator <<= (int shift);
00099 INLINE void operator >>= (int shift);
00100
00101 public:
00102 INLINE void generate_hash(ChecksumHashGenerator &hashgen) const;
00103
00104 private:
00105 WordType _word;
00106
00107 public:
00108 static TypeHandle get_class_type() {
00109 return _type_handle;
00110 }
00111 static void init_type();
00112
00113 private:
00114 static TypeHandle _type_handle;
00115 };
00116
00117 #include "bitMask.I"
00118
00119 template<class WordType, int num_bits>
00120 INLINE ostream &operator << (ostream &out, const BitMask<WordType, num_bits> &bitmask) {
00121 bitmask.output(out);
00122 return out;
00123 }
00124
00125
00126
00127 #define BITMASK32_DEF BitMask<PN_uint32, 32>
00128 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, BITMASK32_DEF);
00129
00130 typedef BitMask<PN_uint32, 32> BitMask32;
00131
00132
00133 #ifdef __GNUC__
00134 #pragma interface
00135 #endif
00136
00137 #endif