PageRenderTime 10ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/python/pyprimtypes.swg

#
Unknown | 301 lines | 278 code | 23 blank | 0 comment | 0 complexity | af4ba0fdecaec16a34d4d199ee98890e MD5 | raw file
  1/* ------------------------------------------------------------
  2 * Primitive Types
  3 * ------------------------------------------------------------ */
  4
  5/* boolean */
  6
  7%fragment(SWIG_From_frag(bool),"header") {
  8SWIGINTERNINLINE PyObject*
  9  SWIG_From_dec(bool)(bool value)
 10{
 11  return PyBool_FromLong(value ? 1 : 0);
 12}
 13}
 14
 15%fragment(SWIG_AsVal_frag(bool),"header",
 16	  fragment=SWIG_AsVal_frag(long)) {
 17SWIGINTERN int
 18SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
 19{
 20  int r = PyObject_IsTrue(obj);
 21  if (r == -1)
 22    return SWIG_ERROR;
 23  if (val) *val = r ? true : false;
 24  return SWIG_OK;
 25}
 26}
 27
 28/* int */
 29
 30%fragment(SWIG_From_frag(int),"header") {
 31SWIGINTERNINLINE PyObject*
 32  SWIG_From_dec(int)(int value)
 33{
 34  return PyInt_FromLong((long) value);
 35}
 36}
 37
 38/* long */
 39
 40%fragment(SWIG_From_frag(long),"header") {
 41  %define_as(SWIG_From_dec(long),           PyLong_FromLong)
 42}
 43
 44%fragment(SWIG_AsVal_frag(long),"header",
 45	  fragment="SWIG_CanCastAsInteger") {
 46SWIGINTERN int
 47SWIG_AsVal_dec(long)(PyObject *obj, long* val)
 48{
 49  if (PyInt_Check(obj)) {
 50    if (val) *val = PyInt_AsLong(obj);
 51    return SWIG_OK;
 52  } else if (PyLong_Check(obj)) {
 53    long v = PyLong_AsLong(obj);
 54    if (!PyErr_Occurred()) {
 55      if (val) *val = v;
 56      return SWIG_OK;
 57    } else {
 58      PyErr_Clear();
 59    }
 60  }
 61%#ifdef SWIG_PYTHON_CAST_MODE
 62  {
 63    int dispatch = 0;
 64    long v = PyInt_AsLong(obj);
 65    if (!PyErr_Occurred()) {
 66      if (val) *val = v;
 67      return SWIG_AddCast(SWIG_OK);
 68    } else {
 69      PyErr_Clear();
 70    }
 71    if (!dispatch) {
 72      double d;
 73      int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
 74      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) {
 75	if (val) *val = (long)(d);
 76	return res;
 77      }
 78    }
 79  }
 80%#endif
 81  return SWIG_TypeError;
 82}
 83}
 84
 85/* unsigned long */
 86
 87%fragment(SWIG_From_frag(unsigned long),"header",
 88	  fragment=SWIG_From_frag(long)) {
 89SWIGINTERNINLINE PyObject* 
 90SWIG_From_dec(unsigned long)(unsigned long value)
 91{
 92  return (value > LONG_MAX) ?
 93    PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long)); 
 94}
 95}
 96
 97%fragment(SWIG_AsVal_frag(unsigned long),"header",
 98	  fragment="SWIG_CanCastAsInteger") {
 99SWIGINTERN int
100SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) 
101{
102  if (PyInt_Check(obj)) {
103    unsigned long v = PyInt_AsUnsignedLongMask(obj);
104    if (!PyErr_Occurred()) {
105      if (val) *val = v;
106      return SWIG_OK;
107    }
108    PyErr_Clear();
109  } else if (PyLong_Check(obj)) {
110    unsigned long v = PyLong_AsUnsignedLong(obj);
111    if (!PyErr_Occurred()) {
112      if (val) *val = v;
113      return SWIG_OK;
114    } else {
115      PyErr_Clear();
116    }
117  }
118%#ifdef SWIG_PYTHON_CAST_MODE
119  {
120    int dispatch = 0;
121    unsigned long v = PyLong_AsUnsignedLong(obj);
122    if (!PyErr_Occurred()) {
123      if (val) *val = v;
124      return SWIG_AddCast(SWIG_OK);
125    } else {
126      PyErr_Clear();
127    }
128    if (!dispatch) {
129      double d;
130      int res = SWIG_AddCast(SWIG_AsVal(double)(obj,&d));
131      if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) {
132	if (val) *val = (unsigned long)(d);
133	return res;
134      }
135    }
136  }
137%#endif
138  return SWIG_TypeError;
139}
140}
141
142/* long long */
143
144%fragment(SWIG_From_frag(long long),"header",
145	  fragment=SWIG_From_frag(long),
146	  fragment="<limits.h>") {
147SWIGINTERNINLINE PyObject* 
148SWIG_From_dec(long long)(long long value)
149{
150  return ((value < LONG_MIN) || (value > LONG_MAX)) ?
151    PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); 
152}
153}
154
155%fragment(SWIG_AsVal_frag(long long),"header",
156	  fragment=SWIG_AsVal_frag(long),
157	  fragment="SWIG_CanCastAsInteger",
158	  fragment="<limits.h>") {
159SWIGINTERN int
160SWIG_AsVal_dec(long long)(PyObject *obj, long long *val)
161{
162  int res = SWIG_TypeError;
163  if (PyLong_Check(obj)) {
164    long long v = PyLong_AsLongLong(obj);
165    if (!PyErr_Occurred()) {
166      if (val) *val = v;
167      return SWIG_OK;
168    } else {
169      PyErr_Clear();
170    }
171  } else {
172    long v;
173    res = SWIG_AsVal(long)(obj,&v);
174    if (SWIG_IsOK(res)) {
175      if (val) *val = v;
176      return res;
177    }
178  }
179%#ifdef SWIG_PYTHON_CAST_MODE
180  {
181    const double mant_max = 1LL << DBL_MANT_DIG;
182    const double mant_min = -mant_max;
183    double d;
184    res = SWIG_AsVal(double)(obj,&d);
185    if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, mant_min, mant_max)) {
186      if (val) *val = (long long)(d);
187      return SWIG_AddCast(res);
188    }
189    res = SWIG_TypeError;
190  }
191%#endif
192  return res;
193}
194}
195
196/* unsigned long long */
197
198%fragment(SWIG_From_frag(unsigned long long),"header",
199	  fragment=SWIG_From_frag(long long),
200	  fragment="<limits.h>") {
201SWIGINTERNINLINE PyObject* 
202SWIG_From_dec(unsigned long long)(unsigned long long value)
203{
204  return (value > LONG_MAX) ?
205    PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); 
206}
207}
208
209%fragment(SWIG_AsVal_frag(unsigned long long),"header",
210	  fragment=SWIG_AsVal_frag(unsigned long),
211	  fragment="SWIG_CanCastAsInteger",
212	  fragment="<limits.h>") {
213SWIGINTERN int
214SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val)
215{
216  int res = SWIG_TypeError;
217  if (PyLong_Check(obj)) {
218    unsigned long long v = PyLong_AsUnsignedLongLong(obj);
219    if (!PyErr_Occurred()) {
220      if (val) *val = v;
221      return SWIG_OK;
222    } else {
223      PyErr_Clear();
224    }
225  } else {
226    unsigned long v;
227    res = SWIG_AsVal(unsigned long)(obj,&v);
228    if (SWIG_IsOK(res)) {
229      if (val) *val = v;
230      return res;
231    }
232  }
233%#ifdef SWIG_PYTHON_CAST_MODE
234  {
235    const double mant_max = 1LL << DBL_MANT_DIG;
236    double d;
237    res = SWIG_AsVal(double)(obj,&d);
238    if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, mant_max)) {
239      if (val) *val = (unsigned long long)(d);
240      return SWIG_AddCast(res);
241    }
242    res = SWIG_TypeError;
243  }
244%#endif
245  return res;
246}
247}
248
249/* double */
250
251%fragment(SWIG_From_frag(double),"header") {
252  %define_as(SWIG_From_dec(double),          PyFloat_FromDouble)
253}
254
255%fragment(SWIG_AsVal_frag(double),"header") {
256SWIGINTERN int
257SWIG_AsVal_dec(double)(PyObject *obj, double *val)
258{
259  int res = SWIG_TypeError;
260  if (PyFloat_Check(obj)) {
261    if (val) *val = PyFloat_AsDouble(obj);
262    return SWIG_OK;
263  } else if (PyInt_Check(obj)) {
264    if (val) *val = PyInt_AsLong(obj);
265    return SWIG_OK;
266  } else if (PyLong_Check(obj)) {
267    double v = PyLong_AsDouble(obj);
268    if (!PyErr_Occurred()) {
269      if (val) *val = v;
270      return SWIG_OK;
271    } else {
272      PyErr_Clear();
273    }
274  }
275%#ifdef SWIG_PYTHON_CAST_MODE
276  {
277    int dispatch = 0;
278    double d = PyFloat_AsDouble(obj);
279    if (!PyErr_Occurred()) {
280      if (val) *val = d;
281      return SWIG_AddCast(SWIG_OK);
282    } else {
283      PyErr_Clear();
284    }
285    if (!dispatch) {
286      long v = PyLong_AsLong(obj);
287      if (!PyErr_Occurred()) {
288	if (val) *val = v;
289	return SWIG_AddCast(SWIG_AddCast(SWIG_OK));
290      } else {
291	PyErr_Clear();
292      }
293    }
294  }
295%#endif
296  return res;
297}
298}
299
300
301