ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/utils/BitSet.hpp
(Generate patch)

Comparing trunk/OOPSE-4/src/utils/BitSet.hpp (file contents):
Revision 1961 by tim, Tue Feb 1 06:55:00 2005 UTC vs.
Revision 1962 by tim, Tue Feb 1 22:49:23 2005 UTC

# Line 42 | Line 42
42   #ifndef UTILS_BITSET_HPP
43   #define UTILS_BITSET_HPP
44  
45 + #include <functional>
46   #include <vector>
47   namespace oopse {
48  
49   /**
50   * @class BitSet BitSet.hpp "BitSet.hpp"
51 < * @brief BitSet is a wrapper class of std::vector<char>
51 > * @brief BitSet is a wrapper class of std::vector<char> to act as a growable std::bitset
52   */
53   class BitSet {
54      public:
# Line 74 | Line 75 | class BitSet {
75          /** Returns a new BitSet composed of bits from this BitSet from fromIndex(inclusive) to toIndex(exclusive). */
76          BitSet get(int fromIndex, int toIndex);
77          
78 <        /** Returns true if this BitSet contains no bits that are set to true. */
79 <        bool isEmpty();
80 <                
78 >        /** Returns true if any bits are set to true */
79 >        bool any() {return !none(); }
80 >
81 >        /** Returns true if no bits are set to true */
82 >        bool none();
83 >        
84          /** Returns the index of the first bit that is set to false that occurs on or after the specified starting index.*/
85          int nextOffBit(int fromIndex);
86          
# Line 84 | Line 88 | class BitSet {
88          int nextOnBit(int fromIndex);
89          
90          /** Performs a logical AND of this target bit set with the argument bit set. */
91 <        void and(const BitSet& bs);
92 <
89 <        /** Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet. */
90 <        void andNot(const BitSet& bs);
91 <        
91 >        void andOperator (const BitSet& bs);
92 >      
93          /** Performs a logical OR of this bit set with the bit set argument. */
94 <        void or(const BitSet& bs);
94 >        void orOperator (const BitSet& bs);
95          
96          /** Performs a logical XOR of this bit set with the bit set argument. */
97 <        void xor(const BitSet& bs);        
97 >        void xorOperator (const BitSet& bs);        
98                
99          void setBitOn(int bitIndex) {  setBit(bitIndex, true);  }
100  
# Line 107 | Line 108 | class BitSet {
108          void clear() {  setRangeOff(0, size());  }        
109          
110          /** Returns the number of bits of space actually in use by this BitSet to represent bit values. */
111 <        int size() {  return bitset_.size();  }
111 >        int size() const {  return bitset_.size();  }
112  
113          /** Changes the size of BitSet*/
114 <        bool resize(int nbits) {  bitset_.resize();  }
114 >        void resize(int nbits) {  bitset_.resize(nbits);  }
115          
116 <        BitSet& operator&= (const BitSet &bs) {  and(bs); return *this; }
117 <        BitSet& operator|= (const BitSet &bs) { or(bs); return *this; }
118 <        BitSet& operator^= (const BitSet &bs) { xor(bs); return *this; }
116 >        BitSet& operator&= (const BitSet &bs) {  andOperator (bs); return *this; }
117 >        BitSet& operator|= (const BitSet &bs) { orOperator (bs); return *this; }
118 >        BitSet& operator^= (const BitSet &bs) { xorOperator (bs); return *this; }
119          bool operator[] (int bitIndex) {  return bitset_[bitIndex];  }
120  
121 <        friend BitSet operator| (BitSet& bs1, BitSet& bs2);
122 <        friend BitSet operator& (BitSet& bs1, BitSet& bs2);
123 <        friend BitSet operator^ (BitSet& bs1, BitSet& bs2);
121 >        friend BitSet operator| (const BitSet& bs1, const BitSet& bs2);
122 >        friend BitSet operator& (const BitSet& bs1, const BitSet& bs2);
123 >        friend BitSet operator^ (const BitSet& bs1, const BitSet& bs2);
124          friend bool operator== (const BitSet & bs1, const BitSet &bs2);
125  
126 <        friend std::istream& operator>> ( std::istream&, BitSet& bs);
126 >        friend std::istream& operator>> ( std::istream&, const BitSet& bs);
127          friend std::ostream& operator<< ( std::ostream&, const BitSet& bs) ;
128  
129      private:
# Line 131 | Line 132 | class BitSet {
132          void setBit(int bitIndex, bool value) { bitset_[bitIndex] = value; }
133          
134          /** Sets the bits from the specified fromIndex(inclusive) to the specified toIndex(exclusive) to the specified value. */
135 <        void setBits(int fromIndex, int toIndex, bool value) {}
135 >        void setBits(int fromIndex, int toIndex, bool value);
136          
137          std::vector<char> bitset_;
138   };
139  
140 + template<typename T>
141 + struct logical_xor :public std::binary_function<T, T, bool> {
142 +    double operator()(T x, T y) { return x ^ y; }
143 + };
144 +
145   }
146   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines