cobia/
cape_array_byte.rs

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