comp.lang.ada
 help / color / mirror / Atom feed
From: Lucretia <laguest9000@googlemail.com>
Subject: Re: Interface Ada string with C++ std::string
Date: Wed, 4 Jul 2018 04:52:34 -0700 (PDT)
Date: 2018-07-04T04:52:34-07:00	[thread overview]
Message-ID: <bcd99977-2edb-4a68-9ab9-c278854c6e52@googlegroups.com> (raw)
In-Reply-To: <4b11d923-8412-48bc-9406-d3aaaa81e6f2@googlegroups.com>

On Wednesday, 4 July 2018 12:45:30 UTC+1, Roger  wrote:
> On Wednesday, July 4, 2018 at 9:23:23 PM UTC+10, Lucretia wrote:
> 
> > All you probably need is a C function which returns the string c_str() to Ada which Ada can then use, wrap that in Ada. Just define a private type for the string class which is an address and pass that to the C function.
> > 
> > package CPP_Strings is
> >    type CPP_String is private;
> > 
> >    function Get (S : in CPP_String) return String; -- Wrap the C->Ada stuff inside here.
> > private
> >    type CPP_String is System.Address;
> > end CPP_Strings;
> 
> Thanks,
> I was playing around today modifying your test_binding code then managed to accidentally delete everything I'd done!
> I think I'll have another go at it as it is an educational experience.
> Once I've done that, I'll be in a better position to understand and implement what you've just suggested.
> Everything is pretty much in line with my thinking. My main problem is my minimal experience with C++ so your helping hand is very welcome.
> Once I found it impossible to directly interface std::string to Ada, I thought the way ahead would be to write a C interface to C++ and then wrap the C interface to Ada as you have suggested.
> My original post was due to not being sure how to do it. So your advice has been a tremendous help and makes me confident that I'll get there eventually.

The test_binding is the extreme way to do it.

The simpler, kind of, and preferred way would be to work out what you need from the string class. Pass around the C++ pointer inside Ada. Then have C functions which are imported to Ada which handle the messy C/C++ stuff, then wrap those in Ada handling the Messy Ada/C stuff there.

  reply	other threads:[~2018-07-04 11:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 12:59 Interface Ada string with C++ std::string Roger
2018-07-03 13:13 ` Dan'l Miller
2018-07-03 13:16   ` Roger
2018-07-03 16:34     ` Jacob Sparre Andersen
2018-07-03 16:52       ` Roger
2018-07-03 16:56 ` Lucretia
2018-07-04  3:33   ` Roger
2018-07-04  4:13     ` Roger
2018-07-04 11:23     ` Lucretia
2018-07-04 11:45       ` Roger
2018-07-04 11:52         ` Lucretia [this message]
2018-07-05  1:08           ` Roger
2018-07-05 23:32 ` Roger
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox