JuliaInterop / CxxWrap.jl

Package to make C++ libraries available in Julia
Other
418 stars 67 forks source link

add_type<...>("TemplatedType") as subtype of julia's type #109

Closed kalmarek closed 6 years ago

kalmarek commented 6 years ago

I'm interfacing a C++ library which implements its own Set type I add the declaration as follows:

Module.add_type<jlcxx::Parametric<jlcxx::TypeVar<1>>>("pm_Set")
 ...

Is it possible to declare the created Module.pm_Set{T} as a subtype of Base.AbstractSet?

in julia-0.7 most of the set functionality has been split into methods with AbstractSets (29 of them) and implementation specific methods with Sets (just 15). To make pm_Set behave as julia Sets do would require implementing only those 15.

barche commented 6 years ago

You should be able to define the type like this:

Module.add_type<jlcxx::Parametric<jlcxx::TypeVar<1>>>("pm_Set", jlcxx::julia_type("AbstractSet", "Base"))

The downside is that it will no longer inherit from CxxWrap.CppAny then, but at this point that type is only used to determine the smart pointer type, so if you need smart pointers holding pm_Set objects you can add this after the @wrapmodule:

CxxWrap.smart_pointer_type(x::Type{T}) where {T <: pm_Set} = CxxWrap.ptrunion(x)

I should really try to find a way to make the CppAny base type obsolete (maybe using traits), since it gets in the way in cases like these.

kalmarek commented 6 years ago

thanks!