ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/antlr/BitSet.cpp
Revision: 2469
Committed: Fri Dec 2 15:38:03 2005 UTC (18 years, 7 months ago) by tim
File size: 1185 byte(s)
Log Message:
End of the Link --> List
Return of the Oject-Oriented
replace yacc/lex parser with antlr parser

File Contents

# User Rev Content
1 tim 2469 /* ANTLR Translator Generator
2     * Project led by Terence Parr at http://www.jGuru.com
3     * Software rights: http://www.antlr.org/license.html
4     *
5     * $Id: BitSet.cpp,v 1.1 2005-12-02 15:38:02 tim Exp $
6     */
7     #include "antlr/BitSet.hpp"
8     #include <string>
9    
10     #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
11     namespace antlr {
12     #endif
13    
14     BitSet::BitSet(unsigned int nbits)
15     : storage(nbits)
16     {
17     for (unsigned int i = 0; i < nbits ; i++ )
18     storage[i] = false;
19     }
20    
21     BitSet::BitSet( const unsigned long* bits_, unsigned int nlongs )
22     : storage(nlongs*32)
23     {
24     for ( unsigned int i = 0 ; i < (nlongs * 32); i++)
25     storage[i] = (bits_[i>>5] & (1UL << (i&31))) ? true : false;
26     }
27    
28     BitSet::~BitSet()
29     {
30     }
31    
32     void BitSet::add(unsigned int el)
33     {
34     if( el >= storage.size() )
35     storage.resize( el+1, false );
36    
37     storage[el] = true;
38     }
39    
40     bool BitSet::member(unsigned int el) const
41     {
42     if ( el >= storage.size())
43     return false;
44    
45     return storage[el];
46     }
47    
48     ANTLR_USE_NAMESPACE(std)vector<unsigned int> BitSet::toArray() const
49     {
50     ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems;
51     for (unsigned int i = 0; i < storage.size(); i++)
52     {
53     if (storage[i])
54     elems.push_back(i);
55     }
56    
57     return elems;
58     }
59    
60     #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
61     }
62     #endif