@@ -20,14 +20,42 @@ namespace hal
20
20
.value (" X" , BooleanFunction::Value::X, R"( Represents an undefined value.)" )
21
21
.export_values ();
22
22
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"(
25
24
Translates the Boolean function value into its string representation.
26
25
27
26
:returns: The value as a string.
28
27
:rtype: str
29
28
)" );
30
29
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
+
31
59
py_boolean_function.def_static (
32
60
" to_string" ,
33
61
[](const std::vector<BooleanFunction::Value>& value, u8 base = 2 ) -> std::optional<std::string> {
@@ -1230,8 +1258,7 @@ namespace hal
1230
1258
:rtype: set[str]
1231
1259
)" );
1232
1260
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"(
1235
1262
Translates the Boolean function into its string representation.
1236
1263
1237
1264
:returns: The Boolean function as a string.
@@ -1540,8 +1567,7 @@ namespace hal
1540
1567
:rtype: hal_py.BooleanFunction.Node
1541
1568
)" );
1542
1569
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"(
1545
1571
Translates the Boolean function node into its string representation.
1546
1572
1547
1573
:returns: The Boolean function node as a string.
0 commit comments