Version: 9.15.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)
 
void releaseData () override
 
void put (PyObject *data)
 
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
 
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
 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...
 
bool canSafelySqueezeMemory () const
 
bool isBackLinked () const
 
virtual ~InPort ()
 

Protected Member Functions

void releaseDataUnsafe ()
 
- 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)
 
void releaseDataUnsafe ()
 
- Protected Member Functions inherited from YACS::ENGINE::DataFlowPort
 DataFlowPort (const DataFlowPort &other, Node *newHelder)
 
 DataFlowPort (const std::string &name, Node *node, TypeCode *type)
 
- Protected Member Functions inherited from YACS::ENGINE::DataPort
virtual ~DataPort ()
 
 DataPort (const DataPort &other, Node *newHelder)
 
 DataPort (const std::string &name, Node *node, TypeCode *type)
 
- Protected Member Functions inherited from YACS::ENGINE::Port
 Port (Node *node)
 
 Port (const Port &other, Node *newHelder)
 
- Protected Member Functions inherited from YACS::ENGINE::InPort
 InPort (const InPort &other, Node *newHelder)
 
 InPort (const std::string &name, Node *node, TypeCode *type)
 
void edRemoveAllLinksLinkedWithMe ()
 
virtual void edNotifyReferencedBy (OutPort *fromPort, bool isLoopProof=true)
 
virtual void edNotifyDereferencedBy (OutPort *fromPort)
 
virtual void getAllRepresentants (std::set< InPort * > &repr) const
 

Protected Attributes

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

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"
 
- Static Public Attributes inherited from YACS::ENGINE::DataFlowPort
static const char NAME [] ="DataFlowPort"
 
- Static Public Attributes inherited from YACS::ENGINE::DataPort
static const char NAME [] ="DataPort"
 
- 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() [1/2]

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

Definition at line 84 of file PythonPorts.cxx.

85  : InputPort(name, node, type)
86  , DataPort(name, node, type)
87  , Port(node)
88  , _data(Py_None)
89  ,_initData(nullptr)
90  ,_isEmpty(true)
91 {
92  Py_INCREF(_data);
93 }
DataPort(const DataPort &other, Node *newHelder)
Definition: DataPort.cxx:41
InputPort(const InputPort &other, Node *newHelder)
Definition: InputPort.cxx:36
Port(Node *node)
Definition: Port.cxx:34

References _data.

Referenced by clone().

◆ InputPyPort() [2/2]

InputPyPort::InputPyPort ( const InputPyPort other,
Node newHelder 
)

Definition at line 106 of file PythonPorts.cxx.

106  :InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder)
107 {
108  _initData=other._initData;
109  Py_XINCREF(_initData);
110  _data=other._data;
111  Py_INCREF(_data);
112  _isEmpty=other._isEmpty;
113 }

References _data, _initData, and _isEmpty.

◆ ~InputPyPort()

InputPyPort::~InputPyPort ( )

Definition at line 94 of file PythonPorts.cxx.

95 {
96  PyGILState_STATE gstate = PyGILState_Ensure();
97  DEBTRACE( "_data refcnt: " << (_data ? _data->ob_refcnt : -1) );
98  DEBTRACE( "_initData refcnt: " << (_initData ? _initData->ob_refcnt : -1));
99  // Release or not release : all GenericObj are deleted when the input port is deleted
101  Py_XDECREF(_data);
102  Py_XDECREF(_initData);
103  PyGILState_Release(gstate);
104 }
void releasePyObj(PyObject *data)
Definition: PythonPorts.cxx:74
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

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

Member Function Documentation

◆ clone()

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

Implements YACS::ENGINE::InputPort.

Definition at line 161 of file PythonPorts.cxx.

162 {
163  return new InputPyPort(*this,newHelder);
164 }
InputPyPort(const std::string &name, Node *node, TypeCode *type)
Definition: PythonPorts.cxx:84

References InputPyPort().

◆ dump()

std::string InputPyPort::dump ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 238 of file PythonPorts.cxx.

239 {
240  if( _isEmpty)
241  return "<value>None</value>";
242 
245 }
TypeCode * edGetType() const
Definition: DataPort.hxx:53
std::string convertPyObjectXml(const TypeCode *t, PyObject *data)

References _data, _isEmpty, YACS::ENGINE::convertPyObjectXml(), YACS::ENGINE::DataPort::edGetType(), and testCppPluginInvokation::l.

Referenced by getHumanRepr().

◆ edIsManuallyInitialized()

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 115 of file PythonPorts.cxx.

116 {
117  return _initData!=nullptr;
118 }

References _initData.

◆ edRemoveManInit()

void InputPyPort::edRemoveManInit ( )
virtual

Removes eventually previous manual initialisation.

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 120 of file PythonPorts.cxx.

121 {
122  Py_XDECREF(_initData);
123  _initData=nullptr;
124  Py_XDECREF(_data);
125  _data=Py_None;
126  Py_INCREF(_data);
127  _isEmpty=true;
129 }
virtual void edRemoveManInit()
Removes eventually previous manual initialisation.
Definition: InputPort.cxx:140

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

◆ exRestoreInit()

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 227 of file PythonPorts.cxx.

228 {
229  if(!_initData)return;
230  Py_XDECREF(_data);
232  Py_XINCREF(_data);
233  _isEmpty = false;
234  DEBTRACE( "_initData.ob refcnt: " << _initData->ob_refcnt );
235  DEBTRACE( "_data.ob refcnt: " << _data->ob_refcnt );
236 }

References _data, _initData, _isEmpty, and DEBTRACE.

◆ exSaveInit()

void InputPyPort::exSaveInit ( )
virtual

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

Implements YACS::ENGINE::InputPort.

Definition at line 211 of file PythonPorts.cxx.

212 {
213  // Interpreter lock seems necessary when deleting lists in Python 2.7
214  PyGILState_STATE gstate = PyGILState_Ensure();
215  Py_XDECREF(_initData);
217  Py_INCREF(_initData);
218  PyGILState_Release(gstate);
219  DEBTRACE( "_initData.ob refcnt: " << (_initData ? _initData->ob_refcnt : -1));
220  DEBTRACE( "_data.ob refcnt: " << _data->ob_refcnt );
221 }

References _data, _initData, and DEBTRACE.

◆ get()

void * InputPyPort::get ( ) const
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 171 of file PythonPorts.cxx.

172 {
173  return (void*) _data;
174 }

References _data.

◆ getAsString()

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 176 of file PythonPorts.cxx.

177 {
178  std::string ret;
179  //protect _data against modification or delete in another thread
180  PyObject* data=_data;
181  Py_INCREF(data);
182  ret = convertPyObjectToString(data);
183  Py_XDECREF(data);
184  return ret;
185 }
std::string convertPyObjectToString(PyObject *ob)

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

◆ getHumanRepr()

std::string InputPyPort::getHumanRepr ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 187 of file PythonPorts.cxx.

188 {
189  if(!_data)
190  return dump();
191  PyObject *ret(PyObject_Str(_data));
192  if(!ret)
193  return dump();
194  std::string retCpp;
195  char *val(PyBytes_AsString(ret));
196  if(val)
197  retCpp=val;
198  Py_XDECREF(ret);
199  return retCpp;
200 }
virtual std::string dump()

References _data, and dump().

◆ getPyObj()

PyObject * InputPyPort::getPyObj ( ) const
virtual

Definition at line 166 of file PythonPorts.cxx.

167 {
168  return _data;
169 }

References _data.

Referenced by valToStr().

◆ isEmpty()

bool InputPyPort::isEmpty ( )
virtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 202 of file PythonPorts.cxx.

203 {
204  return _isEmpty;
205 }

References _isEmpty.

◆ put() [1/2]

void InputPyPort::put ( const void *  data)
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 131 of file PythonPorts.cxx.

132 {
133  put((PyObject *)data);
134 }
virtual void put(const void *data)

Referenced by YACS::ENGINE::PythonNode::squeezeMemory(), and YACS::ENGINE::PythonNode::squeezeMemoryRemote().

◆ put() [2/2]

void InputPyPort::put ( PyObject *  data)

Definition at line 149 of file PythonPorts.cxx.

150 {
153  _data = data;
154  _stringRef="";
155  Py_INCREF(_data);
157  _isEmpty=false;
158  DEBTRACE( "_data refcnt: " << _data->ob_refcnt );
159 }
void registerPyObj(PyObject *data)
Definition: PythonPorts.cxx:79
std::string _stringRef
Definition: InputPort.hxx:90

References _data, _isEmpty, YACS::ENGINE::InputPort::_stringRef, DEBTRACE, testCppPluginInvokation::l, registerPyObj(), and releaseDataUnsafe().

◆ releaseData()

void InputPyPort::releaseData ( )
overridevirtual

Implements YACS::ENGINE::InputPort.

Definition at line 143 of file PythonPorts.cxx.

144 {
147 }

References testCppPluginInvokation::l, and releaseDataUnsafe().

◆ releaseDataUnsafe()

void InputPyPort::releaseDataUnsafe ( )
protected

Definition at line 136 of file PythonPorts.cxx.

137 {
139  Py_XDECREF(_data);
140  _data = nullptr;
141 }

References _data, and releasePyObj().

Referenced by put(), and releaseData().

◆ typeName()

virtual std::string YACS::ENGINE::InputPyPort::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 94 of file PythonPorts.hxx.

94 {return "YACS__ENGINE__InputPyPort";}

◆ valFromStr()

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 261 of file PythonPorts.cxx.

262 {
263 }

◆ valToStr()

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 247 of file PythonPorts.cxx.

248 {
249  int isString = PyBytes_Check(getPyObj());
250  //DEBTRACE("isString=" << isString);
251  PyObject *strPyObj = PyObject_Str(getPyObj());
252  //DEBTRACE(PyString_Size(strPyObj));
253  string val = PyBytes_AsString(strPyObj);
254  if (isString)
255  val = "\"" + val + "\"";
256  //DEBTRACE(val);
257  Py_DECREF(strPyObj);
258  return val;
259 }
virtual PyObj * getPyObj() const

References getPyObj().

Member Data Documentation

◆ _data

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

◆ _initData

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

◆ _isEmpty

bool YACS::ENGINE::InputPyPort::_isEmpty
protected

Definition at line 102 of file PythonPorts.hxx.

Referenced by dump(), edRemoveManInit(), exRestoreInit(), InputPyPort(), isEmpty(), and put().


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