Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for virtual operators #362

Closed
thirstycrow opened this issue Nov 20, 2019 · 2 comments
Closed

Support for virtual operators #362

thirstycrow opened this issue Nov 20, 2019 · 2 comments
Labels

Comments

@thirstycrow
Copy link

I am trying to write a faiss index to a java output stream. The write_index method accept an IOWriter struct, and write data using its () operator. The generated code contains a super_operator () method that fails to compile. Some kind of name escaping seems required for it to work.

void write_index (const Index *idx, IOWriter *writer);
struct IOWriter {
    // name that can be used in error messages
    std::string name;

    // fwrite
    virtual size_t operator()(
         const void *ptr, size_t size, size_t nitems) = 0;

    // return a file number that can be memory-mapped
    virtual int fileno ();

    virtual ~IOWriter() {}
};
@Namespace("faiss")
@NoOffset
@Properties(@Platform(
        link = { "faiss", "gomp" },
        preload = "faiss",
        include = { "faiss/impl/io.h" }))
public class IOWriter extends Pointer {
    static { Loader.load(); }

    public IOWriter() { allocate(); }

    private native void allocate();

    @Cast("size_t")
    @Name("operator ()")
    @Virtual(true)
    public native long apply(@Const Pointer ptr, @Cast("size_t") long size, @Cast("size_t") long nitems);
}
class JavaCPP_hidden JavaCPP_faiss_0003a_0003aIOWriter : public faiss::IOWriter {
public:
    jobject obj;
    static jmethodID apply__Lorg_bytedeco_javacpp_Pointer_2JJ;

    using faiss::IOWriter::operator ();
    virtual size_t operator ()(const void* arg0, size_t arg1, size_t arg2);
    size_t super_operator ()(const void* arg0, size_t arg1, size_t arg2) { throw JavaCPP_exception("Cannot call pure virtual function faiss::IOWriter::operator ()()."); }
    JavaCPP_faiss_0003a_0003aIOWriter() : faiss::IOWriter(), obj(NULL) { }
};
@saudet
Copy link
Member

saudet commented Nov 20, 2019

Yeah, we'll need to do something about that. Maybe we could just use the Java identifier in those cases?

@saudet saudet added the bug label Nov 20, 2019
saudet added a commit that referenced this issue Dec 22, 2019
@saudet
Copy link
Member

saudet commented Apr 15, 2020

Fix included in JavaCPP 1.5.3. Thanks for reporting!

@saudet saudet closed this as completed Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants