rust-qt-binding-generator/tests/rust_list_types/src/interface.rs

514 lines
14 KiB
Rust

/* generated by rust_qt_binding_generator */
#![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_char, c_ushort, c_int, c_void};
use std::slice;
use std::char::decode_utf16;
use std::sync::{Arc, Mutex};
use std::ptr::null;
use implementation::*;
#[repr(C)]
pub struct COption<T> {
data: T,
some: bool,
}
impl<T> From<Option<T>> for COption<T>
where
T: Default,
{
fn from(t: Option<T>) -> COption<T> {
if let Some(v) = t {
COption {
data: v,
some: true,
}
} else {
COption {
data: T::default(),
some: false,
}
}
}
}
pub enum QString {}
fn set_string_from_utf16(s: &mut String, str: *const c_ushort, 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);
}
pub enum QByteArray {}
#[repr(C)]
pub enum SortOrder {
Ascending = 0,
Descending = 1,
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct ListQObject {}
#[derive(Clone)]
pub struct ListEmitter {
qobject: Arc<Mutex<*const ListQObject>>,
new_data_ready: fn(*const ListQObject),
}
unsafe impl Send for ListEmitter {}
impl ListEmitter {
fn clear(&self) {
*self.qobject.lock().unwrap() = null();
}
pub fn new_data_ready(&self) {
let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() {
(self.new_data_ready)(ptr);
}
}
}
pub struct ListList {
qobject: *const ListQObject,
data_changed: fn(*const ListQObject, usize, usize),
begin_reset_model: fn(*const ListQObject),
end_reset_model: fn(*const ListQObject),
begin_insert_rows: fn(*const ListQObject, usize, usize),
end_insert_rows: fn(*const ListQObject),
begin_remove_rows: fn(*const ListQObject, usize, usize),
end_remove_rows: fn(*const ListQObject),
}
impl ListList {
pub fn data_changed(&self, first: usize, last: usize) {
(self.data_changed)(self.qobject, first, last);
}
pub fn begin_reset_model(&self) {
(self.begin_reset_model)(self.qobject);
}
pub fn end_reset_model(&self) {
(self.end_reset_model)(self.qobject);
}
pub fn begin_insert_rows(&self, first: usize, last: usize) {
(self.begin_insert_rows)(self.qobject, first, last);
}
pub fn end_insert_rows(&self) {
(self.end_insert_rows)(self.qobject);
}
pub fn begin_remove_rows(&self, first: usize, last: usize) {
(self.begin_remove_rows)(self.qobject, first, last);
}
pub fn end_remove_rows(&self) {
(self.end_remove_rows)(self.qobject);
}
}
pub trait ListTrait {
fn new(emit: ListEmitter, model: ListList) -> Self;
fn emit(&self) -> &ListEmitter;
fn row_count(&self) -> usize;
fn insert_rows(&mut self, _row: usize, _count: usize) -> bool { false }
fn remove_rows(&mut self, _row: usize, _count: usize) -> bool { false }
fn can_fetch_more(&self) -> bool {
false
}
fn fetch_more(&mut self) {}
fn sort(&mut self, u8, SortOrder) {}
fn boolean(&self, item: usize) -> bool;
fn set_boolean(&mut self, item: usize, bool) -> bool;
fn bytearray(&self, item: usize) -> &[u8];
fn set_bytearray(&mut self, item: usize, Vec<u8>) -> bool;
fn f32(&self, item: usize) -> f32;
fn set_f32(&mut self, item: usize, f32) -> bool;
fn f64(&self, item: usize) -> f64;
fn set_f64(&mut self, item: usize, f64) -> bool;
fn i16(&self, item: usize) -> i16;
fn set_i16(&mut self, item: usize, i16) -> bool;
fn i32(&self, item: usize) -> i32;
fn set_i32(&mut self, item: usize, i32) -> bool;
fn i64(&self, item: usize) -> i64;
fn set_i64(&mut self, item: usize, i64) -> bool;
fn i8(&self, item: usize) -> i8;
fn set_i8(&mut self, item: usize, i8) -> bool;
fn optional_boolean(&self, item: usize) -> Option<bool>;
fn set_optional_boolean(&mut self, item: usize, Option<bool>) -> bool;
fn optional_bytearray(&self, item: usize) -> Option<&[u8]>;
fn set_optional_bytearray(&mut self, item: usize, Option<Vec<u8>>) -> bool;
fn optional_string(&self, item: usize) -> Option<&str>;
fn set_optional_string(&mut self, item: usize, Option<String>) -> bool;
fn string(&self, item: usize) -> &str;
fn set_string(&mut self, item: usize, String) -> bool;
fn u16(&self, item: usize) -> u16;
fn set_u16(&mut self, item: usize, u16) -> bool;
fn u32(&self, item: usize) -> u32;
fn set_u32(&mut self, item: usize, u32) -> bool;
fn u64(&self, item: usize) -> u64;
fn set_u64(&mut self, item: usize, u64) -> bool;
fn u8(&self, item: usize) -> u8;
fn set_u8(&mut self, item: usize, u8) -> bool;
}
#[no_mangle]
pub extern "C" fn list_new(
list: *mut ListQObject,
list_new_data_ready: fn(*const ListQObject),
list_data_changed: fn(*const ListQObject, usize, usize),
list_begin_reset_model: fn(*const ListQObject),
list_end_reset_model: fn(*const ListQObject),
list_begin_insert_rows: fn(*const ListQObject, usize, usize),
list_end_insert_rows: fn(*const ListQObject),
list_begin_remove_rows: fn(*const ListQObject, usize, usize),
list_end_remove_rows: fn(*const ListQObject),
) -> *mut List {
let list_emit = ListEmitter {
qobject: Arc::new(Mutex::new(list)),
new_data_ready: list_new_data_ready,
};
let model = ListList {
qobject: list,
data_changed: list_data_changed,
begin_reset_model: list_begin_reset_model,
end_reset_model: list_end_reset_model,
begin_insert_rows: list_begin_insert_rows,
end_insert_rows: list_end_insert_rows,
begin_remove_rows: list_begin_remove_rows,
end_remove_rows: list_end_remove_rows,
};
let d_list = List::new(list_emit, model);
Box::into_raw(Box::new(d_list))
}
#[no_mangle]
pub unsafe extern "C" fn list_free(ptr: *mut List) {
Box::from_raw(ptr).emit().clear();
}
#[no_mangle]
pub unsafe extern "C" fn list_row_count(ptr: *const List) -> c_int {
(&*ptr).row_count() as c_int
}
#[no_mangle]
pub unsafe extern "C" fn list_insert_rows(ptr: *mut List, row: c_int, count: c_int) -> bool {
(&mut *ptr).insert_rows(row as usize, count as usize)
}
#[no_mangle]
pub unsafe extern "C" fn list_remove_rows(ptr: *mut List, row: c_int, count: c_int) -> bool {
(&mut *ptr).remove_rows(row as usize, count as usize)
}
#[no_mangle]
pub unsafe extern "C" fn list_can_fetch_more(ptr: *const List) -> bool {
(&*ptr).can_fetch_more()
}
#[no_mangle]
pub unsafe extern "C" fn list_fetch_more(ptr: *mut List) {
(&mut *ptr).fetch_more()
}
#[no_mangle]
pub unsafe extern "C" fn list_sort(
ptr: *mut List,
column: u8,
order: SortOrder,
) {
(&mut *ptr).sort(column, order)
}
#[no_mangle]
pub extern "C" fn list_data_boolean(ptr: *const List, row: c_int) -> bool {
let o = unsafe { &*ptr };
o.boolean(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_boolean(
ptr: *mut List, row: c_int,
v: bool,
) -> bool {
(&mut *ptr).set_boolean(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_bytearray(
ptr: *const List, row: c_int,
d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int),
) {
let o = unsafe { &*ptr };
let data = o.bytearray(row as usize);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
}
#[no_mangle]
pub extern "C" fn list_set_data_bytearray(
ptr: *mut List, row: c_int,
s: *const c_char, len: c_int,
) -> bool {
let o = unsafe { &mut *ptr };
let mut v = Vec::new();
let slice = unsafe { ::std::slice::from_raw_parts(s as *const u8, len as usize) };
v.extend_from_slice(slice);
o.set_bytearray(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_f32(ptr: *const List, row: c_int) -> f32 {
let o = unsafe { &*ptr };
o.f32(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_f32(
ptr: *mut List, row: c_int,
v: f32,
) -> bool {
(&mut *ptr).set_f32(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_f64(ptr: *const List, row: c_int) -> f64 {
let o = unsafe { &*ptr };
o.f64(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_f64(
ptr: *mut List, row: c_int,
v: f64,
) -> bool {
(&mut *ptr).set_f64(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_i16(ptr: *const List, row: c_int) -> i16 {
let o = unsafe { &*ptr };
o.i16(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_i16(
ptr: *mut List, row: c_int,
v: i16,
) -> bool {
(&mut *ptr).set_i16(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_i32(ptr: *const List, row: c_int) -> i32 {
let o = unsafe { &*ptr };
o.i32(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_i32(
ptr: *mut List, row: c_int,
v: i32,
) -> bool {
(&mut *ptr).set_i32(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_i64(ptr: *const List, row: c_int) -> i64 {
let o = unsafe { &*ptr };
o.i64(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_i64(
ptr: *mut List, row: c_int,
v: i64,
) -> bool {
(&mut *ptr).set_i64(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_i8(ptr: *const List, row: c_int) -> i8 {
let o = unsafe { &*ptr };
o.i8(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_i8(
ptr: *mut List, row: c_int,
v: i8,
) -> bool {
(&mut *ptr).set_i8(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_optional_boolean(ptr: *const List, row: c_int) -> COption<bool> {
let o = unsafe { &*ptr };
o.optional_boolean(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_optional_boolean(
ptr: *mut List, row: c_int,
v: bool,
) -> bool {
(&mut *ptr).set_optional_boolean(row as usize, Some(v))
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_optional_boolean_none(ptr: *mut List, row: c_int) -> bool {
(&mut *ptr).set_optional_boolean(row as usize, None)
}
#[no_mangle]
pub extern "C" fn list_data_optional_bytearray(
ptr: *const List, row: c_int,
d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int),
) {
let o = unsafe { &*ptr };
let data = o.optional_bytearray(row as usize);
if let Some(data) = data {
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
}
}
#[no_mangle]
pub extern "C" fn list_set_data_optional_bytearray(
ptr: *mut List, row: c_int,
s: *const c_char, len: c_int,
) -> bool {
let o = unsafe { &mut *ptr };
let mut v = Vec::new();
let slice = unsafe { ::std::slice::from_raw_parts(s as *const u8, len as usize) };
v.extend_from_slice(slice);
o.set_optional_bytearray(row as usize, Some(v))
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_optional_bytearray_none(ptr: *mut List, row: c_int) -> bool {
(&mut *ptr).set_optional_bytearray(row as usize, None)
}
#[no_mangle]
pub extern "C" fn list_data_optional_string(
ptr: *const List, row: c_int,
d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int),
) {
let o = unsafe { &*ptr };
let data = o.optional_string(row as usize);
if let Some(data) = data {
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
}
}
#[no_mangle]
pub extern "C" fn list_set_data_optional_string(
ptr: *mut List, row: c_int,
s: *const c_ushort, len: c_int,
) -> bool {
let o = unsafe { &mut *ptr };
let mut v = String::new();
set_string_from_utf16(&mut v, s, len);
o.set_optional_string(row as usize, Some(v))
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_optional_string_none(ptr: *mut List, row: c_int) -> bool {
(&mut *ptr).set_optional_string(row as usize, None)
}
#[no_mangle]
pub extern "C" fn list_data_string(
ptr: *const List, row: c_int,
d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int),
) {
let o = unsafe { &*ptr };
let data = o.string(row as usize);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
}
#[no_mangle]
pub extern "C" fn list_set_data_string(
ptr: *mut List, row: c_int,
s: *const c_ushort, len: c_int,
) -> bool {
let o = unsafe { &mut *ptr };
let mut v = String::new();
set_string_from_utf16(&mut v, s, len);
o.set_string(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_u16(ptr: *const List, row: c_int) -> u16 {
let o = unsafe { &*ptr };
o.u16(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_u16(
ptr: *mut List, row: c_int,
v: u16,
) -> bool {
(&mut *ptr).set_u16(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_u32(ptr: *const List, row: c_int) -> u32 {
let o = unsafe { &*ptr };
o.u32(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_u32(
ptr: *mut List, row: c_int,
v: u32,
) -> bool {
(&mut *ptr).set_u32(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_u64(ptr: *const List, row: c_int) -> u64 {
let o = unsafe { &*ptr };
o.u64(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_u64(
ptr: *mut List, row: c_int,
v: u64,
) -> bool {
(&mut *ptr).set_u64(row as usize, v)
}
#[no_mangle]
pub extern "C" fn list_data_u8(ptr: *const List, row: c_int) -> u8 {
let o = unsafe { &*ptr };
o.u8(row as usize).into()
}
#[no_mangle]
pub unsafe extern "C" fn list_set_data_u8(
ptr: *mut List, row: c_int,
v: u8,
) -> bool {
(&mut *ptr).set_u8(row as usize, v)
}