* ada binding
@ 2006-02-09 12:56 Szymon Guz
2006-02-09 14:31 ` Maciej Sobczak
2006-02-10 16:06 ` Lucretia
0 siblings, 2 replies; 12+ messages in thread
From: Szymon Guz @ 2006-02-09 12:56 UTC (permalink / raw)
Hi,
I've got a very simple question, lets assume that I've got a library
written in "C++" (e.g. wxWindows) and I want to make an Ada binding. I
saw that there is a project wxAda, but noone developes that. On the
wxAda page there is information that between wxWindows and Ada there is
another layer - it is a C library and I don't understand just one thing:
how to make an Ada binding for a "C++" class using this C layer ?
regars
Szymon Guz
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
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-10 16:06 ` Lucretia
1 sibling, 1 reply; 12+ messages in thread
From: Maciej Sobczak @ 2006-02-09 14:31 UTC (permalink / raw)
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.
--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
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
0 siblings, 2 replies; 12+ messages in thread
From: Szymon Guz @ 2006-02-09 15:56 UTC (permalink / raw)
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 ?
regards
Szymon Guz
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 15:56 ` Szymon Guz
@ 2006-02-09 16:39 ` Georg Bauhaus
2006-02-09 17:17 ` Martin Krischik
1 sibling, 0 replies; 12+ messages in thread
From: Georg Bauhaus @ 2006-02-09 16:39 UTC (permalink / raw)
On Thu, 2006-02-09 at 16:56 +0100, Szymon Guz wrote:
>
> 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 ?
>
This tends to be compiler specific AFAICT.
At least Aonix and AdaCore explain what you can do
to make a C++ OO type available to an Ada program.
If you have some "generalized" OO architecture
like with CORBA or .NET or Mono, binding to an OO module
should be easier.
-- Georg
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 15:56 ` Szymon Guz
2006-02-09 16:39 ` Georg Bauhaus
@ 2006-02-09 17:17 ` Martin Krischik
2006-02-09 18:05 ` Szymon Guz
2006-02-09 19:28 ` Martin Dowie
1 sibling, 2 replies; 12+ messages in thread
From: Martin Krischik @ 2006-02-09 17:17 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 17:17 ` Martin Krischik
@ 2006-02-09 18:05 ` Szymon Guz
2006-02-09 19:34 ` Martin Krischik
2006-02-09 19:28 ` Martin Dowie
1 sibling, 1 reply; 12+ messages in thread
From: Szymon Guz @ 2006-02-09 18:05 UTC (permalink / raw)
Martin Krischik napisał(a):
> 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
I know but I wander if I can do that using other compilers and with the
middle layer written in C.
regards
Szymon Guz
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 17:17 ` Martin Krischik
2006-02-09 18:05 ` Szymon Guz
@ 2006-02-09 19:28 ` Martin Dowie
1 sibling, 0 replies; 12+ messages in thread
From: Martin Dowie @ 2006-02-09 19:28 UTC (permalink / raw)
Martin Krischik wrote:
> 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
Don't think this is true...
ObjectAda 8.2 comes with a manual "Ada Binding Technology C++ Mapping
Guide Version 3.1"
I suspect that pretty much every Ada compiler comes with some mechanism
to do this - shame it isn't standardized.
Cheers
-- Martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 18:05 ` Szymon Guz
@ 2006-02-09 19:34 ` Martin Krischik
2006-02-09 19:37 ` sg
0 siblings, 1 reply; 12+ messages in thread
From: Martin Krischik @ 2006-02-09 19:34 UTC (permalink / raw)
Szymon Guz wrote:
> Martin Krischik napisa?(a):
>> 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
>
> I know but I wander if I can do that using other compilers and with the
> middle layer written in C.
You would need to use proxy classes then. Just as much work :-(
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 19:34 ` Martin Krischik
@ 2006-02-09 19:37 ` sg
2006-02-11 6:52 ` Martin Krischik
0 siblings, 1 reply; 12+ messages in thread
From: sg @ 2006-02-09 19:37 UTC (permalink / raw)
Martin Krischik napisał(a):
> Szymon Guz wrote:
>
>> Martin Krischik napisa?(a):
>>> 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
>> I know but I wander if I can do that using other compilers and with the
>> middle layer written in C.
>
> You would need to use proxy classes then. Just as much work :-(
>
> Martin
>
Well... if this is the only way, so I think that there a very little
chance for having the wxWindows Ada binding
Szymon Guz
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 12:56 ada binding Szymon Guz
2006-02-09 14:31 ` Maciej Sobczak
@ 2006-02-10 16:06 ` Lucretia
1 sibling, 0 replies; 12+ messages in thread
From: Lucretia @ 2006-02-10 16:06 UTC (permalink / raw)
Szymon Guz wrote:
> Hi,
> I've got a very simple question, lets assume that I've got a library
> written in "C++" (e.g. wxWindows) and I want to make an Ada binding. I
> saw that there is a project wxAda, but noone developes that. On the
Actually, I do. It's not got very far yet, as it's extremely confusing
and time consuming and I just haven't had the time to do it.
> wxAda page there is information that between wxWindows and Ada there is
> another layer - it is a C library and I don't understand just one thing:
> how to make an Ada binding for a "C++" class using this C layer ?
As the other poster has pointed out, the C layer is what the Ada code
interfaces with. Inside the Ada layer it is then possible to inherit
from the C++ classes.
The idea of wxAda is provide wxWidgets for any Ada compiler, not just
those that *can* import C++ libraries - but saying that, when you
interface with C++ libraries you end up with a C++ like library in Ada
- not very Ada like.
Luke.
P.S: the source isn't anywhere near ready yet.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-09 19:37 ` sg
@ 2006-02-11 6:52 ` Martin Krischik
2006-02-11 12:45 ` Lucretia
0 siblings, 1 reply; 12+ messages in thread
From: Martin Krischik @ 2006-02-11 6:52 UTC (permalink / raw)
sg wrote:
> Well... if this is the only way, so I think that there a very little
> chance for having the wxWindows Ada binding
Or any other binding. I don't think an Ada binding to wxWindows is more
work then a Fortran 2003 binding would be (once Fortan 2003 becomes
available).
And it's the same for any large C++ library. There are several large
projects for KDE which want to make KDE available to other languages. Most
of those use then C/Proxy class approach as well.
The problem is that the C++ compilation model does not lend itself to
automated generation of binding files. All the #if, #defined and #include
are in the way. At least the usual implementation of #include - the ISO
standard allows implementations not using a plain text file.
Martin
--
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ada binding
2006-02-11 6:52 ` Martin Krischik
@ 2006-02-11 12:45 ` Lucretia
0 siblings, 0 replies; 12+ messages in thread
From: Lucretia @ 2006-02-11 12:45 UTC (permalink / raw)
Martin Krischik wrote:
> sg wrote:
>
> > Well... if this is the only way, so I think that there a very little
> > chance for having the wxWindows Ada binding
>
> Or any other binding. I don't think an Ada binding to wxWindows is more
> work then a Fortran 2003 binding would be (once Fortan 2003 becomes
> available).
Have no clue about this ;-D
> And it's the same for any large C++ library. There are several large
> projects for KDE which want to make KDE available to other languages. Most
> of those use then C/Proxy class approach as well.
It's the easiest, most portable method.
> The problem is that the C++ compilation model does not lend itself to
> automated generation of binding files. All the #if, #defined and #include
> are in the way. At least the usual implementation of #include - the ISO
> standard allows implementations not using a plain text file.
Yup, in wxAda, I've decided to add dummy primitives where functions
differ for different platforms. For example, there is a function in
wxFrame (can't remember which one off the top of my head) which is only
available under Win32, so in wxAda I just have a null sub program for
other platforms, calling it isn't really going to matter and will only
effect Win32.
Luke.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2006-02-11 12:45 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox