Skip to content

Commit

Permalink
cxx-qt-lib: use std int for qset and add i64/u64
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab authored and Be-ing committed Dec 19, 2022
1 parent 7552bf6 commit 6892f82
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 12 deletions.
16 changes: 10 additions & 6 deletions crates/cxx-qt-lib-headers/include/qset.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include <cstdint>

#include <QtCore/QSet>

#include <QtCore/QDate>
Expand Down Expand Up @@ -61,14 +63,16 @@ qsetLen(const QSet<T>& s) noexcept
using QSet_bool = QSet<bool>;
using QSet_f32 = QSet<float>;
using QSet_f64 = QSet<double>;
using QSet_i8 = QSet<::qint8>;
using QSet_i16 = QSet<::qint16>;
using QSet_i32 = QSet<::qint32>;
using QSet_i8 = QSet<::std::int8_t>;
using QSet_i16 = QSet<::std::int16_t>;
using QSet_i32 = QSet<::std::int32_t>;
using QSet_i64 = QSet<::std::int64_t>;
using QSet_QDate = QSet<::QDate>;
using QSet_QDateTime = QSet<::QDateTime>;
using QSet_QString = QSet<::QString>;
using QSet_QTime = QSet<::QTime>;
using QSet_QUrl = QSet<::QUrl>;
using QSet_u8 = QSet<::quint8>;
using QSet_u16 = QSet<::quint16>;
using QSet_u32 = QSet<::quint32>;
using QSet_u8 = QSet<::std::uint8_t>;
using QSet_u16 = QSet<::std::uint16_t>;
using QSet_u32 = QSet<::std::uint32_t>;
using QSet_u64 = QSet<::std::uint64_t>;
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn main() {
"qset/qset_i8",
"qset/qset_i16",
"qset/qset_i32",
"qset/qset_i64",
"qset/qset_qdate",
"qset/qset_qdatetime",
"qset/qset_qstring",
Expand All @@ -42,6 +43,7 @@ fn main() {
"qset/qset_u8",
"qset/qset_u16",
"qset/qset_u32",
"qset/qset_u64",
"qsize",
"qsizef",
"qstring",
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib/src/types/qset/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ generate_bridge_primitive "f64"
generate_bridge_primitive "i8"
generate_bridge_primitive "i16"
generate_bridge_primitive "i32"
generate_bridge_primitive "i64"
generate_bridge_qt "QDate" "qdate"
generate_bridge_qt "QDateTime" "qdatetime"
generate_bridge_qt "QString" "qstring"
Expand All @@ -166,3 +167,4 @@ generate_bridge_qt "QUrl" "qurl"
generate_bridge_primitive "u8"
generate_bridge_primitive "u16"
generate_bridge_primitive "u32"
generate_bridge_primitive "u64"
4 changes: 4 additions & 0 deletions crates/cxx-qt-lib/src/types/qset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod qset_f32;
mod qset_f64;
mod qset_i16;
mod qset_i32;
mod qset_i64;
mod qset_i8;
mod qset_qdate;
mod qset_qdatetime;
Expand All @@ -19,6 +20,7 @@ mod qset_qtime;
mod qset_qurl;
mod qset_u16;
mod qset_u32;
mod qset_u64;
mod qset_u8;

/// The QSet class is a template class that provides a hash-table-based set.
Expand Down Expand Up @@ -248,6 +250,7 @@ impl_qset_element!(f64, qset_f64, "QSet_f64");
impl_qset_element!(i8, qset_i8, "QSet_i8");
impl_qset_element!(i16, qset_i16, "QSet_i16");
impl_qset_element!(i32, qset_i32, "QSet_i32");
impl_qset_element!(i64, qset_i64, "QSet_i64");
impl_qset_element!(QDate, qset_qdate, "QSet_QDate");
impl_qset_element!(QDateTime, qset_qdatetime, "QSet_QDateTime");
impl_qset_element!(QString, qset_qstring, "QSet_QString");
Expand All @@ -256,3 +259,4 @@ impl_qset_element!(QUrl, qset_qurl, "QSet_QUrl");
impl_qset_element!(u8, qset_u8, "QSet_u8");
impl_qset_element!(u16, qset_u16, "QSet_u16");
impl_qset_element!(u32, qset_u32, "QSet_u32");
impl_qset_element!(u64, qset_u64, "QSet_u64");
14 changes: 8 additions & 6 deletions crates/cxx-qt-lib/src/types/qset/qset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
CXX_QT_QSET_ASSERTS(bool, bool);
CXX_QT_QSET_ASSERTS(float, f32);
CXX_QT_QSET_ASSERTS(double, f64);
CXX_QT_QSET_ASSERTS(::qint8, i8);
CXX_QT_QSET_ASSERTS(::qint16, i16);
CXX_QT_QSET_ASSERTS(::qint32, i32);
CXX_QT_QSET_ASSERTS(::std::int8_t, i8);
CXX_QT_QSET_ASSERTS(::std::int16_t, i16);
CXX_QT_QSET_ASSERTS(::std::int32_t, i32);
CXX_QT_QSET_ASSERTS(::std::int64_t, i64);
CXX_QT_QSET_ASSERTS(::QDate, QDate);
CXX_QT_QSET_ASSERTS(::QDateTime, QDateTime);
CXX_QT_QSET_ASSERTS(::QString, QString);
CXX_QT_QSET_ASSERTS(::QTime, QTime);
CXX_QT_QSET_ASSERTS(::QUrl, QUrl);
CXX_QT_QSET_ASSERTS(::quint8, u8);
CXX_QT_QSET_ASSERTS(::quint16, u16);
CXX_QT_QSET_ASSERTS(::quint32, u32);
CXX_QT_QSET_ASSERTS(::std::uint8_t, u8);
CXX_QT_QSET_ASSERTS(::std::uint16_t, u16);
CXX_QT_QSET_ASSERTS(::std::uint32_t, u32);
CXX_QT_QSET_ASSERTS(::std::uint64_t, u64);
64 changes: 64 additions & 0 deletions crates/cxx-qt-lib/src/types/qset/qset_i64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#[cxx::bridge]
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qset.h");
type QSet_i64 = crate::QSet<i64>;
}

unsafe extern "C++" {
#[rust_name = "cxx_clear"]
fn clear(self: &mut QSet_i64);
#[rust_name = "cxx_contains"]
fn contains(self: &QSet_i64, _: &i64) -> bool;
#[rust_name = "cxx_remove"]
fn remove(self: &mut QSet_i64, _: &i64) -> bool;
}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");

#[rust_name = "clone_i64"]
fn construct(_: &QSet_i64) -> QSet_i64;
#[rust_name = "default_i64"]
fn construct() -> QSet_i64;
#[rust_name = "drop_i64"]
fn drop(_: &mut QSet_i64);
#[rust_name = "get_unchecked_i64"]
#[allow(clippy::needless_lifetimes)]
unsafe fn qsetGetUnchecked<'a>(set: &'a QSet_i64, pos: usize) -> &'a i64;
#[rust_name = "insert_i64"]
fn qsetInsert(_: &mut QSet_i64, _: &i64);
#[rust_name = "len_i64"]
fn qsetLen(_: &QSet_i64) -> usize;
}
}

pub(crate) fn clone(s: &ffi::QSet_i64) -> ffi::QSet_i64 {
ffi::clone_i64(s)
}

pub(crate) fn default() -> ffi::QSet_i64 {
ffi::default_i64()
}

pub(crate) fn drop(s: &mut ffi::QSet_i64) {
ffi::drop_i64(s);
}

pub(crate) unsafe fn get_unchecked(s: &ffi::QSet_i64, pos: usize) -> &i64 {
ffi::get_unchecked_i64(s, pos)
}

pub(crate) fn insert(s: &mut ffi::QSet_i64, value: &i64) {
ffi::insert_i64(s, value);
}

pub(crate) fn len(s: &ffi::QSet_i64) -> usize {
ffi::len_i64(s)
}
64 changes: 64 additions & 0 deletions crates/cxx-qt-lib/src/types/qset/qset_u64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#[cxx::bridge]
pub mod ffi {
unsafe extern "C++" {
include!("cxx-qt-lib/qset.h");
type QSet_u64 = crate::QSet<u64>;
}

unsafe extern "C++" {
#[rust_name = "cxx_clear"]
fn clear(self: &mut QSet_u64);
#[rust_name = "cxx_contains"]
fn contains(self: &QSet_u64, _: &u64) -> bool;
#[rust_name = "cxx_remove"]
fn remove(self: &mut QSet_u64, _: &u64) -> bool;
}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
include!("cxx-qt-lib/common.h");

#[rust_name = "clone_u64"]
fn construct(_: &QSet_u64) -> QSet_u64;
#[rust_name = "default_u64"]
fn construct() -> QSet_u64;
#[rust_name = "drop_u64"]
fn drop(_: &mut QSet_u64);
#[rust_name = "get_unchecked_u64"]
#[allow(clippy::needless_lifetimes)]
unsafe fn qsetGetUnchecked<'a>(set: &'a QSet_u64, pos: usize) -> &'a u64;
#[rust_name = "insert_u64"]
fn qsetInsert(_: &mut QSet_u64, _: &u64);
#[rust_name = "len_u64"]
fn qsetLen(_: &QSet_u64) -> usize;
}
}

pub(crate) fn clone(s: &ffi::QSet_u64) -> ffi::QSet_u64 {
ffi::clone_u64(s)
}

pub(crate) fn default() -> ffi::QSet_u64 {
ffi::default_u64()
}

pub(crate) fn drop(s: &mut ffi::QSet_u64) {
ffi::drop_u64(s);
}

pub(crate) unsafe fn get_unchecked(s: &ffi::QSet_u64, pos: usize) -> &u64 {
ffi::get_unchecked_u64(s, pos)
}

pub(crate) fn insert(s: &mut ffi::QSet_u64, value: &u64) {
ffi::insert_u64(s, value);
}

pub(crate) fn len(s: &ffi::QSet_u64) -> usize {
ffi::len_u64(s)
}

0 comments on commit 6892f82

Please sign in to comment.