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

Contents of /FreeELKS/trunk/library/kernel/pointer_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: 5916 byte(s)
Initial revision

1 indexing
2
3 description: "[
4 References to objects containing reference to object
5 meant to be exchanged with non-Eiffel software.
6 ]"
7
8 status: "See notice at end of class"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 class POINTER_REF inherit
13
14 HASHABLE
15 redefine
16 out, is_hashable
17 end
18
19 feature -- Access
20
21 item: POINTER
22 -- Pointer value
23
24 hash_code: INTEGER is
25 -- Hash code value
26 do
27 Result := c_hashcode (item).hash_code
28 end
29
30 feature -- Element change
31
32 frozen set_item (p: POINTER) is
33 -- Make `p' the `item' value.
34 do
35 item := p
36 end
37
38 feature -- Status report
39
40 is_hashable: BOOLEAN is
41 -- May current object be hashed?
42 -- (True if it is not its type's default.)
43 do
44 Result := item /= default_pointer
45 end
46
47 feature -- Operations
48
49 infix "+" (offset: INTEGER): POINTER is
50 -- Pointer moved by an offset of `offset' bytes.
51 do
52 Result := c_offset_pointer (item, offset)
53 end
54
55 feature {NONE} -- Initialization
56
57 make_from_reference (v: POINTER_REF) is
58 -- Initialize `Current' with `v.item'.
59 require
60 v_not_void: v /= Void
61 do
62 item := v.item
63 ensure
64 item_set: item = v.item
65 end
66
67 feature -- Conversion
68
69 to_reference: POINTER_REF is
70 -- Associated reference of Current
71 do
72 create Result
73 Result.set_item (item)
74 ensure
75 to_reference_not_void: Result /= Void
76 end
77
78 feature -- Memory copy
79
80 memory_copy (a_source: POINTER; a_size: INTEGER) is
81 -- Copy `a_size' bytes from `a_source' to `Current'.
82 -- `a_source' and `Current' should not overlap.
83 require
84 valid_size: a_size >= 0
85 valid_source: a_source /= default_pointer
86 do
87 c_memcpy (item, a_source, a_size)
88 end
89
90 memory_move (a_source: POINTER; a_size: INTEGER) is
91 -- Copy `a_size' bytes from `a_source' to `Current'.
92 -- `a_source' and `Current' can overlap.
93 require
94 valid_size: a_size >= 0
95 valid_source: a_source /= default_pointer
96 do
97 c_memmove (item, a_source, a_size)
98 end
99
100 memory_set (val, n: INTEGER) is
101 -- Fill first `n' bytes of the memory pointed by `Current'
102 -- with constant `val'.
103 require
104 valid_val: val >= 0
105 valid_n: n >= 0
106 do
107 c_memset (item, val, n)
108 end
109
110 feature -- Allocation/free
111
112 memory_alloc (a_size: INTEGER): POINTER is
113 -- Allocated `size' bytes using `malloc'.
114 require
115 valid_size: a_size > 0
116 do
117 Result := c_malloc (a_size)
118 end
119
120 memory_calloc (a_count, a_element_size: INTEGER): POINTER is
121 -- Allocate `a_count' elements of size `a_element_size' bytes using `calloc.
122 require
123 valid_element_count: a_count > 0
124 valid_element_size: a_element_size > 0
125 do
126 Result := c_calloc (a_count, a_element_size)
127 end
128
129 memory_realloc (a_size: INTEGER): POINTER is
130 -- Realloc `Current'.
131 require
132 valid_size: a_size >= 0
133 do
134 Result := c_realloc (item, a_size)
135 end
136
137 memory_free is
138 -- Free allocated memory with `malloc'.
139 do
140 c_free (item)
141 item := default_pointer
142 end
143
144 feature -- Comparison
145
146 memory_compare (other: POINTER; a_size: INTEGER): BOOLEAN is
147 -- True if `Current' and `other' are identical on `a_size' bytes.
148 require
149 valid_size: a_size > 0
150 valid_other: other /= default_pointer
151 do
152 Result := c_memcmp (item, other, a_size) = 0
153 end
154
155 feature -- Output
156
157 out: STRING is
158 -- Printable representation of pointer value
159 do
160 Result := c_outp (item)
161 end
162
163 feature {NONE} -- Implementation
164
165 c_outp (p: POINTER): STRING is
166 -- Printable representation of pointer value
167 external
168 "C | %"eif_out.h%""
169 end
170
171 c_hashcode (p: POINTER): INTEGER is
172 -- Hash code value of `p'
173 external
174 "C [macro %"eif_misc.h%"]"
175 alias
176 "conv_pi"
177 end
178
179 c_offset_pointer (p: POINTER; o: INTEGER): POINTER is
180 -- Pointer moved by an offset of `o' bytes from `p'.
181 external
182 "C [macro %"eif_macros.h%"]"
183 alias
184 "RTPOF"
185 end
186
187 c_memcpy (destination, source: POINTER; count: INTEGER) is
188 -- C memcpy
189 external
190 "C (void *, const void *, size_t) | <string.h>"
191 alias
192 "memcpy"
193 end
194
195 c_memmove (destination, source: POINTER; count: INTEGER) is
196 -- C memmove
197 external
198 "C (void *, const void *, size_t) | <string.h>"
199 alias
200 "memmove"
201 end
202
203 c_memset (source: POINTER; val: INTEGER; count: INTEGER) is
204 -- C memset
205 external
206 "C (void *, int, size_t) | <string.h>"
207 alias
208 "memset"
209 end
210
211 c_memcmp (source, other: POINTER; count: INTEGER): INTEGER is
212 -- C memcmp
213 external
214 "C (void *, void *, size_t): EIF_INTEGER | <string.h>"
215 alias
216 "memcmp"
217 end
218
219 c_malloc (size: INTEGER): POINTER is
220 -- C malloc
221 external
222 "C (size_t): EIF_POINTER | <stdlib.h>"
223 alias
224 "malloc"
225 end
226
227 c_calloc (nmemb, size: INTEGER): POINTER is
228 -- C calloc
229 external
230 "C (size_t, size_t): EIF_POINTER | <stdlib.h>"
231 alias
232 "calloc"
233 end
234
235 c_realloc (source: POINTER; size: INTEGER): POINTER is
236 -- C realloc
237 external
238 "C (void *, size_t): EIF_POINTER | <stdlib.h>"
239 alias
240 "realloc"
241 end
242
243 c_free (p: POINTER) is
244 -- C free
245 external
246 "C (void *) | <stdlib.h>"
247 alias
248 "free"
249 end
250
251 indexing
252
253 library: "[
254 EiffelBase: Library of reusable components for Eiffel.
255 ]"
256
257 status: "[
258 Copyright 1986-2001 Interactive Software Engineering (ISE).
259 For ISE customers the original versions are an ISE product
260 covered by the ISE Eiffel license and support agreements.
261 ]"
262
263 license: "[
264 EiffelBase may now be used by anyone as FREE SOFTWARE to
265 develop any product, public-domain or commercial, without
266 payment to ISE, under the terms of the ISE Free Eiffel Library
267 License (IFELL) at http://eiffel.com/products/base/license.html.
268 ]"
269
270 source: "[
271 Interactive Software Engineering Inc.
272 ISE Building
273 360 Storke Road, Goleta, CA 93117 USA
274 Telephone 805-685-1006, Fax 805-685-6869
275 Electronic mail <info@eiffel.com>
276 Customer support http://support.eiffel.com
277 ]"
278
279 info: "[
280 For latest info see award-winning pages: http://eiffel.com
281 ]"
282
283 end -- class POINTER_REF
284
285
286

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23