1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License as *
7 * published by the Free Software Foundation and appearing *
8 * in the file LICENSE.GPL included in the packaging of this file. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * General Public License for more details. *
15 ***************************************************************************/
25 /* {{{ BitField::BitField(size_t) */
26 BitField::BitField(size_t len
) : length(len
), remaining(length
)
28 size_t s
= (len
>> 3) + (len
& 0x07 ? 1 : 0);
34 /* {{{ BitField::BitField(const char *, size_t) */
35 BitField::BitField(const char *mem
, size_t len
) : length(len
), remaining(length
)
37 size_t s
= (len
>> 3) + (len
& 0x07 ? 1 : 0);
41 for (size_t i
= 0; i
< len
; ++i
)
47 /* {{{ BitField::~BitField() */
54 /* {{{ BitField::getBit(size_t) */
55 bool BitField::getBit(size_t index
)
57 return data
[index
>> 3] & (0x80 >> (index
& 0x07));
61 /* {{{ BitField::setAll(bool) */
62 void BitField::setAll(bool value
)
64 size_t s
= (length
>> 3) + (length
& 0x07 ? 1 : 0);
65 memset(data
, value
? 0xff : 0x00, s
);
70 /* {{{ BitField::setBit(size_t, bool) */
71 void BitField::setBit(size_t index
, bool value
)
73 char orig
= data
[index
>> 3];
75 data
[index
>> 3] |= 0x80 >> (index
& 0x07);
76 remaining
-= orig
^ data
[index
>> 3] ? 1 : 0;
78 data
[index
>> 3] &= 0x7f >> (index
& 0x07);
79 remaining
+= orig
^ data
[index
>> 3] ? 1 : 0;
86 }; // namespace Tairent
88 // vim: ai sw=4 ts=4 noet fdm=marker