NOTE:
These are a little sketchy...I'll fill in details 'soon'.
long String::size(void) const
{
return length;
}
bool String::operator!(void) const
{
return (string == nullptr);
}
bool String::good(void) const
{
return (translate_state & goodbit) != 0;
}
bool String::fail(void) const
{
return (translate_state & failbit) != 0;
}
bool String::eos(void) const
{
return (translate_state & eosbit) != 0;
}
long String::clear(long new_state) const // default state = goodbit
{
long hold = translate_state;
translate_state = new_state;
return hold;
}
long String::seekg(long new_position) const // default pos = 0
{
long hold = translate_position;
translate_position = new_position;
return hold;
}
long String::tellg(void) const
{
return translate_position;
}
long String::setf(long new_flags) const
{
long hold = flags;
flags |= new_flags; // bit-wise or with assign
return hold;
}
The |= here will allow the flags to contain multiple bit flags
-- setting the newly requested one(s) and leaving others alone:
11000101101
| 00001011001
---------------
11001111101
Note how the first three set (one) bits were 0 in the new flags
but remain on in the result. The next originally on bit was
requested to be set and stayed on.
long String::unsetf(long drop_flags) const
{
long hold = flags;
flags ^= drop_flags; // bit-wise xor with assign
return hold;
}
XOR with assignment here will toggle those flags requested
while leaving other flags unaffected:
11000101101
^ 00001011001
---------------
11001110100
The first three on flags are unaltered by the XOR. Flags that
were off become on. Flags that were on become off. Otherwise,
flags that were off stay off.
This form of 'unsetf' is, as stated, toggling the flags -- not strictly turning them off. To strictly turn off the flags, we could do this:
flags &= ~drop_flags;
This is a bit-wise AND with assignment to the 1's complement
of the flags requested to be removed:
11000101101
~ 00001011001 & 11110100110
--------------- ---------------
11110100110 11000100100
Now the flags requested off are turned to off in the bit-wise NOT
(the 1's complement -- the ~ operator) and all other bits are turned
on. Then, in the AND, the 0's force the requested bits off (false AND
anything is false) and the toggled 1's allow the originally on bits
to stay on (true AND true is true).
bool String::case_sensitive(void) const
{
return (flags & case_on) != 0; // bit-wise and
}
The & here tests to see if the requested bit(s) are on. When
the result is not 0, they are on. When the result is 0, they are
off:
11000101101
& 00001011001
---------------
00000001001
Of the 4 bits whose status we requested, two were on. We can even
check exactly which ones were on with further &ing.