forked from KDAB/cxx-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qtypes: add support for Qt alias types that don't match
Some times don't match the Rust types so add these missing types. Closes KDAB#882
- Loading branch information
1 parent
4455c86
commit cc403c4
Showing
6 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// clang-format off | ||
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// clang-format on | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
#pragma once | ||
|
||
#include <QtCore/Qt> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// clang-format off | ||
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// clang-format on | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
#include "cxx-qt-lib/qtypes.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "cxx-qt-lib/assertion_utils.h" | ||
|
||
assert_alignment_and_size(qint64, { ::std::int64_t a0; }); | ||
assert_alignment_and_size(qintptr, { ::std::intptr_t a0; }); | ||
assert_alignment_and_size(quint64, { ::std::uint64_t a0; }); | ||
assert_alignment_and_size(quintptr, { ::std::uintptr_t a0; }); | ||
assert_alignment_and_size(qsizetype, { ::std::size_t a0; }); | ||
// We only support qreal being a double | ||
assert_alignment_and_size(qreal, { double a0; }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
use cxx::{type_id, ExternType}; | ||
|
||
#[cxx::bridge] | ||
mod ffi { | ||
unsafe extern "C++" { | ||
include!("cxx-qt-lib/qtypes.h"); | ||
} | ||
} | ||
|
||
/// Typedef for long long int. This type is guaranteed to be 64-bit on all platforms supported by Qt. | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
#[allow(non_camel_case_types)] | ||
pub struct qint64(i64); | ||
|
||
impl From<i64> for qint64 { | ||
fn from(value: i64) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<qint64> for i64 { | ||
fn from(value: qint64) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for qint64 { | ||
type Id = type_id!("qint64"); | ||
type Kind = cxx::kind::Trivial; | ||
} | ||
|
||
/// Integral type for representing pointers in a signed integer (useful for hashing, etc.). | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
#[allow(non_camel_case_types)] | ||
pub struct qintptr(isize); | ||
|
||
impl From<isize> for qintptr { | ||
fn from(value: isize) -> Self { | ||
qintptr(value) | ||
} | ||
} | ||
|
||
impl From<qintptr> for isize { | ||
fn from(value: qintptr) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for qintptr { | ||
type Id = type_id!("qintptr"); | ||
type Kind = cxx::kind::Trivial; | ||
} | ||
|
||
/// Typedef for double | ||
/// | ||
/// Note that configuring Qt with -qreal float is not supported | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, PartialEq, PartialOrd)] | ||
#[allow(non_camel_case_types)] | ||
pub struct qreal(f64); | ||
|
||
impl From<f64> for qreal { | ||
fn from(value: f64) -> Self { | ||
qreal(value) | ||
} | ||
} | ||
|
||
impl From<qreal> for f64 { | ||
fn from(value: qreal) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for qreal { | ||
type Id = type_id!("qreal"); | ||
type Kind = cxx::kind::Trivial; | ||
} | ||
|
||
/// Typedef for unsigned long long int. This type is guaranteed to be 64-bit on all platforms supported by Qt. | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
#[allow(non_camel_case_types)] | ||
pub struct quint64(u64); | ||
|
||
impl From<u64> for quint64 { | ||
fn from(value: u64) -> Self { | ||
quint64(value) | ||
} | ||
} | ||
|
||
impl From<quint64> for u64 { | ||
fn from(value: quint64) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for quint64 { | ||
type Id = type_id!("quint64"); | ||
type Kind = cxx::kind::Trivial; | ||
} | ||
|
||
/// Integral type for representing pointers in an unsigned integer (useful for hashing, etc.). | ||
#[repr(transparent)] | ||
#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
#[allow(non_camel_case_types)] | ||
pub struct quintptr(usize); | ||
|
||
impl From<usize> for quintptr { | ||
fn from(value: usize) -> Self { | ||
quintptr(value) | ||
} | ||
} | ||
|
||
impl From<quintptr> for usize { | ||
fn from(value: quintptr) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for quintptr { | ||
type Id = type_id!("quintptr"); | ||
type Kind = cxx::kind::Trivial; | ||
} | ||
|
||
/// Integral type providing Posix' ssize_t for all platforms. | ||
/// | ||
/// This type is guaranteed to be the same size as a size_t on all platforms supported by Qt. | ||
#[derive(Clone, Copy, Default, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] | ||
#[repr(transparent)] | ||
#[allow(non_camel_case_types)] | ||
pub struct qsizetype(isize); | ||
|
||
impl From<isize> for qsizetype { | ||
fn from(value: isize) -> Self { | ||
qsizetype(value) | ||
} | ||
} | ||
|
||
impl From<qsizetype> for isize { | ||
fn from(value: qsizetype) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
// Safety: | ||
// | ||
// Static checks on the C++ side to ensure the size is the same. | ||
unsafe impl ExternType for qsizetype { | ||
type Id = type_id!("qsizetype"); | ||
type Kind = cxx::kind::Trivial; | ||
} |