coriolis/hurricane/src/isobar/PyPath.cpp

336 lines
10 KiB
C++
Raw Normal View History

2008-03-06 10:46:43 -06:00
// x-----------------------------------------------------------------x
// | |
// | C O R I O L I S |
// | I s o b a r - Hurricane / Python Interface |
// | |
// | Author : Jean-Paul CHAPUT |
// | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
// | =============================================================== |
// | C++ Module : "./PyPath.cpp" |
// | *************************************************************** |
// | U p d a t e s |
// | |
// x-----------------------------------------------------------------x
2008-11-30 14:33:42 -06:00
#include "hurricane/Cell.h"
using namespace Hurricane;
#include "hurricane/isobar/PyTransformation.h"
#include "hurricane/isobar/PyPath.h"
#include "hurricane/isobar/PyCell.h"
#include "hurricane/isobar/PyInstance.h"
2008-10-17 12:27:20 -05:00
#include "hurricane/isobar/PyInstanceCollection.h"
2008-03-06 10:46:43 -06:00
namespace Isobar {
extern "C" {
#define METHOD_HEAD(function) GENERIC_METHOD_HEAD(Path,path,function)
// x=================================================================x
// | "PyPath" Python Module Code Part |
// x=================================================================x
#if defined(__PYTHON_MODULE__)
// x-------------------------------------------------------------x
// | "PyPath" Attribute Methods |
// x-------------------------------------------------------------x
// Standart Accessors (Attributes).
// Standart Predicates (Attributes).
2008-04-02 07:11:31 -05:00
DirectGetBoolAttribute(PyPath_isEmpty ,isEmpty ,PyPath,Path)
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
// Standart Destroy (Attribute).
DirectDestroyAttribute(PyPath_destroy, PyPath)
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getHeadInstance ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getHeadInstance ( PyPath *self ) {
trace << "PyPath_getHeadInstance()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getHeadInstance()" )
2008-03-06 10:46:43 -06:00
Instance* instance = NULL;
HTRY
2008-03-17 08:54:33 -05:00
instance = path->getHeadInstance();
2008-03-06 10:46:43 -06:00
HCATCH
return PyInstance_Link ( instance );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getTailInstance ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getTailInstance ( PyPath *self ) {
trace << "PyPath_getTailInstance()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getTailInstance()" )
2008-03-06 10:46:43 -06:00
Instance* instance = NULL;
HTRY
2008-03-17 08:54:33 -05:00
instance = path->getTailInstance();
2008-03-06 10:46:43 -06:00
HCATCH
return PyInstance_Link ( instance );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getOwnerCell ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getOwnerCell ( PyPath *self ) {
trace << "PyPath_getOwnerCell()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getOwnerCell()" )
2008-03-06 10:46:43 -06:00
Cell* cell = NULL;
HTRY
2008-03-17 08:54:33 -05:00
cell = path->getOwnerCell();
2008-03-06 10:46:43 -06:00
HCATCH
return PyCell_Link ( cell );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getMasterCell ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getMasterCell ( PyPath *self ) {
trace << "PyPath_getMasterCell()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getMasterCell()" )
2008-03-06 10:46:43 -06:00
Cell* cell = NULL;
HTRY
2008-03-17 08:54:33 -05:00
cell = path->getMasterCell();
2008-03-06 10:46:43 -06:00
HCATCH
return PyCell_Link ( cell );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getName ()"
2008-03-06 10:46:43 -06:00
GetNameMethod(Path, path)
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getHeadPath ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getHeadPath ( PyPath *self ) {
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
trace << "PyPath_getHeadPath ()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getHeadPath()" )
2008-03-06 10:46:43 -06:00
PyPath* pyPath = PyObject_NEW ( PyPath, &PyTypePath );
if ( pyPath == NULL ) { return NULL; }
HTRY
2008-03-17 08:54:33 -05:00
pyPath->_object = new Path ( path->getHeadPath() );
2008-03-06 10:46:43 -06:00
HCATCH
return ( (PyObject*)pyPath );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getTailPath ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getTailPath ( PyPath *self )
2008-03-06 10:46:43 -06:00
{
2008-03-17 08:54:33 -05:00
trace << "PyPath_getTailPath ()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getTailPath()" )
2008-03-06 10:46:43 -06:00
PyPath* pyPath = PyObject_NEW ( PyPath, &PyTypePath );
if ( pyPath == NULL ) { return NULL; }
HTRY
2008-03-17 08:54:33 -05:00
pyPath->_object = new Path ( path->getTailPath() );
2008-03-06 10:46:43 -06:00
HCATCH
return ( (PyObject*)pyPath );
}
// ---------------------------------------------------------------
2008-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getTransformation ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getTransformation ( PyPath *self, PyObject* args )
2008-03-06 10:46:43 -06:00
{
2008-03-17 08:54:33 -05:00
trace << "PyPath_getTransformation ()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Instance.getTransformation()" );
2008-03-06 10:46:43 -06:00
PyObject* arg0;
PyTransformation* pyTransf = PyObject_NEW ( PyTransformation, &PyTypeTransformation );
if ( pyTransf == NULL ) { return NULL; }
2008-11-17 15:55:03 -06:00
__cs.init ("Path.getTransformation");
2008-03-17 08:54:33 -05:00
if ( ! PyArg_ParseTuple(args,"|O&:Path.getTransformation",Converter,&arg0) ) return ( NULL );
2008-03-06 10:46:43 -06:00
HTRY
2008-03-17 08:54:33 -05:00
if ( __cs.getObjectIds() == NO_ARG )
{ pyTransf->_object = new Transformation ( path->getTransformation () ); }
else if ( __cs.getObjectIds() == TRANS_ARG )
{ pyTransf->_object = new Transformation ( path->getTransformation (*PYTRANSFORMATION_O(arg0)) ); }
2008-03-06 10:46:43 -06:00
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Path constructor." );
return ( NULL );
}
HCATCH
return ( (PyObject*)pyTransf );
}
// ---------------------------------------------------------------
2008-10-17 12:27:20 -05:00
// Attribute Method : "PyPath_getInstances()"
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
static PyObject* PyPath_getInstances(PyPath *self) {
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
trace << "PyPath_getInstances()" << endl;
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
METHOD_HEAD ( "Path.getInstances()" )
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
PyInstanceCollection* pyInstanceCollection = NULL;
2008-03-06 10:46:43 -06:00
HTRY
2008-10-17 12:27:20 -05:00
Instances* instances = new Instances(path->getInstances());
2008-03-06 10:46:43 -06:00
2008-10-17 12:27:20 -05:00
pyInstanceCollection = PyObject_NEW(PyInstanceCollection, &PyTypeInstanceCollection);
if (pyInstanceCollection == NULL) {
return NULL;
}
pyInstanceCollection->_object = instances;
HCATCH
return (PyObject*)pyInstanceCollection;
2008-03-06 10:46:43 -06:00
}
// ---------------------------------------------------------------
// PyPath Attribute Method table.
PyMethodDef PyPath_Methods[] =
2008-03-17 08:54:33 -05:00
{ { "getHeadInstance" , (PyCFunction)PyPath_getHeadInstance , METH_NOARGS , "Return the head instance." }
, { "getTailInstance" , (PyCFunction)PyPath_getTailInstance , METH_NOARGS , "Return the tail instance." }
, { "getHeadPath" , (PyCFunction)PyPath_getHeadPath , METH_NOARGS , "Return the head path." }
, { "getTailPath" , (PyCFunction)PyPath_getTailPath , METH_NOARGS , "Return the tail path." }
, { "getOwnerCell" , (PyCFunction)PyPath_getOwnerCell , METH_NOARGS , "Return the cell owning the head instance." }
, { "getMasterCell" , (PyCFunction)PyPath_getMasterCell , METH_NOARGS , "Returns the master cell referenced by the last instance of the path." }
, { "getName" , (PyCFunction)PyPath_getName , METH_NOARGS , "Returns the concatenation of instances names." }
, { "getTransformation" , (PyCFunction)PyPath_getTransformation , METH_VARARGS, "Return the resulting transformation." }
2008-10-17 12:27:20 -05:00
, { "getInstances", (PyCFunction)PyPath_getInstances, METH_NOARGS , "Returns the collection of instances defining the path." }
2008-04-02 07:11:31 -05:00
, { "isEmpty" , (PyCFunction)PyPath_isEmpty , METH_NOARGS , "Return true if the path is empty." }
2008-03-17 08:54:33 -05:00
, { "destroy" , (PyCFunction)PyPath_destroy , METH_NOARGS
, "Destroy associated hurricane object, the python object remains." }
2008-03-06 10:46:43 -06:00
, {NULL, NULL, 0, NULL} /* sentinel */
};
// x-------------------------------------------------------------x
// | "PyPath" Object Methods |
// x-------------------------------------------------------------x
DirectDeleteMethod(PyPath_DeAlloc,PyPath)
PyTypeObjectLinkPyType(Path)
# else // End of Python Module Code Part.
// x=================================================================x
// | "PyPath" Shared Library Code Part |
// x=================================================================x
2008-03-06 10:46:43 -06:00
// ---------------------------------------------------------------
// Attribute Method : "PyPath_create ()"
2008-03-06 10:46:43 -06:00
PyObject* PyPath_create ( PyObject *module, PyObject *args ) {
trace << "PyPath_create()" << endl;
2008-03-06 10:46:43 -06:00
Path* path = NULL;
PyObject* arg0 = NULL;
PyObject* arg1 = NULL;
PyPath* pyPath = NULL;
__cs.init ("Path.create");
if ( ! PyArg_ParseTuple(args,"|O&O&:Path.create"
2008-03-06 10:46:43 -06:00
,Converter,&arg0
,Converter,&arg1
)) {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Path constructor." );
return NULL;
}
2008-03-06 10:46:43 -06:00
HTRY
2008-03-17 08:54:33 -05:00
if ( __cs.getObjectIds() == NO_ARG ) { path = new Path (); }
else if ( __cs.getObjectIds() == INST_ARG ) { path = new Path ( PYINSTANCE_O(arg0) ); }
else if ( __cs.getObjectIds() == INST_PATH_ARG ) { path = new Path ( PYINSTANCE_O(arg0)
2008-03-06 10:46:43 -06:00
, *PYPATH_O(arg1) ); }
2008-03-17 08:54:33 -05:00
else if ( __cs.getObjectIds() == PATH_INST_ARG ) { path = new Path ( *PYPATH_O(arg0)
2008-03-06 10:46:43 -06:00
, PYINSTANCE_O(arg1) ); }
2008-03-17 08:54:33 -05:00
else if ( __cs.getObjectIds() == CELL_STRING_ARG ) { path = new Path ( PYCELL_O(arg0)
2008-03-06 10:46:43 -06:00
, PyString_AsString(arg1) ); }
else {
PyErr_SetString ( ConstructorError, "invalid number of parameters for Path constructor." );
return ( NULL );
}
pyPath = PyObject_NEW(PyPath, &PyTypePath);
if (pyPath == NULL) return NULL;
pyPath->_object = path;
HCATCH
return ( (PyObject*)pyPath );
}
// ---------------------------------------------------------------
// PyPath Object Definitions.
PyTypeObjectDefinitions(Path)
2008-03-06 10:46:43 -06:00
#endif // End of Shared Library Code Part.
2008-03-06 10:46:43 -06:00
} // End of extern "C".
} // End of Isobar namespace.