Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / CppPythonConv.cxx
1
2 #include "CppPythonConv.hxx"
3 #include "TypeConversions.hxx"
4
5 #include <iostream>
6
7 //#define _DEVDEBUG_
8 #include "YacsTrace.hxx"
9
10 using namespace std;
11
12 namespace YACS 
13 {
14   namespace ENGINE
15   {
16
17     PyObject *convertCppPyObject(const TypeCode *t, Any *a)
18     {
19       return convertNeutralPyObject(t, (Any *) a);
20     }
21
22     CppPy::CppPy(InputPyPort* p)
23       : ProxyPort(p), DataPort(p->getName(), p->getNode(), p->edGetType()), Port(p->getNode())
24     {
25     }
26
27     //!Convert the received C++ value to PyObject * and send it to proxy port
28     /*!
29      *   \param data : C++ value received 
30      */
31     void CppPy::put(const void *data) throw(ConversionException)
32     {
33       put((Any *) data);
34     }
35
36     void CppPy::put(Any *data) throw(ConversionException)
37     {
38       DEBTRACE(" CppPython::put(Any *data)");
39       PyObject *ob;
40       InterpreterUnlocker l;
41       ob=convertCppPyObject(edGetType(), data);
42 #ifdef _DEVDEBUG_
43       PyObject_Print(ob,stderr,Py_PRINT_RAW);
44       std::cerr << std::endl;
45 #endif
46       DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
47       _port->put(ob);
48       Py_DECREF(ob);
49       DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
50     }
51
52     int isAdaptablePyObjectCpp(const TypeCode *t1, const TypeCode *t2)
53     {
54       return isAdaptablePyObjectNeutral(t1, t2);
55     }
56
57   }
58 }