Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit 3ea0a66

Browse files
author
Dilawar Singh
committed
Support more return types.
1 parent 0862930 commit 3ea0a66

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

pybind11/Finfo.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ namespace py = pybind11;
2727
__Finfo__::__Finfo__(const ObjId& oid, const Finfo* f, const string& finfoType)
2828
: oid_(oid), f_(f), finfoType_(finfoType)
2929
{
30-
// cout << " __Finfo__ type " << finfoType << endl;
31-
3230
if (finfoType == "DestFinfo")
3331
func_ = [oid, f](const py::object& key) {
3432
return getLookupValueFinfoItem(oid, f, key);
@@ -103,6 +101,14 @@ py::object __Finfo__::getLookupValueFinfoItem(const ObjId& oid, const Finfo* f,
103101
} else if (srcType == "unsigned int") {
104102
auto k = py::cast<unsigned int>(key);
105103
r = getLookupValueFinfoItemInner<unsigned int>(oid, f, k, tgtType);
104+
} else if (srcType == "ObjId") {
105+
auto k = py::cast<ObjId>(key);
106+
r = getLookupValueFinfoItemInner<ObjId>(oid, f, k, tgtType);
107+
} else if (srcType == "Id") {
108+
auto k = py::cast<Id>(key);
109+
r = getLookupValueFinfoItemInner<Id>(oid, f, k, tgtType);
110+
} else {
111+
r = py::none();
106112
}
107113

108114
if (r.is(py::none())) {
@@ -116,12 +122,13 @@ py::object __Finfo__::getLookupValueFinfoItem(const ObjId& oid, const Finfo* f,
116122

117123
py::object __Finfo__::getItem(const py::object& key)
118124
{
119-
// py::print("Fetching value for", key, finfoType_);
125+
py::print("Fetching value for", key, finfoType_);
120126
return func_(key);
121127
}
122128

123129
py::object __Finfo__::operator()(const py::object& key)
124130
{
131+
py::print("Calling function with key", key);
125132
return func_(key);
126133
}
127134

@@ -166,7 +173,6 @@ py::cpp_function __Finfo__::getDestFinfoSetterFunc2(const ObjId& oid,
166173
oid.path());
167174
}
168175

169-
170176
// Get DestFinfo1.
171177
py::cpp_function __Finfo__::getDestFinfoSetterFunc1(const ObjId& oid,
172178
const Finfo* finfo,
@@ -180,17 +186,13 @@ py::cpp_function __Finfo__::getDestFinfoSetterFunc1(const ObjId& oid,
180186
return func;
181187
}
182188

183-
if (ftype == "double")
184-
return getSetGetFunc1<double>(oid, fname);
185-
if (ftype == "ObjId")
186-
return getSetGetFunc1<ObjId>(oid, fname);
187-
if (ftype == "Id")
188-
return getSetGetFunc1<Id>(oid, fname);
189-
if (ftype == "vector<Id>")
190-
return getSetGetFunc1<vector<Id>>(oid, fname);
191-
if (ftype == "vector<ObjId>")
189+
if (ftype == "double") return getSetGetFunc1<double>(oid, fname);
190+
if (ftype == "ObjId") return getSetGetFunc1<ObjId>(oid, fname);
191+
if (ftype == "Id") return getSetGetFunc1<Id>(oid, fname);
192+
if (ftype == "vector<Id>") return getSetGetFunc1<vector<Id>>(oid, fname);
193+
if (ftype == "vector<ObjId>")
192194
return getSetGetFunc1<vector<ObjId>>(oid, fname);
193-
if (ftype == "vector<double>")
195+
if (ftype == "vector<double>")
194196
return getSetGetFunc1<vector<double>>(oid, fname);
195197

196198
throw runtime_error("getFieldPropertyDestFinfo1::NotImplemented " + fname +
@@ -257,7 +259,6 @@ py::list __Finfo__::getElementFinfo(const ObjId& objid, const Finfo* f)
257259
py::object __Finfo__::getElementFinfoItem(const ObjId& oid, const Finfo* f,
258260
unsigned int index)
259261
{
260-
// cout << "Fetching at index " << index << " " << getNumField() << endl ;
261262
if (index >= getNumFieldStatic(oid, f)) {
262263
throw py::index_error("Index " + to_string(index) + " out of range.");
263264
}
@@ -270,11 +271,6 @@ string __Finfo__::type() const
270271
return finfoType_;
271272
}
272273

273-
// py::object __Finfo__::getAttr(const string& key)
274-
// {
275-
// std::cout << "Accessing " << key << std::endl;
276-
// }
277-
278274
unsigned int __Finfo__::getNumField()
279275
{
280276
return __Finfo__::getNumFieldStatic(oid_, f_);

pybind11/Finfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ class __Finfo__ {
2424
return py::cast(LookupField<T, bool>::get(oid, fname, key));
2525
if (tgtType == "double")
2626
return py::cast(LookupField<T, double>::get(oid, fname, key));
27+
if (tgtType == "unsigned int")
28+
return py::cast(LookupField<T, unsigned int>::get(oid, fname, key));
29+
if (tgtType == "int")
30+
return py::cast(LookupField<T, int>::get(oid, fname, key));
31+
if (tgtType == "string")
32+
return py::cast(LookupField<T, string>::get(oid, fname, key));
33+
if (tgtType == "ObjId")
34+
return py::cast(LookupField<T, ObjId>::get(oid, fname, key));
35+
if (tgtType == "Id")
36+
return py::cast(LookupField<T, Id>::get(oid, fname, key));
2737
if (tgtType == "vector<double>")
2838
return py::cast(
2939
LookupField<T, vector<double>>::get(oid, fname, key));

pybind11/pymoose.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ bool setFieldGeneric(const ObjId &oid, const string &fieldName,
9494
}
9595
if (fieldType == "vector<double>") {
9696
// NB: Note that we cast to ObjId here and not to Id.
97-
return Field<vector<double>>::set(
98-
oid.id, fieldName, val.cast<vector<double>>());
97+
return Field<vector<double>>::set(oid.id, fieldName,
98+
val.cast<vector<double>>());
9999
}
100100
if (fieldType == "vector<vector<double>>") {
101101
// NB: Note that we cast to ObjId here and not to Id.

0 commit comments

Comments
 (0)