dorothy_ssr/dora/
array.rs1extern "C" {
2 fn array_type() -> i32;
3 fn array_get_count(slf: i64) -> i64;
4 fn array_is_empty(slf: i64) -> i32;
5 fn array_add_range(slf: i64, other: i64);
6 fn array_remove_from(slf: i64, other: i64);
7 fn array_clear(slf: i64);
8 fn array_reverse(slf: i64);
9 fn array_shrink(slf: i64);
10 fn array_swap(slf: i64, index_a: i32, index_b: i32);
11 fn array_remove_at(slf: i64, index: i32) -> i32;
12 fn array_fast_remove_at(slf: i64, index: i32) -> i32;
13 fn array_new() -> i64;
14}
15use crate::dora::IObject;
16pub struct Array { raw: i64 }
17crate::dora_object!(Array);
18impl Array {
19 pub fn type_info() -> (i32, fn(i64) -> Option<Box<dyn IObject>>) {
20 (unsafe { array_type() }, |raw: i64| -> Option<Box<dyn IObject>> {
21 match raw {
22 0 => None,
23 _ => Some(Box::new(Array { raw: raw }))
24 }
25 })
26 }
27 pub fn get_count(&self) -> i64 {
28 return unsafe { array_get_count(self.raw()) };
29 }
30 pub fn is_empty(&self) -> bool {
31 return unsafe { array_is_empty(self.raw()) != 0 };
32 }
33 pub fn add_range(&mut self, other: &crate::dora::Array) {
34 unsafe { array_add_range(self.raw(), other.raw()); }
35 }
36 pub fn remove_from(&mut self, other: &crate::dora::Array) {
37 unsafe { array_remove_from(self.raw(), other.raw()); }
38 }
39 pub fn clear(&mut self) {
40 unsafe { array_clear(self.raw()); }
41 }
42 pub fn reverse(&mut self) {
43 unsafe { array_reverse(self.raw()); }
44 }
45 pub fn shrink(&mut self) {
46 unsafe { array_shrink(self.raw()); }
47 }
48 pub fn swap(&mut self, index_a: i32, index_b: i32) {
49 unsafe { array_swap(self.raw(), index_a, index_b); }
50 }
51 pub fn remove_at(&mut self, index: i32) -> bool {
52 unsafe { return array_remove_at(self.raw(), index) != 0; }
53 }
54 pub fn fast_remove_at(&mut self, index: i32) -> bool {
55 unsafe { return array_fast_remove_at(self.raw(), index) != 0; }
56 }
57 pub fn new() -> Array {
58 unsafe { return Array { raw: array_new() }; }
59 }
60}