Skip to content

Commit 04eb86e

Browse files
committed
added pybind needed for boolean function creation from nodes
1 parent 27e3489 commit 04eb86e

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/python_bindings/bindings/boolean_function.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,42 @@ namespace hal
2020
.value("X", BooleanFunction::Value::X, R"(Represents an undefined value.)")
2121
.export_values();
2222

23-
py_boolean_function_value.def(
24-
"__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"(
23+
py_boolean_function_value.def("__str__", [](const BooleanFunction::Value& v) { return BooleanFunction::to_string(v); }, R"(
2524
Translates the Boolean function value into its string representation.
2625
2726
:returns: The value as a string.
2827
:rtype: str
2928
)");
3029

30+
py_boolean_function.def_static(
31+
"build",
32+
[](const std::vector<BooleanFunction::Node>& nodes) -> std::optional<BooleanFunction> {
33+
std::vector<BooleanFunction::Node> nodes_cloned;
34+
for (const auto& node : nodes)
35+
{
36+
nodes_cloned.push_back(node.clone());
37+
}
38+
39+
auto res = BooleanFunction::build(std::move(nodes_cloned));
40+
if (res.is_ok())
41+
{
42+
return res.get();
43+
}
44+
else
45+
{
46+
log_error("python_context", "{}", res.get_error().get());
47+
return std::nullopt;
48+
}
49+
},
50+
py::arg("nodes"),
51+
R"(
52+
Builds a Boolean function from a list of nodes.
53+
54+
:param list[hal_py.BooleanFunction.Node] nodes: The nodes to build the Boolean function from.
55+
:returns: The Boolean function on success, None otherwise.
56+
:rtype: hal_py.BooleanFunction or None
57+
)");
58+
3159
py_boolean_function.def_static(
3260
"to_string",
3361
[](const std::vector<BooleanFunction::Value>& value, u8 base = 2) -> std::optional<std::string> {
@@ -1230,8 +1258,7 @@ namespace hal
12301258
:rtype: set[str]
12311259
)");
12321260

1233-
py_boolean_function.def(
1234-
"__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"(
1261+
py_boolean_function.def("__str__", [](const BooleanFunction& f) { return f.to_string(); }, R"(
12351262
Translates the Boolean function into its string representation.
12361263
12371264
:returns: The Boolean function as a string.
@@ -1540,8 +1567,7 @@ namespace hal
15401567
:rtype: hal_py.BooleanFunction.Node
15411568
)");
15421569

1543-
py_boolean_function_node.def(
1544-
"__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"(
1570+
py_boolean_function_node.def("__str__", [](const BooleanFunction::Node& n) { return n.to_string(); }, R"(
15451571
Translates the Boolean function node into its string representation.
15461572
15471573
:returns: The Boolean function node as a string.

0 commit comments

Comments
 (0)