%include <pycontainer.swg>
%fragment("StdPairTraits","header",
fragment="StdTraits",fragment="PyObject_var") {
template <class T, class U >
struct traits_asptr<std::pair<T,U> > {
static int asptr(PyObject *obj, std::pair<T,U> **val) {
typedef std::pair<T,U> value_type;
if (PySequence_Check(obj) && (PySequence_Size(obj) == 2)) {
swig::PyObject_var first = PySequence_GetItem(obj,0);
swig::PyObject_var second = PySequence_GetItem(obj,1);
*val = new std::pair<T,U>;
pfirst = &((*val)->first);
psecond = &((*val)->second);
if (swig::asval(first,pfirst) && swig::asval(second,psecond)) {
if (SWIG_ConvertPtr(obj,(void**)&p,
swig::type_info<value_type>(),0) != -1) {
PyErr_Format(PyExc_TypeError, "a %s is expected",
swig::type_name<value_type>());
template <class T, class U >
struct traits_from<std::pair<T,U> > {
static PyObject *from(const std::pair<T,U>& val) {
PyObject* obj = PyTuple_New(2);
PyTuple_SetItem(obj,0,swig::from(val.first));
PyTuple_SetItem(obj,1,swig::from(val.second));
%define %swig_pair_methods(pair...)
def __getitem__(self, index):
def __setitem__(self, index, val):
return str((self.first, self.second))
%include <std/std_pair.i>