|
| 1 | +// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> |
| 2 | +// SPDX-FileContributor: Andrew Hayzen <[email protected]> |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 5 | + |
| 6 | +use cxx::{type_id, ExternType}; |
| 7 | + |
| 8 | +#[cxx::bridge] |
| 9 | +mod ffi { |
| 10 | + unsafe extern "C++" { |
| 11 | + include!("cxx-qt-lib/qtypes.h"); |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +/// Typedef for long long int. This type is guaranteed to be 64-bit on all platforms supported by Qt. |
| 16 | +#[repr(transparent)] |
| 17 | +#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 18 | +#[allow(non_camel_case_types)] |
| 19 | +pub struct qint64(i64); |
| 20 | + |
| 21 | +impl From<i64> for qint64 { |
| 22 | + fn from(value: i64) -> Self { |
| 23 | + Self(value) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +impl From<qint64> for i64 { |
| 28 | + fn from(value: qint64) -> Self { |
| 29 | + value.0 |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +// Safety: |
| 34 | +// |
| 35 | +// Static checks on the C++ side to ensure the size is the same. |
| 36 | +unsafe impl ExternType for qint64 { |
| 37 | + type Id = type_id!("qint64"); |
| 38 | + type Kind = cxx::kind::Trivial; |
| 39 | +} |
| 40 | + |
| 41 | +/// Integral type for representing pointers in a signed integer (useful for hashing, etc.). |
| 42 | +#[repr(transparent)] |
| 43 | +#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 44 | +#[allow(non_camel_case_types)] |
| 45 | +pub struct qintptr(isize); |
| 46 | + |
| 47 | +impl From<isize> for qintptr { |
| 48 | + fn from(value: isize) -> Self { |
| 49 | + qintptr(value) |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +impl From<qintptr> for isize { |
| 54 | + fn from(value: qintptr) -> Self { |
| 55 | + value.0 |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +// Safety: |
| 60 | +// |
| 61 | +// Static checks on the C++ side to ensure the size is the same. |
| 62 | +unsafe impl ExternType for qintptr { |
| 63 | + type Id = type_id!("qintptr"); |
| 64 | + type Kind = cxx::kind::Trivial; |
| 65 | +} |
| 66 | + |
| 67 | +/// Typedef for double |
| 68 | +/// |
| 69 | +/// Note that configuring Qt with -qreal float is not supported |
| 70 | +#[repr(transparent)] |
| 71 | +#[derive(Clone, Copy, Default, Debug, PartialEq, PartialOrd)] |
| 72 | +#[allow(non_camel_case_types)] |
| 73 | +pub struct qreal(f64); |
| 74 | + |
| 75 | +impl From<f64> for qreal { |
| 76 | + fn from(value: f64) -> Self { |
| 77 | + qreal(value) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +impl From<qreal> for f64 { |
| 82 | + fn from(value: qreal) -> Self { |
| 83 | + value.0 |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +// Safety: |
| 88 | +// |
| 89 | +// Static checks on the C++ side to ensure the size is the same. |
| 90 | +unsafe impl ExternType for qreal { |
| 91 | + type Id = type_id!("qreal"); |
| 92 | + type Kind = cxx::kind::Trivial; |
| 93 | +} |
| 94 | + |
| 95 | +/// Typedef for unsigned long long int. This type is guaranteed to be 64-bit on all platforms supported by Qt. |
| 96 | +#[repr(transparent)] |
| 97 | +#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 98 | +#[allow(non_camel_case_types)] |
| 99 | +pub struct quint64(u64); |
| 100 | + |
| 101 | +impl From<u64> for quint64 { |
| 102 | + fn from(value: u64) -> Self { |
| 103 | + quint64(value) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +impl From<quint64> for u64 { |
| 108 | + fn from(value: quint64) -> Self { |
| 109 | + value.0 |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +// Safety: |
| 114 | +// |
| 115 | +// Static checks on the C++ side to ensure the size is the same. |
| 116 | +unsafe impl ExternType for quint64 { |
| 117 | + type Id = type_id!("quint64"); |
| 118 | + type Kind = cxx::kind::Trivial; |
| 119 | +} |
| 120 | + |
| 121 | +/// Integral type for representing pointers in an unsigned integer (useful for hashing, etc.). |
| 122 | +#[repr(transparent)] |
| 123 | +#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 124 | +#[allow(non_camel_case_types)] |
| 125 | +pub struct quintptr(usize); |
| 126 | + |
| 127 | +impl From<usize> for quintptr { |
| 128 | + fn from(value: usize) -> Self { |
| 129 | + quintptr(value) |
| 130 | + } |
| 131 | +} |
| 132 | + |
| 133 | +impl From<quintptr> for usize { |
| 134 | + fn from(value: quintptr) -> Self { |
| 135 | + value.0 |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +// Safety: |
| 140 | +// |
| 141 | +// Static checks on the C++ side to ensure the size is the same. |
| 142 | +unsafe impl ExternType for quintptr { |
| 143 | + type Id = type_id!("quintptr"); |
| 144 | + type Kind = cxx::kind::Trivial; |
| 145 | +} |
| 146 | + |
| 147 | +/// Integral type providing Posix' ssize_t for all platforms. |
| 148 | +/// |
| 149 | +/// This type is guaranteed to be the same size as a size_t on all platforms supported by Qt. |
| 150 | +#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] |
| 151 | +#[repr(transparent)] |
| 152 | +#[allow(non_camel_case_types)] |
| 153 | +pub struct qsizetype(isize); |
| 154 | + |
| 155 | +impl From<isize> for qsizetype { |
| 156 | + fn from(value: isize) -> Self { |
| 157 | + qsizetype(value) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +impl From<qsizetype> for isize { |
| 162 | + fn from(value: qsizetype) -> Self { |
| 163 | + value.0 |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +// Safety: |
| 168 | +// |
| 169 | +// Static checks on the C++ side to ensure the size is the same. |
| 170 | +unsafe impl ExternType for qsizetype { |
| 171 | + type Id = type_id!("qsizetype"); |
| 172 | + type Kind = cxx::kind::Trivial; |
| 173 | +} |
0 commit comments