]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/NeutralPythonConv.cxx
Salome HOME
add83cb4759933eef90035cd06335d797c9ff5f4
[modules/yacs.git] / src / runtime / NeutralPythonConv.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "TypeConversions.hxx"
20 #include "NeutralPythonConv.hxx"
21 #include "RuntimeSALOME.hxx"
22
23 #include <iostream>
24 #include <string>
25
26 //#define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace YACS::ENGINE;
30 using namespace std;
31
32 void NeutralPyDouble::put(const void *data) throw(ConversionException)
33 {
34   put((YACS::ENGINE::Any *)data);
35 }
36
37 //!Convert a YACS::ENGINE::Any (double) to a PyObject (PyFloat)
38 /*!
39  *   \param data : YACS::ENGINE::Any object
40  */
41 void NeutralPyDouble::put(YACS::ENGINE::Any *data) throw(ConversionException)
42 {
43   InterpreterUnlocker loc;
44   PyObject* ob=convertNeutralPyObject(edGetType(),data);
45   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
46   _port->put(ob);
47   Py_DECREF(ob);
48 }
49
50
51 void NeutralPyInt::put(const void *data) throw(ConversionException)
52 {
53   put((YACS::ENGINE::Any *)data);
54 }
55
56 //!Convert a YACS::ENGINE::Any (integer) to a PyObject (PyLong)
57 /*!
58  *   \param data : YACS::ENGINE::Any object
59  */
60 void NeutralPyInt::put(YACS::ENGINE::Any *data) throw(ConversionException)
61 {
62   InterpreterUnlocker loc;
63   PyObject* ob=convertNeutralPyObject(edGetType(),data);
64   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
65   _port->put(ob);
66   Py_DECREF(ob);
67 }
68
69 void NeutralPyString::put(const void *data) throw(ConversionException)
70 {
71   put((YACS::ENGINE::Any *)data);
72 }
73
74 //!Convert a YACS::ENGINE::Any (string) to a PyObject (PyString)
75 /*!
76  *   \param data : YACS::ENGINE::Any object
77  */
78 void NeutralPyString::put(YACS::ENGINE::Any *data) throw(ConversionException)
79 {
80   InterpreterUnlocker loc;
81   PyObject* ob=convertNeutralPyObject(edGetType(),data);
82   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
83   _port->put(ob);
84   Py_DECREF(ob);
85 }
86
87 void NeutralPyBool::put(const void *data) throw(ConversionException)
88 {
89   put((YACS::ENGINE::Any *)data);
90 }
91
92 //!Convert a YACS::ENGINE::Any (bool) to a PyObject (PyLong)
93 /*!
94  *   \param data : YACS::ENGINE::Any object
95  */
96 void NeutralPyBool::put(YACS::ENGINE::Any *data) throw(ConversionException)
97 {
98   InterpreterUnlocker loc;
99   PyObject* ob=convertNeutralPyObject(edGetType(),data);
100   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
101   _port->put(ob);
102   Py_DECREF(ob);
103 }
104
105 void NeutralPyObjref::put(const void *data) throw(ConversionException)
106 {
107   put((YACS::ENGINE::Any *)data);
108 }
109
110 //!Convert a Neutral::Any Objref to a PyObject Objref
111 /*!
112  *   \param data : Neutral::Any object
113  */
114 void NeutralPyObjref::put(YACS::ENGINE::Any *data) throw(ConversionException)
115 {
116   InterpreterUnlocker loc;
117   PyObject* ob=convertNeutralPyObject(edGetType(),data);
118   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
119   _port->put(ob);
120   Py_DECREF(ob);
121   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
122 }
123
124 void NeutralPySequence::put(const void *data) throw(ConversionException)
125 {
126   put((YACS::ENGINE::Any *)data);
127 }
128
129 //!Convert a Neutral::Any sequence to a PyObject Sequence
130 /*!
131  *   \param data : Neutral::Any object
132  */
133 void NeutralPySequence::put(YACS::ENGINE::Any *data) throw(ConversionException)
134 {
135   DEBTRACE( "--------NeutralPySequence::put" );
136   InterpreterUnlocker loc;
137   PyObject* ob=convertNeutralPyObject(edGetType(),data);
138   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
139 #ifdef _DEVDEBUG_
140   cerr << "Sequence= ";
141   PyObject_Print(ob,stderr,Py_PRINT_RAW);
142   cerr << endl;
143 #endif
144   _port->put(ob);
145   Py_DECREF(ob);
146   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
147 }
148
149