Return to the future for some parts...

PyParse_Tuple raises an exception on failure so it must be used only one time when
testing arguments
This commit is contained in:
Christophe Alexandre 2008-12-12 13:16:47 +00:00
parent 96c031c224
commit a23a682c64
4 changed files with 255 additions and 114 deletions

View File

@ -145,23 +145,24 @@ extern "C" {
static PyObject* PyBox_contains ( PyBox *self, PyObject* args ) {
trace << "PyBox_contains ()" << endl;
bool result = false;
HTRY
PyBox* pyBox = NULL;
PyPoint* pyPoint = NULL;
DbU::Unit x = 0, y = 0;
METHOD_HEAD ( "Box.contains()" )
if (PyArg_ParseTuple(args,"O!:Box.contains", &PyTypeBox, &pyBox)) {
result = box->contains(*PYBOX_O(pyBox));
} else if (PyArg_ParseTuple(args,"O!:Box.contains", &PyTypePoint, &pyPoint)) {
result = box->contains(*PYPOINT_O(pyPoint));
} else if (PyArg_ParseTuple(args,"ll:Box.contains", &x, &y)) {
result = box->contains(x,y);
} else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Box.contains." );
PyObject* arg0;
PyObject* arg1;
bool result = false;
HTRY
__cs.init ("Box.contains");
if ( ! PyArg_ParseTuple(args,"|O&O&:Box.contains",Converter,&arg0,Converter,&arg1) )
return NULL;
if ( __cs.getObjectIds() == BOX_ARG ) { result = box->contains ( *PYBOX_O(arg0) ); }
else if ( __cs.getObjectIds() == POINT_ARG ) { result = box->contains ( *PYPOINT_O(arg0) ); }
else if ( __cs.getObjectIds() == INTS2_ARG ) { result = box->contains ( PyInt_AsLong(arg0)
, PyInt_AsLong(arg1) ); }
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Box.contains constructor." );
return NULL;
}
@ -251,34 +252,40 @@ extern "C" {
// ---------------------------------------------------------------
// Attribute Method : "PyBox_inflate ()"
static PyObject* PyBox_inflate(PyBox *self, PyObject* args) {
static PyObject* PyBox_inflate ( PyBox *self, PyObject* args ) {
trace << "PyBox_inflate ()" << endl;
METHOD_HEAD("Box.inflate()")
METHOD_HEAD ( "Box.inflate()" )
PyObject* arg0;
PyObject* arg1;
PyObject* arg2 = NULL;
PyObject* arg3 = NULL;
HTRY
DbU::Unit arg0=0, arg1=0, arg2=0, arg3=0;
if (PyArg_ParseTuple(args,"l:Box.inflate", &arg0)) {
box->inflate(arg0);
} else if (PyArg_ParseTuple(args,"ll:Box.inflate", &arg0, &arg1)) {
box->inflate(arg0, arg1);
} else if (PyArg_ParseTuple(args,"llll:Box.inflate", &arg0, &arg1, &arg2, &arg3)) {
box->inflate(arg0, arg1, arg2, arg3);
} else {
__cs.init ("Box.inflate");
if ( ! PyArg_ParseTuple(args,"|O&O&O&O&:Box.inflate",Converter,&arg0,Converter,&arg1) )
return ( NULL );
if ( __cs.getObjectIds() == INT_ARG ) { box->inflate ( PyInt_AsLong(arg0) ); }
else if ( __cs.getObjectIds() == INTS2_ARG ) { box->inflate ( PyInt_AsLong(arg0)
, PyInt_AsLong(arg1) ); }
else if ( __cs.getObjectIds() == INTS4_ARG ) { box->inflate ( PyInt_AsLong(arg0)
, PyInt_AsLong(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3) ); }
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Box.inflate()" );
return NULL;
return ( NULL );
}
HCATCH
Py_INCREF ( self ); //FIXME ??
return (PyObject*)self;
Py_INCREF ( self );
return ( (PyObject*)self );
}
// ---------------------------------------------------------------
// Attribute Method : "PyBox_merge ()"
@ -287,29 +294,34 @@ extern "C" {
METHOD_HEAD ( "Box.merge()" )
PyObject* arg0;
PyObject* arg1;
PyObject* arg2;
PyObject* arg3;
HTRY
PyBox* pyBox = NULL;
PyPoint* pyPoint = NULL;
DbU::Unit arg0=0, arg1=0, arg2=0, arg3=0;
if (PyArg_ParseTuple(args,"O!:Box.merge", &PyTypeBox, &pyBox)) {
box->merge(*PYBOX_O(pyBox));
} else if (PyArg_ParseTuple(args,"O!:Box.merge", &PyTypePoint, &pyPoint)) {
box->merge(*PYPOINT_O(pyPoint));
} else if (PyArg_ParseTuple(args,"ll:Box.merge", &arg0, &arg1)) {
box->merge(arg0, arg1);
} else if (PyArg_ParseTuple(args,"llll:Box.merge", &arg0, &arg1, &arg2, &arg3)) {
box->merge(arg0, arg1, arg2, arg3);
} else {
__cs.init ("Box.merge");
if ( ! PyArg_ParseTuple(args,"|O&O&O&O&:Box.merge",Converter,&arg0,Converter,&arg1,Converter,&arg2,Converter,&arg3) )
return ( NULL );
if ( __cs.getObjectIds() == POINT_ARG ) { box->merge ( *PYPOINT_O(arg0) ); }
else if ( __cs.getObjectIds() == BOX_ARG ) { box->merge ( *PYBOX_O(arg0) ); }
else if ( __cs.getObjectIds() == INTS2_ARG ) { box->merge ( PyInt_AsLong(arg0)
, PyInt_AsLong(arg1) ); }
else if ( __cs.getObjectIds() == INTS4_ARG ) { box->merge ( PyInt_AsLong(arg0)
, PyInt_AsLong(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3) ); }
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Box.merge()" );
return NULL;
return ( NULL );
}
HCATCH
Py_INCREF ( self );
return (PyObject*)self;
return ( (PyObject*)self );
}
// ---------------------------------------------------------------
@ -369,43 +381,48 @@ extern "C" {
// ---------------------------------------------------------------
// Attribute Method : "PyBox_new ()"
PyObject* PyBox_new (PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyBox_new()" << endl;
PyBox* pyBox=NULL;
HTRY
Box* box = NULL;
PyPoint *pyPoint1=NULL, *pyPoint2=NULL;
DbU::Unit arg0=0, arg1=0, arg2=0, arg3=0;
PyBox* pyBox = NULL;
if (PyArg_ParseTuple(args, ":Box.new")) {
box = new Box;
} else if (PyArg_ParseTuple(args, "O!:Box.new", &PyTypePoint, &pyPoint1)) {
box = new Box(*PYPOINT_O(pyPoint1));
} else if (PyArg_ParseTuple(args, "O!:Box.new", &PyTypeBox, &pyBox)) {
box = new Box(*PYBOX_O(pyBox));
} else if (PyArg_ParseTuple(args, "O!O!:Box.new", &PyTypePoint, &pyPoint1, &PyTypePoint, &pyPoint2)) {
box = new Box(*PYPOINT_O(pyPoint1), *PYPOINT_O(pyPoint2));
} else if (PyArg_ParseTuple(args, "ll:Box.new", &arg0, &arg1)) {
box = new Box(arg0, arg1);
} else if (PyArg_ParseTuple(args, "llll:Box.new", &arg0, &arg1, &arg2, &arg3)) {
box = new Box(arg0, arg1, arg2, arg3);
HTRY
PyObject* arg0;
PyObject* arg1;
PyObject* arg2;
PyObject* arg3;
__cs.init ("Box.new");
if (! PyArg_ParseTuple(args,"|O&O&O&O&:Box.new",
Converter, &arg0,
Converter, &arg1,
Converter, &arg2,
Converter, &arg3)) {
return NULL;
}
if (__cs.getObjectIds() == NO_ARG) { box = new Box (); }
else if ( __cs.getObjectIds() == POINT_ARG ) { box = new Box ( *PYPOINT_O(arg0) ); }
else if ( __cs.getObjectIds() == BOX_ARG ) { box = new Box ( *PYBOX_O(arg0) ); }
else if ( __cs.getObjectIds() == POINTS2_ARG ) { box = new Box ( *PYPOINT_O(arg0) , *PYPOINT_O(arg1) ); }
else if ( __cs.getObjectIds() == INTS2_ARG ) { box = new Box ( PyInt_AsLong(arg0) , PyInt_AsLong(arg1) ); }
else if ( __cs.getObjectIds() == INTS4_ARG ) {
box = new Box ( PyInt_AsLong(arg0), PyInt_AsLong(arg1), PyInt_AsLong(arg2) , PyInt_AsLong(arg3) );
} else {
PyErr_SetString(ConstructorError, "invalid number of parameters for Box constructor." );
return ( NULL );
return NULL;
}
pyBox = PyObject_NEW(PyBox, &PyTypeBox);
if (pyBox == NULL) return NULL;
pyBox->_object = box;
HCATCH
return (PyObject*)pyBox;
return ( (PyObject*)pyBox );
}
// x-------------------------------------------------------------x
// | "PyBox" Object Methods |
// x-------------------------------------------------------------x

View File

@ -73,31 +73,92 @@ extern "C" {
static PyObject* PyHorizontal_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyHorizontal_new()" << endl;
PyObject* arg0;
PyObject* arg1;
PyObject* arg2;
PyObject* arg3;
PyObject* arg4;
PyObject* arg5;
PyObject* arg6;
Horizontal* horizontal = NULL;
HTRY
PyNet* pyNet=NULL;
PyComponent *pySource = NULL, *pyTarget = NULL;
PyLayer* pyLayer = NULL;
long y = 0, width = 0, dxSource = 0, dxTarget = 0;
if (PyArg_ParseTuple(args,"O!O!l|lll:Horizontal.New", &PyTypeNet, &pyNet,
&PyTypeLayer, &pyLayer, &y, &width, &dxSource, &dxTarget)) {
horizontal = Horizontal::create(PYNET_O(pyNet), PYLAYER_O(pyLayer), y, width, dxSource, dxTarget);
} else if (PyArg_ParseTuple(args,"O!O!O!l|lll:Horizontal.New",
&PyTypeComponent, &pySource, &PyTypeComponent, &pyTarget,
&PyTypeLayer, &pyLayer,
&y, &width, &dxSource, &dxTarget)) {
horizontal = Horizontal::create(PYCOMPONENT_O(pySource), PYCOMPONENT_O(pyTarget), PYLAYER_O(pyLayer),
y, width, dxSource, dxTarget);
} else {
__cs.init ("Horizontal.create");
if ( ! PyArg_ParseTuple(args,"O&O&O&|O&O&O&O&:Horizontal.create"
,Converter,&arg0
,Converter,&arg1
,Converter,&arg2
,Converter,&arg3
,Converter,&arg4
,Converter,&arg5
,Converter,&arg6
)) {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Horizontal constructor." );
return NULL;
}
if ( __cs.getObjectIds() == NET_LAYER_INT_ARG )
horizontal = Horizontal::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS2_ARG )
horizontal = Horizontal::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INT_ARG )
horizontal = Horizontal::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS3_ARG )
horizontal = Horizontal::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS2_ARG )
horizontal = Horizontal::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS4_ARG )
horizontal = Horizontal::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS3_ARG )
horizontal = Horizontal::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS4_ARG )
horizontal = Horizontal::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5)
, PyInt_AsLong(arg6) );
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Horizontal constructor." );
return NULL;
}
HCATCH
return PyHorizontal_Link ( horizontal );
}
DBoDeleteMethod(Horizontal)
PyTypeObjectLinkPyType(Horizontal)
PyTypeObjectConstructor(Horizontal)

View File

@ -126,18 +126,22 @@ extern "C" {
static PyObject* PyLibrary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyLibrary_new()" << endl;
PyObject* arg0;
PyObject* arg1;
Library* library = NULL;
HTRY
char* name = NULL;
PyDataBase* pyDataBase = NULL;
PyLibrary* pyRootLibrary = NULL;
if (PyArg_ParseTuple(args,"O!s:Library.new", &PyTypeDataBase, &pyDataBase, &name)) {
DataBase* db = PYDATABASE_O(pyDataBase);
library = Library::create(db, Name(name));
} else if (PyArg_ParseTuple(args,"O!s:Library.new", &PyTypeLibrary, &pyRootLibrary, &name)) {
Library* rootLibrary = PYLIBRARY_O(pyRootLibrary);
library = Library::create(rootLibrary, Name(name));
__cs.init ("Library.new");
if (!PyArg_ParseTuple(args,"O&O&:Library.new", Converter, &arg0, Converter, &arg1)) {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Library constructor." );
return NULL;
}
if (__cs.getObjectIds() == ":db:string") {
DataBase* db = PYDATABASE_O(arg0);
library = Library::create(db, Name(PyString_AsString(arg1)));
} else if (__cs.getObjectIds() == ":library:string") {
Library* masterLibrary = PYLIBRARY_O(arg0);
library = Library::create(masterLibrary, Name(PyString_AsString(arg1)));
} else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Library constructor." );
return NULL;

View File

@ -70,29 +70,88 @@ extern "C" {
static PyObject* PyVertical_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyVertical_new()" << endl;
PyObject* arg0;
PyObject* arg1;
PyObject* arg2;
PyObject* arg3;
PyObject* arg4;
PyObject* arg5;
PyObject* arg6;
Vertical* vertical = NULL;
HTRY
PyNet* pyNet=NULL;
PyComponent *pySource = NULL, *pyTarget = NULL;
PyLayer* pyLayer = NULL;
long x = 0, width = 0, dySource = 0, dyTarget = 0;
if (PyArg_ParseTuple(args,"O!O!l|lll:Vertical.New", &PyTypeNet, &pyNet,
&PyTypeLayer, &pyLayer, &x, &width, &dySource, &dyTarget)) {
vertical = Vertical::create(PYNET_O(pyNet), PYLAYER_O(pyLayer), x, width, dySource, dyTarget);
} else if (PyArg_ParseTuple(args,"O!O!O!l|lll:Vertical.New",
&PyTypeComponent, &pySource, &PyTypeComponent, &pyTarget,
&PyTypeLayer, &pyLayer,
&x, &width, &dySource, &dyTarget)) {
vertical = Vertical::create(PYCOMPONENT_O(pySource), PYCOMPONENT_O(pyTarget), PYLAYER_O(pyLayer),
x, width, dySource, dyTarget);
} else {
__cs.init ("Vertical.new");
if (!PyArg_ParseTuple(args,"O&O&O&|O&O&O&O&:Vertical.new"
,Converter,&arg0
,Converter,&arg1
,Converter,&arg2
,Converter,&arg3
,Converter,&arg4
,Converter,&arg5
,Converter,&arg6
)) {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Vertical constructor." );
return NULL;
}
HCATCH
return PyVertical_Link(vertical);
if ( __cs.getObjectIds() == NET_LAYER_INT_ARG )
vertical = Vertical::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS2_ARG )
vertical = Vertical::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INT_ARG )
vertical = Vertical::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS3_ARG )
vertical = Vertical::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS2_ARG )
vertical = Vertical::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4) );
else if ( __cs.getObjectIds() == NET_LAYER_INTS4_ARG )
vertical = Vertical::create ( PYNET_O(arg0)
, PYLAYER_O(arg1)
, PyInt_AsLong(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS3_ARG )
vertical = Vertical::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5) );
else if ( __cs.getObjectIds() == COMPS2_LAYER_INTS4_ARG )
vertical = Vertical::create ( ComponentCast(arg0)
, ComponentCast(arg1)
, PYLAYER_O(arg2)
, PyInt_AsLong(arg3)
, PyInt_AsLong(arg4)
, PyInt_AsLong(arg5)
, PyInt_AsLong(arg6) );
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Vertical constructor." );
return NULL;
}
HCATCH
return PyVertical_Link(vertical);
}
DBoDeleteMethod(Vertical)