Salome HOME
SMH: Merge with V2_2_3 version (to be compatible with MED from maintainance branch...
[modules/kernel.git] / src / Batch_SWIG / libBatch_Swig_typemap.i
1 /*
2  * _typemap.i : 
3  *
4  * Auteur : Ivan DUTKA-MALEN - EDF R&D
5  * Date   : Septembre 2003
6  * Projet : SALOME 2
7  *
8  */
9
10 %{
11 #include <string>
12 #include <list>
13 #include <map>
14 #include "Batch_Parametre.hxx"
15 #include "Batch_PyVersatile.hxx"
16 #include "Batch_JobId.hxx"
17 #include "Batch_FactBatchManager.hxx"
18 %}
19
20 # // supprime toutes les definitions par defaut => sert au debug
21 # %typemap(in) SWIGTYPE ;
22
23
24 # // construction d'un dictionnaire Python a partir d'un objet BatchManagerCatalog C++
25 %typemap(out) std::map<std::string, Batch::FactBatchManager *> *
26 {
27   $result = PyDict_New();
28
29   // on itere sur toutes les clefs de la map
30   for(std::map<std::string, Batch::FactBatchManager *>::const_iterator it=(* $1).begin(); it!=(* $1).end(); it++) {
31     std::string key = (*it).first;
32     PyObject * obj  = SWIG_NewPointerObj((void *) (*it).second, SWIGTYPE_p_Batch__FactBatchManager, 0);
33     PyDict_SetItem($result, PyString_FromString(key.c_str()), obj);
34   }
35 }
36
37
38 # // construction d'un dictionnaire Python a partir d'un objet Parametre C++
39 %typemap(out) Batch::Parametre
40 {
41   $result = PyDict_New();
42
43   // on itere sur toutes les clefs de la map, et on passe par la classe PyVersatile
44         // qui convertit un Versatile en PyObject et vice versa
45   for(Batch::Parametre::const_iterator it=$1.begin(); it!=$1.end(); it++) {
46     std::string key = (*it).first;
47     Batch::PyVersatile PyV = (*it).second;
48     PyDict_SetItem($result, PyString_FromString(key.c_str()), PyV);
49   }
50 }
51
52
53 # // construction d'un objet Parametre C++ a partir d'un dictionnaire Python
54 %typemap(in) Batch::Parametre & (Batch::Parametre PM)
55 {
56   if (!PyDict_Check($input)) {
57     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
58     return NULL;
59   }
60
61   try { 
62   // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile
63         // qui convertit un Versatile en PyObject et vice versa
64         PyObject *key, *value;
65         int pos = 0;
66         while (PyDict_Next($input, &pos, &key, &value)) {
67                 std::string mk = PyString_AsString(key);
68                 Batch::PyVersatile PyV = value;
69                 PyV.setName(mk);
70                 PM[mk] = PyV;
71         }
72
73   $1 = &PM; // $1 est une reference donc on lui passe une adresse
74   }
75   catch (Batch::GenericException & ex) {
76       std::string msg = ex.type + " : " + ex.message;
77       PyErr_SetString(PyExc_RuntimeWarning, msg.c_str());
78       return NULL;
79   }
80   catch (...) {
81       PyErr_SetString(PyExc_RuntimeWarning, "unknown exception");
82       return NULL;
83   }
84 }
85
86
87 # // construction d'un objet Parametre C++ a partir d'un dictionnaire Python
88 %typemap(in) Batch::Parametre (Batch::Parametre PM)
89 {
90   if (!PyDict_Check($input)) {
91     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
92     return NULL;
93   }
94
95   try {
96   // on itere sur toutes les clefs du dictionnaire, et on passe par la classe PyVersatile
97         // qui convertit un Versatile en PyObject et vice versa
98         PyObject *key, *value;
99         int pos = 0;
100         while (PyDict_Next($input, &pos, &key, &value)) {
101                 std::string mk = PyString_AsString(key);
102                 Batch::PyVersatile PyV = value;
103                 PyV.setName(mk);
104                 PM[mk] = PyV;
105         }
106
107   $1 = PM;
108   }
109   catch (Batch::GenericException & ex) {
110       std::string msg = ex.type + " : " + ex.message;
111       PyErr_SetString(PyExc_RuntimeWarning, msg.c_str());
112       return NULL;
113   }
114   catch (...) {
115       PyErr_SetString(PyExc_RuntimeWarning, "unknown exception");
116       return NULL;
117   }
118 }
119
120
121 # // construction d'un dictionnaire Python a partir d'un objet Environnement C++
122 %typemap(out) Batch::Environnement
123 {
124   $result = PyDict_New();
125
126   // on itere sur toutes les clefs de la map
127   for(Batch::Environnement::const_iterator it=$1.begin(); it!=$1.end(); it++) {
128     std::string key = (*it).first;
129     std::string val = (*it).second;
130     PyDict_SetItem($result, 
131                    PyString_FromString(key.c_str()),
132                    PyString_FromString(val.c_str()));
133   }
134 }
135
136
137 # // construction d'un objet Environnement C++ a partir d'un dictionnaire Python
138 %typemap(in) Batch::Environnement & (Batch::Environnement E)
139 {
140   if (!PyDict_Check($input)) {
141     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
142     return NULL;
143   }
144
145         // on itere sur toutes les clefs du dictionnaire
146         PyObject *key, *value;
147         int pos = 0;
148         while (PyDict_Next($input, &pos, &key, &value)) {
149                 std::string mk  = PyString_AsString(key);
150                 std::string val = PyString_AsString(value);
151                 E[mk] = val;
152         }
153   
154   $1 = &E; // $1 est une reference donc on lui passe une adresse
155 }
156
157
158
159 # // construction d'un objet Environnement C++ a partir d'un dictionnaire Python
160 %typemap(in) Batch::Environnement (Batch::Environnement E)
161 {
162   if (!PyDict_Check($input)) {
163     PyErr_SetString(PyExc_ValueError,"Expected a dictionnary");
164     return NULL;
165   }
166
167         // on itere sur toutes les clefs du dictionnaire
168         PyObject *key, *value;
169         int pos = 0;
170         while (PyDict_Next($input, &pos, &key, &value)) {
171                 std::string mk  = PyString_AsString(key);
172                 std::string val = PyString_AsString(value);
173                 E[mk] = val;
174         }
175   
176   $1 = E;
177 }
178
179
180
181 # // construction d'une string Python a partir d'une string STL
182 %typemap(python,out) std::string
183 {
184         $result = PyString_FromString($1.c_str());
185 }
186
187
188
189 # // construction d'une string STL a partir d'une string Python
190 #%typemap(in) string & (string S)
191 #{
192 ##  if (!PyString_Check($input)) {
193 #    PyErr_SetString(PyExc_ValueError,"Expected a string");
194 #    return NULL;
195 #  }
196 #
197 #  S = string(PyString_AsString($input));
198 #       $1 = &S; // $1 est une reference donc on lui passe une adresse
199 #}
200
201
202
203 # // construction d'une string STL a partir d'une string Python
204 #%typemap(in) string (string S)
205 #{
206 ##  if (!PyString_Check($input)) {
207 #    PyErr_SetString(PyExc_ValueError,"Expected a string");
208 #    return NULL;
209 #  }
210 #
211 #  S = string(PyString_AsString($input));
212 #       $1 = S;
213 #}