Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: swig/Lib/python/std_pair.i

Issue 553095: Checkin swig binaries for win, linux and Mac... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/
Patch Set: '' Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « swig/Lib/python/std_multiset.i ('k') | swig/Lib/python/std_set.i » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 Pairs
3 */
4 %include <pystdcommon.swg>
5
6 //#define SWIG_STD_PAIR_ASVAL
7
8 %fragment("StdPairTraits","header",fragment="StdTraits") {
9 namespace swig {
10 #ifdef SWIG_STD_PAIR_ASVAL
11 template <class T, class U >
12 struct traits_asval<std::pair<T,U> > {
13 typedef std::pair<T,U> value_type;
14
15 static int get_pair(PyObject* first, PyObject* second,
16 std::pair<T,U> *val)
17 {
18 if (val) {
19 T *pfirst = &(val->first);
20 int res1 = swig::asval((PyObject*)first, pfirst);
21 if (!SWIG_IsOK(res1)) return res1;
22 U *psecond = &(val->second);
23 int res2 = swig::asval((PyObject*)second, psecond);
24 if (!SWIG_IsOK(res2)) return res2;
25 return res1 > res2 ? res1 : res2;
26 } else {
27 T *pfirst = 0;
28 int res1 = swig::asval((PyObject*)first, 0);
29 if (!SWIG_IsOK(res1)) return res1;
30 U *psecond = 0;
31 int res2 = swig::asval((PyObject*)second, psecond);
32 if (!SWIG_IsOK(res2)) return res2;
33 return res1 > res2 ? res1 : res2;
34 }
35 }
36
37 static int asval(PyObject *obj, std::pair<T,U> *val) {
38 int res = SWIG_ERROR;
39 if (PyTuple_Check(obj)) {
40 if (PyTuple_GET_SIZE(obj) == 2) {
41 res = get_pair(PyTuple_GET_ITEM(obj,0),PyTuple_GET_ITEM(obj,1), val) ;
42 }
43 } else if (PySequence_Check(obj)) {
44 if (PySequence_Size(obj) == 2) {
45 swig::SwigVar_PyObject first = PySequence_GetItem(obj,0);
46 swig::SwigVar_PyObject second = PySequence_GetItem(obj,1);
47 res = get_pair(first, second, val);
48 }
49 } else {
50 value_type *p;
51 res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
52 if (SWIG_IsOK(res) && val) *val = *p;
53 }
54 return res;
55 }
56 };
57
58 #else
59 template <class T, class U >
60 struct traits_asptr<std::pair<T,U> > {
61 typedef std::pair<T,U> value_type;
62
63 static int get_pair(PyObject* first, PyObject* second,
64 std::pair<T,U> **val)
65 {
66 if (val) {
67 value_type *vp = %new_instance(std::pair<T,U>);
68 T *pfirst = &(vp->first);
69 int res1 = swig::asval((PyObject*)first, pfirst);
70 if (!SWIG_IsOK(res1)) return res1;
71 U *psecond = &(vp->second);
72 int res2 = swig::asval((PyObject*)second, psecond);
73 if (!SWIG_IsOK(res2)) return res2;
74 *val = vp;
75 return SWIG_AddNewMask(res1 > res2 ? res1 : res2);
76 } else {
77 T *pfirst = 0;
78 int res1 = swig::asval((PyObject*)first, pfirst);
79 if (!SWIG_IsOK(res1)) return res1;
80 U *psecond = 0;
81 int res2 = swig::asval((PyObject*)second, psecond);
82 if (!SWIG_IsOK(res2)) return res2;
83 return res1 > res2 ? res1 : res2;
84 }
85 }
86
87 static int asptr(PyObject *obj, std::pair<T,U> **val) {
88 int res = SWIG_ERROR;
89 if (PyTuple_Check(obj)) {
90 if (PyTuple_GET_SIZE(obj) == 2) {
91 res = get_pair(PyTuple_GET_ITEM(obj,0),PyTuple_GET_ITEM(obj,1), val) ;
92 }
93 } else if (PySequence_Check(obj)) {
94 if (PySequence_Size(obj) == 2) {
95 swig::SwigVar_PyObject first = PySequence_GetItem(obj,0);
96 swig::SwigVar_PyObject second = PySequence_GetItem(obj,1);
97 res = get_pair(first, second, val);
98 }
99 } else {
100 value_type *p;
101 res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<value_type>(),0);
102 if (SWIG_IsOK(res) && val) *val = p;
103 }
104 return res;
105 }
106 };
107
108 #endif
109 template <class T, class U >
110 struct traits_from<std::pair<T,U> > {
111 static PyObject *from(const std::pair<T,U>& val) {
112 PyObject* obj = PyTuple_New(2);
113 PyTuple_SetItem(obj,0,swig::from(val.first));
114 PyTuple_SetItem(obj,1,swig::from(val.second));
115 return obj;
116 }
117 };
118 }
119 }
120
121 %define %swig_pair_methods(pair...)
122 %extend {
123 %pythoncode {def __len__(self): return 2
124 def __repr__(self): return str((self.first, self.second))
125 def __getitem__(self, index):
126 if not (index % 2):
127 return self.first
128 else:
129 return self.second
130 def __setitem__(self, index, val):
131 if not (index % 2):
132 self.first = val
133 else:
134 self.second = val}
135 }
136 %enddef
137
138 %include <std/std_pair.i>
139
OLDNEW
« no previous file with comments | « swig/Lib/python/std_multiset.i ('k') | swig/Lib/python/std_set.i » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698