Update template projects to not use struct qstring_t
parent
7fb53a8916
commit
57d557378e
|
@ -1,8 +1,9 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
/* generated by rust_qt_binding_generator */
|
||||||
#![allow(unknown_lints)]
|
#![allow(unknown_lints)]
|
||||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||||
use libc::{c_int, c_void, uint8_t, uint16_t};
|
use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
use std::char::decode_utf16;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::ptr::null;
|
use std::ptr::null;
|
||||||
|
@ -10,42 +11,17 @@ use std::ptr::null;
|
||||||
use implementation::*;
|
use implementation::*;
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
pub enum QString {}
|
||||||
pub struct QString {
|
|
||||||
data: *const uint8_t,
|
fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
|
||||||
len: c_int,
|
let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
|
||||||
|
let characters = decode_utf16(utf16.iter().cloned())
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| r.unwrap());
|
||||||
|
s.clear();
|
||||||
|
s.extend(characters);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QStringIn {
|
|
||||||
data: *const uint16_t,
|
|
||||||
len: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QStringIn {
|
|
||||||
fn convert(&self) -> String {
|
|
||||||
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
|
||||||
String::from_utf16_lossy(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for QString {
|
|
||||||
fn from(string: &'a str) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a String> for QString {
|
|
||||||
fn from(string: &'a String) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SimpleQObject {}
|
pub struct SimpleQObject {}
|
||||||
|
|
||||||
|
@ -95,16 +71,21 @@ pub unsafe extern "C" fn simple_free(ptr: *mut Simple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn simple_message_get(
|
pub extern "C" fn simple_message_get(
|
||||||
ptr: *const Simple,
|
ptr: *const Simple,
|
||||||
p: *mut c_void,
|
p: *mut c_void,
|
||||||
set: fn(*mut c_void, QString),
|
set: fn(*mut c_void, *const c_char, c_int),
|
||||||
) {
|
) {
|
||||||
let data = (&*ptr).message();
|
let o = unsafe { &*ptr };
|
||||||
set(p, data.into());
|
let v = o.message();
|
||||||
|
let s: *const c_char = v.as_ptr() as (*const c_char);
|
||||||
|
set(p, s, v.len() as c_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn simple_message_set(ptr: *mut Simple, v: QStringIn) {
|
pub extern "C" fn simple_message_set(ptr: *mut Simple, v: *const c_ushort, len: c_int) {
|
||||||
(&mut *ptr).set_message(v.convert());
|
let o = unsafe { &mut *ptr };
|
||||||
|
let mut s = String::new();
|
||||||
|
set_string_from_utf16(&mut s, v, len);
|
||||||
|
o.set_message(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,22 +3,9 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct qstring_t {
|
typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
|
||||||
private:
|
void set_qstring(QString* val, const char* utf8, int nbytes) {
|
||||||
const void* data;
|
*val = QString::fromUtf8(utf8, nbytes);
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
inline void simpleMessageChanged(Simple* o)
|
inline void simpleMessageChanged(Simple* o)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +16,7 @@ extern "C" {
|
||||||
Simple::Private* simple_new(Simple*, void (*)(Simple*));
|
Simple::Private* simple_new(Simple*, void (*)(Simple*));
|
||||||
void simple_free(Simple::Private*);
|
void simple_free(Simple::Private*);
|
||||||
void simple_message_get(const Simple::Private*, QString*, qstring_set);
|
void simple_message_get(const Simple::Private*, QString*, qstring_set);
|
||||||
void simple_message_set(Simple::Private*, qstring_t);
|
void simple_message_set(Simple::Private*, const ushort *str, int len);
|
||||||
};
|
};
|
||||||
|
|
||||||
Simple::Simple(bool /*owned*/, QObject *parent):
|
Simple::Simple(bool /*owned*/, QObject *parent):
|
||||||
|
@ -59,5 +46,5 @@ QString Simple::message() const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
void Simple::setMessage(const QString& v) {
|
void Simple::setMessage(const QString& v) {
|
||||||
simple_message_set(m_d, v);
|
simple_message_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
/* generated by rust_qt_binding_generator */
|
||||||
#![allow(unknown_lints)]
|
#![allow(unknown_lints)]
|
||||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||||
use libc::{c_int, c_void, uint8_t, uint16_t};
|
use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
use std::char::decode_utf16;
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::ptr::null;
|
use std::ptr::null;
|
||||||
|
@ -10,42 +11,17 @@ use std::ptr::null;
|
||||||
use implementation::*;
|
use implementation::*;
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
pub enum QString {}
|
||||||
pub struct QString {
|
|
||||||
data: *const uint8_t,
|
fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
|
||||||
len: c_int,
|
let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
|
||||||
|
let characters = decode_utf16(utf16.iter().cloned())
|
||||||
|
.into_iter()
|
||||||
|
.map(|r| r.unwrap());
|
||||||
|
s.clear();
|
||||||
|
s.extend(characters);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QStringIn {
|
|
||||||
data: *const uint16_t,
|
|
||||||
len: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QStringIn {
|
|
||||||
fn convert(&self) -> String {
|
|
||||||
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
|
||||||
String::from_utf16_lossy(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for QString {
|
|
||||||
fn from(string: &'a str) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a String> for QString {
|
|
||||||
fn from(string: &'a String) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SimpleQObject {}
|
pub struct SimpleQObject {}
|
||||||
|
|
||||||
|
@ -95,16 +71,21 @@ pub unsafe extern "C" fn simple_free(ptr: *mut Simple) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn simple_message_get(
|
pub extern "C" fn simple_message_get(
|
||||||
ptr: *const Simple,
|
ptr: *const Simple,
|
||||||
p: *mut c_void,
|
p: *mut c_void,
|
||||||
set: fn(*mut c_void, QString),
|
set: fn(*mut c_void, *const c_char, c_int),
|
||||||
) {
|
) {
|
||||||
let data = (&*ptr).message();
|
let o = unsafe { &*ptr };
|
||||||
set(p, data.into());
|
let v = o.message();
|
||||||
|
let s: *const c_char = v.as_ptr() as (*const c_char);
|
||||||
|
set(p, s, v.len() as c_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn simple_message_set(ptr: *mut Simple, v: QStringIn) {
|
pub extern "C" fn simple_message_set(ptr: *mut Simple, v: *const c_ushort, len: c_int) {
|
||||||
(&mut *ptr).set_message(v.convert());
|
let o = unsafe { &mut *ptr };
|
||||||
|
let mut s = String::new();
|
||||||
|
set_string_from_utf16(&mut s, v, len);
|
||||||
|
o.set_message(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,22 +3,9 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct qstring_t {
|
typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
|
||||||
private:
|
void set_qstring(QString* val, const char* utf8, int nbytes) {
|
||||||
const void* data;
|
*val = QString::fromUtf8(utf8, nbytes);
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
inline void simpleMessageChanged(Simple* o)
|
inline void simpleMessageChanged(Simple* o)
|
||||||
{
|
{
|
||||||
|
@ -29,7 +16,7 @@ extern "C" {
|
||||||
Simple::Private* simple_new(Simple*, void (*)(Simple*));
|
Simple::Private* simple_new(Simple*, void (*)(Simple*));
|
||||||
void simple_free(Simple::Private*);
|
void simple_free(Simple::Private*);
|
||||||
void simple_message_get(const Simple::Private*, QString*, qstring_set);
|
void simple_message_get(const Simple::Private*, QString*, qstring_set);
|
||||||
void simple_message_set(Simple::Private*, qstring_t);
|
void simple_message_set(Simple::Private*, const ushort *str, int len);
|
||||||
};
|
};
|
||||||
|
|
||||||
Simple::Simple(bool /*owned*/, QObject *parent):
|
Simple::Simple(bool /*owned*/, QObject *parent):
|
||||||
|
@ -59,5 +46,5 @@ QString Simple::message() const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
void Simple::setMessage(const QString& v) {
|
void Simple::setMessage(const QString& v) {
|
||||||
simple_message_set(m_d, v);
|
simple_message_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue