/[escript]/branches/split/escriptcore/src/SplitWorld.cpp
ViewVC logotype

Diff of /branches/split/escriptcore/src/SplitWorld.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4774 by jfenwick, Wed Mar 19 06:45:39 2014 UTC revision 4796 by jfenwick, Mon Mar 24 04:57:35 2014 UTC
# Line 20  Line 20 
20  #include "SplitWorldException.h"  #include "SplitWorldException.h"
21    
22  #include <iostream>  #include <iostream>
23    #include <sstream>
24    
25  using namespace boost::python;  using namespace boost::python;
26  using namespace escript;  using namespace escript;
# Line 192  void SplitWorld::runJobs() Line 193  void SplitWorld::runJobs()
193      }      }
194  }  }
195    
 void SplitWorld::registerCrate(escript::crate_ptr c)  
 {  
     protocrates.push_back(c);  
 }  
   
196  /**  /**
197    stores the constructor/factory to make Jobs and the parameters.    stores the constructor/factory to make Jobs and the parameters.
198  */  */
# Line 207  void SplitWorld::addJob(boost::python::o Line 203  void SplitWorld::addJob(boost::python::o
203      kwargs.push_back(kw);      kwargs.push_back(kw);
204  }  }
205    
206    // At some point, we may need there to be more isolation here
207    // and trap any python exceptions etc, but for now I'll just call the constructor
208    void SplitWorld::addVariable(std::string name, boost::python::object creator, boost::python::tuple ntup, boost::python::dict kwargs)
209    {
210        if (varmap.find(name)!=varmap.end())
211        {
212        std::ostringstream oss;
213        oss << "There is already a variable called " << name;
214        throw SplitWorldException(oss.str());    
215        }
216        object red=creator(*ntup, **kwargs);
217        extract<Reducer_ptr> ex(red);
218        if (!ex.check())
219        {
220        throw SplitWorldException("Creator function did not produce a reducer.");
221        }
222        Reducer_ptr rp=ex();
223        varmap[name]=rp;
224    }
225    
226    
227    void SplitWorld::removeVariable(std::string name)
228    {
229        varmap.erase(name);
230    }
231    
232  void SplitWorld::clearPendingJobs()  void SplitWorld::clearPendingJobs()
233  {  {
234      create.clear();      create.clear();
# Line 308  boost::python::object raw_addJob(boost:: Line 330  boost::python::object raw_addJob(boost::
330      return object();      return object();
331  }  }
332    
333    // expects, splitworld, name of var, constructor function for the reducer, any constructor params
334    boost::python::object raw_addVariable(boost::python::tuple t, boost::python::dict kwargs)
335    {
336        int l=len(t);
337        if (l<3)
338        {
339        throw SplitWorldException("Insufficient parameters to addReducer.");
340        }
341        extract<SplitWorld&> exw(t[0]);
342        if (!exw.check())
343        {
344        throw SplitWorldException("First parameter to addVariable must be a SplitWorld.");
345        }
346        SplitWorld& ws=exw();
347        object pname=t[1];
348        extract<std::string> ex2(pname);
349        if (!ex2.check())
350        {
351        throw SplitWorldException("Second parameter to addVariable must be a string");
352        }
353        std::string name=ex2();
354        object creator=t[2];
355        tuple ntup=tuple(t.slice(3,l)); // strip off the object param
356        ws.addVariable(name, creator, ntup, kwargs);
357        return object();
358    }
359    
360    
361    
362  }  }

Legend:
Removed from v.4774  
changed lines
  Added in v.4796

  ViewVC Help
Powered by ViewVC 1.1.26