/[eiffelstudio]/FreeELKS/trunk/library/kernel/bit_ref.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/bit_ref.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 5567 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2 description: "Bit sequences of length `count', with binary operations"
3 library: "Free implementation of ELKS library"
4 copyright: "Copyright (c) 1986-2004, Eiffel Software and others"
5 license: "Eiffel Forum License v2 (see forum.txt)"
6 date: "$Date$"
7 revision: "$Revision$"
8
9 class BIT_REF inherit
10
11 ANY
12 redefine
13 out,
14 generator,
15 conforms_to
16 end
17
18 feature -- Access
19
20 item alias "[]", infix "@" (i: INTEGER): BOOLEAN assign put is
21 -- `i'-th bit
22 require
23 index_large_enough: i >= 1
24 index_small_enough: i <= count
25 do
26 Result := b_item ($Current, i)
27 end
28
29 generator: STRING is
30 -- Name of the current object's generating class.
31 do
32 create Result.make (10)
33 Result.append ("BIT ")
34 Result.append_integer (count)
35 end
36
37 conforms_to (other: ANY): BOOLEAN is
38 -- Is dynamic type of current object a descendant of
39 -- dynamic type of `other'?
40 local
41 b: BIT_REF
42 do
43 b ?= other
44 if b /= Void then
45 Result := count <= b.count
46 end
47 end
48
49 feature -- Measurement
50
51 count: INTEGER is
52 -- Size of the current bit object
53 do
54 Result := b_count ($Current)
55 end
56
57 feature -- Element change
58
59 put (value: BOOLEAN; i: INTEGER) is
60 -- Set the `i'-th bit to 1 if `value' is True, 0 if False
61 require
62 index_large_enough: i >= 1
63 index_small_enough: i <= count
64 do
65 b_put ($Current, value, i)
66 ensure
67 value_inserted: item (i) = value
68 end
69
70 feature -- Basic operations
71
72 infix "^" (s: INTEGER): like Current is
73 -- Result of shifting bit sequence by `s' positions
74 -- (Positive `s' shifts right, negative `s' shifts left;
75 -- bits falling off the sequence's bounds are lost.)
76 do
77 Result := b_shift ($Current, s)
78 end
79
80 infix "#" (s: INTEGER): like Current is
81 -- Result of rotating bit sequence by `s' positions
82 -- (Positive `s' rotates right, negative `s' rotates left.)
83 do
84 Result := b_rotate ($Current, s)
85 end
86
87 infix "and" (other: BIT_REF): like Current is
88 -- Bit-by-bit boolean conjunction with `other'
89 require
90 other_exists: other /= Void
91 conformance: other.count <= count
92 do
93 Result := b_and ($Current, $other)
94 end
95
96 infix "implies" (other: BIT_REF): like Current is
97 -- Bit-by-bit boolean implication of `other'
98 require
99 other_exists: other /= Void
100 conformance: other.count <= count
101 do
102 Result := b_implies ($Current, $other)
103 end
104
105 infix "or", infix "|" (other: BIT_REF): like Current is
106 -- Bit-by-bit boolean disjunction with `other'
107 require
108 other_exists: other /= Void
109 conformance: other.count <= count
110 do
111 Result := b_or ($Current, $other)
112 end
113
114 infix "xor" (other: BIT_REF): like Current is
115 -- Bit-by-bit exclusive or with `other'
116 require
117 other_exists: other /= Void
118 conformance: other.count <= count
119 do
120 Result := b_xor ($Current, $other)
121 end
122
123 prefix "not": like Current is
124 -- Bit-by-bit negation
125 do
126 Result := b_not ($Current)
127 end
128
129 feature -- Output
130
131 out: STRING is
132 -- Tagged printable representation.
133 do
134 Result := c_out ($Current)
135 end
136
137 feature -- Conversion
138
139 to_reference: BIT_REF is
140 -- Associated reference of Current.
141 local
142 l_out: ANY
143 do
144 l_out := out.to_c
145 Result := b_makebit_from ($l_out, count)
146 end
147
148 feature {NONE} -- Implementation
149
150 b_item (a_bit: POINTER; index: INTEGER): BOOLEAN is
151 -- Boolean item at position `i' in `a_bit'
152 external
153 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_BOOLEAN use %"eif_bits.h%""
154 end
155
156 b_count (a_bit: POINTER): INTEGER is
157 -- Size of `a_bit'
158 external
159 "C signature (EIF_REFERENCE): EIF_INTEGER use %"eif_bits.h%""
160 end
161
162 b_shift (a_bit: POINTER; s: INTEGER): like Current is
163 -- Result of shifting `a_bit' by `s' positions
164 external
165 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
166 end
167
168 b_rotate (a_bit: POINTER; s: INTEGER): like Current is
169 -- Result of rotating `a_bit' by `s' positions
170 external
171 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
172 end
173
174 b_and (a_bit1, a_bit2: POINTER): like Current is
175 -- Conjunction of `a_bit1' with `a_bit2'
176 external
177 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
178 end
179
180 b_implies (a_bit1, a_bit2: POINTER): like Current is
181 -- Implication for `a_bit1' of `a_bit2'
182 external
183 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
184 end
185
186 b_or (a_bit1, a_bit2: POINTER): like Current is
187 -- Disjunction of `a_bit1' with `a_bit2'
188 external
189 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
190 end
191
192 b_xor (a_bit1, a_bit2: POINTER): like Current is
193 -- Exclusive or of `a_bit1' with `a_bit2'
194 external
195 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
196 end
197
198 b_not (a_bit: POINTER): like Current is
199 -- Negation of `a_bit'
200 external
201 "C signature (EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
202 end
203
204 b_put (a_bit: POINTER; val: BOOLEAN; index: INTEGER) is
205 -- Put `val' in `a_bit' at position `index'.
206 external
207 "C signature (EIF_REFERENCE, char, int) use %"eif_bits.h%""
208 end
209
210 c_out (b: POINTER): STRING is
211 -- Out representation of Current
212 external
213 "C signature (EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
214 alias
215 "b_eout"
216 end
217
218 b_makebit_from (p: POINTER; n: INTEGER): BIT_REF is
219 -- From Eiffel object `p' generate a new BIT_REF instance of count `n'
220 external
221 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
222 alias
223 "RTMB"
224 end
225
226 invariant
227 valid_count: count > 0
228
229 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23