bytedeco/javacpp-presets

Quick Preset

masterav10 opened this issue · 3 comments

I got another one that I can't quite pinpoint the right magic for.

I have the following definition:

class dng_shared
	{
	
	public:
		
		dng_std_vector<dng_fingerprint> fBigTableDigests;
		dng_std_vector<uint64>          fBigTableOffsets;
		dng_std_vector<uint32>          fBigTableByteCounts;
		
	};

        template <class T> using dng_std_vector = std::vector<T, dng_std_allocator<T> >;

Here is the generated code for fBigTableOffsets, which fails at the commented line:

    JNIEXPORT jobject JNICALL Java_org_bytedeco_dng_dng_1shared_fBigTableOffsets__Lorg_bytedeco_javacpp_LongPointer_2(JNIEnv* env, jobject obj, jobject arg0) {
        dng_shared* ptr = (dng_shared*)jlong_to_ptr(env->GetLongField(obj, JavaCPP_addressFID));
        if (ptr == NULL) {
            env->ThrowNew(JavaCPP_getClass(env, 7), "This pointer address is NULL.");
            return 0;
        }
        jlong position = env->GetLongField(obj, JavaCPP_positionFID);
        ptr += position;
        jlong* ptr0 = arg0 == NULL ? NULL : (jlong*)jlong_to_ptr(env->GetLongField(arg0, JavaCPP_addressFID));
        jlong size0 = arg0 == NULL ? 0 : env->GetLongField(arg0, JavaCPP_limitFID);
        void* owner0 = JavaCPP_getPointerOwner(env, arg0);
        jlong position0 = arg0 == NULL ? 0 : env->GetLongField(arg0, JavaCPP_positionFID);
        ptr0 += position0;
        size0 -= position0;
        VectorAdapter< uint64 > adapter0((uint64*)ptr0, size0, owner0);  // XXX: Fails to compile
        jobject rarg = obj;
        ptr->fBigTableOffsets = adapter0;
        return rarg;
    }

Here's the error:

jnidng.cpp(56698): error C2664: 'VectorAdapter<uint64,P,std::allocator<T>>::VectorAdapter(const std::vector<T,A> &)': cannot convert argument 1 from 'std::vector<uint64,dng_std_allocator<uint64>>' to 'const std::vector<T,A> &'
        with
        [
            P=uint64,
            T=uint64,
            A=std::allocator<uint64>
        ]
        and
        [
            T=uint64,
            A=std::allocator<uint64>
        ]	
jnidng.cpp(56698): note: Reason: cannot convert from 'std::vector<uint64,dng_std_allocator<uint64>>' to 'const std::vector<T,A>'
        with
        [
            T=uint64,
            A=std::allocator<uint64>
        ]
jnidng.cpp(56698): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

I've tried the following:

infoMap.put(new Info("dng_std_vector<uint64>").pointerTypes("dng_std_vector_uint64").define());

It doesn't generate the dng_std_vector_uint64. I think because it assumes it is an std::vector and tries the adapter route. Not sure how to overcome this. Any thoughts?

You'll need to declare it first as part of the "basic/containers" like this:
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#defining-wrappers-for-basic-c-containers

Can't say I fully understand what's going on here, but it looks like I got what I need for now. Thanks Sam!

It's just a way to tell JavaCPP that the template definition isn't available in C++ and to fall back on some basic code.