PageRenderTime 5ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/foreign_interface/foreign_types.e

http://github.com/tybor/Liberty
Specman e | 269 lines | 202 code | 43 blank | 24 comment | 0 complexity | d5e52b730e1f87935231a75f18451081 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4expanded class FOREIGN_TYPES
  5
  6insert
  7   FFI_EXTERNALS
  8   ANY
  9        redefine
 10            copy,
 11            is_equal
 12        end
 13
 14feature {ANY}
 15   copy (other: like Current)
 16       do
 17       end
 18
 19   is_equal (other: like Current): BOOLEAN
 20      do
 21         Result := True
 22      end
 23
 24feature {ANY} -- Types
 25   nothing: FOREIGN_TYPE
 26      once
 27         Result.set_ffi_type(address_of_ffi_type_void, Void, "nothing")
 28      end
 29
 30   uint8: FOREIGN_TYPE
 31      once
 32         Result.set_ffi_type(address_of_ffi_type_uint8, agent new_uint8, "uint8")
 33      end
 34
 35   sint8: FOREIGN_TYPE
 36      once
 37         Result.set_ffi_type(address_of_ffi_type_sint8, agent new_sint8, "sint8")
 38      end
 39
 40   uint16: FOREIGN_TYPE
 41      once
 42         Result.set_ffi_type(address_of_ffi_type_uint16, agent new_uint16, "uint16")
 43      end
 44
 45   sint16: FOREIGN_TYPE
 46      once
 47         Result.set_ffi_type(address_of_ffi_type_sint16, agent new_sint16, "sint16")
 48      end
 49
 50   uint32: FOREIGN_TYPE
 51      once
 52         Result.set_ffi_type(address_of_ffi_type_uint32, agent new_uint32, "uint32")
 53      end
 54
 55   sint32: FOREIGN_TYPE
 56      once
 57         Result.set_ffi_type(address_of_ffi_type_sint32, agent new_sint32, "sint32")
 58      end
 59
 60   uint64: FOREIGN_TYPE
 61      once
 62         Result.set_ffi_type(address_of_ffi_type_uint64, agent new_uint64, "uint64")
 63      end
 64
 65   sint64: FOREIGN_TYPE
 66      once
 67         Result.set_ffi_type(address_of_ffi_type_sint64, agent new_sint64, "sint64")
 68      end
 69
 70   float: FOREIGN_TYPE
 71      once
 72         Result.set_ffi_type(address_of_ffi_type_float, agent new_float, "float")
 73      end
 74
 75   double: FOREIGN_TYPE
 76      once
 77         Result.set_ffi_type(address_of_ffi_type_double, agent new_double, "double")
 78      end
 79
 80   schar: FOREIGN_TYPE
 81      once
 82         Result.set_ffi_type(address_of_ffi_type_sint8, agent new_schar, "schar")
 83      end
 84
 85   c_string, pointer: FOREIGN_TYPE
 86      once
 87         Result.set_ffi_type(address_of_ffi_type_pointer, agent new_pointer, "pointer")
 88      end
 89
 90feature {ANY} -- Objects factory
 91   create_uint8 (data: NATURAL_8): FOREIGN_OBJECT
 92      do
 93         create {FOREIGN_TYPED_OBJECT[NATURAL_8]} Result.make(uint8, data)
 94      end
 95
 96   create_sint8 (data: INTEGER_8): FOREIGN_OBJECT
 97      do
 98         create {FOREIGN_TYPED_OBJECT[INTEGER_8]} Result.make(sint8, data)
 99      end
100
101   create_uint16 (data: NATURAL_16): FOREIGN_OBJECT
102      do
103         create {FOREIGN_TYPED_OBJECT[NATURAL_16]} Result.make(uint16, data)
104      end
105
106   create_sint16 (data: INTEGER_16): FOREIGN_OBJECT
107      do
108         create {FOREIGN_TYPED_OBJECT[INTEGER_16]} Result.make(sint16, data)
109      end
110
111   create_uint32 (data: NATURAL_32): FOREIGN_OBJECT
112      do
113         create {FOREIGN_TYPED_OBJECT[NATURAL_32]} Result.make(uint32, data)
114      end
115
116   create_sint32 (data: INTEGER_32): FOREIGN_OBJECT
117      do
118         create {FOREIGN_TYPED_OBJECT[INTEGER_32]} Result.make(sint32, data)
119      end
120
121   create_uint64 (data: NATURAL_64): FOREIGN_OBJECT
122      do
123         create {FOREIGN_TYPED_OBJECT[NATURAL_64]} Result.make(uint64, data)
124      end
125
126   create_sint64 (data: INTEGER_64): FOREIGN_OBJECT
127      do
128         create {FOREIGN_TYPED_OBJECT[INTEGER_64]} Result.make(sint64, data)
129      end
130
131   create_float (data: REAL_32): FOREIGN_OBJECT
132      do
133         create {FOREIGN_TYPED_OBJECT[REAL_32]} Result.make(float, data)
134      end
135
136   create_double (data: REAL_64): FOREIGN_OBJECT
137      do
138         create {FOREIGN_TYPED_OBJECT[REAL_64]} Result.make(double, data)
139      end
140
141   create_schar (data: CHARACTER): FOREIGN_OBJECT
142      do
143         create {FOREIGN_TYPED_OBJECT[CHARACTER]} Result.make(schar, data)
144      end
145
146   create_string (a_string: ABSTRACT_STRING): FOREIGN_OBJECT
147         -- A newly allocated FOREIGN_OBJECT referring to the interned buffer of `a_string'
148      do
149         create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, a_string.intern.to_external)
150      end
151
152   create_pointer (data: POINTER): FOREIGN_OBJECT
153      do
154         create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
155      end
156
157feature {} -- Objects conversion back from the external call
158   new_uint8: FOREIGN_OBJECT
159      local
160         data: NATURAL_8
161      do
162         create {FOREIGN_TYPED_OBJECT[NATURAL_8]} Result.make(uint8, data)
163      end
164
165   new_sint8: FOREIGN_OBJECT
166      local
167         data: INTEGER_8
168      do
169         create {FOREIGN_TYPED_OBJECT[INTEGER_8]} Result.make(sint8, data)
170      end
171
172   new_uint16: FOREIGN_OBJECT
173      local
174         data: NATURAL_16
175      do
176         create {FOREIGN_TYPED_OBJECT[NATURAL_16]} Result.make(uint16, data)
177      end
178
179   new_sint16: FOREIGN_OBJECT
180      local
181         data: INTEGER_16
182      do
183         create {FOREIGN_TYPED_OBJECT[INTEGER_16]} Result.make(sint16, data)
184      end
185
186   new_uint32: FOREIGN_OBJECT
187      local
188         data: NATURAL_32
189      do
190         create {FOREIGN_TYPED_OBJECT[NATURAL_32]} Result.make(uint32, data)
191      end
192
193   new_sint32: FOREIGN_OBJECT
194      local
195         data: INTEGER_32
196      do
197         create {FOREIGN_TYPED_OBJECT[INTEGER_32]} Result.make(sint32, data)
198      end
199
200   new_uint64: FOREIGN_OBJECT
201      local
202         data: NATURAL_64
203      do
204         create {FOREIGN_TYPED_OBJECT[NATURAL_64]} Result.make(uint64, data)
205      end
206
207   new_sint64: FOREIGN_OBJECT
208      local
209         data: INTEGER_64
210      do
211         create {FOREIGN_TYPED_OBJECT[INTEGER_64]} Result.make(sint64, data)
212      end
213
214   new_float: FOREIGN_OBJECT
215      local
216         data: REAL_32
217      do
218         create {FOREIGN_TYPED_OBJECT[REAL_32]} Result.make(float, data)
219      end
220
221   new_double: FOREIGN_OBJECT
222      local
223         data: REAL_64
224      do
225         create {FOREIGN_TYPED_OBJECT[REAL_64]} Result.make(double, data)
226      end
227
228   new_schar: FOREIGN_OBJECT
229      local
230         data: CHARACTER
231      do
232         create {FOREIGN_TYPED_OBJECT[CHARACTER]} Result.make(schar, data)
233      end
234
235   new_pointer: FOREIGN_OBJECT
236      local
237         data: POINTER
238      do
239         create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
240      end
241
242   new_c_string: FOREIGN_OBJECT
243      local
244         data: POINTER
245      do
246         create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
247      end
248
249end -- class FOREIGN_TYPES
250--
251-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
252--
253-- Permission is hereby granted, free of charge, to any person obtaining a copy
254-- of this software and associated documentation files (the "Software"), to deal
255-- in the Software without restriction, including without limitation the rights
256-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
257-- copies of the Software, and to permit persons to whom the Software is
258-- furnished to do so, subject to the following conditions:
259--
260-- The above copyright notice and this permission notice shall be included in
261-- all copies or substantial portions of the Software.
262--
263-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
264-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
265-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
266-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
267-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
268-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
269-- THE SOFTWARE.