HAL
module_pin_group.cpp
Go to the documentation of this file.
2 
3 namespace hal
4 {
6  {
7  py::class_<PinGroup<ModulePin>, RawPtrWrapper<PinGroup<ModulePin>>> py_module_pin_group(m, "ModulePinGroup", R"(
8  A group of module pins made up of a name, the pins, a pin order, and a start index.
9  )");
10 
11  py_module_pin_group.def(py::self == py::self, R"(
12  Check whether two module pin groups are equal.
13 
14  :returns: True if both module pin groups are equal, False otherwise.
15  :rtype: bool
16  )");
17 
18  py_module_pin_group.def(py::self != py::self, R"(
19  Check whether two module pin groups are unequal.
20 
21  :returns: True if both module pin groups are unequal, False otherwise.
22  :rtype: bool
23  )");
24 
25  py_module_pin_group.def("__hash__", &PinGroup<ModulePin>::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_module_pin_group.def_property_readonly("id", &PinGroup<ModulePin>::get_id, R"(
33  The ID of the module pin group. The ID is unique within a module.
34 
35  :type: int
36  )");
37 
38  py_module_pin_group.def("get_id", &PinGroup<ModulePin>::get_id, R"(
39  Get the ID of the module pin group. The ID is unique within a module.
40 
41  :returns: The ID of the pin.
42  :rtype: int
43  )");
44 
45  py_module_pin_group.def_property_readonly("name", &PinGroup<ModulePin>::get_name, R"(
46  The name of the pin group.
47 
48  :type: str
49  )");
50 
51  py_module_pin_group.def("get_name", &PinGroup<ModulePin>::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_module_pin_group.def_property_readonly("direction", &PinGroup<ModulePin>::get_direction, R"(
59  The direction of the pin group.
60 
61  :type: hal_py.PinDirection
62  )");
63 
64  py_module_pin_group.def("get_direction", &PinGroup<ModulePin>::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_module_pin_group.def_property_readonly("type", &PinGroup<ModulePin>::get_type, R"(
72  The type of the pin group.
73 
74  :type: hal_py.PinType
75  )");
76 
77  py_module_pin_group.def("get_type", &PinGroup<ModulePin>::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_module_pin_group.def_property_readonly("pins", [](const PinGroup<ModulePin>& self) -> std::vector<ModulePin*> { return self.get_pins(nullptr); }, R"(
85  The (ordered) pins of the pin groups.
86 
87  :type: list[hal_py.ModulePin]
88  )");
89 
90  py_module_pin_group.def("get_pins", &PinGroup<ModulePin>::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.ModulePin]
97  )");
98 
99  py_module_pin_group.def(
100  "get_pin_at_index",
101  [](const PinGroup<ModulePin>& self, u32 index) -> ModulePin* {
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.ModulePin or None
120  )");
121 
122  py_module_pin_group.def(
123  "get_index",
124  [](const PinGroup<ModulePin>& self, const ModulePin* 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.ModulePin pin: The pin
141  :returns: The index of the pin on success, -1 otherwise.
142  :rtype: int
143  )");
144 
145  py_module_pin_group.def("contains_pin", &PinGroup<ModulePin>::contains_pin, py::arg("pin"), R"(
146  Check whether the pin group contaisn the given pin.
147 
148  :param hal_py.ModulePin pin: The pin to check.
149  :returns: True if the pin group contains the pin, True otherwise.
150  :rtype: bool
151  )");
152 
153  py_module_pin_group.def_property_readonly("ascending", &PinGroup<ModulePin>::is_ascending, R"(
154  ``True`` if the pin order of a pin group comprising n pins is ascending, e.g., from index ``0`` to ``n-1``, ``False`` otherwise.
155 
156  :type: bool
157  )");
158 
159  py_module_pin_group.def("is_ascending", &PinGroup<ModulePin>::is_ascending, R"(
160  Check whether the pin order of a pin group comprising n pins is ascending, e.g., from index ``0`` to ``n-1``.
161 
162  :returns: ``True`` for ascending bit order, ``False`` otherwise.
163  :rtype: bool
164  )");
165 
166  py_module_pin_group.def_property_readonly("descending", &PinGroup<ModulePin>::is_descending, R"(
167  ``True`` if the pin order of a pin group comprising n pins is descending, e.g., from index ``n-1`` to ``0``, ``False`` otherwise.
168 
169  :type: bool
170  )");
171 
172  py_module_pin_group.def("is_descending", &PinGroup<ModulePin>::is_descending, R"(
173  Check whether the pin order of a pin group comprising n pins is descending, e.g., from index ``n-1`` to ``0``.
174 
175  :returns: ``True`` for descending bit order, ``False`` otherwise.
176  :rtype: bool
177  )");
178 
179  py_module_pin_group.def_property_readonly("lowest_index", &PinGroup<ModulePin>::get_lowest_index, R"(
180  The numerically lowest index of the pin group.
181 
182  :type: int
183  )");
184 
185  py_module_pin_group.def("get_lowest_index", &PinGroup<ModulePin>::get_lowest_index, R"(
186  Get the numerically lowest index of the pin group.
187 
188  :returns: The lowest index.
189  :rtype: int
190  )");
191 
192  py_module_pin_group.def_property_readonly("highest_index", &PinGroup<ModulePin>::get_highest_index, R"(
193  The numerically highest index of the pin group.
194 
195  :type: int
196  )");
197 
198  py_module_pin_group.def("get_highest_index", &PinGroup<ModulePin>::get_highest_index, R"(
199  Get the numerically highest index of the pin group.
200 
201  :returns: The highest index.
202  :rtype: int
203  )");
204 
205  py_module_pin_group.def_property_readonly("start_index", &PinGroup<ModulePin>::get_start_index, R"(
206  The start index of the pin group.
207  For ascending pin groups, this index equals the lowest index of the pin group.
208  For descending pin groups, it is equal to the highest index of the pin group.
209 
210  :type: int
211  )");
212 
213  py_module_pin_group.def("get_start_index", &PinGroup<ModulePin>::get_start_index, R"(
214  Get the start index of the pin group.
215  For ascending pin groups, this index equals the lowest index of the pin group.
216  For descending pin groups, it is equal to the highest index of the pin group.
217 
218  :returns: The start index.
219  :rtype: int
220  )");
221 
222  py_module_pin_group.def_property_readonly("ordered", &PinGroup<ModulePin>::is_ordered, R"(
223  ``True`` if the pin group is inherently ordered, ``False`` otherwise.
224 
225  :type: bool
226  )");
227 
228  py_module_pin_group.def("is_ordered", &PinGroup<ModulePin>::is_ordered, R"(
229  Check whether the pin group features an inherent order.
230 
231  :returns: ``True`` if the pin group is inherently ordered, ``False`` otherwise.
232  :rtype: bool
233  )");
234 
235  py_module_pin_group.def("set_ordered", &PinGroup<ModulePin>::set_ordered, py::arg("ordered") = true, R"(
236  Set whether the pin group features an inherent order.
237 
238  :param bool ordered: Set ``True`` if the pin group is inherently ordered, ``False`` otherwise. Defaults to ``True``.
239  )");
240 
241  py_module_pin_group.def("empty", &PinGroup<ModulePin>::empty, R"(
242  Check whether the pin group is empty, i.e., contains no pins.
243 
244  :returns: True if the pin group is empty, False otherwise.
245  :rtype: bool
246  )");
247 
248  py_module_pin_group.def("size", &PinGroup<ModulePin>::size, R"(
249  Get the size, i.e., the number of pins, of the pin group.
250 
251  :returns: The size of the pin group.
252  :rtype: int
253  )");
254  }
255 } // namespace hal
int32_t i32
Definition: defines.h:36
std::unique_ptr< T, py::nodelete > RawPtrWrapper
void module_pin_group_init(py::module &m)
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
quint32 u32