mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-13 17:48:34 +05:00
Merge branch 'nested_flags' into 'master'
allow nested flags from nested python dictionaries See merge request ngsolve/netgen!652
This commit is contained in:
commit
1a72309c40
@ -14,13 +14,11 @@ namespace ngcore
|
|||||||
{
|
{
|
||||||
if (py::isinstance<py::dict>(value))
|
if (py::isinstance<py::dict>(value))
|
||||||
{
|
{
|
||||||
py::dict vdd(value);
|
Flags nested_flags;
|
||||||
// call recursively to set dictionary
|
for(auto item : value.cast<py::dict>())
|
||||||
for (auto item : vdd) {
|
SetFlag(nested_flags, item.first.cast<string>(),
|
||||||
string name = item.first.cast<string>();
|
item.second.cast<py::object>());
|
||||||
py::object val = py::reinterpret_borrow<py::object>(item.second);
|
flags.SetFlag(s, nested_flags);
|
||||||
SetFlag(flags, name, val);
|
|
||||||
}
|
|
||||||
return;
|
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)
|
for (auto item : kwargs)
|
||||||
{
|
{
|
||||||
|
@ -149,12 +149,18 @@ PYBIND11_MODULE(pyngcore, m) // NOLINT
|
|||||||
py::class_<Flags>(m, "Flags")
|
py::class_<Flags>(m, "Flags")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("__str__", &ToString<Flags>)
|
.def("__str__", &ToString<Flags>)
|
||||||
.def(py::init([](py::object & obj) {
|
.def(py::init([](py::dict kwargs) {
|
||||||
Flags flags;
|
Flags flags;
|
||||||
py::dict d(obj);
|
for (auto d : kwargs)
|
||||||
SetFlag (flags, "", d);
|
SetFlag(flags, d.first.cast<string>(), d.second.cast<py::object>());
|
||||||
return flags;
|
return flags;
|
||||||
}), py::arg("obj"), "Create Flags by given object")
|
}), "Create flags from dict")
|
||||||
|
.def(py::init([](py::kwargs kwargs) {
|
||||||
|
Flags flags;
|
||||||
|
for (auto d : kwargs)
|
||||||
|
SetFlag(flags, d.first.cast<string>(), d.second.cast<py::object>());
|
||||||
|
return flags;
|
||||||
|
}), "Create flags from kwargs")
|
||||||
.def(py::pickle([] (const Flags& self)
|
.def(py::pickle([] (const Flags& self)
|
||||||
{
|
{
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
|
Loading…
Reference in New Issue
Block a user