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

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

View File

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

View File

@ -126,22 +126,26 @@ extern "C" {
static PyObject* PyLibrary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { static PyObject* PyLibrary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyLibrary_new()" << endl; trace << "PyLibrary_new()" << endl;
PyObject* arg0;
PyObject* arg1;
Library* library = NULL; Library* library = NULL;
HTRY HTRY
char* name = NULL; __cs.init ("Library.new");
PyDataBase* pyDataBase = NULL; if (!PyArg_ParseTuple(args,"O&O&:Library.new", Converter, &arg0, Converter, &arg1)) {
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));
} else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Library constructor." ); PyErr_SetString ( ConstructorError, "invalid number of parameters for Library constructor." );
return NULL; 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;
}
HCATCH HCATCH
return PyLibrary_Link ( library ); return PyLibrary_Link ( library );

View File

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