summaryrefslogtreecommitdiffstats
path: root/tests/samplebinding/pair_conversions.h
blob: 8adf2f6f3e1277e5a85fdf23964ecab0b285fd6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
template <typename StdPair>
struct Converter_std_pair
{
    static PyObject* toPython(ValueHolder<StdPair> holder)
    {
        ValueHolder<typename StdPair::first_type> first(holder.value.first);
        ValueHolder<typename StdPair::second_type> second(holder.value.second);
        PyObject* tuple = PyTuple_New(2);
        PyTuple_SET_ITEM(tuple, 0, Converter<typename StdPair::first_type>::toPython(first));
        PyTuple_SET_ITEM(tuple, 1, Converter<typename StdPair::second_type>::toPython(second));
        return tuple;
    }
    static StdPair toCpp(PyObject* pyobj)
    {
        StdPair result;
        PyObject* pyFirst = PyTuple_GET_ITEM(pyobj, 0);
        PyObject* pySecond = PyTuple_GET_ITEM(pyobj, 1);
        result.first = Converter<typename StdPair::first_type>::toCpp(pyFirst);
        result.second = Converter<typename StdPair::second_type>::toCpp(pySecond);
        return result;
    }
};

template<typename FT, typename ST>
struct Converter<std::pair<FT, ST> > : Converter_std_pair<std::pair<FT, ST> > {};