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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 3 months ago) by manus_eiffel
File size: 5859 byte(s)
Initial revision

1 indexing
2
3 description: "[
4 Special objects: homogeneous sequences of values,
5 used to represent arrays and strings
6 ]"
7
8 status: "See notice at end of class"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 frozen class
13 SPECIAL [T]
14
15 create
16 make
17
18 feature {NONE} -- Initialization
19
20 frozen make (n: INTEGER) is
21 -- Creates a special object for `n' entries.
22 require
23 non_negative_argument: n >= 0
24 external
25 "built_in"
26 ensure
27 area_allocated: count = n
28 end
29
30 feature -- Access
31
32 frozen item, frozen infix "@" (i: INTEGER): T is
33 -- Item at `i'-th position
34 -- (indices begin at 0)
35 require
36 index_big_enough: i >= 0
37 index_small_enough: i < count
38 external
39 "built_in"
40 end
41
42 frozen index_of (v: T; start_position: INTEGER): INTEGER is
43 -- Index of first occurrence of item identical to `v'.
44 -- -1 if none.
45 require
46 valid_start_position: start_position >= 0
47 local
48 nb: INTEGER
49 do
50 from
51 Result := start_position
52 nb := count
53 until
54 Result >= nb or else equal (item (Result), v)
55 loop
56 Result := Result + 1
57 end
58 if Result >= nb then
59 Result := -1
60 end
61 ensure
62 found_or_not_found: Result = -1 or else (Result >= 0 and then Result < count)
63 end
64
65 frozen item_address (i: INTEGER): POINTER is
66 -- Address of element at position `i'.
67 require
68 index_big_enough: i >= 0
69 index_small_enough: i < count
70 do
71 Result := $Current
72 Result := Result + i * element_size
73 ensure
74 element_address_not_null: Result /= default_pointer
75 end
76
77 frozen base_address: POINTER is
78 -- Address of element at position `0'.
79 do
80 Result := $Current
81 ensure
82 base_address_not_null: Result /= default_pointer
83 end
84
85 feature -- Measurement
86
87 lower: INTEGER is 0
88 -- Minimum index of Current
89
90 frozen upper: INTEGER is
91 -- Maximum index of Current
92 do
93 Result := capacity
94 end
95
96 frozen count: INTEGER is
97 -- Count of the special area
98 do
99 Result := capacity
100 end
101
102 frozen capacity: INTEGER is
103 -- Count of the special area
104 external
105 "built_in"
106 end
107
108 feature -- Status report
109
110 frozen all_default (upper_bound: INTEGER): BOOLEAN is
111 -- Are all items between index `0' and `upper_bound'
112 -- set to default values?
113 require
114 min_upper_bound: upper_bound >= -1
115 max_upper_bound: upper_bound < count
116 local
117 i: INTEGER
118 t: T
119 do
120 from
121 Result := True
122 until
123 i > upper_bound or else not Result
124 loop
125 Result := item (i) = t
126 i := i + 1
127 end
128 ensure
129 valid_on_empty_area: upper_bound = -1 implies Result
130 end
131
132 frozen same_items (other: like Current; upper_bound: INTEGER): BOOLEAN is
133 -- Do all items between index `0' and `upper_bound' have
134 -- same value?
135 require
136 min_upper_bound: upper_bound >= -1
137 max_upper_bound: upper_bound < count
138 other_not_void: other /= Void
139 other_has_enough_items: upper_bound < other.count
140 local
141 i: INTEGER
142 do
143 from
144 Result := True
145 until
146 i > upper_bound or else not Result
147 loop
148 Result := item (i) = other.item (i)
149 i := i + 1
150 end
151 ensure
152 valid_on_empty_area: upper_bound = -1 implies Result
153 end
154
155 frozen valid_index (i: INTEGER): BOOLEAN is
156 -- Is `i' within the bounds of Current?
157 do
158 Result := (0 <= i) and then (i < count)
159 end
160
161 feature -- Element change
162
163 frozen put (v: T; i: INTEGER) is
164 -- Replace `i'-th item by `v'.
165 -- (Indices begin at 0.)
166 require
167 index_big_enough: i >= 0
168 index_small_enough: i < count
169 external
170 "built_in"
171 end
172
173 frozen subcopy (source: like Current; s, e, i: INTEGER) is
174 -- Copy elements of `source' within bounds `s'
175 -- and `e' to `Current' starting at index `i'.
176 external
177 "built_in"
178 end
179
180 feature -- Resizing
181
182 frozen resized_area (n: INTEGER): like Current is
183 -- Create a copy of Current with a count of `n'.
184 require
185 valid_new_count: n > count
186 local
187 i, nb: INTEGER
188 do
189 create Result.make (n)
190 from
191 nb := count
192 invariant
193 i >= 0 and i <= nb
194 variant
195 nb - i
196 until
197 i = nb
198 loop
199 Result.put (item (i), i)
200 i := i + 1
201 end
202 ensure
203 Result_not_void: Result /= Void
204 Result_different_from_current: Result /= Current
205 new_count: Result.count = n
206 end
207
208 frozen aliased_resized_area (n: INTEGER): like Current is
209 -- Try to resize `Current' with a count of `n', if not
210 -- possible a new copy.
211 require
212 valid_new_count: n > count
213 do
214 Result := sparycpy (n, 0, count)
215 ensure
216 Result_not_void: Result /= Void
217 new_count: Result.count = n
218 end
219
220 feature -- Removal
221
222 frozen clear_all is
223 -- Reset all items to default values.
224 external
225 "built_in"
226 end
227
228 feature {NONE} -- Implementation
229
230 frozen sparycpy (newsize, s, n: INTEGER): SPECIAL [T] is
231 -- New area of size `newsize' containing `n' items from `Current'.
232 -- Old items are at position `s' in new area.
233 external
234 "built_in"
235 end
236
237 frozen element_size: INTEGER is
238 -- Size of elements.
239 external
240 "built_in"
241 end
242
243 indexing
244
245 library: "[
246 EiffelBase: Library of reusable components for Eiffel.
247 ]"
248
249 status: "[
250 Copyright 1986-2001 Interactive Software Engineering (ISE).
251 For ISE customers the original versions are an ISE product
252 covered by the ISE Eiffel license and support agreements.
253 ]"
254
255 license: "[
256 EiffelBase may now be used by anyone as FREE SOFTWARE to
257 develop any product, public-domain or commercial, without
258 payment to ISE, under the terms of the ISE Free Eiffel Library
259 License (IFELL) at http://eiffel.com/products/base/license.html.
260 ]"
261
262 source: "[
263 Interactive Software Engineering Inc.
264 ISE Building
265 360 Storke Road, Goleta, CA 93117 USA
266 Telephone 805-685-1006, Fax 805-685-6869
267 Electronic mail <info@eiffel.com>
268 Customer support http://support.eiffel.com
269 ]"
270
271 info: "[
272 For latest info see award-winning pages: http://eiffel.com
273 ]"
274
275 end -- class SPECIAL
276
277

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23