A RetroSearch Logo

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

Search Query:

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

How to deal with user-define-type array · Issue #493 · bytedeco/javacpp · GitHub

Here is a demo

#include <iostream>
class MyType {
    public:
        MyType() : a(0) {}
        MyType(int i) : a(i) {}
        int a;
};

class MyTypeUser {
    public:
        void use(MyType* a, int count) {
            for (int i = 0; i < count; i++) {
                std::cout<<a[i].a<<std::endl;
            }
        }
};

MyTypeUser::use expects an array of MyType. The generated code is only able to hold one MyType actually.

generated MyTypeUser.use definition

public native void use(MyType a, int count);

generated MyType

public class MyType extends Pointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public MyType(Pointer p) { super(p); }

public MyType() { super((Pointer)null); allocate(); }
private native void allocate();
public MyType(int i) { super((Pointer)null); allocate(i); }
private native void allocate(int i);
public native int a(); public native MyType a(int setter);
}

I tried to add the following mapping info following guide here(https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#specifying-names-to-use-in-java)

        infoMap.put(new Info("MyType").pointerTypes("MyTypePointer"));
        infoMap.put(new Info("MyTypePointer").valueTypes("MyTypePointer").pointerTypes("@Cast(\"MyType*\") PointerPointer", "@ByPtrPtr MyTypePointer").base("IntPointer"));

The generated code is almost the same.

        public native void use(MyTypePointer a, int count);
public class MyTypePointer extends Pointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public MyTypePointer(Pointer p) { super(p); }

        public MyTypePointer() { super((Pointer)null); allocate(); }
        private native void allocate();
        public MyTypePointer(int i) { super((Pointer)null); allocate(i); }
        private native void allocate(int i);
        public native int a(); public native MyTypePointer a(int setter);
}

Is it possible to define UDT pointer similarly to IntPointer, capable of holding one or more elements? @saudet


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