Salome HOME
merge from branch BR_For40_DSC tag mergeto_V4_1_0_maintainance_29may08
[modules/kernel.git] / src / Batch_SWIG / libBatch_Swig_typemap.i
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * _typemap.i : 
22  *
23  * Auteur : Ivan DUTKA-MALEN - EDF R&D
24  * Date   : Septembre 2003
25  * Projet : SALOME 2
26  *
27  */
28
29 %{
30 #include <string>
31 #include <list>
32 #include <map>
33 #include "Batch_Parametre.hxx"
34 #include "Batch_PyVersatile.hxx"
35 #include "Batch_JobId.hxx"
36 #include "Batch_FactBatchManager.hxx"
37 %}
38
39 # // supprime toutes les definitions par defaut => sert au debug
40 # %typemap(in) SWIGTYPE ;
41
42
43 # // construction d'un dictionnaire Python a partir d'un objet BatchManagerCatalog C++
44 %typemap(out) std::map<std::string, Batch::FactBatchManager *> *
45 {
46   $result = PyDict_New();
47
48   // on itere sur toutes les clefs de la map
49   for(std::map<std::string, Batch::FactBatchManager *>::const_iterator it=(* $1).begin(); it!=(* $1).end(); it++) {
50     std::string key = (*it).first;
51     PyObject * obj  = SWIG_NewPointerObj((void *) (*it).second, SWIGTYPE_p_Batch__FactBatchManager, 0);
52     PyDict_SetItem($result, PyString_FromString(key.c_str()), obj);
53   }
54 }
55
56
57 # // construction d'un dictionnaire Python a partir d'un objet Parametre C++
58 %typemap(out) Batch::Parametre
59 {
60   $result = PyDict_New();
61
62   // on itere sur toutes les clefs de la map, et on passe par la classe PyVersatile
63         // qui convertit un Versatile en PyObject et vice versa
64   for(Batch::Parametre::const_iterator it=$1.begin(); it!=$1.end(); it++) {
65     std::string key = (*it).first;
66     Batch::PyVersatile PyV = (*it).second;
67     PyDict_SetItem($result, PyString_FromString(key.c_str()), PyV);
68   }
69 }
70
71
72 # // construction d'un objet Parametre C++ a partir d'un dictionnaire Python
73 %typemap(in) Batch::Parametre & (Batch::Parametre PM)
74 {
75   if (!PyDict_Check($input)) {
76     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
77     return NULL;
78   }
79
80   try { 
81   // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile
82         // qui convertit un Versatile en PyObject et vice versa
83         PyObject *key, *value;
84         int pos = 0;
85         while (PyDict_Next($input, &pos, &key, &value)) {
86                 std::string mk = PyString_AsString(key);
87                 Batch::PyVersatile PyV = value;
88                 PyV.setName(mk);
89                 PM[mk] = PyV;
90         }
91
92   $1 = &PM; // $1 est une reference donc on lui passe une adresse
93   }
94   catch (Batch::GenericException & ex) {
95       std::string msg = ex.type + " : " + ex.message;
96       PyErr_SetString(PyExc_RuntimeWarning, msg.c_str());
97       return NULL;
98   }
99   catch (...) {
100       PyErr_SetString(PyExc_RuntimeWarning, "unknown exception");
101       return NULL;
102   }
103 }
104
105
106 # // construction d'un objet Parametre C++ a partir d'un dictionnaire Python
107 %typemap(in) Batch::Parametre (Batch::Parametre PM)
108 {
109   if (!PyDict_Check($input)) {
110     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
111     return NULL;
112   }
113
114   try {
115   // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile
116         // qui convertit un Versatile en PyObject et vice versa
117         PyObject *key, *value;
118         int pos = 0;
119         while (PyDict_Next($input, &pos, &key, &value)) {
120                 std::string mk = PyString_AsString(key);
121                 Batch::PyVersatile PyV = value;
122                 PyV.setName(mk);
123                 PM[mk] = PyV;
124         }
125
126   $1 = PM;
127   }
128   catch (Batch::GenericException & ex) {
129       std::string msg = ex.type + " : " + ex.message;
130       PyErr_SetString(PyExc_RuntimeWarning, msg.c_str());
131       return NULL;
132   }
133   catch (...) {
134       PyErr_SetString(PyExc_RuntimeWarning, "unknown exception");
135       return NULL;
136   }
137 }
138
139
140 # // construction d'un dictionnaire Python a partir d'un objet Environnement C++
141 %typemap(out) Batch::Environnement
142 {
143   $result = PyDict_New();
144
145   // on itere sur toutes les clefs de la map
146   for(Batch::Environnement::const_iterator it=$1.begin(); it!=$1.end(); it++) {
147     std::string key = (*it).first;
148     std::string val = (*it).second;
149     PyDict_SetItem($result, 
150                    PyString_FromString(key.c_str()),
151                    PyString_FromString(val.c_str()));
152   }
153 }
154
155
156 # // construction d'un objet Environnement C++ a partir d'un dictionnaire Python
157 %typemap(in) Batch::Environnement & (Batch::Environnement E)
158 {
159   if (!PyDict_Check($input)) {
160     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
161     return NULL;
162   }
163
164         // on itere sur toutes les clefs du dictionnaire
165         PyObject *key, *value;
166         int pos = 0;
167         while (PyDict_Next($input, &pos, &key, &value)) {
168                 std::string mk  = PyString_AsString(key);
169                 std::string val = PyString_AsString(value);
170                 E[mk] = val;
171         }
172   
173   $1 = &E; // $1 est une reference donc on lui passe une adresse
174 }
175
176
177
178 # // construction d'un objet Environnement C++ a partir d'un dictionnaire Python
179 %typemap(in) Batch::Environnement (Batch::Environnement E)
180 {
181   if (!PyDict_Check($input)) {
182     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
183     return NULL;
184   }
185
186         // on itere sur toutes les clefs du dictionnaire
187         PyObject *key, *value;
188         int pos = 0;
189         while (PyDict_Next($input, &pos, &key, &value)) {
190                 std::string mk  = PyString_AsString(key);
191                 std::string val = PyString_AsString(value);
192                 E[mk] = val;
193         }
194   
195   $1 = E;
196 }
197
198
199
200 # // construction d'une string Python a partir d'une string STL
201 %typemap(python,out) std::string
202 {
203         $result = PyString_FromString($1.c_str());
204 }
205
206
207
208 # // construction d'une string STL a partir d'une string Python
209 #%typemap(in) string & (string S)
210 #{
211 ##  if (!PyString_Check($input)) {
212 #    PyErr_SetString(PyExc_ValueError,"Expected a string");
213 #    return NULL;
214 #  }
215 #
216 #  S = string(PyString_AsString($input));
217 #       $1 = &S; // $1 est une reference donc on lui passe une adresse
218 #}
219
220
221
222 # // construction d'une string STL a partir d'une string Python
223 #%typemap(in) string (string S)
224 #{
225 ##  if (!PyString_Check($input)) {
226 #    PyErr_SetString(PyExc_ValueError,"Expected a string");
227 #    return NULL;
228 #  }
229 #
230 #  S = string(PyString_AsString($input));
231 #       $1 = S;
232 #}