cobia/
cape_array_vec.rs

1use crate::C;
2use crate::*;
3use std::mem;
4
5/// Vector based implementation of ICapeArray
6///
7/// Base class for several vector based ICapeArray implementations.
8///
9/// Any ICapeArray (e.g. ICapeArrayReal) is passed as data container
10/// between CAPE-OPEN functions. It is up to the caller to provide the 
11/// interface, and its implementation. This class provides a default
12/// impementation, that uses std::vec::Vec as the data container.
13///
14/// # Examples
15///
16/// ```
17/// use cobia::*;
18///
19/// fn set_content(arr: &mut CapeArrayRealOut) {
20///		arr.put_array(&[4.5,6.5]).unwrap();
21/// }
22/// 
23/// let mut arr = cobia::CapeArrayRealVec::from_slice(&[4.5,6.5]);
24/// set_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
25/// assert_eq!(arr.as_vec(), &vec![4.5,6.5]);
26/// ```
27
28#[allow(private_bounds)]
29#[derive (Clone)]
30pub struct CapeArrayVec<Element:Copy+Clone,InterfaceType> {
31	vec: Vec<Element>,
32	interface_type: std::marker::PhantomData<InterfaceType>,
33}
34
35#[allow(private_bounds)]
36impl<Element:Copy+Clone,InterfaceType> CapeArrayVec<Element,InterfaceType> {
37
38	/// Create a new CapeArrayVec
39	///
40	/// Creates a new empty CapeArrayVec
41	///
42	/// # Examples
43	///
44	/// ```
45	/// use cobia;
46	/// use cobia::prelude::*;
47	/// let arr = cobia::CapeArrayRealVec::new();
48	/// assert_eq!(arr.as_vec().len(), 0);
49	/// ```
50	pub fn new() -> Self {
51		Self {
52			vec: Vec::new(),
53			interface_type: std::default::Default::default(),
54		}
55	}
56
57	/// Return a vector
58	///
59	/// Returns a reference to the vector of type T.
60	///
61	/// # Example
62	///
63	/// ```
64	/// use cobia;
65	/// use cobia::prelude::*;
66	/// let arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
67	/// assert_eq!(arr.as_vec(), &vec![2.5,4.5]);
68	/// ```
69
70	pub fn as_vec(&self) -> &Vec<Element> {
71		&self.vec
72	}
73
74	/// Return a mutable vector
75	///
76	/// Returns a mutable reference to the vector of type T.
77	///
78	/// # Example
79	///
80	/// ```
81	/// use cobia;
82	/// use cobia::prelude::*;
83	/// let mut arr = cobia::CapeArrayRealVec::from_vec(vec![2.5,4.5]);
84	/// arr.as_mut_vec().push(6.5);
85	/// assert_eq!(arr.as_vec(), &vec![2.5,4.5,6.5]);
86	/// ```
87
88	pub fn as_mut_vec(&mut self) -> &mut Vec<Element> {
89		&mut self.vec
90	}
91
92	/// Get size
93	///
94	/// Returns the size of the array.
95	///
96	/// # Examples
97	///
98	/// ```
99	/// use cobia;
100	/// use cobia::prelude::*;
101	/// let arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
102	/// assert_eq!(arr.size(), 2);
103	/// ```
104
105	pub fn size(&self) -> usize {
106		self.as_vec().len()	
107	}
108
109	/// Initialize from slice
110	///
111	/// Creates a new CapeArrayVec from a slice.
112	///
113	/// # Arguments
114	///
115	/// * `slice` - A vector or array or slice of values to be converted to a CapeArrayVec - values are copied
116	///
117	/// # Examples
118	///
119	/// ```
120	/// use cobia;
121	/// use cobia::prelude::*;
122	/// let arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
123	/// assert_eq!(arr.as_vec(), &vec![2.5,4.5]);
124	/// ```
125
126	pub fn from_slice(slice: &[Element]) -> Self {
127		let mut a = Self::new();
128		a.as_mut_vec().extend_from_slice(slice);
129		a
130	}
131
132	/// Check if empty
133	///
134	/// Returns true if the array is empty.
135	///
136	/// # Examples
137	///
138	/// ```
139	/// use cobia;
140	/// use cobia::prelude::*;
141	/// let arr = cobia::CapeArrayRealVec::new();
142	/// assert!(arr.is_empty());
143	/// ```
144	pub fn is_empty(&self) -> bool {
145		self.as_vec().is_empty()
146	}
147
148	/// Initialize from vector
149	///
150	/// Creates a new CapeArrayVec from a vector, taking ownwership of the data
151	///
152	/// # Arguments
153	///
154	/// * `vec` - A vector slice of values to be converted to a CapeArrayVec
155	///
156	/// # Examples
157	///
158	/// ```
159	/// use cobia;
160	/// use cobia::prelude::*;
161	/// let arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
162	/// assert_eq!(arr.as_vec(), &vec![2.5,4.5]);
163	/// ```
164
165	pub fn from_vec(mut vec: std::vec::Vec<Element>) -> Self {
166		let mut a = Self::new();
167		mem::swap(a.as_mut_vec(), &mut vec);
168		a
169	}
170
171}
172
173impl<Element:Copy+Clone,InterfacType> Default for CapeArrayVec<Element,InterfacType> {
174    fn default() -> Self {
175        Self::new()
176    }
177}
178
179impl<Element:Copy+Clone,InterfacType> std::ops::Index<usize> for CapeArrayVec<Element,InterfacType> {
180
181	type Output = Element;
182
183	/// Indexing
184	///
185	/// Returns a reference to the element at the given index.
186	///
187	/// # Arguments
188	///
189	/// * `index` - The index of the element to be returned
190	///
191	/// # Examples
192	///
193	/// ```
194	/// use cobia;
195	/// use cobia::prelude::*;
196	/// let arr = cobia::CapeArrayRealVec::from_slice(&[10.1,10.2,10.3]);
197	/// assert_eq!(arr[1], 10.2);
198	/// ```
199
200	fn index(&self, index: usize) -> &Self::Output {
201		&self.vec[index]
202	}
203
204}
205
206impl<Element:Copy+Clone,Interface> std::ops::IndexMut<usize> for CapeArrayVec<Element,Interface> {
207	/// Indexing
208	///
209	/// Returns a mutable reference to the element at the given index.
210	///
211	/// # Arguments
212	///
213	/// * `index` - The index of the element to be returned
214	///
215	/// # Examples
216	///
217	/// ```
218	/// use cobia;
219	/// use cobia::prelude::*;
220	/// let mut arr = cobia::CapeArrayRealVec::from_slice(&[10.1,10.2,10.3]);
221	/// arr[1]=2.2;
222	/// assert_eq!(arr[1], 2.2);
223	/// ```
224
225	fn index_mut(&mut self, index: usize) -> &mut Self::Output {
226		&mut self.vec[index]
227	}
228}
229
230
231impl<Element:Copy+Clone,InterfacType> AsRef<[Element]> for CapeArrayVec<Element,InterfacType> {
232    fn as_ref(&self) -> &[Element] {
233        self.vec.as_ref()
234    }
235}
236
237/// Vector based CapeArrayRealOut implementation
238///
239/// ICapeArrayReal is passed as data container between CAPE-OPEN functions. 
240/// It is up to the caller to provide the interface, and its implementation. 
241/// This class provides a default impementation using a `Vec<C::CapeReal>`.
242///
243/// # Examples
244///
245/// ```
246/// use cobia::*;
247///
248/// fn set_content(arr: &mut CapeArrayRealOut) {
249///		arr.put_array(&[4.5,6.5]).unwrap();
250/// }
251/// 
252/// let mut arr = cobia::CapeArrayRealVec::from_slice(&[4.5,6.5]);
253/// set_content(&mut CapeArrayRealOutFromProvider::from(&mut arr).as_cape_array_real_out());
254/// assert_eq!(arr.as_vec(), &vec![4.5,6.5]);
255/// ```
256pub type CapeArrayRealVec = CapeArrayVec<CapeReal,C::ICapeArrayReal>;
257
258impl CapeArrayRealVec {
259
260	/// Interface member function
261
262	extern "C" fn get(
263		me: *mut ::std::os::raw::c_void,
264		data: *mut *mut CapeReal,
265		size: *mut C::CapeSize,
266	) {
267		let p = me as *mut Self;
268		let arr: &mut Self = unsafe { &mut *p };
269		unsafe {
270			*data = arr.vec.as_ptr() as *mut CapeReal;
271			*size = arr.vec.len() as C::CapeSize;
272		}
273	}
274	
275	/// Resize
276	///
277	/// Resize the array to the given size. If the size is larger than the current size, the new elements are set to `CapeReal::NAN`.
278	///
279	/// # Arguments
280	///
281	/// * `size` - The new size of the array
282	///
283	/// # Examples
284	///
285	/// ```
286	/// use cobia;
287	/// use cobia::prelude::*;
288	/// let mut arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
289	/// arr.resize(4);
290	/// assert_eq!(arr.size(), 4);
291	/// assert!(arr[2].is_nan());
292	/// ```
293	pub fn resize(&mut self, size: usize) {
294		self.vec.resize(size, CapeReal::NAN);
295	}
296	
297	/// Set the content of the real array from any object that implements CapeArrayRealProviderIn.
298	///
299	/// # Arguments
300	/// * `array` - An object that implements CapeArrayRealProviderIn
301	///
302	/// # Example
303	///
304	/// ```
305	/// use cobia;
306	/// let mut arr = cobia::CapeArrayRealVec::new();
307	/// let arr1 = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
308	/// arr.set(&arr1);
309	/// assert_eq!(arr.as_vec(), &vec![2.5,4.5]);
310	/// ```
311	pub fn set<T:CapeArrayRealProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
312		let mut real_array_in_from_provider = CapeArrayRealInFromProvider::from(array);
313		let real_array=real_array_in_from_provider.as_cape_array_real_in();
314		self.vec.clear();
315		self.vec.extend_from_slice(real_array.as_slice());
316		Ok(())
317	}
318
319	/// Interface member function
320
321	extern "C" fn setsize(
322		me: *mut ::std::os::raw::c_void,
323		size: C::CapeSize,
324		data: *mut *mut CapeReal,
325	) -> CapeResult {
326		let p = me as *mut Self;
327		let arr: &mut Self = unsafe { &mut *p };
328		arr.resize(size as usize);
329		unsafe {
330			*data = arr.vec.as_ptr() as *mut CapeReal;
331		}
332		COBIAERR_NOERROR
333	}
334
335	/// Interface v-table
336
337	const VTABLE: C::ICapeArrayReal_VTable = C::ICapeArrayReal_VTable {
338		get: Some(Self::get),
339		setsize: Some(Self::setsize),
340	};
341
342}
343
344impl CapeArrayRealProviderIn for CapeArrayRealVec {
345	/// Convert to ICapeArrayReal
346	///
347	/// Returns a reference to the ICapeArrayReal interface.
348	///
349	/// # Examples
350	///
351	/// ```
352	/// use cobia::*;
353	///
354	/// fn test_content(a: &CapeArrayRealIn) {
355	///     assert_eq!(a.as_vec(), vec![2.5,4.5]);
356	/// }
357	/// 
358	/// let arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
359	/// test_content(&CapeArrayRealInFromProvider::from(&arr).as_cape_array_real_in());
360	/// ```
361
362	fn as_cape_array_real_in(&self) -> C::ICapeArrayReal {
363		C::ICapeArrayReal {
364			me:(self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
365			vTbl: (&CapeArrayRealVec::VTABLE as *const C::ICapeArrayReal_VTable).cast_mut(),
366		}
367	}
368}
369
370impl CapeArrayRealProviderOut for CapeArrayRealVec {
371	/// Convert to ICapeArrayReal
372	///
373	/// Returns a mutable reference to the ICapeArrayReal interface.
374	///
375	/// # Examples
376	///
377	/// ```
378	/// use cobia::*;
379	/// use cobia::prelude::*;
380	/// let mut arr = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
381	///	let i_cape_array_real=arr.as_cape_array_real_out();
382	///	let mut i_cape_array_real_ptr=(&i_cape_array_real as *const C::ICapeArrayReal).cast_mut(); //normally a pointer to the interface is received
383	///	let a = cobia::CapeArrayRealOut::new(&mut i_cape_array_real_ptr); //CapeArrayRealOut from *mut C::ICapeArrayReal
384	/// assert_eq!(a.as_vec(), vec![2.5,4.5]);
385	/// ```
386
387	fn as_cape_array_real_out(&mut self) -> C::ICapeArrayReal {
388		C::ICapeArrayReal {
389			me:(self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
390			vTbl: (&CapeArrayRealVec::VTABLE as *const C::ICapeArrayReal_VTable).cast_mut(),
391		}
392	}
393}
394
395impl<T:CapeArrayRealProviderIn> PartialEq<T> for CapeArrayRealVec {
396	/// Partial equality
397	///
398	/// Checks if the CapeArrayRealVec is equal to another CapeArrayRealProviderIn.
399	///
400	/// # Arguments
401	///
402	/// * `other` - The other CapeArrayRealProviderIn to compare with
403	///
404	/// # Examples
405	///
406	/// ```
407	/// use cobia::*;
408	/// use cobia::prelude::*;
409	/// let arr1 = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
410	/// let arr2 = cobia::CapeArrayRealVec::from_slice(&[2.5,4.5]);
411	/// let arr3 = cobia::CapeArrayRealVec::from_slice(&[2.0,4.5]);
412	/// assert!(arr1 == arr2);
413	/// assert!(arr1 != arr3);
414	/// ```
415	fn eq(&self, other: &T) -> bool {
416		let mut provider=CapeArrayRealInFromProvider::from(other);
417		let other=provider.as_cape_array_real_in(); 
418		self.as_vec() == other.as_slice()
419	}
420}
421
422/// Vector based CapeArrayIntegerOut implementation
423///
424/// ICapeArrayInteger is passed as data container between CAPE-OPEN functions. 
425/// It is up to the caller to provide the interface, and its implementation. 
426/// This class provides a default impementation using a `Vec<C::CapeInteger>`.
427///
428/// # Examples
429///
430///
431/// ```
432/// use cobia::*;
433///
434/// fn set_content(a: &mut CapeArrayIntegerOut) {
435///     a.put_array(&[2,8,10]).unwrap();
436/// }
437/// 
438/// let mut arr = cobia::CapeArrayIntegerVec::new();
439/// set_content(&mut CapeArrayIntegerOutFromProvider::from(&mut arr).as_cape_array_integer_out());
440/// assert_eq!(arr.as_vec(), &vec![2,8,10]);
441/// ```
442pub type CapeArrayIntegerVec = CapeArrayVec<CapeInteger,C::ICapeArrayInteger>;
443
444impl CapeArrayIntegerVec {
445
446	/// Interface member function
447
448	extern "C" fn get(
449		me: *mut ::std::os::raw::c_void,
450		data: *mut *mut CapeInteger,
451		size: *mut C::CapeSize,
452	) {
453		let p = me as *mut Self;
454		let arr: &mut Self = unsafe { &mut *p };
455		unsafe {
456			*data = arr.vec.as_ptr() as *mut CapeInteger;
457			*size = arr.vec.len() as C::CapeSize;
458		}
459	}
460
461	/// Interface member function
462
463	extern "C" fn setsize(
464		me: *mut ::std::os::raw::c_void,
465		size: C::CapeSize,
466		data: *mut *mut CapeInteger,
467	) -> CapeResult {
468		let p = me as *mut Self;
469		let arr: &mut Self = unsafe { &mut *p };
470		arr.resize(size as usize);
471		unsafe {
472			*data = arr.vec.as_ptr() as *mut CapeInteger;
473		}
474		COBIAERR_NOERROR
475	}
476
477	/// Resize
478	///
479	/// Resize the array to the given size. If the size is larger than the current size, the new elements are set to `0`.
480	///
481	/// # Arguments
482	///
483	/// * `size` - The new size of the array
484	///
485	/// # Examples
486	///
487	/// ```
488	/// use cobia;
489	/// use cobia::prelude::*;
490	/// let mut arr = cobia::CapeArrayIntegerVec::from_slice(&[2,4]);
491	/// arr.resize(4);
492	/// assert_eq!(arr.as_vec(), &vec![2 as cobia::CapeInteger,4 as cobia::CapeInteger,0 as cobia::CapeInteger,0 as cobia::CapeInteger]);
493	/// ```
494	pub fn resize(&mut self, size: usize) {
495		self.vec.resize(size, 0);
496	}
497
498	/// Set the content of the integer array from any object that implements CapeArrayIntegerProviderIn.
499	///
500	/// # Arguments
501	/// * `array` - An object that implements CapeArrayIntegerProviderIn
502	///
503	/// # Example
504	///
505	/// ```
506	/// use cobia;
507	/// let mut arr = cobia::CapeArrayIntegerVec::new();
508	/// let arr1 = cobia::CapeArrayIntegerVec::from_slice(&[8,9,7]);
509	/// arr.set(&arr1);
510	/// assert_eq!(arr.as_vec(), &vec![8,9,7]);
511	/// ```
512	pub fn set<T:CapeArrayIntegerProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
513		let mut integer_array_in_from_provider = CapeArrayIntegerInFromProvider::from(array);
514		let integer_array=integer_array_in_from_provider.as_cape_array_integer_in();
515		self.vec.clear();
516		self.vec.extend_from_slice(integer_array.as_slice());
517		Ok(())
518	}
519
520	/// Interface v-table
521
522	const VTABLE: C::ICapeArrayInteger_VTable = C::ICapeArrayInteger_VTable {
523		get: Some(Self::get),
524		setsize: Some(Self::setsize),
525	};
526
527}
528
529impl CapeArrayIntegerProviderIn for CapeArrayIntegerVec {
530	/// Convert to ICapeArrayInteger
531	///
532	/// Returns a reference to the ICapeArrayInteger interface.
533	///
534	/// # Examples
535	///
536	/// ```
537	/// use cobia::*;
538	/// use cobia::prelude::*;
539	/// let mut arr = cobia::CapeArrayIntegerVec::from_slice(&[9,10,2]);
540	///	let i_cape_array_integer=arr.as_cape_array_integer_out();
541	///	let mut i_cape_array_integer_ptr=(&i_cape_array_integer as *const C::ICapeArrayInteger).cast_mut(); //normally a pointer to the interface is received
542	///	let a = cobia::CapeArrayIntegerOut::new(&mut i_cape_array_integer_ptr); //CapeArrayIntegerOut from *mut C::ICapeArrayInteger
543	/// assert_eq!(a.as_vec(), vec![9,10,2]);
544	/// ```
545
546	fn as_cape_array_integer_in(&self) -> C::ICapeArrayInteger {
547		C::ICapeArrayInteger {
548			vTbl: (&CapeArrayIntegerVec::VTABLE as *const C::ICapeArrayInteger_VTable).cast_mut(),
549			me:(self as *const Self).cast_mut() as *mut ::std::os::raw::c_void
550		}
551	}
552}
553
554
555impl CapeArrayIntegerProviderOut for CapeArrayIntegerVec {
556	/// Convert to ICapeArrayInteger
557	///
558	/// Returns a mutable reference to the ICapeArrayInteger interface.
559	///
560	/// # Examples
561	///
562	/// ```
563	/// use cobia::*;
564	/// use cobia::prelude::*;
565	/// let mut arr = cobia::CapeArrayIntegerVec::from_slice(&[9,10,2]);
566	///	let i_cape_array_integer=arr.as_cape_array_integer_out();
567	///	let mut i_cape_array_integer_ptr=(&i_cape_array_integer as *const C::ICapeArrayInteger).cast_mut(); //normally a pointer to the interface is received
568	///	let a = cobia::CapeArrayIntegerOut::new(&mut i_cape_array_integer_ptr); //CapeArrayIntegerOut from *mut C::ICapeArrayInteger
569	/// assert_eq!(a.as_vec(), vec![9,10,2]);
570	/// ```
571
572	fn as_cape_array_integer_out(&mut self) -> C::ICapeArrayInteger {
573		C::ICapeArrayInteger {
574			vTbl: (&CapeArrayIntegerVec::VTABLE as *const C::ICapeArrayInteger_VTable).cast_mut(),
575			me:(self as *const Self).cast_mut() as *mut ::std::os::raw::c_void
576		}
577	}
578}
579
580impl<T:CapeArrayIntegerProviderIn> PartialEq<T> for CapeArrayIntegerVec {
581	/// Partial equality
582	///
583	/// Checks if the CapeArrayIntegerVec is equal to another CapeArrayIntegerProviderIn.
584	///
585	/// # Arguments
586	///
587	/// * `other` - The other CapeArrayIntegerProviderIn to compare with
588	///
589	/// # Examples
590	///
591	/// ```
592	/// use cobia::*;
593	/// use cobia::prelude::*;
594	/// let arr1 = cobia::CapeArrayIntegerVec::from_slice(&[2,4]);
595	/// let arr2 = cobia::CapeArrayIntegerVec::from_slice(&[2,4]);
596	/// let arr3 = cobia::CapeArrayIntegerVec::from_slice(&[2,3,4]);
597	/// assert!(arr1 == arr2);
598	/// assert!(arr1 != arr3);
599	/// ```
600	fn eq(&self, other: &T) -> bool {
601		let mut provider=CapeArrayIntegerInFromProvider::from(other);
602		let other=provider.as_cape_array_integer_in(); 
603		self.as_vec() == other.as_slice()
604	}
605}
606
607/// Vector based CapeArrayByteOut implementation
608///
609/// ICapeArrayByte is passed as data container between CAPE-OPEN functions. 
610/// It is up to the caller to provide the interface, and its implementation. 
611/// This class provides a default impementation using a `Vec<C::CapeByte>`.
612///
613/// # Examples
614///
615///
616/// ```
617/// use cobia::*;
618///
619/// fn set_content(a: &mut CapeArrayByteOut) {
620///		a.put_array(&[2u8,4u8]).unwrap();
621/// }
622/// 
623/// let mut arr = cobia::CapeArrayByteVec::from_slice(&[2u8,4u8]);
624/// set_content(&mut CapeArrayByteOutFromProvider::from(&mut arr).as_cape_array_byte_out());
625/// assert_eq!(arr.as_vec(), &vec![2u8,4u8]);
626/// ```
627pub type CapeArrayByteVec = CapeArrayVec<CapeByte,C::ICapeArrayByte>;
628
629impl CapeArrayByteVec {
630
631	/// Interface member function
632
633	extern "C" fn get(
634		me: *mut ::std::os::raw::c_void,
635		data: *mut *mut CapeByte,
636		size: *mut C::CapeSize,
637	) {
638		let p = me as *mut Self;
639		let arr: &mut Self = unsafe { &mut *p };
640		unsafe {
641			*data = arr.vec.as_ptr() as *mut CapeByte;
642			*size = arr.vec.len() as C::CapeSize;
643		}
644	}
645
646	/// Interface member function
647
648	extern "C" fn setsize(
649		me: *mut ::std::os::raw::c_void,
650		size: C::CapeSize,
651		data: *mut *mut CapeByte,
652	) -> C::CapeResult {
653		let p = me as *mut Self;
654		let arr: &mut Self = unsafe { &mut *p };
655		arr.resize(size as usize);
656		unsafe {
657			*data = arr.vec.as_ptr() as *mut CapeByte;
658		}
659		COBIAERR_NOERROR
660	}
661
662	/// Resize
663	///
664	/// Resize the array to the given size. If the size is larger than the current size, the new elements are set to `0`.
665	///
666	/// # Arguments
667	///
668	/// * `size` - The new size of the array
669	///
670	/// # Examples
671	///
672	/// ```
673	/// use cobia;
674	/// use cobia::prelude::*;
675	/// let mut arr = cobia::CapeArrayByteVec::from_slice(&[2u8,4u8]);
676	/// arr.resize(4);
677	/// assert_eq!(arr.as_vec(), &vec![2u8,4u8,0,0]);
678	/// ```
679	pub fn resize(&mut self, size: usize) {
680		self.vec.resize(size, 0);
681	}
682
683	/// Set the content of the byte array from any object that implements CapeArrayByteProviderIn.
684	///
685	/// # Arguments
686	/// * `array` - An object that implements CapeArrayByteProviderIn
687	///
688	/// # Example
689	///
690	/// ```
691	/// use cobia;
692	/// let mut arr = cobia::CapeArrayByteVec::new();
693	/// let arr1 = cobia::CapeArrayByteVec::from_slice(&[8,9,7]);
694	/// arr.set(&arr1);
695	/// assert_eq!(arr.as_vec(), &vec![8,9,7]);
696	/// ```
697	pub fn set<T:CapeArrayByteProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
698		let mut byte_array_in_from_provider = CapeArrayByteInFromProvider::from(array);
699		let byte_array=byte_array_in_from_provider.as_cape_array_byte_in();
700		self.vec.clear();
701		self.vec.extend_from_slice(byte_array.as_slice());
702		Ok(())
703	}
704
705	/// Interface v-table
706
707	const VTABLE: C::ICapeArrayByte_VTable = C::ICapeArrayByte_VTable {
708		get: Some(Self::get),
709		setsize: Some(Self::setsize),
710	};
711
712}
713
714impl CapeArrayByteProviderIn for CapeArrayByteVec {
715	/// Convert to ICapeArrayByte
716	///
717	/// Returns a reference to the ICapeArrayByte interface.
718	///
719	/// # Examples
720	///
721	/// ```
722	/// use cobia::*;
723	/// use cobia::prelude::*;
724	/// let arr = cobia::CapeArrayByteVec::from_slice(&[9u8,10u8,2u8]);
725	///	let i_cape_array_byte=arr.as_cape_array_byte_in();
726	///	let mut i_cape_array_byte_ptr=(&i_cape_array_byte as *const C::ICapeArrayByte).cast_mut(); //normally a pointer to the interface is received
727	///	let a = cobia::CapeArrayByteIn::new(&mut i_cape_array_byte_ptr); //CapeArrayByteIn from *mut C::ICapeArrayByte
728	/// assert_eq!(a.as_vec(), vec![9u8,10u8,2u8]);
729	/// ```
730
731	fn as_cape_array_byte_in(&self) -> C::ICapeArrayByte {
732		C::ICapeArrayByte {
733			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
734			vTbl: (&CapeArrayByteVec::VTABLE as *const C::ICapeArrayByte_VTable).cast_mut(),
735		}
736	}
737}
738
739impl CapeArrayByteProviderOut for CapeArrayByteVec {
740	/// Convert to ICapeArrayByte
741	///
742	/// Returns a mutable reference to the ICapeArrayByte interface.
743	///
744	/// # Examples
745	///
746	/// ```
747	/// use cobia::*;
748	/// use cobia::prelude::*;
749	/// let mut arr = cobia::CapeArrayByteVec::from_slice(&[9u8,10u8,2u8]);
750	///	let i_cape_array_byte=arr.as_cape_array_byte_out();
751	///	let mut i_cape_array_byte_ptr=(&i_cape_array_byte as *const C::ICapeArrayByte).cast_mut(); //normally a pointer to the interface is received
752	///	let a = cobia::CapeArrayByteOut::new(&mut i_cape_array_byte_ptr); //CapeArrayByteOut from *mut C::ICapeArrayByte
753	/// assert_eq!(a.as_vec(), vec![9u8,10u8,2u8]);
754	/// ```
755
756	fn as_cape_array_byte_out(&mut self) -> C::ICapeArrayByte {
757		C::ICapeArrayByte {
758			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
759			vTbl: (&CapeArrayByteVec::VTABLE as *const C::ICapeArrayByte_VTable).cast_mut(),
760		}
761	}
762}
763
764impl<T:CapeArrayByteProviderIn> PartialEq<T> for CapeArrayByteVec {
765	/// Partial equality
766	///
767	/// Checks if the CapeArrayByteVec is equal to another CapeArrayByteProviderIn.
768	///
769	/// # Arguments
770	///
771	/// * `other` - The other CapeArrayByteProviderIn to compare with
772	///
773	/// # Examples
774	///
775	/// ```
776	/// use cobia::*;
777	/// use cobia::prelude::*;
778	/// let arr1 = cobia::CapeArrayByteVec::from_slice(&[2u8,4u8]);
779	/// let arr2 = cobia::CapeArrayByteVec::from_slice(&[2u8,4u8]);
780	/// let arr3 = cobia::CapeArrayByteVec::from_slice(&[2u8,3u8,4u8]);
781	/// assert!(arr1 == arr2);
782	/// assert!(arr1 != arr3);
783	/// ```
784	fn eq(&self, other: &T) -> bool {
785		let mut provider=CapeArrayByteInFromProvider::from(other);
786		let other=provider.as_cape_array_byte_in(); 
787		self.as_vec() == other.as_slice()
788	}
789}
790
791/// Vector based CapeArrayBooleanOut implementation
792///
793/// ICapeArrayBoolean is passed as data container between CAPE-OPEN functions. 
794/// It is up to the caller to provide the interface, and its implementation. 
795/// This class provides a default impementation using a `Vec<C::CapeBoolean>`.
796///
797/// # Examples
798///
799///
800/// ```
801/// use cobia::*;
802///
803/// fn test_content(a: &CapeArrayBooleanIn) {
804///     assert_eq!(a.as_bool_vec(), vec![true,false]);
805/// }
806/// 
807/// let arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[true,false]);
808/// test_content(&CapeArrayBooleanInFromProvider::from(&arr).as_cape_array_boolean_in())
809/// ```
810pub type CapeArrayBooleanVec = CapeArrayVec<CapeBoolean,C::ICapeArrayBoolean>;
811
812impl CapeArrayBooleanVec {
813
814	/// Interface member function
815
816	extern "C" fn get(
817		me: *mut ::std::os::raw::c_void,
818		data: *mut *mut CapeBoolean,
819		size: *mut C::CapeSize,
820	) {
821		let p = me as *mut Self;
822		let arr: &mut Self = unsafe { &mut *p };
823		unsafe {
824			*data = arr.vec.as_ptr() as *mut CapeBoolean;
825			*size = arr.vec.len() as C::CapeSize;
826		}
827	}
828
829	/// Resize
830	///
831	/// Resize the array to the given size. If the size is larger than the current size, the new elements are set to `false`.
832	///
833	/// # Arguments
834	///
835	/// * `size` - The new size of the array
836	///
837	/// # Examples
838	///
839	/// ```
840	/// use cobia;
841	/// use cobia::prelude::*;
842	/// let mut arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[true,false]);
843	/// arr.resize(4);
844	/// assert_eq!(arr.as_vec(), &vec![true as cobia::CapeBoolean,false as cobia::CapeBoolean,false as cobia::CapeBoolean,false as cobia::CapeBoolean]);
845	/// ```
846	pub fn resize(&mut self, size: usize) {
847		self.vec.resize(size, 0);
848	}
849
850	/// Interface member function
851
852	extern "C" fn setsize(
853		me: *mut ::std::os::raw::c_void,
854		size: C::CapeSize,
855		data: *mut *mut CapeBoolean,
856	) -> CapeResult {
857		let p = me as *mut Self;
858		let arr: &mut Self = unsafe { &mut *p };
859		arr.resize(size as usize);
860		unsafe {
861			*data = arr.vec.as_ptr() as *mut CapeBoolean;
862		}
863		COBIAERR_NOERROR
864	}
865
866	/// Set the content of the boolean array from any object that implements CapeArrayBooleanProviderIn.
867	///
868	/// # Arguments
869	/// * `array` - An object that implements CapeArrayBooleanProviderIn
870	///
871	/// # Example
872	///
873	/// ```
874	/// use cobia;
875	/// let mut arr = cobia::CapeArrayBooleanVec::new();
876	/// let arr1 = cobia::CapeArrayBooleanVec::from_slice(&[8,9,7]);
877	/// arr.set(&arr1);
878	/// assert_eq!(arr.as_vec(), &vec![8,9,7]);
879	/// ```
880	pub fn set<T:CapeArrayBooleanProviderIn>(&mut self,array:&T) -> Result<(), COBIAError> {
881		let mut boolean_array_in_from_provider = CapeArrayBooleanInFromProvider::from(array);
882		let boolean_array=boolean_array_in_from_provider.as_cape_array_boolean_in();
883		self.vec.clear();
884		self.vec.extend_from_slice(boolean_array.as_slice());
885		Ok(())
886	}
887
888	/// Interface v-table
889
890	const VTABLE: C::ICapeArrayBoolean_VTable = C::ICapeArrayBoolean_VTable {
891		get: Some(Self::get),
892		setsize: Some(Self::setsize),
893	};
894
895}
896
897impl CapeArrayBooleanProviderIn for CapeArrayBooleanVec {
898	/// Convert to ICapeArrayBoolean
899	///
900	/// Returns a reference to the ICapeArrayBoolean interface.
901	///
902	/// # Examples
903	///
904	/// ```
905	/// use cobia::*;
906	/// use cobia::prelude::*;
907	/// let arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,true,false]);
908	///	let i_cape_array_boolean=arr.as_cape_array_boolean_in();
909	///	let mut i_cape_array_boolean_ptr=(&i_cape_array_boolean as *const C::ICapeArrayBoolean).cast_mut(); //normally a pointer to the interface is received
910	///	let a = cobia::CapeArrayBooleanIn::new(&mut i_cape_array_boolean_ptr); //CapeArrayBooleanIn from *mut C::ICapeArrayBoolean
911	/// assert_eq!(a.as_bool_vec(), vec![false,true,false]);
912	/// ```
913
914	fn as_cape_array_boolean_in(&self) -> C::ICapeArrayBoolean {
915		C::ICapeArrayBoolean {
916			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
917			vTbl: (&CapeArrayBooleanVec::VTABLE as *const C::ICapeArrayBoolean_VTable).cast_mut(),
918		}
919	}
920}
921
922impl CapeArrayBooleanProviderOut for CapeArrayBooleanVec {
923	/// Convert to ICapeArrayBoolean
924	///
925	/// Returns a mutable reference to the ICapeArrayBoolean interface.
926	///
927	/// # Examples
928	///
929	/// ```
930	/// use cobia::*;
931	/// use cobia::prelude::*;
932	/// let mut arr = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,true,false]);
933	///	let i_cape_array_boolean=arr.as_cape_array_boolean_in();
934	///	let mut i_cape_array_boolean_ptr=(&i_cape_array_boolean as *const C::ICapeArrayBoolean).cast_mut(); //normally a pointer to the interface is received
935	///	let a = cobia::CapeArrayBooleanIn::new(&mut i_cape_array_boolean_ptr); //CapeArrayBooleanIn from *mut C::ICapeArrayBoolean
936	/// assert_eq!(a.as_bool_vec(), vec![false,true,false]);
937	/// ```
938
939	fn as_cape_array_boolean_out(&mut self) -> C::ICapeArrayBoolean {
940		C::ICapeArrayBoolean {
941			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
942			vTbl: (&CapeArrayBooleanVec::VTABLE as *const C::ICapeArrayBoolean_VTable).cast_mut(),
943		}
944	}
945}
946
947impl CapeArrayBooleanVec {
948
949	/// Initialize from bool slice
950	///
951	/// Creates a new CapeArrayTypeImpl from a bool slice.
952	///
953	/// # Arguments
954	///
955	/// * `slice` - A vector or array or slice of values to be converted to a CapeArrayTypeImpl - values are copied
956	///
957	/// # Examples
958	///
959	/// ```
960	/// use cobia::*;
961	/// use cobia::prelude::*;
962	/// let arr = CapeArrayBooleanVec::from_bool_slice(&[true,false,false]);
963	/// assert_eq!(arr.as_vec(), &vec![true as CapeBoolean,false as CapeBoolean,false as CapeBoolean]);
964	/// ```
965
966	pub fn from_bool_slice(slice: &[bool]) -> Self {
967		let mut a = Self::new();
968		let v=a.as_mut_vec();
969		v.reserve(slice.len());
970		for i in 0..slice.len() {
971			v.push(slice[i] as CapeBoolean);
972		}
973		a
974	}
975
976}
977
978impl<T:CapeArrayBooleanProviderIn> PartialEq<T> for CapeArrayBooleanVec {
979	/// Partial equality
980	///
981	/// Checks if the CapeArrayBooleanVec is equal to another CapeArrayBooleanProviderIn.
982	///
983	/// # Arguments
984	///
985	/// * `other` - The other CapeArrayBooleanProviderIn to compare with
986	///
987	/// # Examples
988	///
989	/// ```
990	/// use cobia::*;
991	/// use cobia::prelude::*;
992	/// let arr1 = cobia::CapeArrayBooleanVec::from_bool_slice(&[true,false]);
993	/// let arr2 = cobia::CapeArrayBooleanVec::from_bool_slice(&[true,false]);
994	/// let arr3 = cobia::CapeArrayBooleanVec::from_bool_slice(&[false,false]);
995	/// assert!(arr1 == arr2);
996	/// assert!(arr1 != arr3);
997	/// ```
998	fn eq(&self, other: &T) -> bool {
999		let mut provider=CapeArrayBooleanInFromProvider::from(other);
1000		let other=provider.as_cape_array_boolean_in(); 
1001		self.as_vec() == other.as_slice()
1002	}
1003}
1004
1005
1006/// Vector based CapeArrayEnumerationOut implementation
1007///
1008/// ICapeArrayEnmeration is passed as data container between CAPE-OPEN functions. 
1009/// It is up to the caller to provide the interface, and its implementation. 
1010/// This class provides a default impementation using a `Vec<Element>`.
1011///
1012/// All CAPE-OPEN and COBIA enumeration types are represented as CapeEnumeration
1013///
1014/// # Examples
1015///
1016/// ```
1017/// use cobia::*;
1018///
1019/// fn resize(a: &mut CapeArrayEnumerationOut<cobia::CapePMCServiceType>) {
1020///    a.resize(4).unwrap();
1021/// }
1022/// 
1023/// let mut arr = cobia::CapeArrayEnumerationVec::<cobia::CapePMCServiceType>::from_slice(&[cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1024/// resize(&mut CapeArrayEnumerationOutFromProvider::from(&mut arr).as_cape_array_enumeration_out());
1025/// assert_eq!(arr.size(), 4); 
1026/// ```
1027pub type CapeArrayEnumerationVec<Element> = CapeArrayVec<Element,C::ICapeArrayEnumeration>;
1028
1029type CapeArrayEnumerationVecRaw = CapeArrayVec<C::CapeEnumeration,C::ICapeArrayEnumeration>;
1030
1031impl CapeArrayEnumerationVecRaw {
1032
1033	/// Interface member function
1034
1035	extern "C" fn get_raw(
1036		me: *mut ::std::os::raw::c_void,
1037		data: *mut *mut C::CapeEnumeration,
1038		size: *mut C::CapeSize,
1039	) {
1040		let p = me as *mut Self;
1041		let arr: &mut Self = unsafe { &mut *p };
1042		unsafe {
1043			*data = arr.vec.as_ptr() as *mut C::CapeEnumeration;
1044			*size = arr.vec.len() as C::CapeSize;
1045		}
1046	}
1047
1048	/// Interface member function
1049
1050	extern "C" fn setsize_raw(
1051		me: *mut ::std::os::raw::c_void,
1052		size: C::CapeSize,
1053		data: *mut *mut C::CapeEnumeration,
1054	) -> CapeResult {
1055		let p = me as *mut Self;
1056		let arr: &mut Self = unsafe { &mut *p };
1057		arr.vec.resize(size as usize, 0);
1058		unsafe {
1059			*data = arr.vec.as_ptr() as *mut C::CapeEnumeration;
1060		}
1061		COBIAERR_NOERROR
1062	}
1063
1064	/// Interface v-table
1065
1066	const VTABLE_RAW: C::ICapeArrayEnumeration_VTable = C::ICapeArrayEnumeration_VTable {
1067		get: Some(Self::get_raw),
1068		setsize: Some(Self::setsize_raw),
1069	};
1070
1071}
1072
1073impl<Element:Copy+Clone> CapeArrayEnumerationProviderIn for CapeArrayEnumerationVec<Element> {
1074	/// Convert to ICapeArrayEnumeration
1075	///
1076	/// Returns a reference to the ICapeArrayEnumeration interface.
1077	///
1078	/// # Examples
1079	///
1080	/// ```
1081	/// use cobia::*;
1082	/// use cobia::prelude::*;
1083	/// let arr = cobia::CapeArrayEnumerationVec::from_slice(&[cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1084	///	let i_cape_array_enumeration=arr.as_cape_array_enumeration_in();
1085	///	let mut i_cape_array_enumeration_ptr=(&i_cape_array_enumeration as *const C::ICapeArrayEnumeration).cast_mut(); //normally a pointer to the interface is received
1086	///	let a = cobia::CapeArrayEnumerationIn::<cobia::CapePMCServiceType>::new(&mut i_cape_array_enumeration_ptr); //CapeArrayEnumerationIn from *mut C::ICapeArrayEnumeration
1087	/// assert_eq!(a.as_vec(), vec![cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1088	/// ```
1089
1090	fn as_cape_array_enumeration_in(&self) -> C::ICapeArrayEnumeration {
1091		C::ICapeArrayEnumeration {
1092			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
1093			vTbl: (&CapeArrayEnumerationVecRaw::VTABLE_RAW as *const C::ICapeArrayEnumeration_VTable).cast_mut(),
1094		}
1095	}
1096}
1097
1098impl<Element:Copy+Clone> CapeArrayEnumerationVec<Element> {
1099
1100	/// Resize
1101	///
1102	/// Resize the array to the given size. If the size is larger than the current size, the new elements are set specified value.
1103	///
1104	/// # Arguments
1105	///
1106	/// * `size` - The new size of the array
1107	/// * `value` - The value to set the new elements to
1108	///
1109	/// # Examples
1110	///
1111	/// ```
1112	/// use cobia;
1113	/// use cobia::prelude::*;
1114	/// let mut arr = cobia::CapeArrayEnumerationVec::from_slice(&[cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1115	/// arr.resize(4,cobia::CapePMCServiceType::Inproc32);
1116	/// assert_eq!(arr.as_vec(), &vec![cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64,cobia::CapePMCServiceType::Inproc32,cobia::CapePMCServiceType::Inproc32]);
1117	/// ```
1118	pub fn resize(&mut self, size: usize, value: Element) {
1119		self.vec.resize(size, value);
1120	}
1121
1122}
1123
1124impl<Element:Copy+Clone> CapeArrayEnumerationProviderOut for CapeArrayEnumerationVec<Element> {
1125	/// Convert to ICapeArrayEnumeration
1126	///
1127	/// Returns a mutable reference to the ICapeArrayEnumeration interface.
1128	///
1129	/// # Examples
1130	///
1131	/// ```
1132	/// use cobia::*;
1133	/// use cobia::prelude::*;
1134	/// let mut arr = cobia::CapeArrayEnumerationVec::from_slice(&[cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1135	///	let i_cape_array_enumeration=arr.as_cape_array_enumeration_out();
1136	///	let mut i_cape_array_enumeration_ptr=(&i_cape_array_enumeration as *const C::ICapeArrayEnumeration).cast_mut(); //normally a pointer to the interface is received
1137	///	let a = cobia::CapeArrayEnumerationOut::<cobia::CapePMCServiceType>::new(&mut i_cape_array_enumeration_ptr); //CapeArrayEnumerationOut from *mut C::ICapeArrayEnumeration
1138	/// assert_eq!(a.as_vec(), vec![cobia::CapePMCServiceType::Inproc64,cobia::CapePMCServiceType::COM64]);
1139	/// ```
1140
1141	fn as_cape_array_enumeration_out(&mut self) -> C::ICapeArrayEnumeration {
1142		C::ICapeArrayEnumeration {
1143			me: (self as *const Self).cast_mut() as *mut ::std::os::raw::c_void,
1144			vTbl: (&CapeArrayEnumerationVecRaw::VTABLE_RAW as *const C::ICapeArrayEnumeration_VTable).cast_mut(),
1145		}
1146	}
1147}