Warning, /sdk/rust-qt-binding-generator/tests/rust_list_types/src/interface.rs is written in an unsupported language. File is not indexed.

0001 /* generated by rust_qt_binding_generator */
0002 use libc::{c_char, c_ushort, c_int};
0003 use std::slice;
0004 use std::char::decode_utf16;
0005 
0006 use std::sync::Arc;
0007 use std::sync::atomic::{AtomicPtr, Ordering};
0008 use std::ptr::null;
0009 
0010 use implementation::*;
0011 
0012 
0013 #[repr(C)]
0014 pub struct COption<T> {
0015     data: T,
0016     some: bool,
0017 }
0018 
0019 impl<T> COption<T> {
0020     #![allow(dead_code)]
0021     fn into(self) -> Option<T> {
0022         if self.some {
0023             Some(self.data)
0024         } else {
0025             None
0026         }
0027     }
0028 }
0029 
0030 impl<T> From<Option<T>> for COption<T>
0031 where
0032     T: Default,
0033 {
0034     fn from(t: Option<T>) -> COption<T> {
0035         if let Some(v) = t {
0036             COption {
0037                 data: v,
0038                 some: true,
0039             }
0040         } else {
0041             COption {
0042                 data: T::default(),
0043                 some: false,
0044             }
0045         }
0046     }
0047 }
0048 
0049 
0050 pub enum QString {}
0051 
0052 fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
0053     let utf16 = unsafe { slice::from_raw_parts(str, to_usize(len)) };
0054     let characters = decode_utf16(utf16.iter().cloned())
0055         .map(|r| r.unwrap());
0056     s.clear();
0057     s.extend(characters);
0058 }
0059 
0060 
0061 
0062 pub enum QByteArray {}
0063 
0064 
0065 #[repr(C)]
0066 #[derive(PartialEq, Eq, Debug)]
0067 pub enum SortOrder {
0068     Ascending = 0,
0069     Descending = 1,
0070 }
0071 
0072 #[repr(C)]
0073 pub struct QModelIndex {
0074     row: c_int,
0075     internal_id: usize,
0076 }
0077 
0078 
0079 fn to_usize(n: c_int) -> usize {
0080     if n < 0 {
0081         panic!("Cannot cast {} to usize", n);
0082     }
0083     n as usize
0084 }
0085 
0086 
0087 fn to_c_int(n: usize) -> c_int {
0088     if n > c_int::max_value() as usize {
0089         panic!("Cannot cast {} to c_int", n);
0090     }
0091     n as c_int
0092 }
0093 
0094 
0095 pub struct ListQObject {}
0096 
0097 pub struct ListEmitter {
0098     qobject: Arc<AtomicPtr<ListQObject>>,
0099     new_data_ready: extern fn(*mut ListQObject),
0100 }
0101 
0102 unsafe impl Send for ListEmitter {}
0103 
0104 impl ListEmitter {
0105     /// Clone the emitter
0106     ///
0107     /// The emitter can only be cloned when it is mutable. The emitter calls
0108     /// into C++ code which may call into Rust again. If emmitting is possible
0109     /// from immutable structures, that might lead to access to a mutable
0110     /// reference. That is undefined behaviour and forbidden.
0111     pub fn clone(&mut self) -> ListEmitter {
0112         ListEmitter {
0113             qobject: self.qobject.clone(),
0114             new_data_ready: self.new_data_ready,
0115         }
0116     }
0117     fn clear(&self) {
0118         let n: *const ListQObject = null();
0119         self.qobject.store(n as *mut ListQObject, Ordering::SeqCst);
0120     }
0121     pub fn new_data_ready(&mut self) {
0122         let ptr = self.qobject.load(Ordering::SeqCst);
0123         if !ptr.is_null() {
0124             (self.new_data_ready)(ptr);
0125         }
0126     }
0127 }
0128 
0129 #[derive(Clone)]
0130 pub struct ListList {
0131     qobject: *mut ListQObject,
0132     layout_about_to_be_changed: extern fn(*mut ListQObject),
0133     layout_changed: extern fn(*mut ListQObject),
0134     data_changed: extern fn(*mut ListQObject, usize, usize),
0135     begin_reset_model: extern fn(*mut ListQObject),
0136     end_reset_model: extern fn(*mut ListQObject),
0137     begin_insert_rows: extern fn(*mut ListQObject, usize, usize),
0138     end_insert_rows: extern fn(*mut ListQObject),
0139     begin_move_rows: extern fn(*mut ListQObject, usize, usize, usize),
0140     end_move_rows: extern fn(*mut ListQObject),
0141     begin_remove_rows: extern fn(*mut ListQObject, usize, usize),
0142     end_remove_rows: extern fn(*mut ListQObject),
0143 }
0144 
0145 impl ListList {
0146     pub fn layout_about_to_be_changed(&mut self) {
0147         (self.layout_about_to_be_changed)(self.qobject);
0148     }
0149     pub fn layout_changed(&mut self) {
0150         (self.layout_changed)(self.qobject);
0151     }
0152     pub fn data_changed(&mut self, first: usize, last: usize) {
0153         (self.data_changed)(self.qobject, first, last);
0154     }
0155     pub fn begin_reset_model(&mut self) {
0156         (self.begin_reset_model)(self.qobject);
0157     }
0158     pub fn end_reset_model(&mut self) {
0159         (self.end_reset_model)(self.qobject);
0160     }
0161     pub fn begin_insert_rows(&mut self, first: usize, last: usize) {
0162         (self.begin_insert_rows)(self.qobject, first, last);
0163     }
0164     pub fn end_insert_rows(&mut self) {
0165         (self.end_insert_rows)(self.qobject);
0166     }
0167     pub fn begin_move_rows(&mut self, first: usize, last: usize, destination: usize) {
0168         (self.begin_move_rows)(self.qobject, first, last, destination);
0169     }
0170     pub fn end_move_rows(&mut self) {
0171         (self.end_move_rows)(self.qobject);
0172     }
0173     pub fn begin_remove_rows(&mut self, first: usize, last: usize) {
0174         (self.begin_remove_rows)(self.qobject, first, last);
0175     }
0176     pub fn end_remove_rows(&mut self) {
0177         (self.end_remove_rows)(self.qobject);
0178     }
0179 }
0180 
0181 pub trait ListTrait {
0182     fn new(emit: ListEmitter, model: ListList) -> Self;
0183     fn emit(&mut self) -> &mut ListEmitter;
0184     fn row_count(&self) -> usize;
0185     fn insert_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0186     fn remove_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0187     fn can_fetch_more(&self) -> bool {
0188         false
0189     }
0190     fn fetch_more(&mut self) {}
0191     fn sort(&mut self, _: u8, _: SortOrder) {}
0192     fn boolean(&self, index: usize) -> bool;
0193     fn set_boolean(&mut self, index: usize, _: bool) -> bool;
0194     fn bytearray(&self, index: usize) -> &[u8];
0195     fn set_bytearray(&mut self, index: usize, _: &[u8]) -> bool;
0196     fn f32(&self, index: usize) -> f32;
0197     fn set_f32(&mut self, index: usize, _: f32) -> bool;
0198     fn f64(&self, index: usize) -> f64;
0199     fn set_f64(&mut self, index: usize, _: f64) -> bool;
0200     fn i16(&self, index: usize) -> i16;
0201     fn set_i16(&mut self, index: usize, _: i16) -> bool;
0202     fn i32(&self, index: usize) -> i32;
0203     fn set_i32(&mut self, index: usize, _: i32) -> bool;
0204     fn i64(&self, index: usize) -> i64;
0205     fn set_i64(&mut self, index: usize, _: i64) -> bool;
0206     fn i8(&self, index: usize) -> i8;
0207     fn set_i8(&mut self, index: usize, _: i8) -> bool;
0208     fn optional_boolean(&self, index: usize) -> Option<bool>;
0209     fn set_optional_boolean(&mut self, index: usize, _: Option<bool>) -> bool;
0210     fn optional_bytearray(&self, index: usize) -> Option<&[u8]>;
0211     fn set_optional_bytearray(&mut self, index: usize, _: Option<&[u8]>) -> bool;
0212     fn optional_string(&self, index: usize) -> Option<&str>;
0213     fn set_optional_string(&mut self, index: usize, _: Option<String>) -> bool;
0214     fn string(&self, index: usize) -> &str;
0215     fn set_string(&mut self, index: usize, _: String) -> bool;
0216     fn u16(&self, index: usize) -> u16;
0217     fn set_u16(&mut self, index: usize, _: u16) -> bool;
0218     fn u32(&self, index: usize) -> u32;
0219     fn set_u32(&mut self, index: usize, _: u32) -> bool;
0220     fn u64(&self, index: usize) -> u64;
0221     fn set_u64(&mut self, index: usize, _: u64) -> bool;
0222     fn u8(&self, index: usize) -> u8;
0223     fn set_u8(&mut self, index: usize, _: u8) -> bool;
0224 }
0225 
0226 #[no_mangle]
0227 pub extern "C" fn list_new(
0228     list: *mut ListQObject,
0229     list_new_data_ready: extern fn(*mut ListQObject),
0230     list_layout_about_to_be_changed: extern fn(*mut ListQObject),
0231     list_layout_changed: extern fn(*mut ListQObject),
0232     list_data_changed: extern fn(*mut ListQObject, usize, usize),
0233     list_begin_reset_model: extern fn(*mut ListQObject),
0234     list_end_reset_model: extern fn(*mut ListQObject),
0235     list_begin_insert_rows: extern fn(*mut ListQObject, usize, usize),
0236     list_end_insert_rows: extern fn(*mut ListQObject),
0237     list_begin_move_rows: extern fn(*mut ListQObject, usize, usize, usize),
0238     list_end_move_rows: extern fn(*mut ListQObject),
0239     list_begin_remove_rows: extern fn(*mut ListQObject, usize, usize),
0240     list_end_remove_rows: extern fn(*mut ListQObject),
0241 ) -> *mut List {
0242     let list_emit = ListEmitter {
0243         qobject: Arc::new(AtomicPtr::new(list)),
0244         new_data_ready: list_new_data_ready,
0245     };
0246     let model = ListList {
0247         qobject: list,
0248         layout_about_to_be_changed: list_layout_about_to_be_changed,
0249         layout_changed: list_layout_changed,
0250         data_changed: list_data_changed,
0251         begin_reset_model: list_begin_reset_model,
0252         end_reset_model: list_end_reset_model,
0253         begin_insert_rows: list_begin_insert_rows,
0254         end_insert_rows: list_end_insert_rows,
0255         begin_move_rows: list_begin_move_rows,
0256         end_move_rows: list_end_move_rows,
0257         begin_remove_rows: list_begin_remove_rows,
0258         end_remove_rows: list_end_remove_rows,
0259     };
0260     let d_list = List::new(list_emit, model);
0261     Box::into_raw(Box::new(d_list))
0262 }
0263 
0264 #[no_mangle]
0265 pub unsafe extern "C" fn list_free(ptr: *mut List) {
0266     Box::from_raw(ptr).emit().clear();
0267 }
0268 
0269 #[no_mangle]
0270 pub unsafe extern "C" fn list_row_count(ptr: *const List) -> c_int {
0271     to_c_int((&*ptr).row_count())
0272 }
0273 #[no_mangle]
0274 pub unsafe extern "C" fn list_insert_rows(ptr: *mut List, row: c_int, count: c_int) -> bool {
0275     (&mut *ptr).insert_rows(to_usize(row), to_usize(count))
0276 }
0277 #[no_mangle]
0278 pub unsafe extern "C" fn list_remove_rows(ptr: *mut List, row: c_int, count: c_int) -> bool {
0279     (&mut *ptr).remove_rows(to_usize(row), to_usize(count))
0280 }
0281 #[no_mangle]
0282 pub unsafe extern "C" fn list_can_fetch_more(ptr: *const List) -> bool {
0283     (&*ptr).can_fetch_more()
0284 }
0285 #[no_mangle]
0286 pub unsafe extern "C" fn list_fetch_more(ptr: *mut List) {
0287     (&mut *ptr).fetch_more()
0288 }
0289 #[no_mangle]
0290 pub unsafe extern "C" fn list_sort(
0291     ptr: *mut List,
0292     column: u8,
0293     order: SortOrder,
0294 ) {
0295     (&mut *ptr).sort(column, order)
0296 }
0297 
0298 #[no_mangle]
0299 pub unsafe extern "C" fn list_data_boolean(ptr: *const List, row: c_int) -> bool {
0300     let o = &*ptr;
0301     o.boolean(to_usize(row))
0302 }
0303 
0304 #[no_mangle]
0305 pub unsafe extern "C" fn list_set_data_boolean(
0306     ptr: *mut List, row: c_int,
0307     v: bool,
0308 ) -> bool {
0309     (&mut *ptr).set_boolean(to_usize(row), v)
0310 }
0311 
0312 #[no_mangle]
0313 pub unsafe extern "C" fn list_data_bytearray(
0314     ptr: *const List, row: c_int,
0315     d: *mut QByteArray,
0316     set: extern fn(*mut QByteArray, *const c_char, len: c_int),
0317 ) {
0318     let o = &*ptr;
0319     let data = o.bytearray(to_usize(row));
0320     let s: *const c_char = data.as_ptr() as *const c_char;
0321     set(d, s, to_c_int(data.len()));
0322 }
0323 
0324 #[no_mangle]
0325 pub unsafe extern "C" fn list_set_data_bytearray(
0326     ptr: *mut List, row: c_int,
0327     s: *const c_char, len: c_int,
0328 ) -> bool {
0329     let o = &mut *ptr;
0330     let slice = ::std::slice::from_raw_parts(s as *const u8, to_usize(len));
0331     o.set_bytearray(to_usize(row), slice)
0332 }
0333 
0334 #[no_mangle]
0335 pub unsafe extern "C" fn list_data_f32(ptr: *const List, row: c_int) -> f32 {
0336     let o = &*ptr;
0337     o.f32(to_usize(row))
0338 }
0339 
0340 #[no_mangle]
0341 pub unsafe extern "C" fn list_set_data_f32(
0342     ptr: *mut List, row: c_int,
0343     v: f32,
0344 ) -> bool {
0345     (&mut *ptr).set_f32(to_usize(row), v)
0346 }
0347 
0348 #[no_mangle]
0349 pub unsafe extern "C" fn list_data_f64(ptr: *const List, row: c_int) -> f64 {
0350     let o = &*ptr;
0351     o.f64(to_usize(row))
0352 }
0353 
0354 #[no_mangle]
0355 pub unsafe extern "C" fn list_set_data_f64(
0356     ptr: *mut List, row: c_int,
0357     v: f64,
0358 ) -> bool {
0359     (&mut *ptr).set_f64(to_usize(row), v)
0360 }
0361 
0362 #[no_mangle]
0363 pub unsafe extern "C" fn list_data_i16(ptr: *const List, row: c_int) -> i16 {
0364     let o = &*ptr;
0365     o.i16(to_usize(row))
0366 }
0367 
0368 #[no_mangle]
0369 pub unsafe extern "C" fn list_set_data_i16(
0370     ptr: *mut List, row: c_int,
0371     v: i16,
0372 ) -> bool {
0373     (&mut *ptr).set_i16(to_usize(row), v)
0374 }
0375 
0376 #[no_mangle]
0377 pub unsafe extern "C" fn list_data_i32(ptr: *const List, row: c_int) -> i32 {
0378     let o = &*ptr;
0379     o.i32(to_usize(row))
0380 }
0381 
0382 #[no_mangle]
0383 pub unsafe extern "C" fn list_set_data_i32(
0384     ptr: *mut List, row: c_int,
0385     v: i32,
0386 ) -> bool {
0387     (&mut *ptr).set_i32(to_usize(row), v)
0388 }
0389 
0390 #[no_mangle]
0391 pub unsafe extern "C" fn list_data_i64(ptr: *const List, row: c_int) -> i64 {
0392     let o = &*ptr;
0393     o.i64(to_usize(row))
0394 }
0395 
0396 #[no_mangle]
0397 pub unsafe extern "C" fn list_set_data_i64(
0398     ptr: *mut List, row: c_int,
0399     v: i64,
0400 ) -> bool {
0401     (&mut *ptr).set_i64(to_usize(row), v)
0402 }
0403 
0404 #[no_mangle]
0405 pub unsafe extern "C" fn list_data_i8(ptr: *const List, row: c_int) -> i8 {
0406     let o = &*ptr;
0407     o.i8(to_usize(row))
0408 }
0409 
0410 #[no_mangle]
0411 pub unsafe extern "C" fn list_set_data_i8(
0412     ptr: *mut List, row: c_int,
0413     v: i8,
0414 ) -> bool {
0415     (&mut *ptr).set_i8(to_usize(row), v)
0416 }
0417 
0418 #[no_mangle]
0419 pub unsafe extern "C" fn list_data_optional_boolean(ptr: *const List, row: c_int) -> COption<bool> {
0420     let o = &*ptr;
0421     o.optional_boolean(to_usize(row)).into()
0422 }
0423 
0424 #[no_mangle]
0425 pub unsafe extern "C" fn list_set_data_optional_boolean(
0426     ptr: *mut List, row: c_int,
0427     v: bool,
0428 ) -> bool {
0429     (&mut *ptr).set_optional_boolean(to_usize(row), Some(v))
0430 }
0431 
0432 #[no_mangle]
0433 pub unsafe extern "C" fn list_set_data_optional_boolean_none(ptr: *mut List, row: c_int) -> bool {
0434     (&mut *ptr).set_optional_boolean(to_usize(row), None)
0435 }
0436 
0437 #[no_mangle]
0438 pub unsafe extern "C" fn list_data_optional_bytearray(
0439     ptr: *const List, row: c_int,
0440     d: *mut QByteArray,
0441     set: extern fn(*mut QByteArray, *const c_char, len: c_int),
0442 ) {
0443     let o = &*ptr;
0444     let data = o.optional_bytearray(to_usize(row));
0445     if let Some(data) = data {
0446         let s: *const c_char = data.as_ptr() as *const c_char;
0447         set(d, s, to_c_int(data.len()));
0448     }
0449 }
0450 
0451 #[no_mangle]
0452 pub unsafe extern "C" fn list_set_data_optional_bytearray(
0453     ptr: *mut List, row: c_int,
0454     s: *const c_char, len: c_int,
0455 ) -> bool {
0456     let o = &mut *ptr;
0457     let slice = ::std::slice::from_raw_parts(s as *const u8, to_usize(len));
0458     o.set_optional_bytearray(to_usize(row), Some(slice))
0459 }
0460 
0461 #[no_mangle]
0462 pub unsafe extern "C" fn list_set_data_optional_bytearray_none(ptr: *mut List, row: c_int) -> bool {
0463     (&mut *ptr).set_optional_bytearray(to_usize(row), None)
0464 }
0465 
0466 #[no_mangle]
0467 pub unsafe extern "C" fn list_data_optional_string(
0468     ptr: *const List, row: c_int,
0469     d: *mut QString,
0470     set: extern fn(*mut QString, *const c_char, len: c_int),
0471 ) {
0472     let o = &*ptr;
0473     let data = o.optional_string(to_usize(row));
0474     if let Some(data) = data {
0475         let s: *const c_char = data.as_ptr() as *const c_char;
0476         set(d, s, to_c_int(data.len()));
0477     }
0478 }
0479 
0480 #[no_mangle]
0481 pub unsafe extern "C" fn list_set_data_optional_string(
0482     ptr: *mut List, row: c_int,
0483     s: *const c_ushort, len: c_int,
0484 ) -> bool {
0485     let o = &mut *ptr;
0486     let mut v = String::new();
0487     set_string_from_utf16(&mut v, s, len);
0488     o.set_optional_string(to_usize(row), Some(v))
0489 }
0490 
0491 #[no_mangle]
0492 pub unsafe extern "C" fn list_set_data_optional_string_none(ptr: *mut List, row: c_int) -> bool {
0493     (&mut *ptr).set_optional_string(to_usize(row), None)
0494 }
0495 
0496 #[no_mangle]
0497 pub unsafe extern "C" fn list_data_string(
0498     ptr: *const List, row: c_int,
0499     d: *mut QString,
0500     set: extern fn(*mut QString, *const c_char, len: c_int),
0501 ) {
0502     let o = &*ptr;
0503     let data = o.string(to_usize(row));
0504     let s: *const c_char = data.as_ptr() as *const c_char;
0505     set(d, s, to_c_int(data.len()));
0506 }
0507 
0508 #[no_mangle]
0509 pub unsafe extern "C" fn list_set_data_string(
0510     ptr: *mut List, row: c_int,
0511     s: *const c_ushort, len: c_int,
0512 ) -> bool {
0513     let o = &mut *ptr;
0514     let mut v = String::new();
0515     set_string_from_utf16(&mut v, s, len);
0516     o.set_string(to_usize(row), v)
0517 }
0518 
0519 #[no_mangle]
0520 pub unsafe extern "C" fn list_data_u16(ptr: *const List, row: c_int) -> u16 {
0521     let o = &*ptr;
0522     o.u16(to_usize(row))
0523 }
0524 
0525 #[no_mangle]
0526 pub unsafe extern "C" fn list_set_data_u16(
0527     ptr: *mut List, row: c_int,
0528     v: u16,
0529 ) -> bool {
0530     (&mut *ptr).set_u16(to_usize(row), v)
0531 }
0532 
0533 #[no_mangle]
0534 pub unsafe extern "C" fn list_data_u32(ptr: *const List, row: c_int) -> u32 {
0535     let o = &*ptr;
0536     o.u32(to_usize(row))
0537 }
0538 
0539 #[no_mangle]
0540 pub unsafe extern "C" fn list_set_data_u32(
0541     ptr: *mut List, row: c_int,
0542     v: u32,
0543 ) -> bool {
0544     (&mut *ptr).set_u32(to_usize(row), v)
0545 }
0546 
0547 #[no_mangle]
0548 pub unsafe extern "C" fn list_data_u64(ptr: *const List, row: c_int) -> u64 {
0549     let o = &*ptr;
0550     o.u64(to_usize(row))
0551 }
0552 
0553 #[no_mangle]
0554 pub unsafe extern "C" fn list_set_data_u64(
0555     ptr: *mut List, row: c_int,
0556     v: u64,
0557 ) -> bool {
0558     (&mut *ptr).set_u64(to_usize(row), v)
0559 }
0560 
0561 #[no_mangle]
0562 pub unsafe extern "C" fn list_data_u8(ptr: *const List, row: c_int) -> u8 {
0563     let o = &*ptr;
0564     o.u8(to_usize(row))
0565 }
0566 
0567 #[no_mangle]
0568 pub unsafe extern "C" fn list_set_data_u8(
0569     ptr: *mut List, row: c_int,
0570     v: u8,
0571 ) -> bool {
0572     (&mut *ptr).set_u8(to_usize(row), v)
0573 }