blob: d1fabc4da35f09027e103911636c6465e771cb27 (
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
|
/*
* 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>
IvlBitField :: IvlBitField ()
{
memset ((char*) Chunks, 0, 8 * sizeof (long));
}
IvlBitRef
IvlBitField :: 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 IvlBitRef (*this, q, r);
}
IvlBitRef :: operator bool () const
{
return bool (Field.Chunks [Chunk] & (1L << Offset));
}
bool
IvlBitRef :: operator = (bool b) const
{
long* l = Field.Chunks + Chunk;
long m = (1L << Offset);
if (b)
(*l) |= m;
else
(*l) &= ~m;
return b;
}
|