Class representing a pointer with a known type.
| 120 | |
| 121 | |
| 122 | class TypedCPointer(_CDeref[T], BaseCPointer[T]): |
| 123 | """Class representing a pointer with a known type.""" |
| 124 | |
| 125 | def __init__( |
| 126 | self, |
| 127 | address: int, |
| 128 | data_type: Type[T], |
| 129 | size: int, |
| 130 | void_p: bool = True, |
| 131 | decref: bool = True, |
| 132 | alt: bool = False, |
| 133 | ) -> None: |
| 134 | self._void_p = void_p |
| 135 | super().__init__(address, size) |
| 136 | self._type = data_type |
| 137 | self._decref = decref |
| 138 | self.alt = alt |
| 139 | |
| 140 | @property |
| 141 | def size(self) -> int: |
| 142 | return self._size |
| 143 | |
| 144 | @property |
| 145 | def decref(self) -> bool: |
| 146 | return self._decref |
| 147 | |
| 148 | @property |
| 149 | def type(self): |
| 150 | return self._type |
| 151 | |
| 152 | @property |
| 153 | def address(self) -> Optional[int]: |
| 154 | return self._address |
| 155 | |
| 156 | @property # type: ignore |
| 157 | @handle |
| 158 | def _as_parameter_(self) -> ctypes._CData: |
| 159 | ctype = get_mapped(self.type) |
| 160 | |
| 161 | if (ctype is ctypes.c_char_p) and (self.alt): |
| 162 | deref = ctype(self.ensure()) |
| 163 | return deref |
| 164 | else: |
| 165 | deref = ctype.from_address(self.ensure()) |
| 166 | |
| 167 | value = deref.value # type: ignore |
| 168 | |
| 169 | if isinstance(value, (TypedCPointer, VoidPointer)): |
| 170 | return ctypes.pointer(value._as_parameter_) # type: ignore |
| 171 | |
| 172 | return ctypes.pointer(deref) |
| 173 | |
| 174 | @handle |
| 175 | def dereference(self) -> T: |
| 176 | """Dereference the pointer.""" |
| 177 | ctype = get_mapped(self.type) |
| 178 | |
| 179 | if (ctype is ctypes.c_char_p) and (self.alt): |
no outgoing calls
no test coverage detected