RE: C++ questions

3 views
Skip to first unread message

Emmanuel Stapf [ES]

unread,
Sep 8, 2015, 4:32:45 AM9/8/15
to eiffel_...@yahoogroups.com

I'm not a C++ expert but looks like the tStatus C++ class needs its own wrapper in
Eiffel and when the signature of a C++ expects the tStatus & it means passing the
pointer to the memory area allocated for an instance of the tStatus class.

So in Eiffel, you will need to have a class which has `item: POINTER' available.
This is `item' that you will pass to your C++ code `cpp_create' or `c_get_nxt'.
For `cpp_create', I believe you could simplify it to be just:

cpp_create (bt: BOOLEAN; a_timeout: INTEGER; a_status: POINTER): POINTER
-- Call the C external to create an iNXTIterator
-- "The NXT iterator can be used to find all NXTs that are
connected (USB)
-- or in range (Bluetooth). The NXT iterator is not created if the
specified
-- status is fatal. The returned NXT iterator object should be
destroyed using
-- the iNXT::destroyNXTIterator method."
external
"C++ inline use %"iNXT.h%""
alias
"[
nFANTOM100::iNXTIterator* it;
it = nFANTOM100::iNXT::createNXTIterator (
(ViBoolean) $bt,
(ViUInt32) $a_timeout,
(nFANTOM100::tStatus &) $a_status);
if (((nFANTOM100::tStatus &) $a_status).isNotFatal()) {
return (EIF_POINTER) it;
} else {
return (EIF_POINTER) 0;
}
]"
end

The code you had for `c_get_nxt' seem just fine.

Regards,
Manu



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/eiffel_software/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/eiffel_software/join
(Yahoo! ID required)

<*> To change settings via email:
eiffel_soft...@yahoogroups.com
eiffel_softwar...@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
eiffel_softwa...@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/

Jimmy Johnson

unread,
Sep 8, 2015, 4:46:50 AM9/8/15
to eiffel_...@yahoogroups.com

I am trying to wrap c++ function (LEGO Mindstorms fantom) calls but they all return a value in a "status" object which is then checked to see if the call succeeded. I'm not sure how to approach this, so I include two of my features for illustration.

The C++ calls use a parameter "a_status". I don't know if the call creates the object or if the object passed in is changed. My question is: how do I get this object out? Isn't "a_status" not writable? Can I even do an assignment in the c code to an Eiffel parameter? It compiles and runs, but I really don't know if the result I am getting is correct.

Second question: Is this the correct way to do these c++ calls? Which one is better?

thanks.


cpp_create (bt: BOOLEAN; a_timeout: INTEGER; a_status: POINTER): POINTER
-- Call the C external to create an iNXTIterator
-- "The NXT iterator can be used to find all NXTs that are connected (USB)
-- or in range (Bluetooth). The NXT iterator is not created if the specified
-- status is fatal. The returned NXT iterator object should be destroyed using
-- the iNXT::destroyNXTIterator method."
external
"C++ inline use %"iNXT.h%""
alias
"[
nFANTOM100::iNXTIterator* it;
nFANTOM100::tStatus & s = (nFANTOM100::tStatus &) $a_status;
it = nFANTOM100::iNXT::createNXTIterator (
(ViBoolean) $bt,
(ViUInt32) $a_timeout,
s);
$a_status = (EIF_POINTER) &s;
if (s.isNotFatal()) {
return (EIF_POINTER) it;
} else {
return (EIF_POINTER) 0;
}
]"
end

c_get_nxt (obj: POINTER; a_status: POINTER): POINTER
-- Call the cpp method to "create an NXT object for
-- the NXT referenced by this iterator."
-- virtual iNXT * getNXT (tStatus &status)=0
external
"C++ inline use %"iNXTIterator.h%""
alias
"[
return (EIF_POINTER) ((nFANTOM100::iNXTIterator *) ($obj))->getNXT (
(nFANTOM100::tStatus &) $a_status);
]"
end

Liberty Lover

unread,
4:32 PM (4 hours ago) 4:32 PM
to Eiffel Users

Liberty Lover

unread,
4:38 PM (4 hours ago) 4:38 PM
to eiffel...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/eiffel-users/abe94b40-4e53-4752-b036-643b655b3177n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages