diff options
Diffstat (limited to 'utils/BitField.cc')
-rw-r--r-- | utils/BitField.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/utils/BitField.cc b/utils/BitField.cc new file mode 100644 index 0000000..ad9532a --- /dev/null +++ b/utils/BitField.cc @@ -0,0 +1,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; +} |