Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / StyleSheet / BitVector.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: BitVector.h /main/4 1996/08/21 15:49:59 drk $ */
24
25 #ifndef _BitVector_h
26 #define _BitVector_h 1
27
28 #include <sstream>
29 #include <ostream>
30 using namespace std;
31
32 #ifndef CDE_NEXT
33
34 #else
35 //#include <StyleSheet/cde_next.h>
36 #include "dti_cc/CC_Slist.h"
37 #endif
38
39 #define WORD_SIZE 32
40
41 class posRecord
42 {
43 public:
44    posRecord(unsigned int x = 0, unsigned int y = 0) : 
45         pathTermPos(x), bitPos(y) {};
46    ~posRecord() {};
47
48    unsigned int operator ==(const posRecord&);
49
50 public:
51    unsigned int pathTermPos;
52    unsigned int bitPos;
53 };
54
55 typedef CC_TValSlist<posRecord> positionArrayT;
56 typedef CC_TValSlistIterator<posRecord> positionArrayIteratorT;
57
58 ///////////////////////////////////////////////////////
59 // A storage/manipulation efficient bit vector class
60 ///////////////////////////////////////////////////////
61 class BitVector 
62 {
63    unsigned int *f_array;
64    unsigned int f_bits;
65    unsigned int f_words;
66    positionArrayT *f_positionArray;
67
68 public:
69    BitVector(int bits, unsigned int initValue);
70    ~BitVector();
71
72 //
73 // bits range: 0 .. bits-1
74 // the 0th bit is LSB, the (bits-1)th bit is MSB
75 //
76    void setAllBitsTo(unsigned int);
77    void setTo(BitVector&);
78
79    void recordPositions(unsigned int pathTermPos, unsigned int BitPos);
80    positionArrayT* positionArray() { return f_positionArray; };
81
82    void setBitTo(int i, unsigned int);
83    unsigned int getBit(int i);
84
85    BitVector& operator &=(BitVector&);
86    BitVector& operator ^=(BitVector&);
87    BitVector& operator |=(BitVector&);
88
89 // Note: the MSB is set to 1 after each shiftRightOneBit() call.
90    BitVector& shiftRightOneBit();
91    BitVector& shiftLeftOneBit();
92
93    friend ostream& operator<<(ostream&, BitVector&);
94 };
95
96 #endif