/[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 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 6048 byte(s)
Initial revision

1 indexing
2
3 description: "Bit sequences of length `count', with binary operations"
4 status: "See notice at end of class"
5 date: "$Date$"
6 revision: "$Revision$"
7
8 --| Caution:
9 --| For implementation reasons, additional operations on BIT types can
10 --| only be introduced by ISE
11
12 class BIT_REF inherit
13
14 ANY
15 redefine
16 out
17 end
18
19 convert
20 to_reference: {BIT_REF, ANY}
21
22 feature -- Access
23
24 item, infix "@" (i: INTEGER): BOOLEAN is
25 -- `i'-th bit
26 require
27 index_large_enough: i >= 1
28 index_small_enough: i <= count
29 do
30 Result := b_item ($Current, i)
31 end
32
33 feature -- Measurement
34
35 count: INTEGER is
36 -- Size of the current bit object
37 do
38 Result := b_count ($Current)
39 end
40
41 feature -- Element change
42
43 put (value: BOOLEAN; i: INTEGER) is
44 -- Set the `i'-th bit to 1 if `value' is True, 0 if False
45 require
46 index_large_enough: i >= 1
47 index_small_enough: i <= count
48 do
49 b_put ($Current, value, i)
50 ensure
51 value_inserted: item (i) = value
52 end
53
54 feature -- Basic operations
55
56 infix "^" (s: INTEGER): like Current is
57 -- Result of shifting bit sequence by `s' positions
58 -- (Positive `s' shifts right, negative `s' shifts left;
59 -- bits falling off the sequence's bounds are lost.)
60 do
61 Result := b_shift ($Current, s)
62 end
63
64 infix "#" (s: INTEGER): like Current is
65 -- Result of rotating bit sequence by `s' positions
66 -- (Positive `s' rotates right, negative `s' rotates left.)
67 do
68 Result := b_rotate ($Current, s)
69 end
70
71 infix "and" (other: BIT_REF): like Current is
72 -- Bit-by-bit boolean conjunction with `other'
73 require
74 other_exists: other /= Void
75 conformance: other.count <= count
76 do
77 Result := b_and ($Current, $other)
78 end
79
80 infix "implies" (other: BIT_REF): like Current is
81 -- Bit-by-bit boolean implication of `other'
82 require
83 other_exists: other /= Void
84 conformance: other.count <= count
85 do
86 Result := b_implies ($Current, $other)
87 end
88
89 infix "or", infix "|" (other: BIT_REF): like Current is
90 -- Bit-by-bit boolean disjunction with `other'
91 require
92 other_exists: other /= Void
93 conformance: other.count <= count
94 do
95 Result := b_or ($Current, $other)
96 end
97
98 infix "xor" (other: BIT_REF): like Current is
99 -- Bit-by-bit exclusive or with `other'
100 require
101 other_exists: other /= Void
102 conformance: other.count <= count
103 do
104 Result := b_xor ($Current, $other)
105 end
106
107 prefix "not": like Current is
108 -- Bit-by-bit negation
109 do
110 Result := b_not ($Current)
111 end
112
113 feature -- Output
114
115 out: STRING is
116 -- Tagged printable representation.
117 do
118 Result := c_out ($Current)
119 end
120
121 feature -- Conversion
122
123 to_reference: BIT_REF is
124 -- Associated reference of Current.
125 local
126 l_out: ANY
127 do
128 l_out := out.to_c
129 Result := b_makebit_from ($l_out, count)
130 end
131
132 feature {NONE} -- Implementation
133
134 b_item (a_bit: POINTER; index: INTEGER): BOOLEAN is
135 -- Boolean item at position `i' in `a_bit'
136 external
137 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_BOOLEAN use %"eif_bits.h%""
138 end
139
140 b_count (a_bit: POINTER): INTEGER is
141 -- Size of `a_bit'
142 external
143 "C signature (EIF_REFERENCE): EIF_INTEGER use %"eif_bits.h%""
144 end
145
146 b_shift (a_bit: POINTER; s: INTEGER): like Current is
147 -- Result of shifting `a_bit' by `s' positions
148 external
149 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
150 end
151
152 b_rotate (a_bit: POINTER; s: INTEGER): like Current is
153 -- Result of rotating `a_bit' by `s' positions
154 external
155 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
156 end
157
158 b_and (a_bit1, a_bit2: POINTER): like Current is
159 -- Conjunction of `a_bit1' with `a_bit2'
160 external
161 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
162 end
163
164 b_implies (a_bit1, a_bit2: POINTER): like Current is
165 -- Implication for `a_bit1' of `a_bit2'
166 external
167 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
168 end
169
170 b_or (a_bit1, a_bit2: POINTER): like Current is
171 -- Disjunction of `a_bit1' with `a_bit2'
172 external
173 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
174 end
175
176 b_xor (a_bit1, a_bit2: POINTER): like Current is
177 -- Exclusive or of `a_bit1' with `a_bit2'
178 external
179 "C signature (EIF_REFERENCE, EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
180 end
181
182 b_not (a_bit: POINTER): like Current is
183 -- Negation of `a_bit'
184 external
185 "C signature (EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
186 end
187
188 b_put (a_bit: POINTER; val: BOOLEAN; index: INTEGER) is
189 -- Put `val' in `a_bit' at position `index'.
190 external
191 "C signature (EIF_REFERENCE, char, int) use %"eif_bits.h%""
192 end
193
194 c_out (b: POINTER): STRING is
195 -- Out representation of Current
196 external
197 "C signature (EIF_REFERENCE): EIF_REFERENCE use %"eif_bits.h%""
198 alias
199 "b_eout"
200 end
201
202 b_makebit_from (p: POINTER; n: INTEGER): BIT_REF is
203 -- From Eiffel object `p' generate a new BIT_REF instance of count `n'
204 external
205 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_bits.h%""
206 alias
207 "RTMB"
208 end
209
210 invariant
211 valid_count: count > 0
212
213 indexing
214
215 library: "[
216 EiffelBase: Library of reusable components for Eiffel.
217 ]"
218
219 status: "[
220 Copyright 1986-2001 Interactive Software Engineering (ISE).
221 For ISE customers the original versions are an ISE product
222 covered by the ISE Eiffel license and support agreements.
223 ]"
224
225 license: "[
226 EiffelBase may now be used by anyone as FREE SOFTWARE to
227 develop any product, public-domain or commercial, without
228 payment to ISE, under the terms of the ISE Free Eiffel Library
229 License (IFELL) at http://eiffel.com/products/base/license.html.
230 ]"
231
232 source: "[
233 Interactive Software Engineering Inc.
234 ISE Building
235 360 Storke Road, Goleta, CA 93117 USA
236 Telephone 805-685-1006, Fax 805-685-6869
237 Electronic mail <info@eiffel.com>
238 Customer support http://support.eiffel.com
239 ]"
240
241 info: "[
242 For latest info see award-winning pages: http://eiffel.com
243 ]"
244
245 end -- class BIT_REF
246
247

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23