Fix std::vector of const pointers
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11704 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4b2ced5095
commit
132376bade
5 changed files with 67 additions and 2 deletions
|
|
@ -1,6 +1,9 @@
|
|||
Version 1.3.41 (in progress)
|
||||
============================
|
||||
|
||||
2009-10-20: wsfulton
|
||||
[Python] Fix std::vector<const T*>. This would previously compile, but not run correctly.
|
||||
|
||||
2009-10-20: wsfulton
|
||||
Fixed previously fairly poor template partial specialization and explicit
|
||||
specialization support. Numerous bugs in this area have been fixed including:
|
||||
|
|
|
|||
|
|
@ -125,15 +125,16 @@ std::vector<std::string> vecStr(std::vector<std::string> v) {
|
|||
|
||||
%inline %{
|
||||
int *makeIntPtr(int v) { return new int(v); }
|
||||
const short *makeConstShortPtr(int v) { return new short(v); }
|
||||
double *makeDoublePtr(double v) { return new double(v); }
|
||||
int extractInt(int *p) { return *p; }
|
||||
short extractConstShort(const short *p) { return *p; }
|
||||
%}
|
||||
|
||||
%template(pyvector) std::vector<swig::SwigPtr_PyObject>;
|
||||
|
||||
namespace std {
|
||||
%template(ConstShortVector) vector<const short *>;
|
||||
// %template(ConstIntVector) vector<const int *>; // interferes with vector<int *>... see new testcase li_std_vector_ptr
|
||||
%template(ConstShortPtrVector) vector<const short *>;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// Bug 2359417
|
||||
%module li_std_vector_ptr
|
||||
|
||||
%include "std_vector.i"
|
||||
|
|
|
|||
|
|
@ -154,3 +154,23 @@ if extractInt(vi[0]) != 11:
|
|||
if extractInt(vi[1]) != 22:
|
||||
raise RuntimeError
|
||||
|
||||
# vector const pointer checks
|
||||
csp = makeConstShortPtr(111)
|
||||
|
||||
error = 0
|
||||
try:
|
||||
vcs = ConstShortPtrVector((csp, dp)) # check vector<const unsigned short *> does not accept double * element
|
||||
error = 1
|
||||
except:
|
||||
pass
|
||||
|
||||
if error:
|
||||
raise RuntimeError
|
||||
|
||||
vcs = ConstShortPtrVector((csp, makeConstShortPtr(222)))
|
||||
if extractConstShort(vcs[0]) != 111:
|
||||
raise RuntimeError
|
||||
|
||||
if extractConstShort(vcs[1]) != 222:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,46 @@ namespace std {
|
|||
%std_vector_methods_val(vector);
|
||||
};
|
||||
|
||||
// ***
|
||||
// const pointer specialization
|
||||
// ***
|
||||
template<class _Tp, class _Alloc >
|
||||
class vector<const _Tp *, _Alloc > {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef const _Tp * value_type;
|
||||
typedef value_type* pointer;
|
||||
typedef const value_type* const_pointer;
|
||||
typedef value_type reference;
|
||||
typedef value_type const_reference;
|
||||
typedef _Alloc allocator_type;
|
||||
|
||||
%traits_swigtype(_Tp);
|
||||
|
||||
%fragment(SWIG_Traits_frag(std::vector<const _Tp *, _Alloc >), "header",
|
||||
fragment=SWIG_Traits_frag(_Tp),
|
||||
fragment="StdVectorTraits") {
|
||||
namespace swig {
|
||||
template <> struct traits<std::vector<const _Tp *, _Alloc > > {
|
||||
typedef value_category category;
|
||||
static const char* type_name() {
|
||||
return "std::vector<const " #_Tp " *," #_Alloc " >";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<const _Tp *, _Alloc >);
|
||||
|
||||
#ifdef %swig_vector_methods_val
|
||||
// Add swig/language extra methods
|
||||
%swig_vector_methods_val(std::vector<const _Tp *, _Alloc >);
|
||||
#endif
|
||||
|
||||
%std_vector_methods_val(vector);
|
||||
};
|
||||
|
||||
// ***
|
||||
// ***
|
||||
// bool specialization
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue