added backward comp for old As/Check/From methods

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5785 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-22 00:17:54 +00:00
commit b6a08780a7

View file

@ -20,6 +20,12 @@
#define SWIG_STD_EXTEND_COMPARISON
//
// Use the following macro if you need the old common
// methods (SwigInt_FromBool,SwigNumber_Check,...).
//
// #define SWIG_STD_BACKWARD_COMP
//
// Common code for supporting the STD C++ namespace
//
@ -428,3 +434,33 @@ namespace swigpy {
#define %std_definst(Class,...)
#define %std_definst_2(Class,...)
#endif
//
// Backward compatibility
//
#ifdef SWIG_STD_BACKWARD_COMP
%{
#include <string>
PyObject* SwigInt_FromBool(bool b) {
return PyInt_FromLong(b ? 1L : 0L);
}
double SwigNumber_Check(PyObject* o) {
return PyFloat_Check(o) || PyInt_Check(o) || PyLong_Check(o);
}
double SwigNumber_AsDouble(PyObject* o) {
return PyFloat_Check(o) ? PyFloat_AsDouble(o)
: (PyInt_Check(o) ? double(PyInt_AsLong(o))
: double(PyLong_AsLong(o)));
}
PyObject* SwigString_FromString(const std::string& s) {
return PyString_FromStringAndSize(s.data(),s.size());
}
std::string SwigString_AsString(PyObject* o) {
return std::string(PyString_AsString(o));
}
%}
#endif