1 | #ifndef INC_BitSet_hpp__ |
---|
2 | #define INC_BitSet_hpp__ |
---|
3 | |
---|
4 | /* ANTLR Translator Generator |
---|
5 | * Project led by Terence Parr at http://www.jGuru.com |
---|
6 | * Software rights: http://www.antlr.org/license.html |
---|
7 | * |
---|
8 | * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/BitSet.hpp#2 $ |
---|
9 | */ |
---|
10 | |
---|
11 | #include <antlr/config.hpp> |
---|
12 | #include <vector> |
---|
13 | #include <stdexcept> |
---|
14 | |
---|
15 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
---|
16 | namespace antlr { |
---|
17 | #endif |
---|
18 | |
---|
19 | /** A BitSet to replace java.util.BitSet. |
---|
20 | * Primary differences are that most set operators return new sets |
---|
21 | * as opposed to oring and anding "in place". Further, a number of |
---|
22 | * operations were added. I cannot contain a BitSet because there |
---|
23 | * is no way to access the internal bits (which I need for speed) |
---|
24 | * and, because it is final, I cannot subclass to add functionality. |
---|
25 | * Consider defining set degree. Without access to the bits, I must |
---|
26 | * call a method n times to test the ith bit...ack! |
---|
27 | * |
---|
28 | * Also seems like or() from util is wrong when size of incoming set is bigger |
---|
29 | * than this.length. |
---|
30 | * |
---|
31 | * This is a C++ version of the Java class described above, with only |
---|
32 | * a handful of the methods implemented, because we don't need the |
---|
33 | * others at runtime. It's really just a wrapper around vector<bool>, |
---|
34 | * which should probably be changed to a wrapper around bitset, once |
---|
35 | * bitset is more widely available. |
---|
36 | * |
---|
37 | * @author Terence Parr, MageLang Institute |
---|
38 | * @author <br><a href="mailto:pete@yamuna.demon.co.uk">Pete Wells</a> |
---|
39 | */ |
---|
40 | class ANTLR_API BitSet { |
---|
41 | private: |
---|
42 | ANTLR_USE_NAMESPACE(std)vector<bool> storage; |
---|
43 | |
---|
44 | public: |
---|
45 | BitSet( unsigned int nbits=64 ); |
---|
46 | BitSet( const unsigned long* bits_, unsigned int nlongs); |
---|
47 | ~BitSet(); |
---|
48 | |
---|
49 | void add( unsigned int el ); |
---|
50 | |
---|
51 | bool member( unsigned int el ) const; |
---|
52 | |
---|
53 | ANTLR_USE_NAMESPACE(std)vector<unsigned int> toArray() const; |
---|
54 | }; |
---|
55 | |
---|
56 | #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
---|
57 | } |
---|
58 | #endif |
---|
59 | |
---|
60 | #endif //INC_BitSet_hpp__ |
---|