Skip to content

Commit

Permalink
cxx-qt-lib: implement QSetElement for QByteArray
Browse files Browse the repository at this point in the history
  • Loading branch information
ahayzen-kdab committed Dec 19, 2022
1 parent 2d3028b commit a6e1b07
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/cxx-qt-lib-headers/include/qset.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <QtCore/QSet>

#include <QtCore/QByteArray>
#include <QtCore/QDate>
#include <QtCore/QDateTime>
#include <QtCore/QString>
Expand Down Expand Up @@ -67,6 +68,7 @@ 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_QByteArray = QSet<::QByteArray>;
using QSet_QDate = QSet<::QDate>;
using QSet_QDateTime = QSet<::QDateTime>;
using QSet_QString = QSet<::QString>;
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fn main() {
"qset/qset_i16",
"qset/qset_i32",
"qset/qset_i64",
"qset/qset_qbytearray",
"qset/qset_qdate",
"qset/qset_qdatetime",
"qset/qset_qstring",
Expand Down
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/src/types/qset/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ generate_bridge_primitive "i8"
generate_bridge_primitive "i16"
generate_bridge_primitive "i32"
generate_bridge_primitive "i64"
generate_bridge_qt "QByteArray" "qbytearray"
generate_bridge_qt "QDate" "qdate"
generate_bridge_qt "QDateTime" "qdatetime"
generate_bridge_qt "QString" "qstring"
Expand Down
4 changes: 3 additions & 1 deletion crates/cxx-qt-lib/src/types/qset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{QDate, QDateTime, QString, QTime, QUrl};
use crate::{QByteArray, QDate, QDateTime, QString, QTime, QUrl};
use core::{marker::PhantomData, mem::MaybeUninit};
use cxx::{type_id, ExternType};

Expand All @@ -13,6 +13,7 @@ mod qset_i16;
mod qset_i32;
mod qset_i64;
mod qset_i8;
mod qset_qbytearray;
mod qset_qdate;
mod qset_qdatetime;
mod qset_qstring;
Expand Down Expand Up @@ -251,6 +252,7 @@ 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!(QByteArray, qset_qbytearray, "QSet_QByteArray");
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 Down
1 change: 1 addition & 0 deletions crates/cxx-qt-lib/src/types/qset/qset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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(::QByteArray, QByteArray);
CXX_QT_QSET_ASSERTS(::QDate, QDate);
CXX_QT_QSET_ASSERTS(::QDateTime, QDateTime);
CXX_QT_QSET_ASSERTS(::QString, QString);
Expand Down
66 changes: 66 additions & 0 deletions crates/cxx-qt-lib/src/types/qset/qset_qbytearray.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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/qbytearray.h");
type QByteArray = crate::QByteArray;

include!("cxx-qt-lib/qset.h");
type QSet_QByteArray = crate::QSet<QByteArray>;
}

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

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

#[rust_name = "clone_QByteArray"]
fn construct(_: &QSet_QByteArray) -> QSet_QByteArray;
#[rust_name = "default_QByteArray"]
fn construct() -> QSet_QByteArray;
#[rust_name = "drop_QByteArray"]
fn drop(_: &mut QSet_QByteArray);
#[rust_name = "get_unchecked_QByteArray"]
unsafe fn qsetGetUnchecked(set: &QSet_QByteArray, pos: usize) -> &QByteArray;
#[rust_name = "insert_QByteArray"]
fn qsetInsert(_: &mut QSet_QByteArray, _: &QByteArray);
#[rust_name = "len_QByteArray"]
fn qsetLen(_: &QSet_QByteArray) -> usize;
}
}

pub(crate) fn clone(s: &ffi::QSet_QByteArray) -> ffi::QSet_QByteArray {
ffi::clone_QByteArray(s)
}

pub(crate) fn default() -> ffi::QSet_QByteArray {
ffi::default_QByteArray()
}

pub(crate) fn drop(s: &mut ffi::QSet_QByteArray) {
ffi::drop_QByteArray(s);
}

pub(crate) unsafe fn get_unchecked(s: &ffi::QSet_QByteArray, pos: usize) -> &ffi::QByteArray {
ffi::get_unchecked_QByteArray(s, pos)
}

pub(crate) fn insert(s: &mut ffi::QSet_QByteArray, value: &ffi::QByteArray) {
ffi::insert_QByteArray(s, value);
}

pub(crate) fn len(s: &ffi::QSet_QByteArray) -> usize {
ffi::len_QByteArray(s)
}

0 comments on commit a6e1b07

Please sign in to comment.