2 * $TOG: BitField.hh /main/5 1998/04/17 11:35:57 mgreess $
4 * Copyright (c) 1992 HAL Computer Systems International, Ltd.
5 * All rights reserved. Unpublished -- rights reserved under
6 * the Copyright Laws of the United States. USE OF A COPYRIGHT
7 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
10 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
11 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
12 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
13 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
16 * RESTRICTED RIGHTS LEGEND
17 * Use, duplication, or disclosure by the Government is subject
18 * to the restrictions as set forth in subparagraph (c)(l)(ii)
19 * of the Rights in Technical Data and Computer Software clause
20 * at DFARS 252.227-7013.
22 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
27 #if defined(SVR4) || defined(hpux) || defined(linux)
30 #include <sys/limits.h>
33 const int bytes_per_word = sizeof(unsigned long);
34 const int bits_per_byte = CHAR_BIT ;
35 const int bits_per_word = bytes_per_word * bits_per_byte ;
37 typedef unsigned long BitHandle ;
42 BitField(unsigned long initial_bits = CHAR_BIT * sizeof(unsigned long) - 1) ;
45 void return_bit(unsigned long bit); // give back previously
47 BitHandle get_handle(); // allocate a bit for future use
48 void free_handle(BitHandle); // return bit for other use
50 /* -------- bit operations -------- */
51 bool is_set(BitHandle);
53 bool unset(BitHandle);
59 bool is_used(BitHandle);
60 ostream &BitField::dump(ostream &);
64 /* -------- internal functions that do the real work -------- */
65 void check_allocation (unsigned long word);
66 bool i_is_set(BitHandle);
67 bool i_set(BitHandle);
68 bool i_unset(BitHandle);
71 /* -------- suplementary (inline) functions -------- */
72 bool word_has_zero_bit(unsigned long);
73 bool byte_has_zero_bit(unsigned char byte);
74 unsigned char get_byte(int byte, unsigned long word);
78 unsigned long f_num_words ; // number of allocated machine words
79 unsigned long *f_words ; // array of words for bits
80 unsigned long *f_bits_in_use ; // maps bits already allocated
83 // the assert(is_used(handle)) is commented out as OutlineLists do not
84 // allocate separate data handles for thier child lists - jbm
87 BitField::is_set(BitHandle handle)
90 // assert(is_used(handle));
91 return i_is_set(handle);
95 BitField::set(BitHandle handle)
98 // assert(is_used(handle));
103 BitField::unset(BitHandle handle)
106 // assert(is_used(handle));
107 return i_unset(handle);
112 BitField::word_has_zero_bit(unsigned long word)
114 return !((word & ULONG_MAX) == ULONG_MAX);
118 BitField::byte_has_zero_bit(unsigned char byte)
120 return !((byte & UCHAR_MAX) == UCHAR_MAX) ;
123 // return a byte within a word
126 BitField::get_byte(int byte, unsigned long word)
128 return (word >> (byte * bits_per_byte)) & UCHAR_MAX ;
134 operator << (ostream &o, BitField &bf)