From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: ada binding
Date: Thu, 09 Feb 2006 15:31:56 +0100
Date: 2006-02-09T15:31:56+01:00 [thread overview]
Message-ID: <dsfjor$pg1$1@sunnews.cern.ch> (raw)
In-Reply-To: <dsfe5n$97s$1@node3.news.atman.pl>
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/
next prev parent reply other threads:[~2006-02-09 14:31 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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox