1#[cxx::bridge]
2pub(crate) mod ffi {
3 unsafe extern "C++" {
4 include!("vtk_algorithm.h");
5
6 pub type vtkAlgorithm;
7 pub type vtkAlgorithmOutput;
8 pub type vtkInformation;
9 pub type vtkInformationVector;
10 pub type vtkExecutive;
11
12 fn vtk_algorithm_new() -> *mut vtkAlgorithm;
13 fn vtk_algorithm_delete(algorithm: Pin<&mut vtkAlgorithm>);
14
15 fn vtk_algorithm_set_input_connection(
16 algorithm: Pin<&mut vtkAlgorithm>,
17 port: i64,
18 input: &vtkAlgorithmOutput,
19 );
20 fn vtk_algorithm_has_executive(algorithm: &vtkAlgorithm) -> bool;
21 fn vtk_algorithm_get_executive(algorithm: &vtkAlgorithm) -> &vtkExecutive;
22 fn vtk_algorithm_set_executive(
23 algorithm: Pin<&mut vtkAlgorithm>,
24 executive: Pin<&mut vtkExecutive>,
25 );
26 unsafe fn vtk_algorithm_process_request(
27 algorithm: &vtkAlgorithm,
28 request: &vtkInformation,
29 in_info: &mut [*mut vtkInformationVector],
30 out_info: Pin<&mut vtkInformationVector>,
31 ) -> bool;
32 }
33}
34
35crate::define_object!(
36 "https://vtk.org/doc/nightly/html/classvtkAlgorithm.html",
37 @name Algorithm, ffi::vtkAlgorithm,
38 @new ffi::vtk_algorithm_new,
39 @delete ffi::vtk_algorithm_delete,
40 @inherit vtkAlgorithm
41);
42
43pub(crate) mod private {
44 pub trait Sealed {}
45}
46
47#[allow(non_camel_case_types)]
49pub trait vtkAlgorithm: private::Sealed {
50 #[doc(hidden)]
51 fn as_vtk_algorithm(&self) -> core::pin::Pin<&ffi::vtkAlgorithm>;
52 #[doc(hidden)]
53 fn as_vtk_algorithm_mut(&mut self) -> core::pin::Pin<&mut ffi::vtkAlgorithm>;
54
55 fn has_executive(&self) -> bool {
56 ffi::vtk_algorithm_has_executive(&self.as_vtk_algorithm())
57 }
58
59 fn get_executive(&self) -> Option<&crate::vtk_executive::Executive> {
60 let x = ffi::vtk_algorithm_get_executive(&self.as_vtk_algorithm()) as *const _
62 as *const crate::vtk_executive::Executive;
63 unsafe { x.as_ref() }
64 }
65
66 fn set_executive(&mut self, executive: &mut impl crate::vtk_executive::vtkExecutive) {
67 let executive = unsafe {
68 executive
69 .as_vtk_executive_mut()
70 .map_unchecked_mut(|x| &mut *(x as *mut _ as *mut ffi::vtkExecutive))
71 };
72 let sself = self.as_vtk_algorithm_mut();
73 ffi::vtk_algorithm_set_executive(sself, executive);
74 }
75
76 fn set_input_connection(&mut self, port: i64, input: &impl crate::vtkAlgorithmOutput) {
77 let sself = self.as_vtk_algorithm_mut();
78 let input = &input.as_vtk_algorithm_output() as *const _ as *const ffi::vtkAlgorithmOutput;
79 ffi::vtk_algorithm_set_input_connection(sself, port, unsafe { &*input });
80 }
81}