3 %include <octstdcommon.swg>
5 //#define SWIG_STD_PAIR_ASVAL
7 %fragment("StdPairTraits","header",fragment="StdTraits") {
9 #ifdef SWIG_STD_PAIR_ASVAL
10 template <class T, class U >
11 struct traits_asval<std::pair<T,U> > {
12 typedef std::pair<T,U> value_type;
14 static int get_pair(const octave_value& first, octave_value second,
18 T *pfirst = &(val->first);
19 int res1 = swig::asval(first, pfirst);
22 U *psecond = &(val->second);
23 int res2 = swig::asval(second, psecond);
26 return res1 > res2 ? res1 : res2;
29 int res1 = swig::asval(first, pfirst);
33 int res2 = swig::asval((PyObject*)second, psecond);
36 return res1 > res2 ? res1 : res2;
40 static int asval(const octave_value& obj, std::pair<T,U> *val) {
42 Cell c=obj.cell_value();
44 error("pair from Cell array requires at least two elements");
47 return get_pair(c(0),c(1),val);
50 int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
51 if (SWIG_IsOK(res) && val)
60 template <class T, class U >
61 struct traits_asptr<std::pair<T,U> > {
62 typedef std::pair<T,U> value_type;
64 static int get_pair(const octave_value& first, octave_value second,
68 value_type *vp = %new_instance(std::pair<T,U>);
69 T *pfirst = &(vp->first);
70 int res1 = swig::asval(first, pfirst);
73 U *psecond = &(vp->second);
74 int res2 = swig::asval(second, psecond);
78 return SWIG_AddNewMask(res1 > res2 ? res1 : res2);
81 int res1 = swig::asval(first, pfirst);
85 int res2 = swig::asval(second, psecond);
88 return res1 > res2 ? res1 : res2;
93 static int asptr(const octave_value& obj, std::pair<T,U> **val) {
95 Cell c=obj.cell_value();
97 error("pair from Cell array requires at least two elements");
100 return get_pair(c(0),c(1),val);
103 int res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
104 if (SWIG_IsOK(res) && val)
113 template <class T, class U >
114 struct traits_from<std::pair<T,U> > {
115 static octave_value from(const std::pair<T,U>& val) {
117 c(0)=swig::from(val.first);
118 c(1)=swig::from(val.second);
125 %define %swig_pair_methods(pair...)
128 %include <std/std_pair.i>