bytedeco/javacpp

`@StdVector` default annotation causing `Parser` to ignore templated constructors and operator overloads with `std::vector` arguments

Open

#735 opened on Jan 17, 2024

View on GitHub
 (10 comments) (0 reactions) (0 assignees)Java (620 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (4,279 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

As described in #732. Title pretty much sums it up. Templated constructors and operators (but not plain functions) are ignored when they have std::vector as a parameter. The behavior is the same whether or not the class itself is templated.

Example:

Header:

template <typename T>
class TemplatedClass
{
public:
    template <typename U> TemplatedClass(std::vector<U> vec);
    template <typename U> void tempFun(std::vector<U> vec);
    template <typename U> void operator=(std::vector<U> vec);
};

InfoMapping:

        infoMap.put(new Info("TemplatedClass<double>").pointerTypes("TemplatedClassDouble"));

        infoMap.put(new Info("std::vector<int>").pointerTypes("IntVec").define());

        infoMap.put(new Info("TemplatedClass<double>::TemplatedClass<int>(std::vector<U>)").define());
        infoMap.put(new Info("TemplatedClass<double>::tempFun<int>").define());
        infoMap.put(new Info("TemplatedClass<double>::operator =<int>(std::vector<U>)").define());

With line 110 in InfoMap.java (.put(new Info("std::vector").annotations("@StdVector"))) commented out:

@Name("TemplatedClass<double>") public static class TemplatedClassDouble extends Pointer {
    static { Loader.load(); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public TemplatedClassDouble(Pointer p) { super(p); }

    public TemplatedClassDouble(@ByVal IntVec vec) { super((Pointer)null); allocate(vec); }
    private native void allocate(@ByVal IntVec vec);
    public native @Name("tempFun<int>") void tempFun(@ByVal IntVec vec);
    public native @Name("operator =") void put(@ByVal IntVec vec);
}

Without commenting out the line:

@Name("TemplatedClass<double>") public static class TemplatedClassDouble extends Pointer {
    static { Loader.load(); }
    /** Default native constructor. */
    public TemplatedClassDouble() { super((Pointer)null); allocate(); }
    /** Native array allocator. Access with {@link Pointer#position(long)}. */
    public TemplatedClassDouble(long size) { super((Pointer)null); allocateArray(size); }
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public TemplatedClassDouble(Pointer p) { super(p); }
    private native void allocate();
    private native void allocateArray(long size);
    @Override public TemplatedClassDouble position(long position) {
        return (TemplatedClassDouble)super.position(position);
    }
    @Override public TemplatedClassDouble getPointer(long i) {
        return new TemplatedClassDouble((Pointer)this).offsetAddress(i);
    }

    public native @Name("tempFun<int>") void tempFun(@ByVal IntVec vec);
}

Contributor guide