@@ -91,17 +91,71 @@ boost::python::object LPY::getFunctionRepr() { return GlobalContext::getFunction
91
91
92
92
/* ---------------------------------------------------------------------------*/
93
93
94
- void processArgList (ParamModule::ParameterList& args, boost::python::object arg, size_t start = 0 ){
95
- object iter_obj = object ( handle<>( PyObject_GetIter ( arg.ptr () ) ) );
96
- for (size_t i = 0 ; i < start; ++i) iter_obj.attr ( " next" )();
97
- try { while ( true ) appendParam (args,iter_obj.attr ( " next" )()); }
98
- catch ( error_already_set ){ PyErr_Clear (); }
94
+ void processArgList (ModuleClassPtr mclass, ParamModule::ParameterList& args, boost::python::object arg, size_t start = 0 ){
95
+ extract<boost::python::dict> isdict (arg);
96
+ if (!isdict.check ()){
97
+ object iter_obj = object ( handle<>( PyObject_GetIter ( arg.ptr () ) ) );
98
+ for (size_t i = 0 ; i < start; ++i) iter_obj.attr ( " next" )();
99
+ try { while ( true ) appendParam (args,iter_obj.attr ( " next" )()); }
100
+ catch ( error_already_set ){ PyErr_Clear (); }
101
+ }
102
+ else {
103
+ boost::python::object iter_obj = isdict ().iteritems ();
104
+ size_t nbstdparam = args.size ();
105
+ if (nbstdparam + len (arg) < mclass->getNamedParameterNb ()){
106
+ std::stringstream str;
107
+ str << mclass->name << " takes exactly " << mclass->getNamedParameterNb ()<< " (" << nbstdparam + len (arg) << " given)" ;
108
+ LsysError (str.str ());
109
+ }
110
+ pgl_hash_set<size_t > missingargs;
111
+
112
+ while ( true )
113
+ {
114
+ boost::python::object obj;
115
+ try { obj = iter_obj.attr ( " next" )(); }
116
+ catch ( boost::python::error_already_set ){ PyErr_Clear (); break ; }
117
+
118
+ std::string pname = extract<std::string>( obj[0 ] )();
119
+ size_t pposition = mclass->getParameterPosition (pname);
120
+ if (pposition == ModuleClass::NOPOS) {
121
+ std::stringstream str;
122
+ str << " Invalid parameter name '" << pname << " ' for module '" << mclass->name << " '." ;
123
+ LsysError (str.str ());
124
+ }
125
+ else if (pposition < nbstdparam) {
126
+ std::stringstream str;
127
+ str << mclass->name << " got multiple values for parameter '" << pname << " '." ;
128
+ LsysError (str.str ());
129
+ }
130
+ else {
131
+ size_t nbactualparam = args.size ();
132
+ if (nbactualparam > pposition) {
133
+ args[pposition] = obj[1 ];
134
+ pgl_hash_set<size_t >::const_iterator itmarg = missingargs.find (pposition);
135
+ if (itmarg != missingargs.end ())
136
+ missingargs.erase (itmarg);
137
+ }
138
+ else {
139
+ for (size_t i = nbactualparam ; i < pposition; ++i ){
140
+ appendParam (args,object ());
141
+ missingargs.insert (i);
142
+ }
143
+ appendParam (args,obj[1 ]);
144
+ }
145
+ }
146
+ }
147
+ if (missingargs.size () > 0 ) {
148
+ std::stringstream str;
149
+ str << mclass->name << " takes exactly " << mclass->getNamedParameterNb ()<< " (" << missingargs.size () << " missing)" ;
150
+ LsysError (str.str ());
151
+ }
152
+ }
99
153
}
100
154
101
- void processLastArg (ParamModule::ParameterList& args, boost::python::object arg){
155
+ void processLastArg (ModuleClassPtr mclass, ParamModule::ParameterList& args, boost::python::object arg){
102
156
extract<PackedArgs> pka (arg);
103
157
if (pka.check ()){
104
- processArgList (args,pka ().args );
158
+ processArgList (mclass, args,pka ().args );
105
159
}
106
160
else { appendParam (args,arg); }
107
161
}
@@ -121,10 +175,11 @@ void processConstruction(ParamModule& module,
121
175
for (size_t i = start; i < l-1 ; ++i){
122
176
appendParam (args,arg[i]);
123
177
}
124
- if (l > start){processLastArg (args,arg[l-1 ]);}
178
+ if (l > start){processLastArg (module. getClass (), args,arg[l-1 ]);}
125
179
}
126
180
}
127
181
182
+
128
183
/* ---------------------------------------------------------------------------*/
129
184
130
185
ParamModule::ParamModule ():
@@ -205,19 +260,19 @@ ParamModule::ParamModule(boost::python::list t):
205
260
206
261
ParamModule::ParamModule (const std::string& name,
207
262
const boost::python::object& a):
208
- BaseType(name) { processLastArg (__args (),a); }
263
+ BaseType(name) { processLastArg (getClass (), __args (),a); }
209
264
210
265
ParamModule::ParamModule (const std::string& name,
211
266
const boost::python::object& a,
212
267
const boost::python::object& b):
213
- BaseType(name) { appendParam (__args (),a); processLastArg (__args (),b); }
268
+ BaseType(name) { appendParam (__args (),a); processLastArg (getClass (), __args (),b); }
214
269
215
270
ParamModule::ParamModule (const std::string& name,
216
271
const boost::python::object& a,
217
272
const boost::python::object& b,
218
273
const boost::python::object& c):
219
274
BaseType(name)
220
- { appendParam (__args (),a); appendParam (__args (),b); processLastArg (__args (),c); }
275
+ { appendParam (__args (),a); appendParam (__args (),b); processLastArg (getClass (), __args (),c); }
221
276
222
277
ParamModule::ParamModule (const std::string& name,
223
278
const boost::python::object& a,
@@ -226,7 +281,7 @@ ParamModule::ParamModule(const std::string& name,
226
281
const boost::python::object& d):
227
282
BaseType(name)
228
283
{ appendParam (__args (),a); appendParam (__args (),b);
229
- appendParam (__args (),c); processLastArg (__args (),d); }
284
+ appendParam (__args (),c); processLastArg (getClass (), __args (),d); }
230
285
231
286
ParamModule::ParamModule (const std::string& name,
232
287
const boost::python::object& a,
@@ -237,14 +292,18 @@ ParamModule::ParamModule(const std::string& name,
237
292
BaseType(name)
238
293
{ appendParam (__args (),a); appendParam (__args (),b);
239
294
appendParam (__args (),c); appendParam (__args (),d);
240
- processLastArg (__args (),e); }
295
+ processLastArg (getClass (), __args (),e); }
241
296
242
297
243
298
244
299
ParamModule::~ParamModule ()
245
300
{
246
301
}
247
302
303
+ void ParamModule::appendArgumentList (const boost::python::object& arglist)
304
+ {
305
+ processArgList (getClass (),__args (),arglist);
306
+ }
248
307
249
308
250
309
0 commit comments