summaryrefslogtreecommitdiff
path: root/utils/BitField.cc
blob: ad9532a5446b5e9f2f6942ff10836baca16393a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 *	CENA C++ Utilities
 *
 *	by Stephane Chatty
 *
 *	Copyright 1992
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	bit fields
 *
 *	$Id$
 *	$CurLog$
 */


#include "BitField.h"
#include <memory.h>
#include <stdio.h>

CcuBitField :: CcuBitField ()
{
	memset ((char*) Chunks, 0, 8 * sizeof (long));
}

CcuBitRef
CcuBitField :: operator [] (int i)
{
	if (i < 0 || i >= 8 * sizeof (long)) {
		fprintf (stderr, "Bad access to bitfield: index %d\n", i);
		i = 0;
	}
	short q = i / sizeof (long);
	short r = i - q * sizeof (long);
	return CcuBitRef (*this, q, r);
}

CcuBitRef :: operator bool () const
{
	return bool (Field.Chunks [Chunk] & (1L << Offset));
}

bool
CcuBitRef :: operator = (bool b) const
{
	long* l = Field.Chunks + Chunk;
	long m = (1L << Offset);
	if (b)
		(*l) |= m;
	else
		(*l) &= ~m;
	return b;
}