Add missing typedefs to std::vector + typedef corrections

Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
This commit is contained in:
William S Fulton 2019-02-13 00:04:26 +00:00
commit e26f6bb4e2
18 changed files with 182 additions and 17 deletions

View file

@ -129,6 +129,7 @@ std::vector<std::string> vecStr(std::vector<std::string> v) {
double *makeDoublePtr(double v) { return new double(v); }
int extractInt(int *p) { return *p; }
short extractConstShort(const short *p) { return *p; }
short extractConstShort2(std::vector<const short *>::value_type p) { return *p; }
%}
%template(pyvector) std::vector<swig::SwigPtr_PyObject>;

View file

@ -15,6 +15,19 @@ using namespace std;
int* makeIntPtr(int v) {
return new int(v);
}
std::vector<int *>::value_type makeIntPtr2(int v) {
return new int(v);
}
int getIntValue(int *p) {
return *p;
}
int getIntValue2(std::vector<int *>::const_reference p) {
return *p;
}
int getIntValue3(std::vector<int *>::reference p) {
return *p;
}
double* makeDoublePtr(double v) {
return new double(v);
}

View file

@ -173,3 +173,11 @@ if extractConstShort(vcs[0]) != 111:
if extractConstShort(vcs[1]) != 222:
raise RuntimeError
for p in vcs[0:1]:
if extractConstShort2(p) != 111:
raise RuntimeError
for p in vcs[1:2]:
if extractConstShort2(p) != 222:
raise RuntimeError

View file

@ -4,12 +4,20 @@ def check(val1, val2):
if val1 != val2:
raise RuntimeError("Values are not the same %s %s" % (val1, val2))
ip1 = makeIntPtr(11)
ip2 = makeIntPtr(22)
ip2 = makeIntPtr2(22)
vi = IntPtrVector((ip1, ip2))
check(getValueFromVector(vi, 0), 11)
check(getValueFromVector(vi, 1), 22)
check(getIntValue(vi[0]), 11)
check(getIntValue(vi[1]), 22)
check(getIntValue2(vi[0]), 11)
check(getIntValue2(vi[1]), 22)
ipp = makeIntPtrPtr(vi[0])
check(getIntValue3(ipp), 11) # Note: getIntValue3 takes int**
vA = APtrVector([makeA(33), makeA(34)])
check(getVectorValueA(vA, 0), 33)