Skip to content

Commit e118e12

Browse files
author
Dilawar Singh
committed
Retuning binding to std::function which return the Finfo value.
1 parent c7a7b24 commit e118e12

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

pybind11/pymoose.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,30 +106,17 @@ py::object getPropertyValueFinfo(const ObjId& oid, const string& fname, const st
106106
return py::none();
107107
}
108108

109-
py::list getPropertyElementFinfo(const ObjId& objid, const string& fname)
109+
py::object getElementFinfo(const ObjId& objid, const string& fname, const size_t i)
110110
{
111111
auto oid = ObjId(objid.path() + '/' + fname);
112112
auto len = Field<unsigned int>::get(oid, "numField");
113113
assert(len >= 0);
114-
vector<ObjId> res(len);
115-
for (size_t i = 0; i < len; i++)
116-
res[i] = ObjId(oid.path(), oid.dataIndex, i);
117-
return py::cast(res);
114+
return py::cast(ObjId(oid.path(), oid.dataIndex, i));
118115
}
119116

120-
template<typename A, typename L>
121117
py::object getLookValueFinfo(const ObjId& oid, const string& fname, const string& key)
122118
{
123-
return py::cast(LookupField<A, L>::get(oid, fname, key));
124-
}
125-
126-
py::dict getPropertyLookValueFinfo(const ObjId& oid, const string& fname)
127-
{
128-
py::dict res;
129-
auto v = [oid, fname](const string& key){
130-
return LookupField<string, bool>::get(oid, fname, key);
131-
};
132-
return res;
119+
return py::cast(LookupField<string, bool>::get(oid, fname, key));
133120
}
134121

135122
py::object getProperty(const ObjId& oid, const string& fname)
@@ -147,10 +134,18 @@ py::object getProperty(const ObjId& oid, const string& fname)
147134

148135
if(finfoType == "ValueFinfo")
149136
return getPropertyValueFinfo(oid, fname, rttType);
150-
else if(finfoType == "FieldElementFinfo")
151-
return getPropertyElementFinfo(oid, fname);
152-
else if(finfoType == "LookupValueFinfo")
153-
return getPropertyLookValueFinfo(oid, fname);
137+
else if(finfoType == "FieldElementFinfo") {
138+
std::function<py::object(size_t)> f = [oid, fname](const size_t& i) {
139+
return getElementFinfo(oid, fname, i);
140+
};
141+
return py::cast(f);
142+
}
143+
else if(finfoType == "LookupValueFinfo") {
144+
std::function<py::object(const string&)> f = [oid, fname](const string& k) {
145+
return getLookValueFinfo(oid, fname, k);
146+
};
147+
return py::cast(f);
148+
}
154149

155150
cout << "Searching for " << fname << " with rttType "
156151
<< rttType << " and type: " << finfoType << endl;

python/moose/moose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __setattr__(self, attr, val):
4040
def __getattr__(self, attr):
4141
return super(__Neutral__, self).getField(attr)
4242

43+
4344
for p in _cmoose.wildcardFind('/##[TYPE=Cinfo]'):
4445
# create a class.
4546
cls = type(p.name, (__Neutral__,), dict(__metaclass__=p.name, objid=p.id))

tests/pybind11/test_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def makereac2():
248248

249249
# Set parameters.
250250
A.concInit = 2
251-
assert A.concInit == 2, A.concIinit
251+
assert A.concInit == 2, A.concInit
252252

253253
e1Pool.concInit = 1
254254
assert e1Pool.concInit == 1.0, e1Pool.concInit

0 commit comments

Comments
 (0)