Salome HOME
Merge branch V7_3_1_BR
[modules/yacs.git] / src / runtime / NeutralPythonConv.cxx
1 // Copyright (C) 2006-2014  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, or (at your option) any later version.
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
20 #include "TypeConversions.hxx"
21 #include "NeutralPythonConv.hxx"
22 #include "RuntimeSALOME.hxx"
23
24 #include <iostream>
25 #include <string>
26
27 //#define _DEVDEBUG_
28 #include "YacsTrace.hxx"
29
30 using namespace YACS::ENGINE;
31 using namespace std;
32
33 void NeutralPyDouble::put(const void *data) throw(ConversionException)
34 {
35   put((YACS::ENGINE::Any *)data);
36 }
37
38 //!Convert a YACS::ENGINE::Any (double) to a PyObject (PyFloat)
39 /*!
40  *   \param data : YACS::ENGINE::Any object
41  */
42 void NeutralPyDouble::put(YACS::ENGINE::Any *data) throw(ConversionException)
43 {
44   InterpreterUnlocker loc;
45   PyObject* ob=convertNeutralPyObject(edGetType(),data);
46   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
47   _port->put(ob);
48   Py_DECREF(ob);
49 }
50
51
52 void NeutralPyInt::put(const void *data) throw(ConversionException)
53 {
54   put((YACS::ENGINE::Any *)data);
55 }
56
57 //!Convert a YACS::ENGINE::Any (integer) to a PyObject (PyLong)
58 /*!
59  *   \param data : YACS::ENGINE::Any object
60  */
61 void NeutralPyInt::put(YACS::ENGINE::Any *data) throw(ConversionException)
62 {
63   InterpreterUnlocker loc;
64   PyObject* ob=convertNeutralPyObject(edGetType(),data);
65   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
66   _port->put(ob);
67   Py_DECREF(ob);
68 }
69
70 void NeutralPyString::put(const void *data) throw(ConversionException)
71 {
72   put((YACS::ENGINE::Any *)data);
73 }
74
75 //!Convert a YACS::ENGINE::Any (string) to a PyObject (PyString)
76 /*!
77  *   \param data : YACS::ENGINE::Any object
78  */
79 void NeutralPyString::put(YACS::ENGINE::Any *data) throw(ConversionException)
80 {
81   InterpreterUnlocker loc;
82   PyObject* ob=convertNeutralPyObject(edGetType(),data);
83   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
84   _port->put(ob);
85   Py_DECREF(ob);
86 }
87
88 void NeutralPyBool::put(const void *data) throw(ConversionException)
89 {
90   put((YACS::ENGINE::Any *)data);
91 }
92
93 //!Convert a YACS::ENGINE::Any (bool) to a PyObject (PyLong)
94 /*!
95  *   \param data : YACS::ENGINE::Any object
96  */
97 void NeutralPyBool::put(YACS::ENGINE::Any *data) throw(ConversionException)
98 {
99   InterpreterUnlocker loc;
100   PyObject* ob=convertNeutralPyObject(edGetType(),data);
101   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
102   _port->put(ob);
103   Py_DECREF(ob);
104 }
105
106 void NeutralPyObjref::put(const void *data) throw(ConversionException)
107 {
108   put((YACS::ENGINE::Any *)data);
109 }
110
111 //!Convert a Neutral::Any Objref to a PyObject Objref
112 /*!
113  *   \param data : Neutral::Any object
114  */
115 void NeutralPyObjref::put(YACS::ENGINE::Any *data) throw(ConversionException)
116 {
117   InterpreterUnlocker loc;
118   PyObject* ob=convertNeutralPyObject(edGetType(),data);
119   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
120   _port->put(ob);
121   Py_DECREF(ob);
122   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
123 }
124
125 void NeutralPySequence::put(const void *data) throw(ConversionException)
126 {
127   put((YACS::ENGINE::Any *)data);
128 }
129
130 //!Convert a Neutral::Any sequence to a PyObject Sequence
131 /*!
132  *   \param data : Neutral::Any object
133  */
134 void NeutralPySequence::put(YACS::ENGINE::Any *data) throw(ConversionException)
135 {
136   DEBTRACE( "--------NeutralPySequence::put" );
137   InterpreterUnlocker loc;
138   PyObject* ob=convertNeutralPyObject(edGetType(),data);
139   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
140 #ifdef _DEVDEBUG_
141   cerr << "Sequence= ";
142   PyObject_Print(ob,stderr,Py_PRINT_RAW);
143   cerr << endl;
144 #endif
145   _port->put(ob);
146   Py_DECREF(ob);
147   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
148 }
149
150 void NeutralPyStruct::put(const void *data) throw(ConversionException)
151 {
152   put((YACS::ENGINE::Any *)data);
153 }
154
155 //!Convert a Neutral::Any Struct to a PyObject Struct
156 /*!
157  *   \param data : Neutral::Any object
158  */
159 void NeutralPyStruct::put(YACS::ENGINE::Any *data) throw(ConversionException)
160 {
161   InterpreterUnlocker loc;
162   PyObject* ob=convertNeutralPyObject(edGetType(),data);
163   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
164   _port->put(ob);
165   Py_DECREF(ob);
166   DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
167 }