HAL
gate_pin_group.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<PinGroup<GatePin>, RawPtrWrapper<PinGroup<GatePin>>> py_gate_pin_group(m, "GatePinGroup", R"(
8  A group of gate pins made up of a name, the pins, a pin order, and a start index.
9  )");
10 
11  py_gate_pin_group.def(py::self == py::self, R"(
12  Check whether two gate pin groups are equal.
13 
14  :returns: True if both gate pin groups are equal, False otherwise.
15  :rtype: bool
16  )");
17 
18  py_gate_pin_group.def(py::self != py::self, R"(
19  Check whether two gate pin groups are unequal.
20 
21  :returns: True if both gate pin groups are unequal, False otherwise.
22  :rtype: bool
23  )");
24 
25  py_gate_pin_group.def("__hash__", &PinGroup<GatePin>::get_hash, R"(
26  Python requires hash for set and dict container.
27 
28  :returns: The hash.
29  :rtype: Py_hash_t
30  )");
31 
32  py_gate_pin_group.def_property_readonly("id", &PinGroup<GatePin>::get_id, R"(
33  The ID of the gate pin group. The ID is unique within a gate type.
34 
35  :type: int
36  )");
37 
38  py_gate_pin_group.def("get_id", &PinGroup<GatePin>::get_id, R"(
39  Get the ID of the gate pin group. The ID is unique within a gate type.
40 
41  :returns: The ID of the pin.
42  :rtype: int
43  )");
44 
45  py_gate_pin_group.def_property_readonly("name", &PinGroup<GatePin>::get_name, R"(
46  The name of the pin group.
47 
48  :type: str
49  )");
50 
51  py_gate_pin_group.def("get_name", &PinGroup<GatePin>::get_name, R"(
52  Get the name of the pin group.
53 
54  :returns: The name of the pin group.
55  :rtype: str
56  )");
57 
58  py_gate_pin_group.def_property_readonly("direction", &PinGroup<GatePin>::get_direction, R"(
59  The direction of the pin group.
60 
61  :type: hal_py.PinDirection
62  )");
63 
64  py_gate_pin_group.def("get_direction", &PinGroup<GatePin>::get_direction, R"(
65  Get the direction of the pin group.
66 
67  :returns: The direction of the pin.
68  :rtype: hal_py.PinDirection
69  )");
70 
71  py_gate_pin_group.def_property_readonly("type", &PinGroup<GatePin>::get_type, R"(
72  The type of the pin group.
73 
74  :type: hal_py.PinType
75  )");
76 
77  py_gate_pin_group.def("get_type", &PinGroup<GatePin>::get_type, R"(
78  Get the type of the pin group.
79 
80  :returns: The type of the pin.
81  :rtype: hal_py.PinType
82  )");
83 
84  py_gate_pin_group.def_property_readonly("pins", [](const PinGroup<GatePin>& self) -> std::vector<GatePin*> { return self.get_pins(nullptr); }, R"(
85  The (ordered) pins of the pin groups.
86 
87  :type: list[hal_py.GatePin]
88  )");
89 
90  py_gate_pin_group.def("get_pins", &PinGroup<GatePin>::get_pins, py::arg("filter") = nullptr, R"(
91  Get the (ordered) pins of the pin groups.
92  The optional filter is evaluated on every pin such that the result only contains pins matching the specified condition.
93 
94  :param lambda filter: Filter function to be evaluated on each pin.
95  :returns: The ordered pins.
96  :rtype: list[hal_py.GatePin]
97  )");
98 
99  py_gate_pin_group.def(
100  "get_pin_at_index",
101  [](const PinGroup<GatePin>& self, u32 index) -> GatePin* {
102  auto res = self.get_pin_at_index(index);
103  if (res.is_ok())
104  {
105  return res.get();
106  }
107  else
108  {
109  log_error("python_context", "{}", res.get_error().get());
110  return nullptr;
111  }
112  },
113  py::arg("index"),
114  R"(
115  Get the pin specified by the given index.
116 
117  :param int index: The index of the pin within the pin group.
118  :returns: The pin on success, None otherwise.
119  :rtype: hal_py.GatePin or None
120  )");
121 
122  py_gate_pin_group.def(
123  "get_index",
124  [](const PinGroup<GatePin>& self, const GatePin* pin) -> i32 {
125  auto res = self.get_index(pin);
126  if (res.is_ok())
127  {
128  return (i32)res.get();
129  }
130  else
131  {
132  log_error("python_context", "{}", res.get_error().get());
133  return -1;
134  }
135  },
136  py::arg("pin"),
137  R"(
138  Get the index within the pin group of the given pin.
139 
140  :param hal_py.GatePin pin: The pin
141  :returns: The index of the pin on success, -1 otherwise.
142  :rtype: int
143  )");
144 
145  py_gate_pin_group.def("contains_pin", &PinGroup<GatePin>::contains_pin, py::arg("pin"), R"(
146  Check whether the pin group contains the given pin.
147 
148  :param hal_py.GatePin pin: The pin to check.
149  :returns: True if the pin group contains the pin, True otherwise.
150  :rtype: bool
151  )");
152 
153  py_gate_pin_group.def_property_readonly("ascending", &PinGroup<GatePin>::is_ascending, R"(
154  ``True`` if the pin order of a pin group comprising n pins is ascending (from 0 to n-1), ``False`` if it is descending (from n-1 to 0).
155 
156  :type: bool
157  )");
158 
159  py_gate_pin_group.def("is_ascending", &PinGroup<GatePin>::is_ascending, R"(
160  Check whether the pin order of a pin group comprising n pins is ascending (from 0 to n-1) or descending (from n-1 to 0).
161 
162  :returns: ``True`` for ascending bit order, ``False`` otherwise.
163  :rtype: bool
164  )");
165 
166  py_gate_pin_group.def_property_readonly("start_index", &PinGroup<GatePin>::get_start_index, R"(
167  The start index of the pin group.
168  Commonly, pin groups start at index 0, but this may not always be the case.
169  Note that the start index for a pin group comprising n pins is 0 independent of whether it is ascending or descending.
170 
171  :type: int
172  )");
173 
174  py_gate_pin_group.def("get_start_index", &PinGroup<GatePin>::get_start_index, R"(
175  Get the start index of the pin group.
176  Commonly, pin groups start at index 0, but this may not always be the case.
177  Note that the start index for a pin group comprising n pins is 0 independent of whether it is ascending or descending.
178 
179  :returns: The start index.
180  :rtype: int
181  )");
182 
183  py_gate_pin_group.def_property_readonly("ordered", &PinGroup<GatePin>::is_ordered, R"(
184  ``True`` if the pin group is inherently ordered, ``False`` otherwise.
185 
186  :type: bool
187  )");
188 
189  py_gate_pin_group.def("is_ordered", &PinGroup<GatePin>::is_ordered, R"(
190  Check whether the pin group features an inherent order.
191 
192  :returns: ``True`` if the pin group is inherently ordered, ``False`` otherwise.
193  :rtype: bool
194  )");
195 
196  py_gate_pin_group.def("empty", &PinGroup<GatePin>::empty, R"(
197  Check whether the pin group is empty, i.e., contains no pins.
198 
199  :returns: True if the pin group is empty, False otherwise.
200  :rtype: bool
201  )");
202 
203  py_gate_pin_group.def("size", &PinGroup<GatePin>::size, R"(
204  Get the size, i.e., the number of pins, of the pin group.
205 
206  :returns: The size of the pin group.
207  :rtype: int
208  )");
209  }
210 } // namespace hal
int32_t i32
Definition: defines.h:36
void gate_pin_group_init(py::module &m)
std::unique_ptr< T, py::nodelete > RawPtrWrapper
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
quint32 u32