From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: ada binding
Date: Thu, 09 Feb 2006 18:17:54 +0100
Date: 2006-02-09T18:17:54+01:00 [thread overview]
Message-ID: <1142859.ZZbdis6YEU@linux1.krischik.com> (raw)
In-Reply-To: dsfonn$h74$1@node1.news.atman.pl
Szymon Guz wrote:
> Maciej Sobczak napisa?(a):
>> Szymon Guz wrote:
>>
>>> how to make an Ada binding for a "C++" class using this C layer ?
>>
>> Basically, if the C++ class is not a template, but just plain "classic"
>> OO stuff, then you can write a wrapper around it in C, which will still
>> be OO, but without the syntax sugar of real class. Something along this:
>>
>> // an existing C++ class:
>> class MyClass
>> {
>> public:
>> void myFun();
>> };
>>
>> // a C wrapper:
>> extern "C"
>> void * MyClass_new()
>> {
>> return new MyClass;
>> }
>>
>> extern "C"
>> void MyClass_delete(void *p)
>> {
>> delete static_cast<MyClass*>(p);
>> }
>>
>> extern "C"
>> void MyClass_myFun(void *vp)
>> {
>> MyClass *mcp = static_cast<MyClass*>(vp);
>> mcp->myFun();
>> }
>>
>> // and so on.
>>
>> Depending on the level of isolation that you want to achieve and the
>> level of type safety that you want to retain, hiding the object behind
>> void* might or might not be the best choice, but this is to give you the
>> idea. Above, MyClass_new, MyClass_delete and MyClass_myFun are plain C
>> functions (you can extract their declarations to separate header file)
>> and you can interface them from just about any sensible language in
>> existence and from Ada in particular.
>>
>>
>
> OK, but what about using the class fields :
>
> class MyClass
> {
> public:
> int X;
> int *p_X;
> }
>
> and what about inheriting this from the class in Ada, is it possible ?
If you are planning to inheriting then you need to directly bind to the C++
class. Only one compiler offers that (GNAT). Start reading here:
http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gnat_rm/Pragma-CPP_005fClass.html
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
next prev parent reply other threads:[~2006-02-09 17:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-09 12:56 ada binding Szymon Guz
2006-02-09 14:31 ` Maciej Sobczak
2006-02-09 15:56 ` Szymon Guz
2006-02-09 16:39 ` Georg Bauhaus
2006-02-09 17:17 ` Martin Krischik [this message]
2006-02-09 18:05 ` Szymon Guz
2006-02-09 19:34 ` Martin Krischik
2006-02-09 19:37 ` sg
2006-02-11 6:52 ` Martin Krischik
2006-02-11 12:45 ` Lucretia
2006-02-09 19:28 ` Martin Dowie
2006-02-10 16:06 ` Lucretia
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox