4242
4343#include " helper.h"
4444#include " pymoose.h"
45+
4546#include " Finfo.hpp"
47+ #include " Vec.hpp"
4648
4749using namespace std ;
4850namespace py = pybind11;
@@ -61,11 +63,10 @@ py::object getValueFinfo(const ObjId& oid, const string& fname, const Finfo* f)
6163 r = pybind11::float_ (getProp<double >(oid, fname));
6264 else if (rttType == " float" )
6365 r = pybind11::float_ (getProp<double >(oid, fname));
64- else if (rttType == " vector<double>" ) {
66+ else if (rttType == " vector<double>" ) {
6567 // r = py::cast(getProp<vector<double>>(oid, fname));
6668 r = getFieldNumpy<double >(oid, fname);
67- }
68- else if (rttType == " string" )
69+ } else if (rttType == " string" )
6970 r = pybind11::str (getProp<string>(oid, fname));
7071 else if (rttType == " char" )
7172 r = pybind11::str (getProp<string>(oid, fname));
@@ -115,12 +116,10 @@ py::function getDestFinfo(const ObjId& obj, const string& fname, const Finfo* f)
115116{
116117 auto rttType = f->rttiType ();
117118 if (rttType == " Id" ) {
118- std::function<bool (const ObjId& tgt)> f = [obj, fname](const ObjId& tgt) {
119- return SetGet1<ObjId>::set (obj, fname, tgt);
120- };
119+ std::function<bool (const ObjId& tgt)> f = [obj, fname](
120+ const ObjId& tgt) { return SetGet1<ObjId>::set (obj, fname, tgt); };
121121 return py::cast (f);
122- }
123- else
122+ } else
124123 cout << " NotImplented: Setting " << fname << " with rttType '"
125124 << rttType << " ' on object " << obj.path () << endl;
126125 return py::function ();
@@ -252,12 +251,16 @@ PYBIND11_MODULE(_cmoose, m)
252251 // ---------------------------------------------------------------------
253252 .def (" __repr__" , [](const ObjId& oid) {
254253 return " <" + oid.element ()->cinfo ()->name () + " id=" +
255- std::to_string (oid.id .value ()) + " path=" + oid.path () +
254+ std::to_string (oid.id .value ())
255+ + " numData=" + to_string (oid.element ()->numData ())
256+ + " path=" + oid.path () +
256257 " >" ;
257258 });
258259
260+ // Variable.
259261 py::class_<Variable>(m, " _Variable" ).def (py::init<>());
260262
263+ // Cinfo.
261264 py::class_<Cinfo>(m, " _Cinfo" )
262265 .def (py::init<>())
263266 .def_property_readonly (" name" , &Cinfo::name)
@@ -267,6 +270,7 @@ PYBIND11_MODULE(_cmoose, m)
267270 .def (" baseCinfo" , &Cinfo::baseCinfo, py::return_value_policy::reference)
268271 .def (" isA" , &Cinfo::isA);
269272
273+ // Shell
270274 py::class_<Shell>(m, " _Shell" )
271275 .def (py::init<>())
272276 .def (" create" , &Shell::doCreate2)
@@ -278,27 +282,37 @@ PYBIND11_MODULE(_cmoose, m)
278282 .def (" start" , &Shell::doStart, " runtime" _a, " notify" _a = false )
279283 .def (" quit" , &Shell::doQuit);
280284
285+ // Vec
286+ py::class_<MooseVec>(m, " vec" )
287+ .def (py::init<const string&, size_t , const string&>(),
288+ " path" _a, " n" _a = 1 , " dtype" _a = " Neutral" ) // Default
289+ .def (" __len__" , &MooseVec::len)
290+ ;
291+
281292 // Module functions.
282293 m.def (" getShell" ,
283294 []() { return reinterpret_cast <Shell*>(Id ().eref ().data ()); },
284295 py::return_value_policy::reference);
285296
286- m.def (" seed" , [](size_t a){ moose::mtseed (a);});
287- m.def (" rand" , [](double a, double b){ return moose::mtrand (a, b);}, " a" _a=0 , " b" _a=1 );
297+ m.def (" seed" , [](size_t a) { moose::mtseed (a); });
298+ m.def (" rand" , [](double a, double b) { return moose::mtrand (a, b); },
299+ " a" _a = 0 , " b" _a = 1 );
288300 m.def (" wildcardFind" , &wildcardFind2);
289301 m.def (" delete" , &mooseDelete);
290302 m.def (" create" , &mooseCreate);
291303 m.def (" reinit" , &mooseReinit);
292304 m.def (" start" , &mooseStart, " runtime" _a, " notify" _a = false );
293305 m.def (" element" , &mooseElement);
294- m.def (" exists" , &doesExist );
306+ m.def (" exists" , &mooseExists );
295307 m.def (" connect" , &mooseConnect);
296308 m.def (" getCwe" , &mooseGetCwe);
297309 m.def (" setClock" , &mooseSetClock);
298310 m.def (" loadModelInternal" , &loadModelInternal);
299- m.def (" getFieldDict" , &mooseGetFieldDict, " className" _a, " finfoType" _a = " " );
300- m.def (" copy" , &mooseCopy, " orig" _a, " newParent" _a, " newName" _a
301- , " num" _a = 1 , " toGlobal" _a = false , " copyExtMsgs" _a = false );
311+ m.def (" getFieldDict" , &mooseGetFieldDict, " className" _a,
312+ " finfoType" _a = " " );
313+ m.def (" copy" , &mooseCopy, " orig" _a, " newParent" _a, " newName" _a, " num" _a = 1 ,
314+ " toGlobal" _a = false , " copyExtMsgs" _a = false );
315+
302316 // Attributes.
303317 m.attr (" NA" ) = NA;
304318 m.attr (" PI" ) = PI;
0 commit comments