Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Using nested Containers with std::future?

20 views
Skip to first unread message

Katherine Yang US

unread,
Sep 14, 2022, 10:03:37 PM9/14/22
to javacpp
Hello, 

I'm trying to use a piece of code that looks like this:

struct  Request  {...}
struct Response {...}
std::future<std::unique_ptr< Response>> AsyncInfer(
      const Request& request)

And I have two nested containers. 
I've tried to write an adapter for std::future:


public class testWrapper implements InfoMapper {
    static { Loader.checkVersion("org.bytedeco", "testWrapper"); }
    @Override
    public void map(InfoMap infoMap) {
        infoMap.putFirst(new Info().enumerate(false))
               .put(new Info("std::future").skip().annotations("@StdFuture"))
               .put(new Info("std::unique_ptr<testWrapper::Response>").pointerTypes("@UniquePtr Response"))
        ;
    }
    @Documented @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD, ElementType.PARAMETER})
    @Adapter("FutureAdapter")
    public @interface StdFuture {
        String value() default "";
    }
}

However the generator is giving me this error
 In function '_jobject* Java_org_bytedeco testWrapper _ ...  _AsyncInfer(JNIEnv*, jobject, jobject)':
/workspace/javacpp/javacpp-presets/ testWrapper   /target/native/org/bytedeco/ testWrapper/linux-x86_64/jnitestWrapper.cpp:15590:159: error: no matching function for call to 'UniquePtrAdapter<Result>::UniquePtrAdapter(std::future<std::unique_ptr<Result> >)'
15590 |         UniquePtrAdapter< Result > radapter(ptr->AsyncInfer(*(const Request*)ptr0));
      |


Am I missing something with creating the adapter to @StdFuture? Is there an example I can follow?

Best,
Katherine

Samuel Audet

unread,
Sep 15, 2022, 7:33:43 AM9/15/22
to javacpp...@googlegroups.com
Hello,

Unfortunately, we can't combine multiple adapters, that's not going to
work. What we need to do is create an instance of
std::future<std::unique_ptr< Response>> named, for example,
ResponseFuture, and define its interface in Java like this:
https://github.com/bytedeco/javacpp/wiki/Interface-Thrust-and-CUDA

Ideally we would want the Parser to generate one for us as as per
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#defining-wrappers-for-basic-c-containers


But that's not currently supported for a container like std::future. If
you have a lot of those though, it would be worth the time to add
support for it though. Please open a feature request on GitHub:
https://github.com/bytedeco/javacpp/issues

Samuel


On 9/15/22 10:07, 'Katherine Yang US' via javacpp wrote:
> Hello,
>
> I'm trying to use a piece of code that looks like this:
>
> struct Request  {...}
> struct Response {...}
> std::future<std::unique_ptr< Response>> AsyncInfer(
>       const Request& request)
>
> And I have two nested containers.
> I've tried to write an adapter for std::future:
>
>
> public class testWrapper implements InfoMapper {
>     static { Loader.checkVersion("org.bytedeco", "testWrapper"); }
>     @Override
>     public void map(InfoMap infoMap) {
>         infoMap.putFirst(new Info().enumerate(false)).put(new Info("std::future").skip().annotations("@StdFuture"))
Reply all
Reply to author
Forward
0 new messages