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::setBit(size_t, bool) */
62 void BitField::setBit(size_t index
, bool value
)
64 char orig
= data
[index
>> 3];
66 data
[index
>> 3] |= 0x80 >> (index
& 0x07);
67 remaining
+= orig
^ data
[index
>> 3] ? 1 : 0;
69 data
[index
>> 3] &= 0x7f >> (index
& 0x07);
70 remaining
-= orig
^ data
[index
>> 3] ? 1 : 0;
77 }; // namespace Tairent
79 // vim: ai sw=4 ts=4 noet fdm=marker