home *** CD-ROM | disk | FTP | other *** search
-
- #define KEEP_ALPHABET_DEFINES
-
- #include "Alphabet.h"
- #include "Alphabet_Private.h"
-
- //________________________________________________________________________
-
- Alphabet& Alphabet::operator+= (const char element)
- {
- SET_ELT(element); // set the element's bit in the buffer
- return *this;
- }
-
- //________________________________________________________________________
-
- Alphabet& Alphabet::operator-= (const char element)
- {
- CLR_ELT(element); // clear the element's bit in the buffer
- return *this;
- }
-
- //________________________________________________________________________
-
- int Alphabet::contains (const char element) const
- {
- return ELT(element); // test the element's bit in the buffer
- }
-
- //________________________________________________________________________
-
- Alphabet& Alphabet::through(int (*action)(const char, Alphabet&), direction_t dir)
- {
- Alphabet copy(*this);
- register int byte, bit; // the byte, resp. bit-counters
- register unsigned char elt8; // the current buffer-byte
- register char element; // the current element
- int stop = 0;
-
- if (dir == FORWARD)
- {
- for (element=ELT_LOW, byte=0; (! stop) && (byte < BUFSIZE); byte++)
- if ((elt8 = copy.buffer[byte]) != 0)
- for (bit=0; (! stop) && (bit < 8); bit++, element++)
- {
- if ((elt8 & (1 << bit)) != 0)
- stop = action(element, *this);
- }
- else
- element += 8;
- }
- else
- {
- for (element=ELT_HIGH, byte=BUFSIZE-1; (! stop) && (byte >= 0); byte--)
- if ((elt8 = copy.buffer[byte]) != 0)
- for (bit=7; (! stop) && (bit >= 0); bit--, element--)
- {
- if ((elt8 & (1 << bit)) != 0)
- stop = action(element, *this);
- }
- else
- element -= 8;
- }
-
- return (*this);
- }
-
- //________________________________________________________________________
-
- unsigned int Alphabet::card (void) const
- {
- unsigned int Number_Of_Elements = 0;
- register int byte, bit; // the byte, resp. bit-counters
- register unsigned char elt8; // the current buffer-byte
-
- for (byte=0; byte < BUFSIZE; byte++)
- if ((elt8 = buffer[byte]) != 0)
- for (bit=0; bit < 8; bit++)
- {
- if ((elt8 & (1 << bit)) != 0)
- Number_Of_Elements++;
- }
-
- return Number_Of_Elements;
- }
-