WordExcludeMask.h

Go to the documentation of this file.
00001 //
00002 // Part of the ht://Dig package   <http://www.htdig.org/>
00003 // Copyright (c) 1999, 2000, 2001 The ht://Dig Group
00004 // For copyright details, see the file COPYING in your distribution
00005 // or the GNU General Public License version 2 or later
00006 // <http://www.gnu.org/copyleft/gpl.html>
00007 //
00008 // $Id: WordExcludeMask_8h-source.html,v 1.1 2008/06/08 10:13:10 sebdiaz Exp $
00009 //
00010 // NAME
00011 //
00012 // WordExclude specialization that ignore some bits
00013 //
00014 // SYNOPSIS
00015 //
00016 // #include <WordExcludeMask.h>
00017 //
00018 // #define BITS              9
00019 // #define IGNORE        0x0f0
00020 // #define IGNORE_MASK   0x050
00021 //
00022 // WordExcludeMask permute;
00023 // permute.Initialize(BITS, IGNORE, IGNORE_MASK);
00024 // while(permute.Next() == WORD_EXCLUDE_OK)
00025 //    ...
00026 //
00027 // DESCRIPTION
00028 //
00029 // Only perform WordExclude operations on the bits that are not set in
00030 // <i>ignore.</i> The bits of <i>ignore_mask</i> that are set in
00031 // <i>ignore</i> are untouched. In the synopsis section, for instance,
00032 // bits 1,2,3,4 and 9 will be permuted and the bits 5,6,7,8 will be
00033 // left untouched.
00034 // 
00035 //
00036 // END
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   // <b>ignore</b> gives the mask of bits to ignore. The actual WordExclude
00052   // operations are made on a number of bits that is <b>length</b> - (the number
00053   // of bits set in <b>ignore).</b>
00054   // The <b>ignore_mask_arg</b> contains the actual values of the bits ignored by 
00055   // the <b>ignore</b> argument.
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   // Return true if bit at <b>position</b> is ignored by permutations,
00084   // i.e. has a fixed value.
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   // The semantic is the same as the Get method of Wordexclude
00101   // except that ignored bits are assigned 3 and 2 instead of 1 and 0
00102   // respectively.
00103   //
00104   virtual void Get(String& buffer) const;
00105   //-
00106   // The semantic is the same as the Get method of Wordexclude
00107   // except that ignored bits are assigned 3 and 2 instead of 1 and 0
00108   // respectively.
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 /* _WordExcludeMask_h */

Generated on Sun Jun 8 10:56:40 2008 for GNUmifluz by  doxygen 1.5.5