[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Liberty-eiffel] Array with integers. real and strings
From: |
Laurie Moye |
Subject: |
Re: [Liberty-eiffel] Array with integers. real and strings |
Date: |
Wed, 30 Mar 2016 16:20:33 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 |
Hi Germán,
On 27/03/16 20:23, Germán Arias wrote:
> Is posible have an array/native array with integers, real and strings? I
> try with ARRAY[ANY], but don't work. Or maybe a tuple with different
> types? The problem is that I don't know. beforehand, the order of the
> arguments. This is, something it can be: integer, string, integer, .....
> and others: string. string, real,... And I need pass it to a C
> function.
I don't know whether this would solve your problem, but I use a generic
wrapper class inheriting from a dummy parent class to wrap up mixed-type
variables in an array.
First, the dummy class
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class POLY_ARG
-- no content at all
end class POLY_ARG
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then a generic wrapper class that inherits POLY_ARG
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class POLY_THIS [G]
inherit
POLY_ARG
create {ANY}
make, make_empty
-------------------------------------------------------------------------------
feature {ANY}-- Public features
item : G
make (x : G) is
do
item := x
end
make_empty is
do
end
put(x : G) is
do
item := x
end
-------------------------------------------------------------------------------
end -- class POLY_THIS
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then you can put POLY_THIS[ INTEGER ], POLY_THIS[ STRING ], etc.
variables into an ARRAY[ POLY_ARG ]. In Eiffel, you can sort them out
with code like this (I'm reading arguments from a parameters file and
need to parse each one correctly), but as you want to pass the array to
C, it might be more difficult to sort them out. I think this is quite an
Eiffelish solution!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-------------------------------------------------------------------------------
feature {} -- Concealed features
vars : ARRAY[ POLY_ARG ]
... ... ...;
feature {ANY} -- Public features
... ... ...
var : POLY_ARG
this_b : POLY_THIS[BOOLEAN]
this_c : POLY_THIS[CHARACTER]
this_i : POLY_THIS[INTEGER]
this_r : POLY_THIS[REAL]
this_s : POLY_THIS[STRING]
... ... ...
var := vars @ i
if var /= Void then
-- convert string and put into variable
this_b ?= var
if this_b /= Void then
this_b.put(s2b(str))
else
this_c ?= var
if this_c /= Void then
this_c.put(s2c(str)
else
this_i ?= var
if this_i /= Void then
this_i.put(s2i(str))
... ... ... -- and so on
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Best wishes,
Laurie
- [Liberty-eiffel] Array with integers. real and strings, Germán Arias, 2016/03/27
- Re: [Liberty-eiffel] Array with integers. real and strings, Paolo Redaelli, 2016/03/27
- Re: [Liberty-eiffel] Array with integers. real and strings, Germán Arias, 2016/03/28
- Message not available
- Re: [Liberty-eiffel] Array with integers. real and strings, Germán Arias, 2016/03/28
- Re: [Liberty-eiffel] Array with integers. real and strings, Paolo Redaelli, 2016/03/29
- Re: [Liberty-eiffel] Array with integers. real and strings, Cyril ADRIAN, 2016/03/29
- Re: [Liberty-eiffel] Array with integers. real and strings, Paolo Redaelli, 2016/03/29
- Re: [Liberty-eiffel] Array with integers. real and strings, Cyril ADRIAN, 2016/03/29
Re: [Liberty-eiffel] Array with integers. real and strings,
Laurie Moye <=