Warning, /sdk/rust-qt-binding-generator/tests/rust_list/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 #[repr(C)]
0063 #[derive(PartialEq, Eq, Debug)]
0064 pub enum SortOrder {
0065     Ascending = 0,
0066     Descending = 1,
0067 }
0068 
0069 #[repr(C)]
0070 pub struct QModelIndex {
0071     row: c_int,
0072     internal_id: usize,
0073 }
0074 
0075 
0076 fn to_usize(n: c_int) -> usize {
0077     if n < 0 {
0078         panic!("Cannot cast {} to usize", n);
0079     }
0080     n as usize
0081 }
0082 
0083 
0084 fn to_c_int(n: usize) -> c_int {
0085     if n > c_int::max_value() as usize {
0086         panic!("Cannot cast {} to c_int", n);
0087     }
0088     n as c_int
0089 }
0090 
0091 
0092 pub struct NoRoleQObject {}
0093 
0094 pub struct NoRoleEmitter {
0095     qobject: Arc<AtomicPtr<NoRoleQObject>>,
0096     new_data_ready: extern fn(*mut NoRoleQObject),
0097 }
0098 
0099 unsafe impl Send for NoRoleEmitter {}
0100 
0101 impl NoRoleEmitter {
0102     /// Clone the emitter
0103     ///
0104     /// The emitter can only be cloned when it is mutable. The emitter calls
0105     /// into C++ code which may call into Rust again. If emmitting is possible
0106     /// from immutable structures, that might lead to access to a mutable
0107     /// reference. That is undefined behaviour and forbidden.
0108     pub fn clone(&mut self) -> NoRoleEmitter {
0109         NoRoleEmitter {
0110             qobject: self.qobject.clone(),
0111             new_data_ready: self.new_data_ready,
0112         }
0113     }
0114     fn clear(&self) {
0115         let n: *const NoRoleQObject = null();
0116         self.qobject.store(n as *mut NoRoleQObject, Ordering::SeqCst);
0117     }
0118     pub fn new_data_ready(&mut self) {
0119         let ptr = self.qobject.load(Ordering::SeqCst);
0120         if !ptr.is_null() {
0121             (self.new_data_ready)(ptr);
0122         }
0123     }
0124 }
0125 
0126 #[derive(Clone)]
0127 pub struct NoRoleList {
0128     qobject: *mut NoRoleQObject,
0129     layout_about_to_be_changed: extern fn(*mut NoRoleQObject),
0130     layout_changed: extern fn(*mut NoRoleQObject),
0131     data_changed: extern fn(*mut NoRoleQObject, usize, usize),
0132     begin_reset_model: extern fn(*mut NoRoleQObject),
0133     end_reset_model: extern fn(*mut NoRoleQObject),
0134     begin_insert_rows: extern fn(*mut NoRoleQObject, usize, usize),
0135     end_insert_rows: extern fn(*mut NoRoleQObject),
0136     begin_move_rows: extern fn(*mut NoRoleQObject, usize, usize, usize),
0137     end_move_rows: extern fn(*mut NoRoleQObject),
0138     begin_remove_rows: extern fn(*mut NoRoleQObject, usize, usize),
0139     end_remove_rows: extern fn(*mut NoRoleQObject),
0140 }
0141 
0142 impl NoRoleList {
0143     pub fn layout_about_to_be_changed(&mut self) {
0144         (self.layout_about_to_be_changed)(self.qobject);
0145     }
0146     pub fn layout_changed(&mut self) {
0147         (self.layout_changed)(self.qobject);
0148     }
0149     pub fn data_changed(&mut self, first: usize, last: usize) {
0150         (self.data_changed)(self.qobject, first, last);
0151     }
0152     pub fn begin_reset_model(&mut self) {
0153         (self.begin_reset_model)(self.qobject);
0154     }
0155     pub fn end_reset_model(&mut self) {
0156         (self.end_reset_model)(self.qobject);
0157     }
0158     pub fn begin_insert_rows(&mut self, first: usize, last: usize) {
0159         (self.begin_insert_rows)(self.qobject, first, last);
0160     }
0161     pub fn end_insert_rows(&mut self) {
0162         (self.end_insert_rows)(self.qobject);
0163     }
0164     pub fn begin_move_rows(&mut self, first: usize, last: usize, destination: usize) {
0165         (self.begin_move_rows)(self.qobject, first, last, destination);
0166     }
0167     pub fn end_move_rows(&mut self) {
0168         (self.end_move_rows)(self.qobject);
0169     }
0170     pub fn begin_remove_rows(&mut self, first: usize, last: usize) {
0171         (self.begin_remove_rows)(self.qobject, first, last);
0172     }
0173     pub fn end_remove_rows(&mut self) {
0174         (self.end_remove_rows)(self.qobject);
0175     }
0176 }
0177 
0178 pub trait NoRoleTrait {
0179     fn new(emit: NoRoleEmitter, model: NoRoleList) -> Self;
0180     fn emit(&mut self) -> &mut NoRoleEmitter;
0181     fn row_count(&self) -> usize;
0182     fn insert_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0183     fn remove_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0184     fn can_fetch_more(&self) -> bool {
0185         false
0186     }
0187     fn fetch_more(&mut self) {}
0188     fn sort(&mut self, _: u8, _: SortOrder) {}
0189     fn user_age(&self, index: usize) -> u8;
0190     fn set_user_age(&mut self, index: usize, _: u8) -> bool;
0191     fn user_name(&self, index: usize) -> &str;
0192     fn set_user_name(&mut self, index: usize, _: String) -> bool;
0193 }
0194 
0195 #[no_mangle]
0196 pub extern "C" fn no_role_new(
0197     no_role: *mut NoRoleQObject,
0198     no_role_new_data_ready: extern fn(*mut NoRoleQObject),
0199     no_role_layout_about_to_be_changed: extern fn(*mut NoRoleQObject),
0200     no_role_layout_changed: extern fn(*mut NoRoleQObject),
0201     no_role_data_changed: extern fn(*mut NoRoleQObject, usize, usize),
0202     no_role_begin_reset_model: extern fn(*mut NoRoleQObject),
0203     no_role_end_reset_model: extern fn(*mut NoRoleQObject),
0204     no_role_begin_insert_rows: extern fn(*mut NoRoleQObject, usize, usize),
0205     no_role_end_insert_rows: extern fn(*mut NoRoleQObject),
0206     no_role_begin_move_rows: extern fn(*mut NoRoleQObject, usize, usize, usize),
0207     no_role_end_move_rows: extern fn(*mut NoRoleQObject),
0208     no_role_begin_remove_rows: extern fn(*mut NoRoleQObject, usize, usize),
0209     no_role_end_remove_rows: extern fn(*mut NoRoleQObject),
0210 ) -> *mut NoRole {
0211     let no_role_emit = NoRoleEmitter {
0212         qobject: Arc::new(AtomicPtr::new(no_role)),
0213         new_data_ready: no_role_new_data_ready,
0214     };
0215     let model = NoRoleList {
0216         qobject: no_role,
0217         layout_about_to_be_changed: no_role_layout_about_to_be_changed,
0218         layout_changed: no_role_layout_changed,
0219         data_changed: no_role_data_changed,
0220         begin_reset_model: no_role_begin_reset_model,
0221         end_reset_model: no_role_end_reset_model,
0222         begin_insert_rows: no_role_begin_insert_rows,
0223         end_insert_rows: no_role_end_insert_rows,
0224         begin_move_rows: no_role_begin_move_rows,
0225         end_move_rows: no_role_end_move_rows,
0226         begin_remove_rows: no_role_begin_remove_rows,
0227         end_remove_rows: no_role_end_remove_rows,
0228     };
0229     let d_no_role = NoRole::new(no_role_emit, model);
0230     Box::into_raw(Box::new(d_no_role))
0231 }
0232 
0233 #[no_mangle]
0234 pub unsafe extern "C" fn no_role_free(ptr: *mut NoRole) {
0235     Box::from_raw(ptr).emit().clear();
0236 }
0237 
0238 #[no_mangle]
0239 pub unsafe extern "C" fn no_role_row_count(ptr: *const NoRole) -> c_int {
0240     to_c_int((&*ptr).row_count())
0241 }
0242 #[no_mangle]
0243 pub unsafe extern "C" fn no_role_insert_rows(ptr: *mut NoRole, row: c_int, count: c_int) -> bool {
0244     (&mut *ptr).insert_rows(to_usize(row), to_usize(count))
0245 }
0246 #[no_mangle]
0247 pub unsafe extern "C" fn no_role_remove_rows(ptr: *mut NoRole, row: c_int, count: c_int) -> bool {
0248     (&mut *ptr).remove_rows(to_usize(row), to_usize(count))
0249 }
0250 #[no_mangle]
0251 pub unsafe extern "C" fn no_role_can_fetch_more(ptr: *const NoRole) -> bool {
0252     (&*ptr).can_fetch_more()
0253 }
0254 #[no_mangle]
0255 pub unsafe extern "C" fn no_role_fetch_more(ptr: *mut NoRole) {
0256     (&mut *ptr).fetch_more()
0257 }
0258 #[no_mangle]
0259 pub unsafe extern "C" fn no_role_sort(
0260     ptr: *mut NoRole,
0261     column: u8,
0262     order: SortOrder,
0263 ) {
0264     (&mut *ptr).sort(column, order)
0265 }
0266 
0267 #[no_mangle]
0268 pub unsafe extern "C" fn no_role_data_user_age(ptr: *const NoRole, row: c_int) -> u8 {
0269     let o = &*ptr;
0270     o.user_age(to_usize(row))
0271 }
0272 
0273 #[no_mangle]
0274 pub unsafe extern "C" fn no_role_set_data_user_age(
0275     ptr: *mut NoRole, row: c_int,
0276     v: u8,
0277 ) -> bool {
0278     (&mut *ptr).set_user_age(to_usize(row), v)
0279 }
0280 
0281 #[no_mangle]
0282 pub unsafe extern "C" fn no_role_data_user_name(
0283     ptr: *const NoRole, row: c_int,
0284     d: *mut QString,
0285     set: extern fn(*mut QString, *const c_char, len: c_int),
0286 ) {
0287     let o = &*ptr;
0288     let data = o.user_name(to_usize(row));
0289     let s: *const c_char = data.as_ptr() as *const c_char;
0290     set(d, s, to_c_int(data.len()));
0291 }
0292 
0293 #[no_mangle]
0294 pub unsafe extern "C" fn no_role_set_data_user_name(
0295     ptr: *mut NoRole, row: c_int,
0296     s: *const c_ushort, len: c_int,
0297 ) -> bool {
0298     let o = &mut *ptr;
0299     let mut v = String::new();
0300     set_string_from_utf16(&mut v, s, len);
0301     o.set_user_name(to_usize(row), v)
0302 }
0303 
0304 pub struct PersonsQObject {}
0305 
0306 pub struct PersonsEmitter {
0307     qobject: Arc<AtomicPtr<PersonsQObject>>,
0308     new_data_ready: extern fn(*mut PersonsQObject),
0309 }
0310 
0311 unsafe impl Send for PersonsEmitter {}
0312 
0313 impl PersonsEmitter {
0314     /// Clone the emitter
0315     ///
0316     /// The emitter can only be cloned when it is mutable. The emitter calls
0317     /// into C++ code which may call into Rust again. If emmitting is possible
0318     /// from immutable structures, that might lead to access to a mutable
0319     /// reference. That is undefined behaviour and forbidden.
0320     pub fn clone(&mut self) -> PersonsEmitter {
0321         PersonsEmitter {
0322             qobject: self.qobject.clone(),
0323             new_data_ready: self.new_data_ready,
0324         }
0325     }
0326     fn clear(&self) {
0327         let n: *const PersonsQObject = null();
0328         self.qobject.store(n as *mut PersonsQObject, Ordering::SeqCst);
0329     }
0330     pub fn new_data_ready(&mut self) {
0331         let ptr = self.qobject.load(Ordering::SeqCst);
0332         if !ptr.is_null() {
0333             (self.new_data_ready)(ptr);
0334         }
0335     }
0336 }
0337 
0338 #[derive(Clone)]
0339 pub struct PersonsList {
0340     qobject: *mut PersonsQObject,
0341     layout_about_to_be_changed: extern fn(*mut PersonsQObject),
0342     layout_changed: extern fn(*mut PersonsQObject),
0343     data_changed: extern fn(*mut PersonsQObject, usize, usize),
0344     begin_reset_model: extern fn(*mut PersonsQObject),
0345     end_reset_model: extern fn(*mut PersonsQObject),
0346     begin_insert_rows: extern fn(*mut PersonsQObject, usize, usize),
0347     end_insert_rows: extern fn(*mut PersonsQObject),
0348     begin_move_rows: extern fn(*mut PersonsQObject, usize, usize, usize),
0349     end_move_rows: extern fn(*mut PersonsQObject),
0350     begin_remove_rows: extern fn(*mut PersonsQObject, usize, usize),
0351     end_remove_rows: extern fn(*mut PersonsQObject),
0352 }
0353 
0354 impl PersonsList {
0355     pub fn layout_about_to_be_changed(&mut self) {
0356         (self.layout_about_to_be_changed)(self.qobject);
0357     }
0358     pub fn layout_changed(&mut self) {
0359         (self.layout_changed)(self.qobject);
0360     }
0361     pub fn data_changed(&mut self, first: usize, last: usize) {
0362         (self.data_changed)(self.qobject, first, last);
0363     }
0364     pub fn begin_reset_model(&mut self) {
0365         (self.begin_reset_model)(self.qobject);
0366     }
0367     pub fn end_reset_model(&mut self) {
0368         (self.end_reset_model)(self.qobject);
0369     }
0370     pub fn begin_insert_rows(&mut self, first: usize, last: usize) {
0371         (self.begin_insert_rows)(self.qobject, first, last);
0372     }
0373     pub fn end_insert_rows(&mut self) {
0374         (self.end_insert_rows)(self.qobject);
0375     }
0376     pub fn begin_move_rows(&mut self, first: usize, last: usize, destination: usize) {
0377         (self.begin_move_rows)(self.qobject, first, last, destination);
0378     }
0379     pub fn end_move_rows(&mut self) {
0380         (self.end_move_rows)(self.qobject);
0381     }
0382     pub fn begin_remove_rows(&mut self, first: usize, last: usize) {
0383         (self.begin_remove_rows)(self.qobject, first, last);
0384     }
0385     pub fn end_remove_rows(&mut self) {
0386         (self.end_remove_rows)(self.qobject);
0387     }
0388 }
0389 
0390 pub trait PersonsTrait {
0391     fn new(emit: PersonsEmitter, model: PersonsList) -> Self;
0392     fn emit(&mut self) -> &mut PersonsEmitter;
0393     fn row_count(&self) -> usize;
0394     fn insert_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0395     fn remove_rows(&mut self, _row: usize, _count: usize) -> bool { false }
0396     fn can_fetch_more(&self) -> bool {
0397         false
0398     }
0399     fn fetch_more(&mut self) {}
0400     fn sort(&mut self, _: u8, _: SortOrder) {}
0401     fn user_name(&self, index: usize) -> &str;
0402     fn set_user_name(&mut self, index: usize, _: String) -> bool;
0403 }
0404 
0405 #[no_mangle]
0406 pub extern "C" fn persons_new(
0407     persons: *mut PersonsQObject,
0408     persons_new_data_ready: extern fn(*mut PersonsQObject),
0409     persons_layout_about_to_be_changed: extern fn(*mut PersonsQObject),
0410     persons_layout_changed: extern fn(*mut PersonsQObject),
0411     persons_data_changed: extern fn(*mut PersonsQObject, usize, usize),
0412     persons_begin_reset_model: extern fn(*mut PersonsQObject),
0413     persons_end_reset_model: extern fn(*mut PersonsQObject),
0414     persons_begin_insert_rows: extern fn(*mut PersonsQObject, usize, usize),
0415     persons_end_insert_rows: extern fn(*mut PersonsQObject),
0416     persons_begin_move_rows: extern fn(*mut PersonsQObject, usize, usize, usize),
0417     persons_end_move_rows: extern fn(*mut PersonsQObject),
0418     persons_begin_remove_rows: extern fn(*mut PersonsQObject, usize, usize),
0419     persons_end_remove_rows: extern fn(*mut PersonsQObject),
0420 ) -> *mut Persons {
0421     let persons_emit = PersonsEmitter {
0422         qobject: Arc::new(AtomicPtr::new(persons)),
0423         new_data_ready: persons_new_data_ready,
0424     };
0425     let model = PersonsList {
0426         qobject: persons,
0427         layout_about_to_be_changed: persons_layout_about_to_be_changed,
0428         layout_changed: persons_layout_changed,
0429         data_changed: persons_data_changed,
0430         begin_reset_model: persons_begin_reset_model,
0431         end_reset_model: persons_end_reset_model,
0432         begin_insert_rows: persons_begin_insert_rows,
0433         end_insert_rows: persons_end_insert_rows,
0434         begin_move_rows: persons_begin_move_rows,
0435         end_move_rows: persons_end_move_rows,
0436         begin_remove_rows: persons_begin_remove_rows,
0437         end_remove_rows: persons_end_remove_rows,
0438     };
0439     let d_persons = Persons::new(persons_emit, model);
0440     Box::into_raw(Box::new(d_persons))
0441 }
0442 
0443 #[no_mangle]
0444 pub unsafe extern "C" fn persons_free(ptr: *mut Persons) {
0445     Box::from_raw(ptr).emit().clear();
0446 }
0447 
0448 #[no_mangle]
0449 pub unsafe extern "C" fn persons_row_count(ptr: *const Persons) -> c_int {
0450     to_c_int((&*ptr).row_count())
0451 }
0452 #[no_mangle]
0453 pub unsafe extern "C" fn persons_insert_rows(ptr: *mut Persons, row: c_int, count: c_int) -> bool {
0454     (&mut *ptr).insert_rows(to_usize(row), to_usize(count))
0455 }
0456 #[no_mangle]
0457 pub unsafe extern "C" fn persons_remove_rows(ptr: *mut Persons, row: c_int, count: c_int) -> bool {
0458     (&mut *ptr).remove_rows(to_usize(row), to_usize(count))
0459 }
0460 #[no_mangle]
0461 pub unsafe extern "C" fn persons_can_fetch_more(ptr: *const Persons) -> bool {
0462     (&*ptr).can_fetch_more()
0463 }
0464 #[no_mangle]
0465 pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons) {
0466     (&mut *ptr).fetch_more()
0467 }
0468 #[no_mangle]
0469 pub unsafe extern "C" fn persons_sort(
0470     ptr: *mut Persons,
0471     column: u8,
0472     order: SortOrder,
0473 ) {
0474     (&mut *ptr).sort(column, order)
0475 }
0476 
0477 #[no_mangle]
0478 pub unsafe extern "C" fn persons_data_user_name(
0479     ptr: *const Persons, row: c_int,
0480     d: *mut QString,
0481     set: extern fn(*mut QString, *const c_char, len: c_int),
0482 ) {
0483     let o = &*ptr;
0484     let data = o.user_name(to_usize(row));
0485     let s: *const c_char = data.as_ptr() as *const c_char;
0486     set(d, s, to_c_int(data.len()));
0487 }
0488 
0489 #[no_mangle]
0490 pub unsafe extern "C" fn persons_set_data_user_name(
0491     ptr: *mut Persons, row: c_int,
0492     s: *const c_ushort, len: c_int,
0493 ) -> bool {
0494     let o = &mut *ptr;
0495     let mut v = String::new();
0496     set_string_from_utf16(&mut v, s, len);
0497     o.set_user_name(to_usize(row), v)
0498 }