Top
BINARY_FILE_WRITE
BIT_STRING
expanded class interface BIT_N
--
-- Indexed Bit sequences of length N. This class is a template,
-- not a real class; to obtain a meaningful class, replace N
-- with a positive integer throughout.
--
-- An INTEGER index can be used to access each bit of the sequence.
-- The leftmost bit has index 1 and the rightmost bit has index N.
--
-- Note 1 : corresponding C mapping depends on actual N and is
-- PLATFORM dependant (see class PLATFORM).
-- When N is in range [0 .. Character_bits], C type
-- is a simple "unsigned char".
-- When N is in range [Character_bits+1 .. Integer_bits],
-- C type is "unsigned".
-- When N is greater than Integer_bits, C type is C array
-- of "unsigned" of the form :
-- "unsigned storage[N div Integer_bits]"
-- The array is obviously big enough to fit with N. As
-- for previous mapping, the left most bit (at index 1 in
-- Eiffel) is always the left most in C memory.
--
-- Note 2 : Eiffel BIT code is portable. Generated C code for class
-- BIT may not be portable (because sizeof(int) may change).
-- To produce a portable C code, you can compile your Eiffel
-- code using a machine with very small sizeof(int). Also note
-- that doing this may run a little bit slowly.
--
-- Also consider class BIT_STRING for very long bit sequences.
--
feature(s) from BIT_N
-- Basic Accessing:
count: INTEGER
-- Number of bits in the sequence (the value of N).
item (idx: INTEGER): BOOLEAN
-- True if idx-th bit is 1, false otherwise.
require
inside_bounds: 1 <= idx and then idx <= count
put (value: BOOLEAN; idx: INTEGER)
-- Set bit idx to 1 if value is true, 0 otherwise.
require
inside_bounds: 1 <= idx and idx <= count
ensure
value = item(idx)
put_1 (idx: INTEGER)
-- Set bit idx to 1.
require
inside_bounds: 1 <= idx and idx <= count
ensure
item(idx)
put_0 (idx: INTEGER)
-- Set bit idx to 0.
require
inside_bounds: 1 <= idx and idx <= count
ensure
not item(idx)
first: BOOLEAN
-- The value of the right-most bit.
ensure
definition: Result = item(1)
last: BOOLEAN
-- The value of the right-most bit.
ensure
definition: Result = item(count)
feature(s) from BIT_N
-- Rotating and shifting:
infix "^" (s: INTEGER): like Current
-- Sequence shifted by s positions (positive s shifts
-- right, negative left; bits falling off the sequence's
-- bounds are lost).
-- See also infix "|>>" and infix "|<<".
require
s.abs < count
infix "|>>" (s: INTEGER): like Current
-- Sequence shifted right by s positions.
-- Same as infix "^" when s is positive (may run a little
-- bit faster).
require
s > 0
infix "|<<" (s: INTEGER): like Current
-- Sequence shifted left by s positions.
-- Same as infix "^" when s is negative (may run a little
-- bit faster.
require
s > 0
infix "#" (s: INTEGER): like Current
-- Sequence rotated by s positions (positive right, negative
-- left).
require
s.abs < count
infix "#>>" (s: INTEGER): like Current
-- Sequence rotated by s positions right.
require
s >= 0;
s < count
infix "#<<" (s: INTEGER): like Current
-- Sequence rotated by s positions left.
require
s >= 0;
s < count
feature(s) from BIT_N
-- Bitwise Logical Operators:
infix "and" (other: like Current): like Current
-- Bitwise and of Current with other
infix "implies" (other: like Current): like Current
-- Bitwise implication of Current with other
prefix "not": like Current
-- Bitwise not of Current.
infix "or" (other: like Current): like Current
-- Bitwise or of Current with other
infix "xor" (other: like Current): like Current
-- Bitwise xor of Current with other
feature(s) from BIT_N
-- Conversions:
to_string: STRING
-- String representation of bit sequence.
-- A zero bit is mapped to '0', a one bit to '1'.
-- Leftmost bit is at index 1 in the returned string.
--
-- Note: see append_in to save memory.
ensure
Result.count = count
to_integer_8: INTEGER_8
-- The corresponding INTEGER value.
-- No sign-extension when count < 8.
require
count <= 8
to_integer_16: INTEGER_16
-- The corresponding INTEGER value.
-- No sign-extension when count < 16.
require
count <= 16
to_integer: INTEGER_32
-- The corresponding INTEGER value.
-- No sign-extension when count < 32.
require
count <= 32
to_integer_32: INTEGER_32
-- The corresponding INTEGER value.
-- No sign-extension when count < 32.
require
count <= 32
to_integer_64: INTEGER_64
-- The corresponding INTEGER value.
-- No sign-extension when count < 64.
require
count <= 64
to_character: CHARACTER
require
count <= character_bits
to_boolean: BOOLEAN
-- Return false if and only if all bits are set to 0,
-- true otherwise.
to_bit_string: BIT_STRING
ensure
count = Result.count
feature(s) from BIT_N
-- Others:
all_cleared: BOOLEAN
-- Are all bits set to 0 ?
all_default: BOOLEAN
-- Are all bits set to 0 ?
all_set: BOOLEAN
-- Are all bits set to 1 ?
feature(s) from BIT_N
-- Printing:
append_in (str: STRING)
out_in_tagged_out_memory
-- Append terse printable represention of current object
-- in tagged_out_memory.
ensure
not_cleared: tagged_out_memory.count >= old tagged_out_memory.count;
append_only: (old tagged_out_memory.twin).is_equal(tagged_out_memory.substring(1,old tagged_out_memory.count))
fill_tagged_out_memory
-- Append terse printable represention of current object
-- in tagged_out_memory.
end of expanded BIT_N
All classes inherit from ANY, ANY inherits from
PLATFORM
and PLATFORM inherits from GENERAL.
Generated by short -html_deb on 31 March 2005.