bytedeco/javacpp

containers: vectors of pairs not properly generated

Open

#673 创建于 2023年4月16日

在 GitHub 查看
 (7 评论) (0 反应) (0 负责人)Java (620 fork)batch import
enhancementhelp wanted

仓库指标

Star
 (4,279 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Parser generates code for pairs and not for vectors for vectors of pairs. Example for std::vector<std::pair<int, X>>:

public class XPairVector extends Pointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public XPairVector(Pointer p) { super(p); }
    public XPairVector(int[] firstValue, X[] secondValue) { this(Math.min(firstValue.length, secondValue.length)); put(firstValue, secondValue); }
    public XPairVector()       { allocate();  }
    public XPairVector(long n) { allocate(n); }
    private native void allocate();
    private native void allocate(@Cast("size_t") long n);
    public native @Name("operator =") @ByRef XPairVector put(@ByRef XPairVector x);

    public boolean empty() { return size() == 0; }
    public native long size();
    public void clear() { resize(0); }
    public native void resize(@Cast("size_t") long n);

    @Index(function = "at") public native int first(@Cast("size_t") long i); public native XPairVector first(@Cast("size_t") long i, int first);
    @Index(function = "at") public native @ByRef X second(@Cast("size_t") long i);  public native XPairVector second(@Cast("size_t") long i, X second);

    public XPairVector put(int[] firstValue, X[] secondValue) {
        for (int i = 0; i < firstValue.length && i < secondValue.length; i++) {
            first(i, firstValue[i]);
            second(i, secondValue[i]);
        }
        return this;
    }
}

This is due to these lines. firstType and secondType being tested here for generating the code of pairs.

What about adding condition dim == 0 line 221 ? Or maybe removing condition indexType != null line 355 ?

贡献者指南