coriolis/hurricane/src/isobar/PyPath.cpp

383 lines
12 KiB
C++
Raw Normal View History

2008-03-06 10:46:43 -06:00
// -*- C++ -*-
//
// This file is part of the Coriolis Project.
// Copyright (C) Laboratoire LIP6 - Departement ASIM
// Universite Pierre et Marie Curie
//
// Main contributors :
// Christophe Alexandre <Christophe.Alexandre@lip6.fr>
// Sophie Belloeil <Sophie.Belloeil@lip6.fr>
// Hugo Cl<43>ment <Hugo.Clement@lip6.fr>
// Jean-Paul Chaput <Jean-Paul.Chaput@lip6.fr>
// Damien Dupuis <Damien.Dupuis@lip6.fr>
// Christian Masson <Christian.Masson@lip6.fr>
// Marek Sroka <Marek.Sroka@lip6.fr>
//
// The Coriolis Project is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// The Coriolis Project is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the Coriolis Project; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
// License-Tag
// Authors-Tag
// ===================================================================
//
// $Id: PyPath.cpp,v 1.6 2006/09/22 11:27:32 tsunami Exp $
//
// 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
#include "hurricane/isobar/PyTransformation.h"
#include "hurricane/isobar/PyName.h"
#include "hurricane/isobar/PyPath.h"
#include "hurricane/isobar/PyCell.h"
#include "hurricane/isobar/PyInstance.h"
#include "hurricane/isobar/PyInstanceLocator.h"
2008-03-06 10:46:43 -06:00
namespace Isobar {
2008-03-28 04:48:47 -05:00
using namespace Hurricane;
2008-03-06 10:46:43 -06:00
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
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getName ( PyPath *self ) {
trace << "PyPath_getName ()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getName()" )
2008-03-06 10:46:43 -06:00
PyName* pyName = PyObject_NEW ( PyName, &PyTypeName );
if ( pyName == NULL ) { return NULL; }
HTRY
2008-03-17 08:54:33 -05:00
pyName->_object = new Name ( path->getName() );
2008-03-06 10:46:43 -06:00
HCATCH
return ( (PyObject*)pyName );
}
// ---------------------------------------------------------------
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-03-17 08:54:33 -05:00
__cs.Init ("Path.getTransformation");
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-03-17 08:54:33 -05:00
// Attribute Method : "PyPath_getInstancesLocator ()"
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
static PyObject* PyPath_getInstancesLocator ( PyPath *self )
2008-03-06 10:46:43 -06:00
{
2008-03-17 08:54:33 -05:00
trace << "PyPath_getInstancesLocator ()" << endl;
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
METHOD_HEAD ( "Path.getInstancesLocator()" )
2008-03-06 10:46:43 -06:00
2008-03-17 08:54:33 -05:00
Instances instances = path->getInstances ();
2008-03-06 10:46:43 -06:00
PyInstanceLocator* pyInstanceLocator = PyObject_NEW ( PyInstanceLocator, &PyTypeInstanceLocator );
if (pyInstanceLocator == NULL) { return NULL; }
HTRY
2008-03-17 08:54:33 -05:00
pyInstanceLocator->_object = instances.getLocator ();
2008-03-06 10:46:43 -06:00
HCATCH
return ( (PyObject*)pyInstanceLocator );
}
// ---------------------------------------------------------------
// 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." }
, { "getInstancesLocator", (PyCFunction)PyPath_getInstancesLocator, 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
// ---------------------------------------------------------------
// Attribute Method : "PyPath_new ()"
static PyObject* PyPath_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
trace << "PyPath_new()" << endl;
Path* path = NULL;
PyObject* arg0 = NULL;
PyObject* arg1 = NULL;
PyPath* pyPath = NULL;
__cs.Init ("Path.new");
if ( ! PyArg_ParseTuple(args,"|O&O&:Path.new"
,Converter,&arg0
,Converter,&arg1
) ) return ( NULL );
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 );
}
DirectDeleteMethod(PyPath_DeAlloc,PyPath)
PyTypeObjectLinkPyType(Path)
PyTypeObjectConstructor(Path)
# else // End of Python Module Code Part.
// x=================================================================x
// | "PyPath" Shared Library Code Part |
// x=================================================================x
// ---------------------------------------------------------------
// 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.