41#ifndef _CHOMP_STRUCT_BITFIELD_H_
42#define _CHOMP_STRUCT_BITFIELD_H_
186 table [n >> 3] |=
static_cast<unsigned char> (0x01 << (n & 0x07));
192 table [n >> 3] &=
static_cast<unsigned char> (~(0x01 << (n & 0x07)));
198 return !!(
table [n >> 3] & (0x01 << (n & 0x07)));
203 unsigned char *tab = field. table;
205 throw "Trying to set values to an undefined bitfield.";
208 *(tab ++) =
static_cast<unsigned char> (bits & 0xFF);
217 const unsigned char *tab = field. table;
219 throw "Trying to set values to an undefined bitfield.";
224 n |= (*(tab ++)) << shiftvalue;
228 const int bitmasks [] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF};
230 n |= ((*(tab ++)) & bitmasks [length]) << shiftvalue;
264 int used (
void)
const;
This class defines a bit field that is part of some larger array or that uses an allocated piece of m...
friend bool thesame(const BitField &b1, const BitField &b2, int_t length)
Compares two bit fields of the giben length.
friend int bits2int(const BitField &field, int_t length)
Converts the bits of a bit field of the given length into an integer.
bool defined() const
Returns true if the bit field has already been defined, that is, it is bound with some memory piece,...
int_t hashadd(int_t length) const
Returns the second key for hashing.
BitField()
The constructor of an undefined bit field.
unsigned char * table
The table of 8-bit cells which store the subsequent bits.
void allocate(int_t length)
Allocates memory for a bit field.
void clearall(int_t length)
Clears all the bits in the entire bit field of specified length.
int test(int_t n) const
Tests the given bit. Returns 0 or 1.
int find(int_t first, int_t length) const
Finds the first bit that is set to 1, beginning at the given one.
void set(int_t n)
Sets the given bit to 1.
void takebits(const BitField &from, int_t length)
Copies all the bits from the given bitfield.
void clear(int_t n)
Clears the given bit (sets it to 0).
void free()
Releases the memory allocated for the bit field.
friend void int2bits(int bits, int_t length, BitField &field)
Converts an integer into the bits of a bit field of the given length.
int_t hashkey(int_t length) const
Returns the first key for hashing.
~BitField()
The destructor which actually does nothing.
void define(unsigned char *buf, int_t length)
Define the bit field as a piece of a larger memory buffer.
This class defines a set of bit fields of the same length which are to be stored in a contiguous piec...
void forget()
Forgets all the bit fields and deallocates the memory.
int used(void) const
Returns the number of bit fields contained in the set.
int check(const BitField &b) const
Returns the value of the given bit field value or return -1 if the bit field is not in the set.
int add(const BitField &b, int value)
Adds a bit field to the set.
int_t length
The length of bit fields.
~SetOfBitFields()
The destructor.
SetOfBitFields(int_t len, int_t maxelem)
The constructor of a set of a fixed maximal number of bit fields, each of the same length.
unsigned char * bufcur
The current position in the buffer.
BitField * bf
The table of bit fields.
int avail
The number of bit fields that still can be stored.
int_t size
The actual size of the table.
unsigned char * buf
The memory buffer used for bit fields.
int usedcount
The number of bit fields used.
BitField values
The values of bit fields.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
int bits2int(const BitField &field, int_t length)
SetOfBitFields bitfieldset
A lower-case version of the name of a bit field set [deprecated].
BitField bitfield
A lower-case version of the name of a bit field [deprecated].
void int2bits(int bits, int_t length, BitField &field)
This namespace contains the entire CHomP library interface.