cobia/
cape_array_integer.rs

1use crate::{COBIAError, CapeArrayIntegerInFromProvider, C};
2use crate::cape_array::{ArrayInterface,CapeArrayIn,CapeArrayOut};
3use crate::{CapeArrayIntegerProviderIn,CapeArrayIntegerProviderOut};
4
5impl ArrayInterface<C::CapeInteger> for C::ICapeArrayInteger {
6
7	fn get(&mut self,data:&mut *mut C::CapeInteger,size:&mut C::CapeSize) {
8		unsafe { (*self.vTbl).get.unwrap()(self.me,data as *mut *mut C::CapeInteger,size) };
9	}
10
11	fn set(&mut self,data:&mut *mut C::CapeInteger,size:C::CapeSize) -> C::CapeResult {
12		unsafe { (*self.vTbl).setsize.unwrap()(self.me,size,data as *mut *mut C::CapeInteger) }
13	}
14
15	fn get_const(&self,data:&mut *const C::CapeInteger,size:&mut C::CapeSize) {
16		unsafe { (*self.vTbl).get.unwrap()(self.me,data as *mut *const C::CapeInteger as *mut *mut C::CapeInteger,size) };
17	}
18
19}
20
21/// CapeArrayIntegerIn wraps an ICapeArrayInteger interface pointer.
22///
23/// Given an ICapeArrayInteger interface pointer, this allows setting
24///  and getting the elements.
25///
26/// This interface is typically used as arguments to rust methods
27/// on traits that are generated from CAPE-OPEN interfaces that have
28/// ICapeArrayInteger input arguments.
29///
30/// # Examples
31///
32/// ```
33/// use cobia::*;
34///
35/// fn test_content(a: &CapeArrayIntegerIn) {
36///     assert_eq!(a.as_vec(), vec![2,8,10]);
37/// }
38/// 
39/// let arr = cobia::CapeArrayIntegerVec::from_slice(&[2,8,10]);
40/// test_content(&CapeArrayIntegerInFromProvider::from(&arr).as_cape_array_integer_in())
41/// ```
42
43pub type CapeArrayIntegerIn<'a> = CapeArrayIn<'a,C::CapeInteger,C::ICapeArrayInteger>;
44
45impl<'a> CapeArrayIntegerProviderIn for CapeArrayIntegerIn<'a> {
46	fn as_cape_array_integer_in(&self) -> C::ICapeArrayInteger {
47		unsafe { **self.interface }
48	}
49}
50
51/// CapeArrayIntegerOut wraps an ICapeArrayInteger interface pointer.
52///
53/// Given an ICapeArrayInteger interface pointer, this allows setting
54///  and getting the elements.
55///
56/// This interface is typically used as arguments to rust methods
57/// on traits that are generated from CAPE-OPEN interfaces that have
58/// ICapeArrayInteger output arguments.
59///
60/// # Examples
61///
62/// ```
63/// use cobia::*;
64///
65/// fn set_content(a: &mut CapeArrayIntegerOut) {
66///     a.put_array(&[2,8,10]).unwrap();
67/// }
68/// 
69/// let mut arr = cobia::CapeArrayIntegerVec::new();
70/// set_content(&mut CapeArrayIntegerOutFromProvider::from(&mut arr).as_cape_array_integer_out());
71/// assert_eq!(arr.as_vec(), &vec![2,8,10]);
72/// ```
73
74pub type CapeArrayIntegerOut<'a> = CapeArrayOut<'a,C::CapeInteger,C::ICapeArrayInteger>;
75
76impl<'a> CapeArrayIntegerOut<'a> {
77
78	/// Set the content of the integer array from any object that implements CapeArrayIntegerProviderIn.
79	///
80	/// # Arguments
81	/// * `array` - An object that implements CapeArrayIntegerProviderIn
82	///
83	/// # Examples
84	///
85	/// ```
86	/// use cobia::*;
87	/// let mut arr = cobia::CapeArrayIntegerVec::new();
88	/// let mut arr1 = cobia::CapeArrayIntegerVec::from_slice(&vec![17,14,9,0]);
89	/// CapeArrayIntegerOutFromProvider::from(&mut arr).as_cape_array_integer_out().set(&arr1);
90	/// assert_eq!(arr.as_vec(), &[17,14,9,0]);
91	/// ```
92
93	pub fn set<T:CapeArrayIntegerProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
94		let mut integer_array_in_from_provider = CapeArrayIntegerInFromProvider::from(array);
95		let integer_array=integer_array_in_from_provider.as_cape_array_integer_in();
96		self.resize(integer_array.size())?;
97		for i in 0..integer_array.size() {
98			self[i]=integer_array[i];
99		}
100		Ok(())
101	}
102
103}
104
105impl<'a> CapeArrayIntegerProviderOut for CapeArrayIntegerOut<'a> {
106	fn as_cape_array_integer_out(&mut self) -> C::ICapeArrayInteger {
107		unsafe { **self.interface }
108	}
109}