/[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 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 5485 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2 description: "[
3 References to objects containing reference to object
4 meant to be exchanged with non-Eiffel software.
5 ]"
6 library: "Free implementation of ELKS library"
7 copyright: "Copyright (c) 1986-2006, Eiffel Software and others"
8 license: "Eiffel Forum License v2 (see forum.txt)"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 class POINTER_REF
13 inherit
14 HASHABLE
15 redefine
16 out, is_equal, is_hashable
17 end
18
19 REFACTORING_HELPER
20 redefine
21 out, is_equal
22 end
23
24 feature -- Access
25
26 item: POINTER is
27 -- Pointer value
28 external
29 "built_in"
30 end
31
32 hash_code: INTEGER is
33 -- Hash code value
34 do
35 Result := item.hash_code
36 end
37
38 feature -- Element change
39
40 frozen set_item (p: POINTER) is
41 -- Make `p' the `item' value.
42 external
43 "built_in"
44 end
45
46 feature -- Comparison
47
48 is_equal (other: like Current): BOOLEAN is
49 -- Is `other' attached to an object of the same type
50 -- as current object and identical to it?
51 do
52 Result := other.item = item
53 end
54
55 feature -- Status report
56
57 is_hashable: BOOLEAN is
58 -- May current object be hashed?
59 -- (True if it is not its type's default.)
60 do
61 Result := item /= default_pointer
62 end
63
64 feature -- Operations
65
66 infix "+" (offset: INTEGER): POINTER is
67 -- Pointer moved by an offset of `offset' bytes.
68 do
69 Result := item + offset
70 end
71
72 feature {NONE} -- Initialization
73
74 make_from_reference (v: POINTER_REF) is
75 -- Initialize `Current' with `v.item'.
76 require
77 v_not_void: v /= Void
78 do
79 set_item (v.item)
80 ensure
81 item_set: item = v.item
82 end
83
84 feature -- Conversion
85
86 to_reference: POINTER_REF is
87 -- Associated reference of Current
88 do
89 create Result
90 Result.set_item (item)
91 ensure
92 to_reference_not_void: Result /= Void
93 end
94
95 to_integer_32: INTEGER is
96 -- Convert `item' into an INTEGER_32 value.
97 require
98 -- not_too_small: item >= feature {INTEGER}.Min_value
99 -- not_too_big: item <= feature {INTEGER}.Max_value
100 do
101 fixme (once "Do not forget to add proper precondition to ensure we can convert pointer %
102 %value into an INTEGER")
103 fixme (once "Change return type to INTEGER_32")
104 Result := item.to_integer_32
105 end
106
107 feature -- Memory copy
108
109 memory_copy (a_source: POINTER; a_size: INTEGER) is
110 -- Copy `a_size' bytes from `a_source' to `Current'.
111 -- `a_source' and `Current' should not overlap.
112 require
113 valid_size: a_size >= 0
114 valid_source: a_source /= default_pointer
115 do
116 c_memcpy (item, a_source, a_size)
117 end
118
119 memory_move (a_source: POINTER; a_size: INTEGER) is
120 -- Copy `a_size' bytes from `a_source' to `Current'.
121 -- `a_source' and `Current' can overlap.
122 require
123 valid_size: a_size >= 0
124 valid_source: a_source /= default_pointer
125 do
126 c_memmove (item, a_source, a_size)
127 end
128
129 memory_set (val, n: INTEGER) is
130 -- Fill first `n' bytes of the memory pointed by `Current'
131 -- with constant `val'.
132 require
133 valid_val: val >= 0
134 valid_n: n >= 0
135 do
136 c_memset (item, val, n)
137 end
138
139 feature -- Allocation/free
140
141 memory_alloc (a_size: INTEGER): POINTER is
142 -- Allocated `size' bytes using `malloc'.
143 require
144 valid_size: a_size > 0
145 do
146 Result := c_malloc (a_size)
147 end
148
149 memory_calloc (a_count, a_element_size: INTEGER): POINTER is
150 -- Allocate `a_count' elements of size `a_element_size' bytes using `calloc.
151 require
152 valid_element_count: a_count > 0
153 valid_element_size: a_element_size > 0
154 do
155 Result := c_calloc (a_count, a_element_size)
156 end
157
158 memory_realloc (a_size: INTEGER): POINTER is
159 -- Realloc `Current'.
160 require
161 valid_size: a_size >= 0
162 do
163 Result := c_realloc (item, a_size)
164 end
165
166 memory_free is
167 -- Free allocated memory with `malloc'.
168 do
169 c_free (item)
170 set_item (default_pointer)
171 end
172
173 feature -- Comparison
174
175 memory_compare (other: POINTER; a_size: INTEGER): BOOLEAN is
176 -- True if `Current' and `other' are identical on `a_size' bytes.
177 require
178 valid_size: a_size > 0
179 valid_other: other /= default_pointer
180 do
181 Result := c_memcmp (item, other, a_size) = 0
182 end
183
184 feature -- Output
185
186 out: STRING is
187 -- Printable representation of pointer value
188 do
189 Result := item.out
190 end
191
192 feature {NONE} -- Implementation
193
194 c_memcpy (destination, source: POINTER; count: INTEGER) is
195 -- C memcpy
196 external
197 "C signature (void *, const void *, size_t) use <string.h>"
198 alias
199 "memcpy"
200 end
201
202 c_memmove (destination, source: POINTER; count: INTEGER) is
203 -- C memmove
204 external
205 "C signature (void *, const void *, size_t) use <string.h>"
206 alias
207 "memmove"
208 end
209
210 c_memset (source: POINTER; val: INTEGER; count: INTEGER) is
211 -- C memset
212 external
213 "C signature (void *, int, size_t) use <string.h>"
214 alias
215 "memset"
216 end
217
218 c_memcmp (source, other: POINTER; count: INTEGER): INTEGER is
219 -- C memcmp
220 external
221 "C signature (void *, void *, size_t): EIF_INTEGER use <string.h>"
222 alias
223 "memcmp"
224 end
225
226 c_malloc (size: INTEGER): POINTER is
227 -- C malloc
228 external
229 "C signature (size_t): EIF_POINTER use <stdlib.h>"
230 alias
231 "malloc"
232 end
233
234 c_calloc (nmemb, size: INTEGER): POINTER is
235 -- C calloc
236 external
237 "C signature (size_t, size_t): EIF_POINTER use <stdlib.h>"
238 alias
239 "calloc"
240 end
241
242 c_realloc (source: POINTER; size: INTEGER): POINTER is
243 -- C realloc
244 external
245 "C signature (void *, size_t): EIF_POINTER use <stdlib.h>"
246 alias
247 "realloc"
248 end
249
250 c_free (p: POINTER) is
251 -- C free
252 external
253 "C signature (void *) use <stdlib.h>"
254 alias
255 "free"
256 end
257
258 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23