00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _WordExcludeMask_h
00040 #define _WordExcludeMask_h
00041
00042 #include <stdlib.h>
00043
00044 #include <WordExclude.h>
00045
00046 #define WORD_EXCLUDE_IGNORED (-1)
00047
00048 class WordExcludeMask : public WordExclude {
00049 public:
00050
00051
00052
00053
00054
00055
00056
00057 virtual inline int Initialize(unsigned int length, unsigned int ignore, unsigned int ignore_mask_arg, int) {
00058 ignore_mask = ignore_mask_arg;
00059 ignore_maxi = length;
00060 unsigned int maxi = 0;
00061 unsigned int i;
00062 for(i = 0, ignore_bits = 0; i < length; i++) {
00063 if(ignore & (1 << i)) {
00064 bit2bit[i] = WORD_EXCLUDE_IGNORED;
00065 if(ignore_mask & (1 << i)) ignore_bits++;
00066 } else {
00067 bit2bit[i] = maxi++;
00068 }
00069 }
00070
00071 return WordExclude::Initialize(maxi, 0, 0, 0);
00072 }
00073
00074 virtual inline unsigned int Excluded(int position) const {
00075 position = WORD_EXCLUDE_POSITION2BIT(ignore_maxi, position);
00076 if(bit2bit[position] == WORD_EXCLUDE_IGNORED)
00077 return ignore_mask & (1 << position);
00078 else
00079 return WordExclude::Mask() & (1 << bit2bit[position]);
00080 }
00081
00082
00083
00084
00085
00086 inline int Ignored(int position) const {
00087 position = WORD_EXCLUDE_POSITION2BIT(ignore_maxi, position);
00088 return bit2bit[position] == WORD_EXCLUDE_IGNORED;
00089 }
00090
00091 virtual inline int NotExcludedCount() const {
00092 return ignore_maxi - ignore_bits - WordExclude::Bits();
00093 }
00094
00095 virtual inline int ExcludedCount() const {
00096 return ignore_bits - WordExclude::Bits();
00097 }
00098
00099
00100
00101
00102
00103
00104 virtual void Get(String& buffer) const;
00105
00106
00107
00108
00109
00110 virtual int Set(const String& buffer);
00111
00112 virtual inline unsigned int& Mask() { static unsigned int dummy; fprintf(stderr, "WordExcludeMask::Mask\n"); abort(); return dummy; }
00113 virtual inline unsigned int Mask() const {
00114 unsigned int ret = ignore_mask;
00115 unsigned int i;
00116 for(i = 0; i < ignore_maxi; i++) {
00117 if(bit2bit[i] != WORD_EXCLUDE_IGNORED) {
00118 if(WordExclude::Mask() & (1 << bit2bit[i]))
00119 ret |= (1 << i);
00120 }
00121 }
00122 return ret;
00123 }
00124
00125 virtual inline unsigned int Maxi() const { return ignore_maxi; }
00126
00127 virtual inline unsigned int Bits() const { return ignore_bits + WordExclude::Bits(); }
00128
00129 private:
00130 unsigned int ignore_mask;
00131 unsigned int ignore_maxi;
00132 unsigned int ignore_bits;
00133 int bit2bit[WORD_EXCLUDE_MAX];
00134 };
00135
00136 #endif