Version: 8.3.0
YACS::ENGINE::InputPyPort Class Reference

Class for Python Ports. More...

#include <PythonPorts.hxx>

Inheritance diagram for YACS::ENGINE::InputPyPort:
Collaboration diagram for YACS::ENGINE::InputPyPort:

Public Member Functions

 InputPyPort (const std::string &name, Node *node, TypeCode *type)
 
 InputPyPort (const InputPyPort &other, Node *newHelder)
 
 ~InputPyPort ()
 
bool edIsManuallyInitialized () const
 Specifies if this port has been manually set by the call of InputPort::edInit. More...
 
void edRemoveManInit ()
 Removes eventually previous manual initialisation. More...
 
virtual void put (const void *data) throw (ConversionException)
 
void put (PyObject *data) throw (ConversionException)
 
InputPortclone (Node *newHelder) const
 
virtual PyObjgetPyObj () const
 
virtual std::string getAsString ()
 returns port value as a string that can be used in a GUI for example More...
 
void * get () const throw (Exception)
 
virtual std::string getHumanRepr ()
 
virtual bool isEmpty ()
 
virtual void exSaveInit ()
 Save the current data value for further reinitialization of the port. More...
 
virtual void exRestoreInit ()
 Restore the saved data value to current data value. More...
 
virtual std::string dump ()
 
virtual std::string typeName ()
 
virtual std::string valToStr ()
 Gives a string representation of the data, for user interfaces. More...
 
virtual void valFromStr (std::string valstr)
 Allows to set data from a string representation used in user interface. More...
 
- Public Member Functions inherited from YACS::ENGINE::InputPort
virtual ~InputPort ()
 
std::string getNameOfTypeOfCurrentInstance () const
 
virtual InputPortgetPublicRepresentant ()
 returns the final physical port behind 'this'. More...
 
virtual bool isIntermediate () const
 
bool edIsInitialized () const
 soon deprecated More...
 
template<class T >
void edInit (T value)
 
void edInit (Any *value)
 
void edInit (const std::string &impl, const void *value)
 Initialize the port with an object (value) coming from a world with implementation impl. More...
 
virtual void checkBasicConsistency () const throw (Exception)
 Check basically that this port has one chance to be specified on time. It's a necessary condition not sufficient at all. More...
 
virtual void exInit (bool start)
 
virtual void setStringRef (std::string strRef)
 
bool canBeNull () const
 
- Public Member Functions inherited from YACS::ENGINE::DataFlowPort
TypeOfChannel getTypeOfChannel () const
 returns type of channel the port will use for data exchange on runtime : DATAFLOW or DATASTREAM. More...
 
virtual ~DataFlowPort ()
 
- Public Member Functions inherited from YACS::ENGINE::DataPort
TypeCodeedGetType () const
 
void edSetType (TypeCode *type)
 
std::string getName () const
 
void setName (std::string theName)
 
bool isDifferentTypeOf (const DataPort *other) const
 
- Public Member Functions inherited from YACS::ENGINE::Port
virtual ~Port ()
 
NodegetNode () const
 
int getNumId () const
 
void modified ()
 
- Public Member Functions inherited from YACS::ENGINE::InPort
virtual int edGetNumberOfLinks () const
 Returns number of physical backlinks NOT number of user backlinks. More...
 
virtual std::set< OutPort * > edSetOutPort () const
 Returns physical backlinks NOT user backlinks. More...
 
virtual ~InPort ()
 

Protected Attributes

PyObject * _data
 
PyObject * _initData
 
- Protected Attributes inherited from YACS::ENGINE::InputPort
Any_initValue
 
std::string _stringRef
 
bool _canBeNull
 
- Protected Attributes inherited from YACS::ENGINE::InPort
std::set< OutPort * > _backLinks
 
- Protected Attributes inherited from YACS::ENGINE::DataPort
TypeCode_type
 
std::string _name
 
- Protected Attributes inherited from YACS::ENGINE::Port
Node_node
 
int _id
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::DataPort
static DataPortisCrossingType (const std::vector< DataPort * > &historyOfLink)
 
- Static Public Attributes inherited from YACS::ENGINE::InputPort
static const char NAME [] ="InputPort"
 
- Protected Member Functions inherited from YACS::ENGINE::InputPort
 InputPort (const InputPort &other, Node *newHelder)
 
 InputPort (const std::string &name, Node *node, TypeCode *type, bool canBeNull=false)
 
- Static Protected Attributes inherited from YACS::ENGINE::Port
static int _total = 0
 
static const char NAME [] ="Port"
 

Detailed Description

Class for Python Ports.

See Also
PythonNode

Definition at line 73 of file PythonPorts.hxx.

Constructor & Destructor Documentation

InputPyPort::InputPyPort ( const std::string &  name,
Node node,
TypeCode type 
)

Definition at line 108 of file PythonPorts.cxx.

References _data, and _initData.

Referenced by clone().

109  : InputPort(name, node, type), DataPort(name, node, type), Port(node), _data(Py_None),_initData(Py_None)
110 {
111  Py_INCREF(_data);
112  Py_INCREF(_initData);
113 }
InputPyPort::InputPyPort ( const InputPyPort other,
Node newHelder 
)

Definition at line 126 of file PythonPorts.cxx.

References _data, and _initData.

126  :InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder)
127 {
128  _initData=other._initData;
129  Py_INCREF(_initData);
130  _data=other._data;
131  Py_INCREF(_data);
132 }
InputPyPort::~InputPyPort ( )

Definition at line 114 of file PythonPorts.cxx.

References _data, _initData, DEBTRACE, and releasePyObj().

115 {
116  PyGILState_STATE gstate = PyGILState_Ensure();
117  DEBTRACE( "_data refcnt: " << _data->ob_refcnt );
118  DEBTRACE( "_initData refcnt: " << _initData->ob_refcnt );
119  // Release or not release : all GenericObj are deleted when the input port is deleted
121  Py_XDECREF(_data);
122  Py_XDECREF(_initData);
123  PyGILState_Release(gstate);
124 }

Member Function Documentation

InputPort * InputPyPort::clone ( Node newHelder) const
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 167 of file PythonPorts.cxx.

References InputPyPort().

168 {
169  return new InputPyPort(*this,newHelder);
170 }
std::string InputPyPort::dump ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 243 of file PythonPorts.cxx.

References _data, YACS::ENGINE::InputPort::_stringRef, YACS::ENGINE::convertPyObjectXml(), YACS::ENGINE::DataPort::edGetType(), and YACS::ENGINE::Objref.

Referenced by getHumanRepr().

244 {
245  if( _data == Py_None)
246  return "<value>None</value>";
247 
249  if (edGetType()->kind() != YACS::ENGINE::Objref)
251  if (! _stringRef.empty())
252  return _stringRef;
253  else
255 // {
256 // stringstream msg;
257 // msg << "Cannot retreive init reference string for port " << _name
258 // << " on node " << _node->getName();
259 // throw Exception(msg.str());
260 // }
261 }
bool InputPyPort::edIsManuallyInitialized ( ) const
virtual

Specifies if this port has been manually set by the call of InputPort::edInit.

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 134 of file PythonPorts.cxx.

References _initData.

135 {
136  return _initData!=Py_None;
137 }
void InputPyPort::edRemoveManInit ( )
virtual

Removes eventually previous manual initialisation.

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 139 of file PythonPorts.cxx.

References _data, _initData, and YACS::ENGINE::InputPort::edRemoveManInit().

140 {
141  Py_XDECREF(_initData);
142  _initData=Py_None;
143  Py_INCREF(_initData);
144  Py_XDECREF(_data);
145  _data=Py_None;
146  Py_INCREF(_data);
148 }
void InputPyPort::exRestoreInit ( )
virtual

Restore the saved data value to current data value.

If no data has been saved (_initData == 0) don't restore

Implements YACS::ENGINE::InputPort.

Definition at line 233 of file PythonPorts.cxx.

References _data, _initData, and DEBTRACE.

234 {
235  if(!_initData)return;
236  Py_XDECREF(_data);
238  Py_INCREF(_data);
239  DEBTRACE( "_initData.ob refcnt: " << _initData->ob_refcnt );
240  DEBTRACE( "_data.ob refcnt: " << _data->ob_refcnt );
241 }
void InputPyPort::exSaveInit ( )
virtual

Save the current data value for further reinitialization of the port.

Implements YACS::ENGINE::InputPort.

Definition at line 217 of file PythonPorts.cxx.

References _data, _initData, and DEBTRACE.

218 {
219  // Interpreter lock seems necessary when deleting lists in Python 2.7
220  PyGILState_STATE gstate = PyGILState_Ensure();
221  Py_XDECREF(_initData);
222  PyGILState_Release(gstate);
224  Py_INCREF(_initData);
225  DEBTRACE( "_initData.ob refcnt: " << _initData->ob_refcnt );
226  DEBTRACE( "_data.ob refcnt: " << _data->ob_refcnt );
227 }
void * InputPyPort::get ( ) const throw (Exception)
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 177 of file PythonPorts.cxx.

References _data.

178 {
179  return (void*) _data;
180 }
std::string InputPyPort::getAsString ( )
virtual

returns port value as a string that can be used in a GUI for example

Do nothing here. To subclass

Reimplemented from YACS::ENGINE::DataPort.

Definition at line 182 of file PythonPorts.cxx.

References _data, YACS::ENGINE::convertPyObjectToString(), and PMMLBasicsTestLauncher::ret.

183 {
184  std::string ret;
185  //protect _data against modification or delete in another thread
186  PyObject* data=_data;
187  Py_INCREF(data);
188  ret = convertPyObjectToString(data);
189  Py_XDECREF(data);
190  return ret;
191 }
std::string InputPyPort::getHumanRepr ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 193 of file PythonPorts.cxx.

References _data, dump(), and PMMLBasicsTestLauncher::ret.

194 {
195  if(!_data)
196  return dump();
197  PyObject *ret(PyObject_Str(_data));
198  if(!ret)
199  return dump();
200  std::string retCpp;
201  char *val(PyString_AsString(ret));
202  if(val)
203  retCpp=val;
204  Py_XDECREF(ret);
205  return retCpp;
206 }
bool InputPyPort::isEmpty ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 208 of file PythonPorts.cxx.

References _data.

209 {
210  return _data == Py_None;
211 }
void InputPyPort::put ( const void *  data) throw (ConversionException)
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 150 of file PythonPorts.cxx.

151 {
152  put((PyObject *)data);
153 }
void InputPyPort::put ( PyObject *  data) throw (ConversionException)

Definition at line 155 of file PythonPorts.cxx.

References DEBTRACE, registerPyObj(), and releasePyObj().

156 {
159  Py_XDECREF(_data);
160  _data = data;
161  _stringRef="";
162  Py_INCREF(_data);
164  DEBTRACE( "_data refcnt: " << _data->ob_refcnt );
165 }
virtual std::string YACS::ENGINE::InputPyPort::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 93 of file PythonPorts.hxx.

93 {return "YACS__ENGINE__InputPyPort";}
void InputPyPort::valFromStr ( std::string  valstr)
virtual

Allows to set data from a string representation used in user interface.

Implemented in derived classes, depending on runtime, to set the data from its user interface representation. Typical use, a Python string representation that can be used in edition or restitution.

Reimplemented from YACS::ENGINE::DataFlowPort.

Definition at line 277 of file PythonPorts.cxx.

278 {
279 }
std::string InputPyPort::valToStr ( )
virtual

Gives a string representation of the data, for user interfaces.

Implemented in derived classes, depending on runtime, to provide the data representation for user interfaces. Typical use, a Python string representation that can be used in edition or restitution.

Reimplemented from YACS::ENGINE::DataFlowPort.

Definition at line 263 of file PythonPorts.cxx.

References getPyObj().

264 {
265  int isString = PyString_Check(getPyObj());
266  //DEBTRACE("isString=" << isString);
267  PyObject *strPyObj = PyObject_Str(getPyObj());
268  //DEBTRACE(PyString_Size(strPyObj));
269  string val = PyString_AsString(strPyObj);
270  if (isString)
271  val = "\"" + val + "\"";
272  //DEBTRACE(val);
273  Py_DECREF(strPyObj);
274  return val;
275 }

Member Data Documentation

PyObject* YACS::ENGINE::InputPyPort::_data
protected
PyObject* YACS::ENGINE::InputPyPort::_initData
protected

The documentation for this class was generated from the following files: