Closed damien-vdb closed 1 month ago
We don't need to use UniquePtr if it's not in the API, no. It looks like you want to use the methods from ICar with a Car object, so we might need to use Info.virtualize() for that to work.
Thank you for the quick feedback.
I'm sorry that the example might lead to confusion because of the naming:
class Car { ICar create(); void destroy(ICar car) }
is the Javacpp generated class englobing ICar.
I don't want to override anything, I just want to instanciate an ICar
, through the create
that was provided (which internally only does a new CCar()
..).
while for classes containing virtual methods that we would like to override in Java, we can use Info.virtualize
Therefore I don't think I need to virtualize() anything.
Well, if create() actually returns a Car instance, Java doesn't know that. I'm pretty sure we'll need to map dynamic_cast<Car>()
somewhere to cast it into a Car so that we can use it from Java as a Car.
@HGuillemet I think you added something for that use case, right?
I finally found the solution for my first issue: instead of .skip()
some method declarations in my InfoMap
, I commented out the .h
declarations, which is apparently not a good way.
Hope it helps some beginners like myself.
For the second issue, I'll look a bit more to the existing java-presets for inspiration. I'm closing the issue.
Well, if create() actually returns a Car instance, Java doesn't know that. I'm pretty sure we'll need to map
dynamic_cast<Car>()
somewhere to cast it into a Car so that we can use it from Java as a Car.@HGuillemet I think you added something for that use case, right?
if create
returns a pointer, says p
to an object of type ICar
, Java will get an object of class ICar
, say c
, that will hold p
.
If we call c.methodA()
from Java, this will map to ((ICar *)p)->methodA()
, which should call the implementation from CCar
.
So that should work without adding anything.
Unless there are some multiple or virtual inheritance involved that @damien-vdb didn't talk about. Are there ?
I am trying to bind my Java application to a legacy C++ library with JavaCPP. I am using the gradle plugin with the Parser, and for the simpler definitions it worked almost out of the box :+1:
I have currently 2 issues:
Here is the exported interface I'm calling:
I managed to find the relevant source code, here is the subclass:
The implementation:
And the delegate where all the logic is done:
My corresponding configuration:
And the test run:
Issue 1: Even though I am using the same Car object, the boolean states seem to be reset between calls. I found out another C++ client successfully uses the Car like this:
Should I use
@UniquePtr
somewhere ?Issue 2: Even with the wiki I struggle with InfoMap declarations. Am I on the right track ?
Thank you