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 (from 0 to n-1), False if it is descending (from n-1 to 0).
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 (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_module_pin_group.def_property_readonly("start_index", &PinGroup<ModulePin>::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_module_pin_group.def("get_start_index", &PinGroup<ModulePin>::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_module_pin_group.def_property_readonly("ordered", &PinGroup<ModulePin>::is_ordered, R"(
184  ``True`` if the pin group is inherently ordered, ``False`` otherwise.
185 
186  :type: bool
187  )");
188 
189  py_module_pin_group.def("is_ordered", &PinGroup<ModulePin>::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_module_pin_group.def("set_ordered", &PinGroup<ModulePin>::set_ordered, py::arg("ordered") = true, R"(
197  Set whether the pin group features an inherent order.
198 
199  :param bool ordered: Set ``True`` if the pin group is inherently ordered, ``False`` otherwise. Defaults to ``True``.
200  )");
201 
202  py_module_pin_group.def("empty", &PinGroup<ModulePin>::empty, R"(
203  Check whether the pin group is empty, i.e., contains no pins.
204 
205  :returns: True if the pin group is empty, False otherwise.
206  :rtype: bool
207  )");
208 
209  py_module_pin_group.def("size", &PinGroup<ModulePin>::size, R"(
210  Get the size, i.e., the number of pins, of the pin group.
211 
212  :returns: The size of the pin group.
213  :rtype: int
214  )");
215  }
216 } // 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