Class representing a pointer to a struct.
| 179 | |
| 180 | |
| 181 | class StructPointer(Pointer[T]): |
| 182 | """Class representing a pointer to a struct.""" |
| 183 | |
| 184 | def __init__( |
| 185 | self, |
| 186 | address: int, |
| 187 | existing: Optional["Struct"] = None, |
| 188 | ): |
| 189 | self._existing = existing |
| 190 | super().__init__(address, True) |
| 191 | |
| 192 | @property # type: ignore |
| 193 | @handle |
| 194 | def _as_parameter_( |
| 195 | self, |
| 196 | ) -> Union[int, "ctypes._PointerLike"]: |
| 197 | existing = self._existing |
| 198 | |
| 199 | if existing: |
| 200 | return ctypes.pointer(existing.struct) |
| 201 | |
| 202 | return self.ensure() |
| 203 | |
| 204 | def __repr__(self) -> str: |
| 205 | return f"StructPointer(address={self.address}, existing={self._existing!r})" # noqa |
| 206 | |
| 207 | def __rich__(self) -> str: |
| 208 | return f"<[bold blue]pointer[/] to struct at {str(self)}>" |
| 209 | |
| 210 | def get_existing_address(self) -> int: |
| 211 | return (~self).get_existing_address() |
no outgoing calls
no test coverage detected