Skip to content

Commit

Permalink
added pybind needed for boolean function creation from nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKlx committed Feb 27, 2025
1 parent 27e3489 commit 04eb86e
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/python_bindings/bindings/boolean_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,42 @@ namespace hal
.value("X", BooleanFunction::Value::X, R"(Represents an undefined value.)")
.export_values();

py_boolean_function_value.def(
"__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"(
py_boolean_function_value.def("__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"(
Translates the Boolean function value into its string representation.
:returns: The value as a string.
:rtype: str
)");

py_boolean_function.def_static(
"build",
[](const std::vector<BooleanFunction::Node>& nodes) -> std::optional<BooleanFunction> {
std::vector<BooleanFunction::Node> nodes_cloned;
for (const auto& node : nodes)
{
nodes_cloned.push_back(node.clone());
}

auto res = BooleanFunction::build(std::move(nodes_cloned));
if (res.is_ok())
{
return res.get();
}
else
{
log_error("python_context", "{}", res.get_error().get());
return std::nullopt;
}
},
py::arg("nodes"),
R"(
Builds a Boolean function from a list of nodes.
:param list[hal_py.BooleanFunction.Node] nodes: The nodes to build the Boolean function from.
:returns: The Boolean function on success, None otherwise.
:rtype: hal_py.BooleanFunction or None
)");

py_boolean_function.def_static(
"to_string",
[](const std::vector<BooleanFunction::Value>& value, u8 base = 2) -> std::optional<std::string> {
Expand Down Expand Up @@ -1230,8 +1258,7 @@ namespace hal
:rtype: set[str]
)");

py_boolean_function.def(
"__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"(
py_boolean_function.def("__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"(
Translates the Boolean function into its string representation.
:returns: The Boolean function as a string.
Expand Down Expand Up @@ -1540,8 +1567,7 @@ namespace hal
:rtype: hal_py.BooleanFunction.Node
)");

py_boolean_function_node.def(
"__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"(
py_boolean_function_node.def("__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"(
Translates the Boolean function node into its string representation.
:returns: The Boolean function node as a string.
Expand Down

0 comments on commit 04eb86e

Please sign in to comment.