I am creating wrappers in order to use a C++ open source library in C#.
I decided to use SWIG because this library uses thousands of classes, and most of them should be usable also on C# side. and SWIG seems doing this fine!
the problem I am facing now, is that there are some c++ classes which are Templated Classes, i.e.:
template <class T>
class aggregate_of {
std::vector<T*> ls;
public:
typedef boost::shared_ptr< aggregate_of<T> > ptr;
...
void remove(T* t) {
typename std::vector<T*>::iterator it;
while ((it = std::find(ls.begin(), ls.end(), t)) != ls.end()) {
ls.erase(it);
}
}
};
but SWIG (by default) generates a lot of unusable files similar to this one:
SWIGTYPE_p_aggregate_ofT_MyClass_t__ptr.cs
public class SWIGTYPE_p_aggregate_ofT_MyClass_t__ptr{
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
internal SWIGTYPE_p_aggregate_ofT_MyClass_t__ptr(global::System.IntPtr cPtr, bool futureUse) {
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
}
protected SWIGTYPE_p_aggregate_ofT_MyClass_t__ptr() {
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SWIGTYPE_p_aggregate_ofT_MyClass_t__ptrobj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
internal static global::System.Runtime.InteropServices.HandleRef swigRelease(SWIGTYPE_p_aggregate_ofT_MyClass_t__ptrobj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
}
using %template
directive with specific types is not ideal because as I said there are thousands of classes that could be used i.e. in the class I shown you.
I would expect (if possible) to have one c# class which uses the T generic type, instead of creating a class for each possible type.
SWIG documentation is very huge, I still have not found anything about this, so I was asking if this is possible.
do you know if is possible to bind somehow the C++ type to the C# T type? or do you know alternative solution/tips to this issue?
Thank you
I tried using %template
directive with specific types but is not ideal because as I said there are thousands of classes that could be used.
maybe there are ways of using it that I don’t know
SWIG documentation is very huge, I still have not found anything about this.
do you know if is possible to bind somehow the C++ type to the C# T type? or do you know alternative solution/tips to this issue?