A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bytedeco/javacpp/issues/613 below:

Problem with std::unique_ptr as callback parameter · Issue #613 · bytedeco/javacpp · GitHub

I have problem with creating FunctionPointer for callback which receives std::unique_ptr as argument.
This is my test function:

class Stream {
public:
    using StreamId = std::int32_t;
public:
    virtual ~Stream() = default;
    [[nodiscard]] virtual StreamId getStreamId() const noexcept = 0;
};

void testOnStreamOpenCb(std::function<void(std::unique_ptr<Stream> stream)>) {
    std::cout << "testOnStreamOpenCb";
}

This is my FunctionPointer:

    public static class OnStreamOpenCbCallback extends FunctionPointer {
        // Loader.load() and allocate() are required only when explicitly creating an instance
        static {
            Loader.load();
        }

        protected OnStreamOpenCbCallback() {
            allocate();
        }

        private native void allocate();

//        public native void call(@ByVal @UniquePtr @Cast("Stream*") Pointer stream);
//        public native void call(@ByVal @Cast("std::unique_ptr<Stream>*") Pointer stream);
        public native void call(@MoveUniquePtr @Cast("Stream*") Pointer stream);
    }

    @Documented
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD, ElementType.PARAMETER})
    @Cast({"std::unique_ptr", "&&"}) @Adapter("UniquePtrAdapter")
    public @interface MoveUniquePtr {
        String value() default "";
    }

I saw uning MoveUniquePtr in tensorflow preset, but there callback returns unique_ptr, not use it as argument.
Here is my map:

infoMap.put(new Info("std::function<void(std::unique_ptr<Stream>stream)>").pointerTypes("OnStreamOpenCbCallback").define());

If I remove cpp function testOnStreamOpenCb, compilation fails because of testOnStreamOpenCb.
Could you please advice me something?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4