added more especial methods for python
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5817 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
74f9ade9f7
commit
e6d14ad72c
2 changed files with 30 additions and 7 deletions
|
|
@ -38,3 +38,4 @@ if pab.first.val != 2:
|
|||
|
||||
pci = lib_std_pair.CIntPair(1,0)
|
||||
|
||||
print len(psii)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,28 @@
|
|||
#include <utility>
|
||||
%}
|
||||
|
||||
|
||||
%define %pypair_methods(pair)
|
||||
%extend {
|
||||
%pythoncode {
|
||||
def __len__(self):
|
||||
return 2
|
||||
def __getitem__(self, index):
|
||||
if not (index % 2):
|
||||
return self.first
|
||||
else:
|
||||
return self.second
|
||||
def __setitem__(self, index, val):
|
||||
if not (index % 2):
|
||||
self.first = val
|
||||
else:
|
||||
self.second = val
|
||||
def __repr__(self):
|
||||
return str((self.first, self.second))
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%fragment("StdPairTraits","header",
|
||||
fragment="StdTraits",fragment="PyObject_var") {
|
||||
namespace swigpy {
|
||||
|
|
@ -85,13 +107,7 @@ namespace std {
|
|||
T first;
|
||||
U second;
|
||||
|
||||
%extend
|
||||
{
|
||||
%pythoncode {
|
||||
def __repr__(self):
|
||||
return "(%s, %s)" %(str(self.first),str(self.second))
|
||||
}
|
||||
}
|
||||
%pypair_methods(pair)
|
||||
};
|
||||
|
||||
// ***
|
||||
|
|
@ -125,6 +141,8 @@ namespace std {
|
|||
|
||||
T first;
|
||||
U* second;
|
||||
|
||||
%pypair_methods(pair)
|
||||
};
|
||||
|
||||
template <class T, class U > struct pair<T*, U> {
|
||||
|
|
@ -154,6 +172,8 @@ namespace std {
|
|||
|
||||
T* first;
|
||||
U second;
|
||||
|
||||
%pypair_methods(pair)
|
||||
};
|
||||
|
||||
template <class T, class U > struct pair<T*, U*> {
|
||||
|
|
@ -180,6 +200,8 @@ namespace std {
|
|||
|
||||
T* first;
|
||||
U* second;
|
||||
|
||||
%pypair_methods(pair)
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue