mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
allow nested flags from nested python dictionaries
This commit is contained in:
parent
0e0ea2d5f8
commit
3029b5422a
@ -14,13 +14,11 @@ namespace ngcore
|
||||
{
|
||||
if (py::isinstance<py::dict>(value))
|
||||
{
|
||||
py::dict vdd(value);
|
||||
// call recursively to set dictionary
|
||||
for (auto item : vdd) {
|
||||
string name = item.first.cast<string>();
|
||||
py::object val = py::reinterpret_borrow<py::object>(item.second);
|
||||
SetFlag(flags, name, val);
|
||||
}
|
||||
Flags nested_flags;
|
||||
for(auto item : value.cast<py::dict>())
|
||||
SetFlag(nested_flags, item.first.cast<string>(),
|
||||
item.second.cast<py::object>());
|
||||
flags.SetFlag(s, nested_flags);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,7 +101,9 @@ namespace ngcore
|
||||
}
|
||||
}
|
||||
|
||||
auto flags = py::cast<Flags>(flags_dict);
|
||||
Flags flags;
|
||||
for(auto item : flags_dict)
|
||||
SetFlag(flags, item.first.cast<string>(), item.second.cast<py::object>());
|
||||
|
||||
for (auto item : kwargs)
|
||||
{
|
||||
|
@ -149,12 +149,12 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
|
||||
py::class_<Flags>(m, "Flags")
|
||||
.def(py::init<>())
|
||||
.def("__str__", &ToString<Flags>)
|
||||
.def(py::init([](py::object & obj) {
|
||||
.def(py::init([](py::kwargs kwargs) {
|
||||
Flags flags;
|
||||
py::dict d(obj);
|
||||
SetFlag (flags, "", d);
|
||||
for (auto d : kwargs)
|
||||
SetFlag(flags, d.first.cast<string>(), d.second.cast<py::object>());
|
||||
return flags;
|
||||
}), py::arg("obj"), "Create Flags by given object")
|
||||
}), "Create flags from kwargs")
|
||||
.def(py::pickle([] (const Flags& self)
|
||||
{
|
||||
std::stringstream str;
|
||||
|
Loading…
Reference in New Issue
Block a user